File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ foreach ($responses as $response) {
110110}
111111```
112112
113- Using Certificate (.pem). Only the initilization differs from JWT code (above). Remember to include the rest of the code by yourself.
113+ Using Certificate (.pem or .p12 ). Only the initilization differs from JWT code (above). Remember to include the rest of the code by yourself.
114114
115115``` php
116116<?php
Original file line number Diff line number Diff line change @@ -76,6 +76,16 @@ public static function create(array $options): Certificate
7676 */
7777 public function authenticateClient (Request $ request )
7878 {
79+ # OpenSSL (versions 0.9.3 and later) also support "P12" for PKCS#12-encoded files.
80+ # see https://curl.se/libcurl/c/CURLOPT_SSLCERTTYPE.html
81+ $ ext = pathinfo ($ this ->certificatePath , \PATHINFO_EXTENSION );
82+ if (preg_match ('#^(der|p12)$#i ' , $ ext )) {
83+ $ request ->addOptions (
84+ [
85+ CURLOPT_SSLCERTTYPE => strtoupper ($ ext )
86+ ]
87+ );
88+ }
7989 $ request ->addOptions (
8090 [
8191 CURLOPT_SSLCERT => $ this ->certificatePath ,
Original file line number Diff line number Diff line change @@ -39,6 +39,27 @@ public function testAuthenticatingClient()
3939 $ this ->assertSame ($ request ->getOptions ()[CURLOPT_SSLCERTPASSWD ], $ options ['certificate_secret ' ]);
4040 }
4141
42+ public function testAuthenticatingClientP12 ()
43+ {
44+ $ certFile = tempnam (sys_get_temp_dir (), "mock_test_cert " );
45+ rename ($ certFile , $ certFile .= '.p12 ' );
46+ try {
47+ $ options = [
48+ 'certificate_path ' => $ certFile ,
49+ 'certificate_secret ' => 'secret ' ,
50+ 'app_bundle_id ' => 'com.apple.test ' ,
51+ ];
52+ $ authProvider = Certificate::create ($ options );
53+
54+ $ request = $ this ->createRequest ();
55+ $ authProvider ->authenticateClient ($ request );
56+
57+ $ this ->assertSame ($ request ->getOptions ()[CURLOPT_SSLCERTTYPE ], 'P12 ' );
58+ } finally {
59+ @\unlink ($ certFile );
60+ }
61+ }
62+
4263 public function testVoipApnsTopic ()
4364 {
4465 $ options = $ this ->getOptions ();
You can’t perform that action at this time.
0 commit comments