I described the error below in details.
I'm sure the Server administrator can fix this issue in 1~2 hours.
I'll pay $100 for this project.
[login to view URL]
1. I generated 2 csr files with command.
openssl genrsa -out ~/certs/[login to view URL] 4096
openssl req -new -sha256 -key ~/certs/[login to view URL] -out ~/certs/[login to view URL]
openssl genrsa -out ~/certs/[login to view URL] 4096
openssl req -new -sha256 -key ~/certs/[login to view URL] -out ~/certs/[login to view URL]
2. I got 2 swish certificates file from swish portal.
[login to view URL]
[login to view URL]
I used one for singing and another for TLS communication between web system and swish platform.
3. I created p12 file from the reference.
[login to view URL]
openssl pkcs12 -export -out [login to view URL] \
-in [login to view URL] -inkey [login to view URL]
4. I used the following code.
[login to view URL]
<?php
$date = new DateTime();
$dateString = $date->format('Y-m-d\TH:i:s\Z');
$payload = [
"payoutInstructionUUID" => "E4D773858AF5459B96ABCA4B9DBFF94E",
"payerPaymentReference" => "Boka",
"payerAlias" => "**********",
"payeeAlias" => "**********",
"payeeSSN" => "***********",
"amount" => "1",
"currency" => "SEK",
"payoutType" => "PAYOUT",
"instructionDate" => $dateString,
"message" => "Message to the recipient.",
"signingCertificateSerialNumber" => "770D93E07DAD96B6A4FBD45E07E1B3D6"
];
$pkey = openssl_pkey_get_private(file_get_contents('[login to view URL]'));
$payloadHash = hash('sha512', json_encode($payload));
$signature = openssl_sign($payloadHash, $signature, $pkey, OPENSSL_ALGO_SHA512) ? base64_encode($signature) : null;
$request = [
"payload" => $payload,
"callbackUrl" => "[login to view URL]",
"signature" => $signature
];
print_r($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '[login to view URL]');
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSLCERT, '[login to view URL]');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'haruka');
// curl_setopt($ch, CURLOPT_SSLKEY, '[login to view URL]');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// curl_setopt($ch, CURLOPT_CAINFO, '[login to view URL]');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
$f = tmpfile();
curl_setopt($ch, CURLOPT_STDERR, $f);
$results = curl_exec($ch);
fseek($f, 0);
echo "Verbose information:\n<pre>", fread($f, 32 * 1024), "</pre>\n";
fclose($f);
$info =curl_errno($ch)>0 ? array("curl_error_".curl_errno($ch)=>curl_error($ch)) : curl_getinfo($ch);
print_r($info);
curl_close($ch);
?>
5. I got the following error.
* Trying [login to view URL]:443...
* Connected to [login to view URL] ([login to view URL]) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=SE; L=Stockholm; O=GetSwish AB; CN=[login to view URL]
* start date: Mar 3 00:00:00 2023 GMT
* expire date: Apr 2 23:59:59 2024 GMT
* subjectAltName: host "[login to view URL]" matched cert's "[login to view URL]"
* issuer: C=US; O=DigiCert Inc; OU=[login to view URL]; CN=GeoTrust RSA CA 2018
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /swish-cpcapi/api/v1/payouts HTTP/1.1
Host: [login to view URL]
Accept: */*
Content-Type:application/json
Content-Length: 1146
* OpenSSL SSL_read: Connection reset by peer, errno 104
* Closing connection 0
Array ( [curl_error_56] => OpenSSL SSL_read: Connection reset by peer, errno 104 )