-
Notifications
You must be signed in to change notification settings - Fork 198
fix(passport-signature): guard ECDSA bruteforce returns and add safe fallbacks #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,8 +111,6 @@ export function parsePassportData( | |
| passportData.signedAttr | ||
| ); | ||
|
|
||
| const brutForcedPublicKeyDetails = brutforceSignatureAlgorithm(passportData); | ||
|
|
||
| let parsedDsc = null; | ||
| let dscSignatureAlgorithmBits = 0; | ||
|
|
||
|
|
@@ -125,6 +123,20 @@ export function parsePassportData( | |
| dscMetaData = parseDscCertificateData(parsedDsc, skiPem); | ||
| } | ||
|
|
||
| // Determine signature algorithm/hash with fallback if brute-force fails | ||
| const brutForcedPublicKeyDetails = brutforceSignatureAlgorithm(passportData); | ||
| let resolvedSignatureAlgorithm = brutForcedPublicKeyDetails?.signatureAlgorithm as string | undefined; | ||
| let resolvedSignedAttrHashFunction = brutForcedPublicKeyDetails?.hashAlgorithm as string | undefined; | ||
| let resolvedSaltLength = (brutForcedPublicKeyDetails?.saltLength as number | undefined) ?? undefined; | ||
|
|
||
| if (!resolvedSignatureAlgorithm || !resolvedSignedAttrHashFunction) { | ||
| if (parsedDsc) { | ||
| resolvedSignatureAlgorithm = parsedDsc.signatureAlgorithm; | ||
| resolvedSignedAttrHashFunction = parsedDsc.hashAlgorithm; | ||
| resolvedSaltLength = 0; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| dataGroups: | ||
| passportData.dgPresents | ||
|
|
@@ -141,9 +153,9 @@ export function parsePassportData( | |
| eContentHashFunction, | ||
| eContentHashOffset, | ||
| signedAttrSize: passportData.signedAttr?.length || 0, | ||
| signedAttrHashFunction: brutForcedPublicKeyDetails.hashAlgorithm, | ||
| signatureAlgorithm: brutForcedPublicKeyDetails.signatureAlgorithm, | ||
| saltLength: brutForcedPublicKeyDetails.saltLength, | ||
| signedAttrHashFunction: resolvedSignedAttrHashFunction, | ||
| signatureAlgorithm: resolvedSignatureAlgorithm, | ||
| saltLength: resolvedSaltLength || 0, | ||
|
Comment on lines
+156
to
+158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add fallbacks for While Apply this diff to add safe fallbacks: signedAttrSize: passportData.signedAttr?.length || 0,
- signedAttrHashFunction: resolvedSignedAttrHashFunction,
- signatureAlgorithm: resolvedSignatureAlgorithm,
+ signedAttrHashFunction: resolvedSignedAttrHashFunction || 'unknown',
+ signatureAlgorithm: resolvedSignatureAlgorithm || 'unknown',
saltLength: resolvedSaltLength || 0,This aligns with the existing pattern of using
🤖 Prompt for AI Agents |
||
| curveOrExponent: parsedDsc ? getCurveOrExponent(parsedDsc) : 'unknown', | ||
| signatureAlgorithmBits: dscSignatureAlgorithmBits, | ||
| countryCode: passportData.mrz ? getCountryCodeFromMrz(passportData.mrz) : 'unknown', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against undefined
cscaSaltLengthin return object.The fallback logic doesn't cover all cases. If both conditions fail (no valid
detailsand nocscaParsed),cscaSaltLengthremainsundefined, but the interfaceDscCertificateMetaDataexpects it to be anumber(line 13). This creates a type safety issue.Apply this diff to ensure a safe default:
if (details && details.hashAlgorithm && details.signatureAlgorithm) { cscaHashAlgorithm = details.hashAlgorithm; cscaSignatureAlgorithm = details.signatureAlgorithm; cscaSaltLength = details.saltLength; } else if (cscaParsed) { cscaHashAlgorithm = cscaParsed.hashAlgorithm; cscaSignatureAlgorithm = cscaParsed.signatureAlgorithm; cscaSaltLength = 0; + } else { + // Fallback to safe defaults if no valid data is available + cscaSaltLength = 0; }Alternatively, update the interface to allow
undefinedvalues if that's the intended behavior.📝 Committable suggestion
🤖 Prompt for AI Agents