Closed Apollon77 closed 1 month ago
I have no React native environment myself but two independent developers could reproduce this. I asked other developers to try in the quick crypto example app too ...
Further test results point to ieee-p1363 dsaEncoding to be the issue.
but ...
The first argument in both sign
and verify
methods is of type EncodingOptions
presented below:
export type EncodingOptions = {
key?: any;
type?: KType;
encoding?: string;
format?: KFormat;
padding?: number;
cipher?: string;
passphrase?: string | ArrayBuffer;
};
There is no dsaEncoding.
When I tried to pass ieee-p1363
to encoding I got the following error:
fail: ECDSA - error: Unknown encoding: ieee-p1363
So I looked through a source code and I realized that both sign
and verify
use this line
const dsaSigEnc = getDSASignatureEncoding(options);
to get the dsaEncoding from the options argument and then pass it to the internal verify.
Here we can see that this method handles the 'ieee-p1363'
.
function getDSASignatureEncoding(options: any) {
if (typeof options === 'object') {
const { dsaEncoding = 'der' } = options;
if (dsaEncoding === 'der') return DSASigEnc.kSigEncDER;
else if (dsaEncoding === 'ieee-p1363') return DSASigEnc.kSigEncP1363;
throw new Error(`options.dsaEncoding: ${dsaEncoding} not a valid encoding`);
}
return DSASigEnc.kSigEncDER;
}
I added the dsaEncoding
to the type Encoding Options
and run the test again, this is the result:
MEUCIQDAUh2lq+fkAEHHOcJPPIBz4XFAUPUHm8IWeT/SoHYboAIgafWT5PLuVwTw3oj4uRcjr864adyXbgdtmRj4TH2QaNwA
Signature length 72
fail: ECDSA - error: kSignMalformedSignature
I hope this helps.
The issue is with the dsaEncoding option, which doesn't exist in QuickCrypto's sign and verify methods. QuickCrypto's methods internally use a function that expects this option, leading to errors when it's provided. To try and fix the issue, I added dsaEncoding to the EncodingOptions type, but the signature length issue persisted, and the verification still failed with a kSignMalformedSignature error.
I assume the reason is https://github.com/margelo/react-native-quick-crypto/blob/3aaa252f0817e040b18f5970efa3fa5d010c8952/cpp/Sig/MGLSignHostObjects.cpp#L288 … in sign the support for the encoding is not implemented but verify seems to support it.
Sooo if the code which is commented out works then that could be an easy fix and with the example above could be easy verifiable.
Please test this with 0.7.2
and let me know if things are looking good. I used your repro code as a new test in the suite, and it passes. But I didn't look at 64 vs 72 length...
Thank you very much, we will verify in the next days!
What's happening?
We sign data with an sha256 hash and an EC based Private key and the response signature can not be used to verify the same data and is also too long (should be 64 bytes but is72 bytes)
Reproducible Code
Relevant log output
Device
Simulator and ios
QuickCrypto Version
0.7.1
Can you reproduce this issue in the QuickCrypto Example app?
I didn't try (⚠️ your issue might get ignored & closed if you don't try this)
Additional information