@@ -80,6 +80,15 @@ impl Client {
8080 Ok ( Self :: new ( connector, None , endpoint) )
8181 }
8282
83+ /// Create a connection to APNs using the raw PEM-formatted certificate and
84+ /// key, extracted from the provider client certificate you obtain from your
85+ /// [Apple developer account](https://developer.apple.com/account/)
86+ pub fn certificate_parts ( cert_pem : & [ u8 ] , key_pem : & [ u8 ] , endpoint : Endpoint ) -> Result < Client , Error > {
87+ let connector = AlpnConnector :: with_client_cert ( cert_pem, key_pem) ?;
88+
89+ Ok ( Self :: new ( connector, None , endpoint) )
90+ }
91+
8392 /// Create a connection to APNs using system certificates, signing every
8493 /// request with a signature using a private key, key id and team id
8594 /// provisioned from your [Apple developer
@@ -181,7 +190,7 @@ mod tests {
181190 use hyper:: Method ;
182191 use hyper_alpn:: AlpnConnector ;
183192
184- const PRIVATE_KEY : & ' static str = "-----BEGIN PRIVATE KEY-----
193+ const PRIVATE_KEY : & str = "-----BEGIN PRIVATE KEY-----
185194MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8g/n6j9roKvnUkwu
186195lCEIvbDqlUhA5FOzcakkG90E8L+hRANCAATKS2ZExEybUvchRDuKBftotMwVEus3
187196jDwmlD1Gg0yJt1e38djFwsxsfr5q2hv0Rj9fTEqAPr8H7mGm0wKxZ7iQ
@@ -458,4 +467,17 @@ jDwmlD1Gg0yJt1e38djFwsxsfr5q2hv0Rj9fTEqAPr8H7mGm0wKxZ7iQ
458467
459468 assert_eq ! ( payload. to_json_string( ) . unwrap( ) , body_str, ) ;
460469 }
470+
471+ #[ tokio:: test]
472+ /// Try to create a test client using the unencrypted key & cert provided.
473+ /// These are test values that do not work with Apple, but mimic the sort
474+ /// of values you should get from the Apple Developer Console.
475+ async fn test_cert_parts ( ) -> Result < ( ) , Error > {
476+ let key: Vec < u8 > = include_str ! ( "../test_cert/test.key" ) . bytes ( ) . collect ( ) ;
477+ let cert: Vec < u8 > = include_str ! ( "../test_cert/test.crt" ) . bytes ( ) . collect ( ) ;
478+
479+ let c = Client :: certificate_parts ( & cert, & key, Endpoint :: Sandbox ) ?;
480+ assert ! ( c. signer. is_none( ) ) ;
481+ Ok ( ( ) )
482+ }
461483}
0 commit comments