Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions app/src/stores/protocolStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useProtocolStore = create<ProtocolState>((set, get) => ({
}
},
fetch_circuits_dns_mapping: async (environment: 'prod' | 'stg') => {
const url = `${environment === 'prod' ? API_URL : API_URL_STAGING}/circuit-dns-mapping`;
const url = `${environment === 'prod' ? API_URL : API_URL_STAGING}/circuit-dns-mapping-gcp`;
try {
const response = await fetch(url);
if (!response.ok) {
Expand Down Expand Up @@ -255,7 +255,7 @@ export const useProtocolStore = create<ProtocolState>((set, get) => ({
}
},
fetch_circuits_dns_mapping: async (environment: 'prod' | 'stg') => {
const url = `${environment === 'prod' ? API_URL : API_URL_STAGING}/circuit-dns-mapping`;
const url = `${environment === 'prod' ? API_URL : API_URL_STAGING}/circuit-dns-mapping-gcp`;
try {
const response = await fetch(url);
if (!response.ok) {
Expand Down
34 changes: 25 additions & 9 deletions app/src/utils/proving/provingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
getCircuitNameFromPassportData,
getSolidityPackedUserContextData,
} from '@selfxyz/common/utils';
import { getPublicKey, verifyAttestation } from '@selfxyz/common/utils/attest';
import {
checkPCR0Mapping,
validatePKIToken,
} from '@selfxyz/common/utils/attest';
import {
clientKey,
clientPublicKeyHex,
Expand Down Expand Up @@ -336,9 +339,25 @@ export const useProvingStore = create<ProvingState>((set, get) => {
trackEvent(ProofEvents.ATTESTATION_RECEIVED);
const attestationData = result.result.attestation;
set({ attestation: attestationData });
const attestationToken =
Buffer.from(attestationData).toString('utf-8');

const { userPubkey, serverPubkey, imageHash, verified } =
validatePKIToken(attestationToken, __DEV__);

const pcr0Mapping = await checkPCR0Mapping(imageHash);

if (!pcr0Mapping) {
console.error('PCR0 mapping not found');
actor!.send({ type: 'CONNECT_ERROR' });
return;
}

const serverPubkey = getPublicKey(attestationData);
const verified = await verifyAttestation(attestationData);
if (clientPublicKeyHex !== userPubkey.toString('hex')) {
console.error('User public key does not match');
actor!.send({ type: 'CONNECT_ERROR' });
return;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Key Format Mismatch Blocks TEE Connections

The public key comparison at line 559 can incorrectly fail because clientPublicKeyHex is in a compressed format, while userPubkey from the attestation token may be uncompressed. This format mismatch prevents successful TEE connections, even when the keys are cryptographically equivalent.

Fix in Cursor Fix in Web


if (!verified) {
console.error('Attestation verification failed');
Expand All @@ -348,11 +367,11 @@ export const useProvingStore = create<ProvingState>((set, get) => {

trackEvent(ProofEvents.ATTESTATION_VERIFIED);

const serverKey = ec.keyFromPublic(serverPubkey as string, 'hex');
const serverKey = ec.keyFromPublic(serverPubkey, 'hex');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Public Key Buffer Parsing Error

The ec.keyFromPublic() method receives serverPubkey as a Buffer from validatePKIToken, but expects a hex string when the 'hex' encoding is specified. This type mismatch prevents elliptic curve key parsing.

Fix in Cursor Fix in Web

const derivedKey = clientKey.derive(serverKey.getPublic());

set({
serverPublicKey: serverPubkey,
serverPublicKey: serverKey.getPublic(true, 'hex'),
sharedKey: Buffer.from(derivedKey.toArray('be', 32)),
});
trackEvent(ProofEvents.SHARED_KEY_DERIVED);
Expand Down Expand Up @@ -541,10 +560,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
method: 'openpassport_hello',
id: 1,
params: {
user_pubkey: [
4,
...Array.from(Buffer.from(clientPublicKeyHex, 'hex')),
],
user_pubkey: [...Array.from(Buffer.from(clientPublicKeyHex, 'hex'))],
uuid: connectionUuid,
},
};
Expand Down
Loading
Loading