diff --git a/circuits/tests/disclose/vc_and_disclose.test.ts b/circuits/tests/disclose/vc_and_disclose.test.ts index 2fa8e37f4..7c362c2f9 100644 --- a/circuits/tests/disclose/vc_and_disclose.test.ts +++ b/circuits/tests/disclose/vc_and_disclose.test.ts @@ -21,6 +21,7 @@ import { getAttributeFromUnpackedReveal, } from '../../../common/src/utils/circuits/formatOutputs'; import { generateCommitment } from '../../../common/src/utils/passports/passport'; +import { hashEndpointWithScope } from '../../../common/src/utils/scope'; describe('Disclose', function () { this.timeout(0); @@ -42,7 +43,9 @@ describe('Disclose', function () { const user_identifier = crypto.randomUUID(); const selector_dg1 = Array(88).fill('1'); const selector_older_than = '1'; - const scope = '@coboyApp'; + const endpoint = 'https://example.com'; + const scope = 'scope'; + const fullScope = hashEndpointWithScope(endpoint, scope); const attestation_id = PASSPORT_ATTESTATION_ID; // compute the commitment and insert it in the tree @@ -78,7 +81,7 @@ describe('Disclose', function () { secret, PASSPORT_ATTESTATION_ID, passportData, - scope, + fullScope, selector_dg1, selector_older_than, tree, @@ -165,7 +168,7 @@ describe('Disclose', function () { } const forbidden_countries_list_packed = await circuit.getOutput(w, [ - 'forbidden_countries_list_packed[1]', + 'forbidden_countries_list_packed[4]', ]); const forbidden_countries_list_unpacked = formatAndUnpackForbiddenCountriesList( forbidden_countries_list_packed @@ -364,7 +367,7 @@ describe('Disclose', function () { secret, PASSPORT_ATTESTATION_ID, passportData, - scope, + fullScope, Array(88).fill('0'), // selector_dg1 selector_older_than, tree, diff --git a/circuits/tests/dsc/test_cases.ts b/circuits/tests/dsc/test_cases.ts index 4419794bb..3fea4a53c 100644 --- a/circuits/tests/dsc/test_cases.ts +++ b/circuits/tests/dsc/test_cases.ts @@ -52,7 +52,4 @@ export const fullSigAlgs = [ { sigAlg: 'ecdsa', hashFunction: 'sha384', domainParameter: 'secp384r1', keyLength: '384' }, { sigAlg: 'ecdsa', hashFunction: 'sha256', domainParameter: 'secp521r1', keyLength: '521' }, { sigAlg: 'ecdsa', hashFunction: 'sha512', domainParameter: 'secp521r1', keyLength: '521' }, - // this last one does not pass right now but only because of the issue - // of the function that selects the position of the pubkey in ecdsa certs - // sometimes being off by one ]; diff --git a/circuits/tests/ofac/ofac.test.ts b/circuits/tests/ofac/ofac.test.ts index d4ed857fa..83dafc2e1 100644 --- a/circuits/tests/ofac/ofac.test.ts +++ b/circuits/tests/ofac/ofac.test.ts @@ -237,7 +237,7 @@ describe('OFAC - Name and YOB match', function () { }); }); -describe.only('OFAC - SMT Security Tests', function () { +describe('OFAC - SMT Security Tests', function () { this.timeout(0); let passNoAndNationality_smt = new SMT(poseidon2, true); let circuit: any; diff --git a/common/src/utils/certificate_parsing/parseCertificateSimple.ts b/common/src/utils/certificate_parsing/parseCertificateSimple.ts index 7426a0fe7..77cc4bb21 100644 --- a/common/src/utils/certificate_parsing/parseCertificateSimple.ts +++ b/common/src/utils/certificate_parsing/parseCertificateSimple.ts @@ -231,8 +231,15 @@ export function getParamsECDSA(cert: Certificate): PublicKeyDetailsECDSA { const x_point = key.getPublic().getX().toString('hex'); const y_point = key.getPublic().getY().toString('hex'); - x = x_point.length % 2 === 0 ? x_point : '0' + x_point; - y = y_point.length % 2 === 0 ? y_point : '0' + y_point; + // For 521 bit curves, pad to expected length of 132 hex chars (66 bytes) + if (curveName === 'secp521r1' || curveName === 'brainpoolP521r1') { + x = x_point.padStart(132, '0'); + y = y_point.padStart(132, '0'); + } else { + // For other curves, ensure even length + x = x_point.length % 2 === 0 ? x_point : '0' + x_point; + y = y_point.length % 2 === 0 ? y_point : '0' + y_point; + } } return { curve: curveName, params: curveParams, bits: bits, x: x, y: y }; } catch (error) { diff --git a/common/src/utils/csca.ts b/common/src/utils/csca.ts index 57a694c31..005e51b1d 100644 --- a/common/src/utils/csca.ts +++ b/common/src/utils/csca.ts @@ -1,34 +1,25 @@ import { SKI_PEM, SKI_PEM_DEV } from '../constants/skiPem'; -export function findStartIndexEC(modulus: string, messagePadded: number[]): [number, number] { - const modulusNumArray = []; - for (let i = 0; i < modulus.length; i += 2) { - modulusNumArray.push(parseInt(modulus.slice(i, i + 2), 16)); +export function findStartIndexEC(point: string, messagePadded: number[]): [number, number] { + const pointNumArray = []; + for (let i = 0; i < point.length; i += 2) { + pointNumArray.push(parseInt(point.slice(i, i + 2), 16)); } let startIndex = -1; - // For ECDSA, look for the ASN.1 tag for EC Point (0x04) - const isECPoint = modulusNumArray[0] === 0x04; - for (let i = 0; i < messagePadded.length - modulusNumArray.length + 1; i++) { - let found = true; - for (let j = 0; j < modulusNumArray.length; j++) { - if (messagePadded[i + j] !== modulusNumArray[j]) { - found = false; - break; - } - if (found && (j === modulusNumArray.length - 1 || (isECPoint && j > 0))) { - startIndex = i; - break; - } + for (let i = 0; i < messagePadded.length - pointNumArray.length + 1; i++) { + const isMatch = pointNumArray.every((byte, j) => messagePadded[i + j] === byte); + if (isMatch) { + startIndex = i; + break; } - if (startIndex !== -1) break; } if (startIndex === -1) { throw new Error('DSC Pubkey not found in CSCA certificate'); } - return [startIndex, modulusNumArray.length]; + return [startIndex, pointNumArray.length]; } // @returns [startIndex, length] where startIndex is the index of the first byte of the modulus in the message and length is the length of the modulus in bytes diff --git a/common/src/utils/passports/passport.ts b/common/src/utils/passports/passport.ts index bb8a8b0db..8b4c813dc 100644 --- a/common/src/utils/passports/passport.ts +++ b/common/src/utils/passports/passport.ts @@ -219,9 +219,7 @@ export function findStartPubKeyIndex( const [x_index, x_totalLength] = findStartIndexEC(x, rawCert); const [y_index, y_totalLength] = findStartIndexEC(y, rawCert); - //zero between x and y - const pad_between_x_y = y_index - x_index - x_totalLength; - return [x_index, x_totalLength + pad_between_x_y + y_totalLength]; + return [x_index, x_totalLength + y_totalLength]; } else { // Splits to 525 words of 8 bits each const { modulus } = publicKeyDetails as PublicKeyDetailsRSA;