edockit 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +84 -11
- package/dist/core/parser/types.d.ts +3 -0
- package/dist/core/revocation/check.d.ts +22 -0
- package/dist/core/revocation/crl.d.ts +34 -0
- package/dist/core/revocation/fetch.d.ts +51 -0
- package/dist/core/revocation/index.d.ts +4 -0
- package/dist/core/revocation/ocsp.d.ts +52 -0
- package/dist/core/revocation/types.d.ts +49 -0
- package/dist/core/timestamp/index.d.ts +2 -0
- package/dist/core/timestamp/types.d.ts +48 -0
- package/dist/core/timestamp/verify.d.ts +32 -0
- package/dist/core/verification.d.ts +12 -0
- package/dist/index.cjs.js +8821 -245
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.esm.js +8819 -247
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +76 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/utils/encoding.d.ts +28 -0
- package/package.json +5 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2025-12-29
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Certificate Revocation Checking** - OCSP-first verification with CRL fallback
|
|
13
|
+
- Soft-fail mode: network errors return `status: 'unknown'`, signature remains valid
|
|
14
|
+
- Issuer certificate retrieval from XAdES chain or AIA extension
|
|
15
|
+
- Optional via `checkRevocation: false` for offline-only verification
|
|
16
|
+
- **RFC 3161 Timestamp Verification**
|
|
17
|
+
- Parse and verify RFC 3161 timestamps (SignatureTimeStamp)
|
|
18
|
+
- Check TSA certificate validity and revocation (OCSP/CRL)
|
|
19
|
+
- Use trusted TSA time for signer certificate validation
|
|
20
|
+
- `revocationOptions` pass-through to `verifySignature()`
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Refactored encoding utilities (consolidated base64/hex/ArrayBuffer helpers)
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Browser compatibility import fixes (direct paths vs barrel imports)
|
|
29
|
+
- Fixed vulnerable dev dependencies
|
|
30
|
+
|
|
31
|
+
## [0.1.2] - 2025-12-29
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- Initial public release
|
|
36
|
+
- Parse ASiC-E containers (including Latvian eDoc files)
|
|
37
|
+
- Extract and verify XAdES signatures
|
|
38
|
+
- Certificate validity checking
|
|
39
|
+
- File checksum verification (SHA-256/384/512)
|
|
40
|
+
- Browser and Node.js support
|
|
41
|
+
|
|
42
|
+
[0.2.0]: https://github.com/edgarsj/edockit/compare/v0.1.2...v0.2.0
|
|
43
|
+
[0.1.2]: https://github.com/edgarsj/edockit/releases/tag/v0.1.2
|
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@ A JavaScript/TypeScript library for viewing and verifying EU standard ASiC-E con
|
|
|
4
4
|
|
|
5
5
|
> **Note: Work in Progress** - This library is under active development and requires more real-world testing with various ASiC-E implementations from different European countries. If you have sample files or encounter issues, please contribute!
|
|
6
6
|
|
|
7
|
-
> **Important:** Certificate validation currently lacks OCSP checks (Online Certificate Status Protocol). Adding OCSP support is on the roadmap and will be implemented in a future release.
|
|
8
|
-
|
|
9
7
|
## About
|
|
10
8
|
|
|
11
9
|
This library supports standard European ASiC-E (.asice, .sce) containers as defined by the ETSI standards. Latvian eDoc (.edoc) files are effectively ASiC-E containers with a different file extension, so they are also supported. While the core functionality exists, extensive testing with real-world documents from various EU countries is still needed to ensure complete compatibility across different implementations.
|
|
@@ -41,13 +39,35 @@ const container = parseEdoc(fileBuffer);
|
|
|
41
39
|
// List files in container
|
|
42
40
|
console.log(Array.from(container.files.keys()));
|
|
43
41
|
|
|
44
|
-
// Verify a signature
|
|
45
|
-
const result = await verifySignature(container.signatures[0], container.files
|
|
42
|
+
// Verify a signature (with revocation and timestamp checking)
|
|
43
|
+
const result = await verifySignature(container.signatures[0], container.files, {
|
|
44
|
+
checkRevocation: true, // OCSP/CRL checking (default: true)
|
|
45
|
+
revocationOptions: { // Optional: configure revocation check behavior
|
|
46
|
+
ocspTimeout: 5000, // OCSP request timeout in ms (default: 5000)
|
|
47
|
+
crlTimeout: 10000, // CRL fetch timeout in ms (default: 10000)
|
|
48
|
+
},
|
|
49
|
+
verifyTimestamps: true, // RFC 3161 timestamp verification (default: true)
|
|
50
|
+
verifyTime: new Date() // Verify certificate at specific time (default: timestamp time if present, otherwise now)
|
|
51
|
+
});
|
|
46
52
|
// result = {
|
|
47
53
|
// isValid: boolean, // Overall validity
|
|
48
|
-
// certificate: {
|
|
54
|
+
// certificate: {
|
|
55
|
+
// isValid: boolean, // Certificate validity (time-based)
|
|
56
|
+
// revocation: { // Revocation check result
|
|
57
|
+
// status: 'good' | 'revoked' | 'unknown' | 'error',
|
|
58
|
+
// method: 'ocsp' | 'crl' | 'none',
|
|
59
|
+
// checkedAt: Date,
|
|
60
|
+
// isValid: boolean
|
|
61
|
+
// }
|
|
62
|
+
// },
|
|
49
63
|
// checksums: {isValid: boolean}, // File checksums validation result
|
|
50
64
|
// signature: {isValid: boolean}, // XML signature validation result
|
|
65
|
+
// timestamp: { // Timestamp verification (if present)
|
|
66
|
+
// isValid: boolean,
|
|
67
|
+
// info: { genTime: Date, policy: string, ... },
|
|
68
|
+
// coversSignature: boolean,
|
|
69
|
+
// tsaRevocation: { status, method, ... }
|
|
70
|
+
// },
|
|
51
71
|
// errors: string[] // Any validation errors (if present)
|
|
52
72
|
// }
|
|
53
73
|
console.log(`Signature valid: ${result.isValid}`);
|
|
@@ -56,18 +76,29 @@ console.log(`Signature valid: ${result.isValid}`);
|
|
|
56
76
|
### Node.js Example
|
|
57
77
|
|
|
58
78
|
```typescript
|
|
59
|
-
import { readFileSync } from
|
|
60
|
-
import { parseEdoc, verifySignature } from
|
|
79
|
+
import { readFileSync } from "fs";
|
|
80
|
+
import { parseEdoc, verifySignature } from "edockit";
|
|
61
81
|
|
|
62
82
|
// Read file
|
|
63
|
-
const fileBuffer = readFileSync(
|
|
83
|
+
const fileBuffer = readFileSync("document.asice");
|
|
64
84
|
const container = parseEdoc(fileBuffer);
|
|
65
85
|
|
|
66
|
-
// Check signatures
|
|
86
|
+
// Check signatures with revocation and timestamp checking
|
|
67
87
|
for (const signature of container.signatures) {
|
|
68
|
-
const result = await verifySignature(signature, container.files
|
|
88
|
+
const result = await verifySignature(signature, container.files, {
|
|
89
|
+
checkRevocation: true,
|
|
90
|
+
verifyTimestamps: true
|
|
91
|
+
});
|
|
69
92
|
console.log(`Signature valid: ${result.isValid}`);
|
|
70
93
|
|
|
94
|
+
if (result.timestamp?.info) {
|
|
95
|
+
console.log(`Signed at (TSA): ${result.timestamp.info.genTime}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (result.certificate.revocation) {
|
|
99
|
+
console.log(`Revocation status: ${result.certificate.revocation.status}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
71
102
|
if (!result.isValid && result.errors) {
|
|
72
103
|
console.log(`Errors: ${result.errors.join(', ')}`);
|
|
73
104
|
}
|
|
@@ -89,22 +120,64 @@ async function verifyDocument(url) {
|
|
|
89
120
|
|
|
90
121
|
for (const signature of container.signatures) {
|
|
91
122
|
const result = await verifySignature(signature, container.files);
|
|
123
|
+
// checkRevocation and verifyTimestamps default to true
|
|
124
|
+
|
|
92
125
|
console.log(`Valid: ${result.isValid}`);
|
|
126
|
+
|
|
127
|
+
if (result.timestamp?.info) {
|
|
128
|
+
console.log(`Timestamp: ${result.timestamp.info.genTime}`);
|
|
129
|
+
}
|
|
130
|
+
if (result.certificate.revocation) {
|
|
131
|
+
console.log(`Revocation: ${result.certificate.revocation.status}`);
|
|
132
|
+
}
|
|
93
133
|
}
|
|
94
134
|
}
|
|
95
135
|
```
|
|
96
136
|
|
|
137
|
+
### Timestamp Utilities
|
|
138
|
+
|
|
139
|
+
For advanced timestamp handling, you can use the timestamp utilities directly:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { parseTimestamp, verifyTimestamp, getTimestampTime } from 'edockit';
|
|
143
|
+
|
|
144
|
+
// Get timestamp time from a signature (quick utility)
|
|
145
|
+
const timestampTime = getTimestampTime(signature.signatureTimestamp);
|
|
146
|
+
console.log(`Signed at: ${timestampTime}`);
|
|
147
|
+
|
|
148
|
+
// Parse timestamp for detailed info
|
|
149
|
+
const info = parseTimestamp(signature.signatureTimestamp);
|
|
150
|
+
// info = {
|
|
151
|
+
// genTime: Date, // When TSA signed
|
|
152
|
+
// policy: string, // TSA policy OID
|
|
153
|
+
// hashAlgorithm: string, // e.g., 'SHA-256'
|
|
154
|
+
// messageImprint: string, // Hash of timestamped data
|
|
155
|
+
// tsaName?: string, // TSA name
|
|
156
|
+
// tsaCertificate?: string, // TSA cert in PEM format
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
// Verify timestamp with options
|
|
160
|
+
const result = await verifyTimestamp(signature.signatureTimestamp, {
|
|
161
|
+
signatureValue: signature.signatureValue, // Verify timestamp covers this signature
|
|
162
|
+
verifyTsaCertificate: true, // Check TSA cert validity
|
|
163
|
+
checkTsaRevocation: true, // Check TSA cert revocation
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
97
167
|
## Features
|
|
98
168
|
|
|
99
169
|
- Support for EU standard ASiC-E containers and Latvian eDoc files/containers (same format, different extension)
|
|
100
170
|
- List files contained in ASiC-E/eDoc container
|
|
101
171
|
- Extract and display signature information
|
|
102
172
|
- Verify XML signatures against file checksums
|
|
103
|
-
- Validate certificate validity (
|
|
173
|
+
- Validate certificate validity (time-based)
|
|
174
|
+
- RFC 3161 timestamp verification (when present, certificate is validated at the trusted TSA timestamp time)
|
|
175
|
+
- OCSP/CRL revocation checking for both signer and TSA certificates (soft-fail behavior - network errors don't invalidate signatures)
|
|
104
176
|
|
|
105
177
|
## Testing Status
|
|
106
178
|
|
|
107
179
|
The library has been tested with a limited set of real Latvian eDoc files (which are ASiC-E containers with a .edoc extension). More testing is needed with:
|
|
180
|
+
|
|
108
181
|
- ASiC-E containers from different EU countries
|
|
109
182
|
- Files created with different software implementations
|
|
110
183
|
- Various signature algorithms and certificate types
|
|
@@ -10,6 +10,7 @@ export interface SignatureInfo {
|
|
|
10
10
|
signingTime: Date;
|
|
11
11
|
certificate: string;
|
|
12
12
|
certificatePEM: string;
|
|
13
|
+
certificateChain?: string[];
|
|
13
14
|
publicKey?: {
|
|
14
15
|
algorithm: string;
|
|
15
16
|
namedCurve?: string;
|
|
@@ -36,4 +37,6 @@ export interface SignatureInfo {
|
|
|
36
37
|
signedInfoXml?: string;
|
|
37
38
|
rawXml?: string;
|
|
38
39
|
canonicalizationMethod?: string;
|
|
40
|
+
/** RFC 3161 timestamp token (base64 encoded) from xades:EncapsulatedTimeStamp */
|
|
41
|
+
signatureTimestamp?: string;
|
|
39
42
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { X509Certificate } from "@peculiar/x509";
|
|
2
|
+
import { RevocationResult, RevocationCheckOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Check certificate revocation status using OCSP (primary) and CRL (fallback)
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* 1. Try OCSP first (faster, real-time)
|
|
8
|
+
* 2. If OCSP fails or returns unknown, try CRL as fallback
|
|
9
|
+
* 3. If both fail, return 'unknown' status (soft fail)
|
|
10
|
+
*
|
|
11
|
+
* @param cert Certificate to check (X509Certificate or PEM string)
|
|
12
|
+
* @param options Revocation check options
|
|
13
|
+
* @returns RevocationResult with status and details
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkCertificateRevocation(cert: X509Certificate | string, options?: RevocationCheckOptions): Promise<RevocationResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Check multiple certificates' revocation status
|
|
18
|
+
* @param certs Array of certificates (X509Certificate or PEM strings)
|
|
19
|
+
* @param options Revocation check options
|
|
20
|
+
* @returns Array of RevocationResults in same order as input
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkCertificatesRevocation(certs: (X509Certificate | string)[], options?: RevocationCheckOptions): Promise<RevocationResult[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { X509Certificate, X509Crl } from "@peculiar/x509";
|
|
2
|
+
import { RevocationResult } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Extract CRL distribution point URLs from certificate
|
|
5
|
+
* @param cert X509Certificate to extract CRL URLs from
|
|
6
|
+
* @returns Array of CRL distribution URLs
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractCRLUrls(cert: X509Certificate): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Check if a certificate serial number is in the CRL
|
|
11
|
+
* @param crl X509Crl to check
|
|
12
|
+
* @param serialNumber Certificate serial number (hex string)
|
|
13
|
+
* @returns Object with isRevoked status and optional revocation date
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSerialInCRL(crl: X509Crl, serialNumber: string): {
|
|
16
|
+
isRevoked: boolean;
|
|
17
|
+
revokedAt?: Date;
|
|
18
|
+
reason?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse CRL from DER or PEM data
|
|
22
|
+
* @param data CRL data (DER or PEM)
|
|
23
|
+
* @returns X509Crl or null if parsing fails
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseCRL(data: ArrayBuffer): X509Crl | null;
|
|
26
|
+
/**
|
|
27
|
+
* Check certificate revocation via CRL
|
|
28
|
+
* @param cert Certificate to check
|
|
29
|
+
* @param options CRL check options
|
|
30
|
+
* @returns Revocation result
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkCRL(cert: X509Certificate, options?: {
|
|
33
|
+
timeout?: number;
|
|
34
|
+
}): Promise<RevocationResult>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform HTTP fetch for OCSP and CRL requests
|
|
3
|
+
* Works in both browser and Node.js environments
|
|
4
|
+
*/
|
|
5
|
+
export interface FetchOptions {
|
|
6
|
+
/** Request timeout in milliseconds */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
/** HTTP method (default: GET) */
|
|
9
|
+
method?: "GET" | "POST";
|
|
10
|
+
/** Request body for POST requests */
|
|
11
|
+
body?: ArrayBuffer | Uint8Array;
|
|
12
|
+
/** Content-Type header */
|
|
13
|
+
contentType?: string;
|
|
14
|
+
/** Accept header */
|
|
15
|
+
accept?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface FetchResult {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
status: number;
|
|
20
|
+
data?: ArrayBuffer;
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Fetch binary data from a URL with timeout support
|
|
25
|
+
* @param url URL to fetch
|
|
26
|
+
* @param options Fetch options
|
|
27
|
+
* @returns FetchResult with binary data or error
|
|
28
|
+
*/
|
|
29
|
+
export declare function fetchBinary(url: string, options?: FetchOptions): Promise<FetchResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch OCSP response
|
|
32
|
+
* @param url OCSP responder URL
|
|
33
|
+
* @param request DER-encoded OCSP request
|
|
34
|
+
* @param timeout Timeout in milliseconds
|
|
35
|
+
* @returns FetchResult with OCSP response data
|
|
36
|
+
*/
|
|
37
|
+
export declare function fetchOCSP(url: string, request: ArrayBuffer, timeout?: number): Promise<FetchResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetch CRL from distribution point
|
|
40
|
+
* @param url CRL distribution point URL
|
|
41
|
+
* @param timeout Timeout in milliseconds
|
|
42
|
+
* @returns FetchResult with CRL data
|
|
43
|
+
*/
|
|
44
|
+
export declare function fetchCRL(url: string, timeout?: number): Promise<FetchResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Fetch issuer certificate from AIA extension
|
|
47
|
+
* @param url CA Issuers URL
|
|
48
|
+
* @param timeout Timeout in milliseconds
|
|
49
|
+
* @returns FetchResult with certificate data
|
|
50
|
+
*/
|
|
51
|
+
export declare function fetchIssuerCertificate(url: string, timeout?: number): Promise<FetchResult>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { checkCertificateRevocation, checkCertificatesRevocation } from "./check";
|
|
2
|
+
export { RevocationResult, RevocationCheckOptions, DEFAULT_REVOCATION_OPTIONS, OID } from "./types";
|
|
3
|
+
export { extractOCSPUrls, extractCAIssuersUrls, findIssuerInChain, checkOCSP } from "./ocsp";
|
|
4
|
+
export { extractCRLUrls, checkCRL } from "./crl";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { X509Certificate } from "@peculiar/x509";
|
|
2
|
+
import { RevocationResult } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Extract OCSP responder URLs from certificate
|
|
5
|
+
* @param cert X509Certificate to extract OCSP URLs from
|
|
6
|
+
* @returns Array of OCSP responder URLs
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractOCSPUrls(cert: X509Certificate): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Extract CA Issuers URLs from certificate (for fetching issuer cert)
|
|
11
|
+
* @param cert X509Certificate to extract URLs from
|
|
12
|
+
* @returns Array of CA Issuers URLs
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractCAIssuersUrls(cert: X509Certificate): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Find issuer certificate from certificate chain
|
|
17
|
+
* @param cert Certificate to find issuer for
|
|
18
|
+
* @param chain Array of PEM-formatted certificates
|
|
19
|
+
* @returns Issuer certificate or null if not found
|
|
20
|
+
*/
|
|
21
|
+
export declare function findIssuerInChain(cert: X509Certificate, chain: string[]): X509Certificate | null;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch issuer certificate from AIA extension
|
|
24
|
+
* @param cert Certificate to fetch issuer for
|
|
25
|
+
* @param timeout Timeout in ms
|
|
26
|
+
* @returns Issuer certificate or null
|
|
27
|
+
*/
|
|
28
|
+
export declare function fetchIssuerFromAIA(cert: X509Certificate, timeout?: number): Promise<X509Certificate | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Build OCSP request for a certificate
|
|
31
|
+
* @param cert Certificate to check
|
|
32
|
+
* @param issuerCert Issuer certificate
|
|
33
|
+
* @returns DER-encoded OCSP request
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildOCSPRequest(cert: X509Certificate, issuerCert: X509Certificate): Promise<ArrayBuffer>;
|
|
36
|
+
/**
|
|
37
|
+
* Parse OCSP response and extract revocation status
|
|
38
|
+
* @param responseData DER-encoded OCSP response
|
|
39
|
+
* @returns Revocation result
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseOCSPResponse(responseData: ArrayBuffer): RevocationResult;
|
|
42
|
+
/**
|
|
43
|
+
* Check certificate revocation via OCSP
|
|
44
|
+
* @param cert Certificate to check
|
|
45
|
+
* @param issuerCert Issuer certificate (optional, will try to find/fetch)
|
|
46
|
+
* @param options OCSP check options
|
|
47
|
+
* @returns Revocation result
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkOCSP(cert: X509Certificate, issuerCert: X509Certificate | null, options?: {
|
|
50
|
+
timeout?: number;
|
|
51
|
+
certificateChain?: string[];
|
|
52
|
+
}): Promise<RevocationResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a certificate revocation check
|
|
3
|
+
*/
|
|
4
|
+
export interface RevocationResult {
|
|
5
|
+
/** Whether the certificate passed revocation check (not revoked) */
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
/** Revocation status */
|
|
8
|
+
status: "good" | "revoked" | "unknown" | "error";
|
|
9
|
+
/** Method used to check revocation */
|
|
10
|
+
method?: "ocsp" | "crl" | "none";
|
|
11
|
+
/** Human-readable reason for the status */
|
|
12
|
+
reason?: string;
|
|
13
|
+
/** Date when certificate was revoked (if revoked) */
|
|
14
|
+
revokedAt?: Date;
|
|
15
|
+
/** When this revocation check was performed */
|
|
16
|
+
checkedAt: Date;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for revocation checking
|
|
20
|
+
*/
|
|
21
|
+
export interface RevocationCheckOptions {
|
|
22
|
+
/** Enable OCSP checking (default: true) */
|
|
23
|
+
ocspEnabled?: boolean;
|
|
24
|
+
/** Enable CRL checking as fallback (default: true) */
|
|
25
|
+
crlEnabled?: boolean;
|
|
26
|
+
/** Timeout for OCSP requests in ms (default: 5000) */
|
|
27
|
+
ocspTimeout?: number;
|
|
28
|
+
/** Timeout for CRL requests in ms (default: 10000) */
|
|
29
|
+
crlTimeout?: number;
|
|
30
|
+
/** Certificate chain for finding issuer (PEM strings) */
|
|
31
|
+
certificateChain?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default options for revocation checking
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_REVOCATION_OPTIONS: Required<Omit<RevocationCheckOptions, "certificateChain">>;
|
|
37
|
+
/**
|
|
38
|
+
* OID constants for certificate extensions
|
|
39
|
+
*/
|
|
40
|
+
export declare const OID: {
|
|
41
|
+
/** Authority Information Access */
|
|
42
|
+
readonly authorityInfoAccess: "1.3.6.1.5.5.7.1.1";
|
|
43
|
+
/** CRL Distribution Points */
|
|
44
|
+
readonly crlDistributionPoints: "2.5.29.31";
|
|
45
|
+
/** OCSP access method */
|
|
46
|
+
readonly ocsp: "1.3.6.1.5.5.7.48.1";
|
|
47
|
+
/** CA Issuers access method */
|
|
48
|
+
readonly caIssuers: "1.3.6.1.5.5.7.48.2";
|
|
49
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RevocationResult } from "../revocation/types";
|
|
2
|
+
/**
|
|
3
|
+
* Parsed timestamp information from RFC 3161 TimeStampToken
|
|
4
|
+
*/
|
|
5
|
+
export interface TimestampInfo {
|
|
6
|
+
/** The timestamp generation time (when TSA signed) */
|
|
7
|
+
genTime: Date;
|
|
8
|
+
/** TSA policy OID */
|
|
9
|
+
policy: string;
|
|
10
|
+
/** Serial number of the timestamp */
|
|
11
|
+
serialNumber: string;
|
|
12
|
+
/** Hash algorithm used for the message imprint */
|
|
13
|
+
hashAlgorithm: string;
|
|
14
|
+
/** The message imprint (hash of timestamped data) */
|
|
15
|
+
messageImprint: string;
|
|
16
|
+
/** TSA name (if provided) */
|
|
17
|
+
tsaName?: string;
|
|
18
|
+
/** TSA certificate (PEM format) */
|
|
19
|
+
tsaCertificate?: string;
|
|
20
|
+
/** Accuracy of the timestamp (in seconds) */
|
|
21
|
+
accuracy?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of timestamp verification
|
|
25
|
+
*/
|
|
26
|
+
export interface TimestampVerificationResult {
|
|
27
|
+
/** Whether the timestamp is valid */
|
|
28
|
+
isValid: boolean;
|
|
29
|
+
/** Parsed timestamp info (if parsing succeeded) */
|
|
30
|
+
info?: TimestampInfo;
|
|
31
|
+
/** Error or status message */
|
|
32
|
+
reason?: string;
|
|
33
|
+
/** Whether the timestamp covers the signature value correctly */
|
|
34
|
+
coversSignature?: boolean;
|
|
35
|
+
/** TSA certificate revocation check result (if checkTsaRevocation was enabled) */
|
|
36
|
+
tsaRevocation?: RevocationResult;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for timestamp verification
|
|
40
|
+
*/
|
|
41
|
+
export interface TimestampVerificationOptions {
|
|
42
|
+
/** The signature value that the timestamp should cover (base64) */
|
|
43
|
+
signatureValue?: string;
|
|
44
|
+
/** Verify the TSA certificate chain */
|
|
45
|
+
verifyTsaCertificate?: boolean;
|
|
46
|
+
/** Check TSA certificate revocation */
|
|
47
|
+
checkTsaRevocation?: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TimestampInfo, TimestampVerificationResult, TimestampVerificationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Parse RFC 3161 TimeStampToken from base64
|
|
4
|
+
* @param timestampBase64 Base64-encoded timestamp token
|
|
5
|
+
* @returns Parsed timestamp info or null if parsing fails
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseTimestamp(timestampBase64: string): TimestampInfo | null;
|
|
8
|
+
/**
|
|
9
|
+
* Verify that timestamp covers the signature value
|
|
10
|
+
* XAdES timestamps can cover either:
|
|
11
|
+
* 1. The decoded signature value bytes (standard per ETSI EN 319 132-1)
|
|
12
|
+
* 2. The base64-encoded string (some implementations)
|
|
13
|
+
*
|
|
14
|
+
* @param timestampInfo Parsed timestamp info
|
|
15
|
+
* @param signatureValueBase64 Base64-encoded signature value
|
|
16
|
+
* @returns True if the timestamp covers the signature
|
|
17
|
+
*/
|
|
18
|
+
export declare function verifyTimestampCoversSignature(timestampInfo: TimestampInfo, signatureValueBase64: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Verify an RFC 3161 timestamp token
|
|
21
|
+
* @param timestampBase64 Base64-encoded timestamp token
|
|
22
|
+
* @param options Verification options
|
|
23
|
+
* @returns Timestamp verification result
|
|
24
|
+
*/
|
|
25
|
+
export declare function verifyTimestamp(timestampBase64: string, options?: TimestampVerificationOptions): Promise<TimestampVerificationResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the trusted timestamp time from a signature
|
|
28
|
+
* This should be used instead of the self-declared signingTime for certificate validation
|
|
29
|
+
* @param timestampBase64 Base64-encoded timestamp token
|
|
30
|
+
* @returns The timestamp generation time, or null if parsing fails
|
|
31
|
+
*/
|
|
32
|
+
export declare function getTimestampTime(timestampBase64: string): Date | null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { CertificateInfo } from "./certificate";
|
|
2
2
|
import { SignatureInfo } from "./parser";
|
|
3
|
+
import { RevocationResult, RevocationCheckOptions } from "./revocation/types";
|
|
4
|
+
import { TimestampVerificationResult } from "./timestamp/types";
|
|
3
5
|
/**
|
|
4
6
|
* Options for verification process
|
|
5
7
|
*/
|
|
@@ -8,6 +10,12 @@ export interface VerificationOptions {
|
|
|
8
10
|
verifySignatures?: boolean;
|
|
9
11
|
verifyChecksums?: boolean;
|
|
10
12
|
verifyTime?: Date;
|
|
13
|
+
/** Check certificate revocation via OCSP/CRL (default: true) */
|
|
14
|
+
checkRevocation?: boolean;
|
|
15
|
+
/** Options for revocation checking (timeouts, etc.) */
|
|
16
|
+
revocationOptions?: RevocationCheckOptions;
|
|
17
|
+
/** Verify RFC 3161 timestamp if present (default: true) */
|
|
18
|
+
verifyTimestamps?: boolean;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
21
|
* Result of a checksum verification
|
|
@@ -42,6 +50,8 @@ export interface CertificateVerificationResult {
|
|
|
42
50
|
isValid: boolean;
|
|
43
51
|
reason?: string;
|
|
44
52
|
info?: CertificateInfo;
|
|
53
|
+
/** Revocation check result (if checkRevocation was enabled) */
|
|
54
|
+
revocation?: RevocationResult;
|
|
45
55
|
}
|
|
46
56
|
/**
|
|
47
57
|
* Complete verification result
|
|
@@ -51,6 +61,8 @@ export interface VerificationResult {
|
|
|
51
61
|
certificate: CertificateVerificationResult;
|
|
52
62
|
checksums: ChecksumVerificationResult;
|
|
53
63
|
signature?: SignatureVerificationResult;
|
|
64
|
+
/** Timestamp verification result (if timestamp present and verifyTimestamps enabled) */
|
|
65
|
+
timestamp?: TimestampVerificationResult;
|
|
54
66
|
errors?: string[];
|
|
55
67
|
}
|
|
56
68
|
/**
|