33namespace CyberSource \Utilities \PGP \BatchUpload ;
44
55use CyberSource \ApiException ;
6+ use CyberSource \Utilities \MultipartHelpers \MultipartHelper ;
67
78class MutualAuthUploadUtility
89{
@@ -95,29 +96,24 @@ private static function doMultipartUpload(
9596 $ verify_ssl ,
9697 $ logger
9798 ){
98- $ boundary = '-------------------------- ' . microtime (true );
99- $ eol = "\r\n" ;
100- // works without this header too: Content-Transfer-Encoding
101- $ multipartBody =
102- "-- $ boundary$ eol " .
103- "Content-Disposition: form-data; name= \"file \"; filename= \"$ fileName \"$ eol " .
104- "Content-Type: application/octet-stream $ eol " .
105- "Content-Transfer-Encoding: binary $ eol$ eol " .
106- $ encryptedPgpBytes . $ eol .
107- "-- $ boundary-- $ eol " ;
108-
99+
100+ $ boundary = uniqid ();
101+ $ formParams = [
102+ $ fileName => $ encryptedPgpBytes
103+ ];
104+ $ multipartBody = MultipartHelper::build_data_files ($ boundary , $ formParams );
109105 $ correlationId = self ::generateCorrelationId ();
110106
111107 $ ch = curl_init ();
112108 curl_setopt ($ ch , CURLOPT_URL , $ endpointUrl );
113109 curl_setopt ($ ch , CURLOPT_POST , 1 );
114110 curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ multipartBody );
115111 curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
116- "Content-Type: multipart/form-data; boundary= $ boundary " ,
112+ "Content-Type: multipart/form-data; boundary=------------- $ boundary " ,
117113 "v-c-correlation-id: $ correlationId "
118114 ]);
119115
120- // mTLS: handle both PKCS#12 and cert and key
116+ //mTLS: handle both PKCS#12 and cert and key
121117 if ($ tlsConfig ['type ' ] === 'p12 ' ) {
122118 curl_setopt ($ ch , CURLOPT_SSLCERT , $ tlsConfig ['cert ' ]);
123119 curl_setopt ($ ch , CURLOPT_SSLCERTTYPE , 'P12 ' );
@@ -132,7 +128,16 @@ private static function doMultipartUpload(
132128
133129 // CA cert for server validation
134130 if ($ caCertPath ) {
135- curl_setopt ($ ch , CURLOPT_CAINFO , $ caCertPath );
131+ print_r ("Using custom CA cert path: $ caCertPath \n" );
132+ $ defaultCaCertPath = __DIR__ . '/../../../ssl/cacert.pem ' ;
133+ $ defaultCa = file_exists ($ defaultCaCertPath ) ? file_get_contents ($ defaultCaCertPath ) : '' ;
134+ $ userCa = file_get_contents ($ caCertPath );
135+ $ combinedCa = rtrim ($ defaultCa , "\r\n" ) . "\n" . ltrim ($ userCa , "\r\n" );
136+ curl_setopt ($ ch , CURLOPT_CAINFO_BLOB , $ combinedCa );
137+ }else {
138+ $ defaultCaCertPath = __DIR__ . '/../../../ssl/cacert.pem ' ;
139+ $ defaultCa = file_exists ($ defaultCaCertPath ) ? file_get_contents ($ defaultCaCertPath ) : '' ;
140+ curl_setopt ($ ch , CURLOPT_CAINFO_BLOB , $ defaultCa );
136141 }
137142
138143 // SSL verification
0 commit comments