@@ -12,10 +12,10 @@ pub mod jobs;
12
12
pub mod notifications;
13
13
pub mod rustc_commits;
14
14
15
- const CERT_URL : & str = "https://s3. amazonaws.com/rds-downloads/rds-ca-2019-root .pem" ;
15
+ const CERT_URL : & str = "https://truststore.pki.rds. amazonaws.com/global/global-bundle .pem" ;
16
16
17
17
lazy_static:: lazy_static! {
18
- static ref CERTIFICATE_PEM : Vec <u8 > = {
18
+ static ref CERTIFICATE_PEMS : Vec <u8 > = {
19
19
let client = reqwest:: blocking:: Client :: new( ) ;
20
20
let resp = client
21
21
. get( CERT_URL )
@@ -94,12 +94,11 @@ impl ClientPool {
94
94
async fn make_client ( ) -> anyhow:: Result < tokio_postgres:: Client > {
95
95
let db_url = std:: env:: var ( "DATABASE_URL" ) . expect ( "needs DATABASE_URL" ) ;
96
96
if db_url. contains ( "rds.amazonaws.com" ) {
97
- let cert = & CERTIFICATE_PEM [ ..] ;
98
- let cert = Certificate :: from_pem ( & cert) . context ( "made certificate" ) ?;
99
- let connector = TlsConnector :: builder ( )
100
- . add_root_certificate ( cert)
101
- . build ( )
102
- . context ( "built TlsConnector" ) ?;
97
+ let mut builder = TlsConnector :: builder ( ) ;
98
+ for cert in make_certificates ( ) {
99
+ builder. add_root_certificate ( cert) ;
100
+ }
101
+ let connector = builder. build ( ) . context ( "built TlsConnector" ) ?;
103
102
let connector = MakeTlsConnector :: new ( connector) ;
104
103
105
104
let ( db_client, connection) = match tokio_postgres:: connect ( & db_url, connector) . await {
@@ -134,6 +133,24 @@ async fn make_client() -> anyhow::Result<tokio_postgres::Client> {
134
133
}
135
134
}
136
135
136
+ fn make_certificates ( ) -> Vec < Certificate > {
137
+ use x509_cert:: der:: pem:: LineEnding ;
138
+ use x509_cert:: der:: EncodePem ;
139
+
140
+ let certs = x509_cert:: Certificate :: load_pem_chain ( & CERTIFICATE_PEMS [ ..] ) . unwrap ( ) ;
141
+ certs
142
+ . into_iter ( )
143
+ . map ( |cert| Certificate :: from_pem ( cert. to_pem ( LineEnding :: LF ) . unwrap ( ) . as_bytes ( ) ) . unwrap ( ) )
144
+ . collect ( )
145
+ }
146
+
147
+ // Makes sure we successfully parse the RDS certificates and load them into native-tls compatible
148
+ // format.
149
+ #[ test]
150
+ fn cert ( ) {
151
+ make_certificates ( ) ;
152
+ }
153
+
137
154
pub async fn run_migrations ( client : & DbClient ) -> anyhow:: Result < ( ) > {
138
155
client
139
156
. execute (
0 commit comments