Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions circuits/tests/disclose/vc_and_disclose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -78,7 +81,7 @@ describe('Disclose', function () {
secret,
PASSPORT_ATTESTATION_ID,
passportData,
scope,
fullScope,
selector_dg1,
selector_older_than,
tree,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -364,7 +367,7 @@ describe('Disclose', function () {
secret,
PASSPORT_ATTESTATION_ID,
passportData,
scope,
fullScope,
Array(88).fill('0'), // selector_dg1
selector_older_than,
tree,
Expand Down
3 changes: 0 additions & 3 deletions circuits/tests/dsc/test_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
2 changes: 1 addition & 1 deletion circuits/tests/ofac/ofac.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions common/src/utils/certificate_parsing/parseCertificateSimple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 10 additions & 19 deletions common/src/utils/csca.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions common/src/utils/passports/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down