Closed BlackEagleXV closed 1 year ago
@BlackEagleXV : Try adding this prior to the call to sign
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->setHash("sha256");
With that, it worked for me. By default, the signature mode would be CRYPT_RSA_SIGNATURE_PSS
and the hash function would be sha1
.
Hi @uherberg Thank you that did the trick, but I found another bug also in the SDK code from you:
foreach ($signatureParams as $signatureParam) {
switch ($signatureParam) {
case '@method':
$signatureBase .= '"@method": ' . $method;
break;
case '@path':
$signatureBase .= '"@path": ' . $this->getPath($endpoint);
break;
case '@authority':
$signatureBase .= '"@authority": ' . $this->getAuthority($endpoint);
break;
case "@target-uri":
$signatureBase .= '"@authority": ' . $endpoint;
break;
case "@scheme":
$signatureBase .= '"@scheme": ' . $this->getScheme($endpoint);
break;
case "@query":
$signatureBase .= '"@query": ' . $this->getQuery($endpoint);
break;
default:
$found = false;
for ($i = 0; $i < count($headers) && $found === false; ++$i) {
$lowerCaseHeader = mb_strtolower($headers[$i]);
if (mb_strpos($lowerCaseHeader, $signatureParam) === 0) {
$signatureBase .= '"' . $signatureParam . '": ' . mb_substr($headers[$i], mb_strlen($signatureParam) + 2);
$found = true;
}
}
}
//Adding a linebreak between params
$signatureBase .= "\n"; // BUG: this happens also in default of switch if header is not found, we don't want that
}
This will add a \n for every missing header, meaning it is not working for a get request. You maybe check that in the PHP SDK?
@BlackEagleXV You are right :-) Someone else just pointed this out to me a couple of days ago, and I fixed it in: https://github.com/eBay/digital-signature-php-sdk/pull/20/files
@BlackEagleXV PS: Make sure to only call EBYGetKeyPair()
when you need a new keypair (likely only the very first time you onboard a new app). You shouldn't call this method for every API call. It's not clear from the above code when you call it.
@uherberg Thank you for pointing out, but it was just there for clarification how I got the key pair. It is not called on every API call.
Hi. I have modified the code a bit, because I didn't like the autoloader/json stuff. Unfortunately, it doesn't work. I will add the code more or less, the missing parts can be hardcoded for testing. The most different part is that the headers are processed in raw format and not in array format.
Also it is working with the old version of phpseclib which is working without autoloader as well, so I'm using RSA which should be supported.
Caller:
Signature.php
SignatureConfig.php
SignatureService.php
This creates the following signature base:
which is then signed with my private key, but it is not working. Always get 215120, Signature validation failed [longMessage], Signature validation failed to fulfill the request.
How do I get this fixed? I tried two times with different keys.