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
14 changes: 4 additions & 10 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@noble/curves": "^2.0.1",
"@noble/hashes": "^2.0.1",
"bwip-js": "^4.5.1",
"dosipas-ts": "^2.0.0",
"dosipas-ts": "^3.0.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"zxing-wasm": "^2.2.1"
Expand Down
24 changes: 12 additions & 12 deletions website/src/components/HexViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ExtractedSignedData } from 'dosipas-ts';
import type { ExtractedTicket } from 'dosipas-ts';

interface Props {
hex: string;
signedData: ExtractedSignedData | null;
signedData: ExtractedTicket | null;
}

interface Region {
Expand Down Expand Up @@ -34,44 +34,44 @@ export default function HexViewer({ hex, signedData }: Props) {
const regions: Region[] = [];

if (signedData) {
const l1Idx = findSubarray(bytes, signedData.level1DataBytes);
const l1Idx = findSubarray(bytes, signedData.level1.signedBytes);
if (l1Idx >= 0) {
regions.push({
start: l1Idx,
end: l1Idx + signedData.level1DataBytes.length,
end: l1Idx + signedData.level1.signedBytes.length,
label: 'L1 data',
color: 'bg-blue-100 text-blue-900',
});
}

const l2Idx = findSubarray(bytes, signedData.level2SignedBytes);
const l2Idx = findSubarray(bytes, signedData.level2.signedBytes);
if (l2Idx >= 0) {
regions.push({
start: l2Idx,
end: l2Idx + signedData.level2SignedBytes.length,
end: l2Idx + signedData.level2.signedBytes.length,
label: 'L2 signed',
color: 'bg-green-100 text-green-900',
});
}

if (signedData.security.level1Signature) {
const sigIdx = findSubarray(bytes, signedData.security.level1Signature);
if (signedData.level1.signature) {
const sigIdx = findSubarray(bytes, signedData.level1.signature);
if (sigIdx >= 0) {
regions.push({
start: sigIdx,
end: sigIdx + signedData.security.level1Signature.length,
end: sigIdx + signedData.level1.signature.length,
label: 'L1 sig',
color: 'bg-orange-100 text-orange-900',
});
}
}

if (signedData.security.level2Signature) {
const sigIdx = findSubarray(bytes, signedData.security.level2Signature);
if (signedData.level2.signature) {
const sigIdx = findSubarray(bytes, signedData.level2.signature);
if (sigIdx >= 0) {
regions.push({
start: sigIdx,
end: sigIdx + signedData.security.level2Signature.length,
end: sigIdx + signedData.level2.signature.length,
label: 'L2 sig',
color: 'bg-purple-100 text-purple-900',
});
Expand Down
10 changes: 5 additions & 5 deletions website/src/hooks/useTicketDecode.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useState, useEffect, useRef } from 'react';
import { decodeTicket, verifySignatures, extractSignedData } from 'dosipas-ts';
import { decodeTicket, verifySignatures, extractTicket } from 'dosipas-ts';
import type {
UicBarcodeTicket,
SignatureVerificationResult,
ExtractedSignedData,
ExtractedTicket,
} from 'dosipas-ts';
import { createKeyProvider } from '../lib/keys';

export interface DecodeResult {
ticket: UicBarcodeTicket | null;
signatures: SignatureVerificationResult | null;
signedData: ExtractedSignedData | null;
signedData: ExtractedTicket | null;
error: string | null;
loading: boolean;
}
Expand All @@ -23,7 +23,7 @@ export function useTicketDecode(
): DecodeResult {
const [ticket, setTicket] = useState<UicBarcodeTicket | null>(null);
const [signatures, setSignatures] = useState<SignatureVerificationResult | null>(null);
const [signedData, setSignedData] = useState<ExtractedSignedData | null>(null);
const [signedData, setSignedData] = useState<ExtractedTicket | null>(null);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const debounceRef = useRef<ReturnType<typeof setTimeout>>(undefined);
Expand Down Expand Up @@ -54,7 +54,7 @@ export function useTicketDecode(
const bytes = new Uint8Array(
clean.match(/.{1,2}/g)!.map((b) => parseInt(b, 16)),
);
const extracted = extractSignedData(bytes);
const extracted = extractTicket(bytes);
setSignedData(extracted);
} catch {
setSignedData(null);
Expand Down
16 changes: 8 additions & 8 deletions website/src/lib/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ export async function createKeyProvider(
): Promise<Level1KeyProvider> {
const xml = await loadKeysXml();
return {
async getPublicKey(securityProvider, keyId) {
async getPublicKey(key) {
// Issuers identified by an IA5 string are not in the UIC registry,
// which is keyed by numeric RICS codes.
if (trustCarJauneKey && securityProvider.ia5 === 'IWN8' && keyId === 1) {
if (trustCarJauneKey && key.securityProviderIA5 === 'IWN8' && key.keyId === 1) {
return getCarJauneKey();
}

const issuerCode = securityProvider.num ?? 0;
const issuerCode = key.securityProviderNum ?? 0;
const keyId = key.keyId ?? 0;
// No algorithms supplied for these two: their barcodes carry their own
// OIDs, and a configured value that disagreed would be a hard error.
if (trustFipsKey && issuerCode === 9999 && keyId === 0) {
Expand All @@ -98,12 +99,11 @@ export async function createKeyProvider(
return { publicKey: getSysdevrunPublicKey() };
}

const key = findKeyInXml(xml, issuerCode, keyId);
if (!key) {
const issuer = securityProvider.ia5 ?? issuerCode;
throw new Error(`Key not found: issuer=${issuer}, keyId=${keyId}`);
const material = findKeyInXml(xml, issuerCode, keyId);
if (!material) {
throw new Error(`Key not found: ${key.id}`);
}
return key;
return material;
},
};
}
Loading