@@ -3,143 +3,19 @@ import { DOMParser } from "@xmldom/xmldom";
33import { SignedXml } from "./signed-xml" ;
44import {
55 KeySelectorFunction ,
6- DigestAlgorithmMap ,
7- TransformAlgorithmMap ,
8- SignatureAlgorithmMap ,
96 SignedXmlOptions ,
107 VerificationIdAttributeType ,
8+ KeySelector ,
9+ XmlDSigVerifierSecurityOptions ,
10+ XmlDSigVerifierOptions ,
11+ XmlDsigVerificationResult ,
1112} from "./types" ;
1213import { isArrayHasLength } from "./utils" ;
1314
1415const DEFAULT_MAX_TRANSFORMS = 4 ;
1516const DEFAULT_THROW_ON_ERROR = false ;
1617const DEFAULT_CHECK_CERT_EXPIRATION = true ;
1718
18- export type CertificateKeySelector = {
19- /** Public certificate or key to use for verification */
20- publicCert : KeyLike ;
21- } ;
22-
23- export type KeyInfoKeySelector = {
24- /** Function to extract the public key from KeyInfo element */
25- getCertFromKeyInfo : ( keyInfo ?: Node | null ) => string | null ;
26- } ;
27-
28- export type KeySelector = CertificateKeySelector | KeyInfoKeySelector ;
29-
30- export interface XmlDSigVerifierSecurityOptions {
31- /**
32- * Maximum number of transforms allowed per Reference element.
33- * Limits complexity to prevent denial-of-service attacks.
34- * @default {@link DEFAULT_MAX_TRANSFORMS }
35- */
36- maxTransforms ?: number ;
37-
38- /**
39- * Check certificate expiration dates during verification.
40- * If true, signatures with expired certificates will be considered invalid.
41- * This only applies when using KeyInfoKeySelector
42- * @default true
43- */
44- checkCertExpiration ?: boolean ;
45-
46- /**
47- * Optional truststore of trusted certificates
48- * When provided, the certificate used to sign the XML must chain to one of these trusted certificates.
49- * These must be PEM or DER encoded X509 certificates
50- */
51- truststore ?: Array < string | Buffer | X509Certificate > ;
52-
53- /**
54- * Signature algorithms allowed during verification.
55- *
56- * @default {@link SignedXml.getDefaultSignatureAlgorithms() }
57- */
58- signatureAlgorithms ?: SignatureAlgorithmMap ;
59-
60- /**
61- * Hash algorithms allowed during verification.
62- *
63- * @default {@link SignedXml.getDefaultDigestAlgorithms() }
64- */
65- hashAlgorithms ?: DigestAlgorithmMap ;
66-
67- /**
68- * Transform algorithms allowed during verification. (This must include canonicalization algorithms)
69- *
70- * @default all algorithms in {@link SignedXml.getDefaultTransformAlgorithms()}
71- */
72- transformAlgorithms ?: TransformAlgorithmMap ;
73-
74- /**
75- * Canonicalization algorithms allowed during verification.
76- *
77- * @default all algorithms in {@link SignedXml.getDefaultCanonicalizationAlgorithms()}
78- */
79- canonicalizationAlgorithms ?: TransformAlgorithmMap ;
80- }
81-
82- /**
83- * Common configuration options for XML-DSig verification.
84- */
85- export interface XmlDSigVerifierOptions {
86- /**
87- * Key selector for determining the public key to use for verification.
88- */
89- keySelector : KeySelector ;
90-
91- /**
92- * Names of XML attributes to treat as element identifiers.
93- * Used when resolving URI references in signatures.
94- * When passing strings, only the localName is matched, ignoring namespace.
95- * To explicitly match attributes without namespaces, use: { localName: "Id", namespaceUri: undefined }
96- * @default {@link SignedXml.getDefaultIdAttributes() }
97- * @example For WS-Security: [{ localName: "Id", namespaceUri: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" }]
98- */
99- idAttributes ?: VerificationIdAttributeType [ ] ;
100-
101- /**
102- * Transforms to apply implicitly during canonicalization.
103- * Used for specific XML-DSig profiles that require additional transforms.
104- */
105- implicitTransforms ?: ReadonlyArray < string > ;
106-
107- /**
108- * Whether to throw an exception on verification failure.
109- * If false, errors are returned in the XmlDsigVerificationResult.
110- * @default false
111- */
112- throwOnError ?: boolean ;
113-
114- /**
115- * Security options for verification.
116- */
117- security ?: XmlDSigVerifierSecurityOptions ;
118- }
119-
120- /**
121- * Verification result containing the outcome and signed content.
122- */
123- export type SuccessfulXmlDsigVerificationResult = {
124- /** Whether the signature was successfully verified */
125- success : true ;
126- error ?: undefined ;
127- /** The canonicalized XML content that passed verification */
128- signedReferences : string [ ] ;
129- } ;
130-
131- export type FailedXmlDsigVerificationResult = {
132- /** Whether the signature was sucessfuly verified */
133- success : false ;
134- /** Error message if verification failed */
135- error : string ;
136- signedReferences ?: undefined ;
137- } ;
138-
139- export type XmlDsigVerificationResult =
140- | SuccessfulXmlDsigVerificationResult
141- | FailedXmlDsigVerificationResult ;
142-
14319type ResolvedXmlDsigVerifierOptions = {
14420 keySelector : KeySelector ;
14521 idAttributes : VerificationIdAttributeType [ ] ;
0 commit comments