@owf/eudi-access-certificate 0.0.0-stage → 0.0.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/README.md +155 -2
- package/dist/index.cjs +381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +295 -0
- package/dist/index.d.mts +295 -0
- package/dist/index.mjs +364 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -4
package/README.md
CHANGED
|
@@ -1,3 +1,156 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @owf/eudi-access-certificate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://npmjs.com/package/@owf/eudi-access-certificate)
|
|
4
|
+
[](https://github.com/openwallet-foundation-labs/identity-common-ts/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Parse, validate and create EUDI **wallet-relying party access certificates** as specified in
|
|
7
|
+
[ETSI TS 119 411-8 V1.1.1](https://www.etsi.org/deliver/etsi_ts/119400_119499/11941108/01.01.01_60/ts_11941108v010101p.pdf)
|
|
8
|
+
(Access Certificate Policy for EUDI Wallet Relying Parties).
|
|
9
|
+
|
|
10
|
+
This package is a profile on top of [`@owf/x509`](../x509). `@owf/x509` handles the generic X.509 work: parsing,
|
|
11
|
+
creation, signature verification and CRLs. This package adds what TS 119 411-8 defines: the policy identifiers, the
|
|
12
|
+
subject and contact requirements, and the QC statements for qualified policies. Like `@owf/x509`, it runs on servers,
|
|
13
|
+
in browsers and in React Native, and signing is a callback.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @owf/eudi-access-certificate @owf/x509
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Parsing
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { parseAccessCertificate } from '@owf/eudi-access-certificate'
|
|
25
|
+
|
|
26
|
+
// PEM, base64 encoded DER, or DER bytes, e.g. the first entry of an x5c header
|
|
27
|
+
const ac = parseAccessCertificate(pem)
|
|
28
|
+
|
|
29
|
+
ac.policies // ['QCP-l-eudiwrp']
|
|
30
|
+
ac.subjectType // 'legal' | 'natural'
|
|
31
|
+
ac.qualified // true for QCP-n-eudiwrp / QCP-l-eudiwrp
|
|
32
|
+
ac.subjectIdentifier // { type: 'VAT', countryCode: 'DE', identifier: '123456789', ... }
|
|
33
|
+
ac.contact // { uris, emails, phoneNumbers } from the SAN (GEN-6.6.1-07)
|
|
34
|
+
|
|
35
|
+
ac.certificate // the generic @owf/x509 Certificate
|
|
36
|
+
ac.certificate.subject.commonName // trade or service name (GEN-6.1.1-04)
|
|
37
|
+
ac.certificate.policies[0].cpsUris // GEN-6.6.1-06
|
|
38
|
+
ac.certificate.subjectAlternativeNames.dnsNames // e.g. for the OpenID4VP x509_san_dns client identifier
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you already have a parsed certificate from `@owf/x509`, use `toAccessCertificate(certificate)`.
|
|
42
|
+
|
|
43
|
+
### Relation to registration certificates
|
|
44
|
+
|
|
45
|
+
A registration certificate (ETSI TS 119 475, see [`@owf/eudi-wrprc`](../eudi-wrprc)) is bound to the access certificate
|
|
46
|
+
through its `sub` claim. `getAccessCertificateSubjectIdentifier(ac)` returns the value to compare it with: the
|
|
47
|
+
`organizationIdentifier` for legal persons, or the `serialNumber` for natural persons.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { getAccessCertificateSubjectIdentifier } from '@owf/eudi-access-certificate'
|
|
51
|
+
import { validateWRPRC } from '@owf/eudi-wrprc'
|
|
52
|
+
|
|
53
|
+
const result = validateWRPRC(header, payload, getAccessCertificateSubjectIdentifier(ac) ?? '')
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Validation
|
|
57
|
+
|
|
58
|
+
`validateAccessCertificate` checks the certificate profile of TS 119 411-8 clause 6.6.1 and the profiles it
|
|
59
|
+
references (ETSI EN 319 412-1/-2/-3/-5):
|
|
60
|
+
|
|
61
|
+
| Code | Severity | Requirement |
|
|
62
|
+
|------|----------|-------------|
|
|
63
|
+
| `MISSING_POLICY` / `CONFLICTING_POLICIES` | error | GEN-6.6.1-03: a TS 119 411-8 policy OID (or an accepted TSP OID); natural and legal policies must not be mixed |
|
|
64
|
+
| `MISSING_CPS_URI` | error | GEN-6.6.1-06 |
|
|
65
|
+
| `MISSING_CONTACT` | error | GEN-6.6.1-07: SAN website, telephone number or email address |
|
|
66
|
+
| `MISSING_ORGANIZATION_IDENTIFIER` / `INVALID_ORGANIZATION_IDENTIFIER` / `INVALID_GREECE_COUNTRY_CODE` | error | GEN-6.6.1-05 (legal persons) |
|
|
67
|
+
| `MISSING_COMMON_NAME` / `MISSING_COUNTRY_NAME` / `MISSING_ORGANIZATION_NAME` | error | EN 319 412-2 / 412-3 |
|
|
68
|
+
| `MISSING_NATURAL_PERSON_NAME` | error | EN 319 412-2: givenName and/or surname, or pseudonym |
|
|
69
|
+
| `MISSING_SERIAL_NUMBER` / `INVALID_SERIAL_NUMBER` | warning | Natural person semantic identifier (EN 319 412-1 clause 5.1.3) |
|
|
70
|
+
| `MISSING_QC_COMPLIANCE` | error | GEN-6.6.1-02: qualified policies need the QcCompliance statement |
|
|
71
|
+
| `QC_TYPE_MISMATCH` | warning | GEN-6.6.1-02: `esign` for natural and `eseal` for legal persons |
|
|
72
|
+
| `CA_CERTIFICATE`, `UNSUPPORTED_VERSION`, `NOT_YET_VALID`, `EXPIRED` | error | X.509 basics |
|
|
73
|
+
| `MISSING_DIGITAL_SIGNATURE_KEY_USAGE` | warning | The key has to sign to authenticate the relying party |
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { parseAndValidateAccessCertificate, validateAccessCertificate } from '@owf/eudi-access-certificate'
|
|
77
|
+
|
|
78
|
+
const { valid, errors, warnings } = validateAccessCertificate(ac, {
|
|
79
|
+
now: new Date(), // or false to skip the validity period check
|
|
80
|
+
acceptedPolicyOids: ['1.2.3.4.5'], // TSP allocated policy OIDs (GEN-6.6.1-03)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// Or throw an AccessCertificateException on errors
|
|
84
|
+
const checked = parseAndValidateAccessCertificate(pem)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Signature and revocation checks
|
|
88
|
+
|
|
89
|
+
These are generic X.509 operations. Run them with `@owf/x509` on `ac.certificate`:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { checkRevocation, parseCrl, verifyCertificateSignature } from '@owf/x509'
|
|
93
|
+
|
|
94
|
+
const signed = await verifyCertificateSignature(ac.certificate, providerCaPem, verifier)
|
|
95
|
+
|
|
96
|
+
// REV-6.3.9-04: access certificates are revoked when the registration is suspended or cancelled
|
|
97
|
+
const crl = parseCrl(await fetchCrl(ac.certificate.crlDistributionPoints[0]))
|
|
98
|
+
const status = await checkRevocation({ certificate: ac.certificate, crl, crlIssuerCertificate: providerCaPem, verifier })
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Take the provider CA from the trusted list of access certificate providers (see [`@owf/eudi-lote`](../eudi-lote)).
|
|
102
|
+
|
|
103
|
+
## Creation
|
|
104
|
+
|
|
105
|
+
Certificates are created without handing over any private key:
|
|
106
|
+
|
|
107
|
+
- the **issuing CA key** stays wherever it lives (WebCrypto, KMS, HSM). The `signer` callback receives the DER encoded
|
|
108
|
+
TBSCertificate and returns the signature.
|
|
109
|
+
- for the **wallet-relying party** only the public key is needed, as SPKI bytes or as a JWK. A JWK that contains
|
|
110
|
+
private key material is rejected.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { createAccessCertificate } from '@owf/eudi-access-certificate'
|
|
114
|
+
|
|
115
|
+
const ac = await createAccessCertificate({
|
|
116
|
+
policy: 'NCP-l-eudiwrp', // or 'QCP-l-eudiwrp', 'NCP-n-eudiwrp', 'QCP-n-eudiwrp'
|
|
117
|
+
cpsUri: 'https://ca.example.com/cps',
|
|
118
|
+
subject: {
|
|
119
|
+
commonName: 'Example Shop',
|
|
120
|
+
organizationName: 'Example Relying Party GmbH',
|
|
121
|
+
organizationIdentifier: 'LEIXG-529900T8BM49AURSDO55',
|
|
122
|
+
countryName: 'DE',
|
|
123
|
+
organizationalUnitNames: ['Online Shop'],
|
|
124
|
+
},
|
|
125
|
+
contact: { uris: ['https://shop.example.com/support'], emails: ['support@shop.example.com'] },
|
|
126
|
+
dnsNames: ['shop.example.com'],
|
|
127
|
+
subjectPublicKey: relyingPartyPublicJwk,
|
|
128
|
+
issuerCertificate: caPem,
|
|
129
|
+
serialNumber: randomSerialHex, // at most 20 octets, generate it with your CSPRNG
|
|
130
|
+
notBefore: new Date(),
|
|
131
|
+
notAfter: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
|
|
132
|
+
signatureAlgorithm: 'ES256',
|
|
133
|
+
crlDistributionPoints: ['https://ca.example.com/crl'],
|
|
134
|
+
signer: async (tbs) => new Uint8Array(await crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, caKey, tbs)),
|
|
135
|
+
signatureEncoding: 'ieee-p1363', // default, as produced by WebCrypto; use 'der' for most KMS/HSM APIs
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
ac.certificate.pem
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The certificate gets the policy OID with the CPS URI, the contact information in the SAN (telephone numbers as
|
|
142
|
+
`otherName` with `id-at-telephoneNumber`), `basicConstraints` `cA=false`, `keyUsage` `digitalSignature`, and an
|
|
143
|
+
authority key identifier taken from the issuer certificate. Qualified policies also get QC statements with
|
|
144
|
+
QcCompliance and QcType (`esign` / `eseal`), optionally QcSSCD, PDS locations and QcCClegislation. The result is
|
|
145
|
+
validated against the profile before it is returned.
|
|
146
|
+
|
|
147
|
+
If the key lives in a separate system, use `prepareAccessCertificate(options)` and
|
|
148
|
+
`assembleAccessCertificate(prepared, signature)`. `toCertificateTemplate(options)` returns the generic `@owf/x509`
|
|
149
|
+
template if you need to adjust it further.
|
|
150
|
+
|
|
151
|
+
## Out of scope
|
|
152
|
+
|
|
153
|
+
- Path building to a trust anchor
|
|
154
|
+
- Certificate transparency (OVR-6.4.5-02)
|
|
155
|
+
- Checking the wallet-relying party against the national register (REG-6.2.2-03), which is the provider's job at
|
|
156
|
+
issuance
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _owf_identity_common = require("@owf/identity-common");
|
|
3
|
+
let _owf_x509 = require("@owf/x509");
|
|
4
|
+
//#region src/access-certificate-exception.ts
|
|
5
|
+
/**
|
|
6
|
+
* AccessCertificateException is thrown when an access certificate cannot be
|
|
7
|
+
* parsed, fails validation in an assert helper, or cannot be created.
|
|
8
|
+
*/
|
|
9
|
+
var AccessCertificateException = class AccessCertificateException extends _owf_identity_common.IdentityException {
|
|
10
|
+
constructor(message, details) {
|
|
11
|
+
super(message, details);
|
|
12
|
+
Object.setPrototypeOf(this, AccessCertificateException.prototype);
|
|
13
|
+
this.name = "AccessCertificateException";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/constants.ts
|
|
18
|
+
/**
|
|
19
|
+
* Certificate policy identifiers defined in ETSI TS 119 411-8 clause 5.3.
|
|
20
|
+
*
|
|
21
|
+
* `{ itu-t(0) identified-organization(4) etsi(0) eudiwrp(194118) policy-identifiers(1) }`
|
|
22
|
+
*/
|
|
23
|
+
const ACCESS_CERTIFICATE_POLICIES = {
|
|
24
|
+
/** Normalized certificate policy for access certificates issued to natural persons */
|
|
25
|
+
"NCP-n-eudiwrp": "0.4.0.194118.1.1",
|
|
26
|
+
/** Normalized certificate policy for access certificates issued to legal persons */
|
|
27
|
+
"NCP-l-eudiwrp": "0.4.0.194118.1.2",
|
|
28
|
+
/** Qualified certificate policy for access certificates issued to natural persons */
|
|
29
|
+
"QCP-n-eudiwrp": "0.4.0.194118.1.3",
|
|
30
|
+
/** Qualified certificate policy for access certificates issued to legal persons */
|
|
31
|
+
"QCP-l-eudiwrp": "0.4.0.194118.1.4"
|
|
32
|
+
};
|
|
33
|
+
const ACCESS_CERTIFICATE_POLICY_INFO = {
|
|
34
|
+
"NCP-n-eudiwrp": {
|
|
35
|
+
subjectType: "natural",
|
|
36
|
+
qualified: false
|
|
37
|
+
},
|
|
38
|
+
"NCP-l-eudiwrp": {
|
|
39
|
+
subjectType: "legal",
|
|
40
|
+
qualified: false
|
|
41
|
+
},
|
|
42
|
+
"QCP-n-eudiwrp": {
|
|
43
|
+
subjectType: "natural",
|
|
44
|
+
qualified: true
|
|
45
|
+
},
|
|
46
|
+
"QCP-l-eudiwrp": {
|
|
47
|
+
subjectType: "legal",
|
|
48
|
+
qualified: true
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/semantic-identifier.ts
|
|
53
|
+
const SEMANTIC_IDENTIFIER = /^([A-Z]{3}|[A-Z]{2}:)([A-Z]{2})(?:\+([A-Z0-9]{1,3}))?-(.+)$/;
|
|
54
|
+
/**
|
|
55
|
+
* Parse a semantic identifier per ETSI EN 319 412-1 clauses 5.1.3 and 5.1.4
|
|
56
|
+
* (`<type><country>[+<subdivision>]-<identifier>`). Returns `undefined` when the
|
|
57
|
+
* value does not follow that structure.
|
|
58
|
+
*/
|
|
59
|
+
function parseSemanticIdentifier(value) {
|
|
60
|
+
const match = value.match(SEMANTIC_IDENTIFIER);
|
|
61
|
+
if (!match) return void 0;
|
|
62
|
+
const [, type, countryCode, subdivision, identifier] = match;
|
|
63
|
+
return {
|
|
64
|
+
value,
|
|
65
|
+
type,
|
|
66
|
+
countryCode,
|
|
67
|
+
subdivision,
|
|
68
|
+
identifier
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Identity type references for legal persons (ETSI EN 319 412-1 clause 5.1.4) */
|
|
72
|
+
const LEGAL_PERSON_IDENTIFIER_TYPES = [
|
|
73
|
+
"VAT",
|
|
74
|
+
"NTR",
|
|
75
|
+
"PSD",
|
|
76
|
+
"LEI"
|
|
77
|
+
];
|
|
78
|
+
/** Identity type references for natural persons (ETSI EN 319 412-1 clause 5.1.3) */
|
|
79
|
+
const NATURAL_PERSON_IDENTIFIER_TYPES = [
|
|
80
|
+
"PAS",
|
|
81
|
+
"IDC",
|
|
82
|
+
"PNO",
|
|
83
|
+
"TAX",
|
|
84
|
+
"TIN"
|
|
85
|
+
];
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/profile.ts
|
|
88
|
+
const POLICY_BY_OID = new Map(Object.entries(ACCESS_CERTIFICATE_POLICIES).map(([name, oid]) => [oid, name]));
|
|
89
|
+
function deriveSubjectType(policies, certificate) {
|
|
90
|
+
const types = new Set(policies.map((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].subjectType));
|
|
91
|
+
if (types.size === 1) return [...types][0];
|
|
92
|
+
if (types.size > 1) return void 0;
|
|
93
|
+
const { subject } = certificate;
|
|
94
|
+
if (subject.organizationIdentifier) return "legal";
|
|
95
|
+
if (subject.givenName || subject.surname || subject.pseudonym) return "natural";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Interpret a parsed X.509 certificate as a wallet-relying party access certificate
|
|
99
|
+
* (ETSI TS 119 411-8). This does not check conformance; use {@link validateAccessCertificate}.
|
|
100
|
+
*/
|
|
101
|
+
function toAccessCertificate(certificate) {
|
|
102
|
+
const policies = certificate.policies.map((p) => POLICY_BY_OID.get(p.oid)).filter((p) => p !== void 0);
|
|
103
|
+
const subjectType = deriveSubjectType(policies, certificate);
|
|
104
|
+
const identifier = subjectType === "natural" ? certificate.subject.serialNumber : certificate.subject.organizationIdentifier;
|
|
105
|
+
const san = certificate.subjectAlternativeNames;
|
|
106
|
+
return {
|
|
107
|
+
certificate,
|
|
108
|
+
policies,
|
|
109
|
+
subjectType,
|
|
110
|
+
qualified: policies.some((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].qualified),
|
|
111
|
+
subjectIdentifier: identifier ? parseSemanticIdentifier(identifier) : void 0,
|
|
112
|
+
contact: {
|
|
113
|
+
uris: san.uris,
|
|
114
|
+
emails: san.emails,
|
|
115
|
+
phoneNumbers: (0, _owf_x509.telephoneNumbers)(san)
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parse a wallet-relying party access certificate (ETSI TS 119 411-8).
|
|
121
|
+
*
|
|
122
|
+
* Shorthand for `toAccessCertificate(parseCertificate(input))`. Parsing only decodes the
|
|
123
|
+
* certificate; it does not check it against the profile or verify its signature.
|
|
124
|
+
*
|
|
125
|
+
* @param input DER bytes, base64 encoded DER, or PEM
|
|
126
|
+
* @throws X509Exception when the input is not a well-formed X.509 certificate
|
|
127
|
+
*/
|
|
128
|
+
function parseAccessCertificate(input) {
|
|
129
|
+
return toAccessCertificate((0, _owf_x509.parseCertificate)(input));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The semantic identifier of the wallet-relying party, i.e. the `organizationIdentifier`
|
|
133
|
+
* for legal persons or the `serialNumber` for natural persons. This is the value a
|
|
134
|
+
* registration certificate (ETSI TS 119 475) is bound to via its `sub` claim.
|
|
135
|
+
*/
|
|
136
|
+
function getAccessCertificateSubjectIdentifier(accessCertificate) {
|
|
137
|
+
const { subject } = accessCertificate.certificate;
|
|
138
|
+
return accessCertificate.subjectType === "natural" ? subject.serialNumber : subject.organizationIdentifier;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/validate.ts
|
|
142
|
+
const ACCESS_CERTIFICATE_VALIDATION_CODES = {
|
|
143
|
+
UNSUPPORTED_VERSION: "UNSUPPORTED_VERSION",
|
|
144
|
+
NOT_YET_VALID: "NOT_YET_VALID",
|
|
145
|
+
EXPIRED: "EXPIRED",
|
|
146
|
+
CA_CERTIFICATE: "CA_CERTIFICATE",
|
|
147
|
+
MISSING_DIGITAL_SIGNATURE_KEY_USAGE: "MISSING_DIGITAL_SIGNATURE_KEY_USAGE",
|
|
148
|
+
MISSING_POLICY: "MISSING_POLICY",
|
|
149
|
+
CONFLICTING_POLICIES: "CONFLICTING_POLICIES",
|
|
150
|
+
MISSING_CPS_URI: "MISSING_CPS_URI",
|
|
151
|
+
MISSING_CONTACT: "MISSING_CONTACT",
|
|
152
|
+
UNKNOWN_SUBJECT_TYPE: "UNKNOWN_SUBJECT_TYPE",
|
|
153
|
+
MISSING_COMMON_NAME: "MISSING_COMMON_NAME",
|
|
154
|
+
MISSING_COUNTRY_NAME: "MISSING_COUNTRY_NAME",
|
|
155
|
+
MISSING_ORGANIZATION_NAME: "MISSING_ORGANIZATION_NAME",
|
|
156
|
+
MISSING_ORGANIZATION_IDENTIFIER: "MISSING_ORGANIZATION_IDENTIFIER",
|
|
157
|
+
INVALID_ORGANIZATION_IDENTIFIER: "INVALID_ORGANIZATION_IDENTIFIER",
|
|
158
|
+
INVALID_GREECE_COUNTRY_CODE: "INVALID_GREECE_COUNTRY_CODE",
|
|
159
|
+
MISSING_NATURAL_PERSON_NAME: "MISSING_NATURAL_PERSON_NAME",
|
|
160
|
+
MISSING_SERIAL_NUMBER: "MISSING_SERIAL_NUMBER",
|
|
161
|
+
INVALID_SERIAL_NUMBER: "INVALID_SERIAL_NUMBER",
|
|
162
|
+
MISSING_QC_COMPLIANCE: "MISSING_QC_COMPLIANCE",
|
|
163
|
+
QC_TYPE_MISMATCH: "QC_TYPE_MISMATCH"
|
|
164
|
+
};
|
|
165
|
+
const C = ACCESS_CERTIFICATE_VALIDATION_CODES;
|
|
166
|
+
/**
|
|
167
|
+
* Check a parsed access certificate against the certificate profile of ETSI TS 119 411-8
|
|
168
|
+
* clause 6.6.1 and the profiles it references (ETSI EN 319 412-2 / 412-3 / 412-5).
|
|
169
|
+
*
|
|
170
|
+
* This checks the certificate content only. Signature, chain and revocation checks
|
|
171
|
+
* against the trusted list of access certificate providers are out of scope.
|
|
172
|
+
*/
|
|
173
|
+
function validateAccessCertificate(accessCertificate, options = {}) {
|
|
174
|
+
const { certificate } = accessCertificate;
|
|
175
|
+
const issues = [];
|
|
176
|
+
const add = (severity, code, message, requirement) => issues.push({
|
|
177
|
+
severity,
|
|
178
|
+
code,
|
|
179
|
+
message,
|
|
180
|
+
requirement
|
|
181
|
+
});
|
|
182
|
+
if (certificate.version !== 3) add("error", C.UNSUPPORTED_VERSION, `Expected an X.509 v3 certificate, got v${certificate.version}`);
|
|
183
|
+
if (options.now !== false) {
|
|
184
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
185
|
+
if (now < certificate.notBefore) add("error", C.NOT_YET_VALID, `Certificate is not valid before ${certificate.notBefore.toISOString()}`);
|
|
186
|
+
if (now > certificate.notAfter) add("error", C.EXPIRED, `Certificate expired at ${certificate.notAfter.toISOString()}`);
|
|
187
|
+
}
|
|
188
|
+
if (certificate.basicConstraints?.cA) add("error", C.CA_CERTIFICATE, "An access certificate must be an end-entity certificate (cA is true)");
|
|
189
|
+
if (certificate.keyUsage && !certificate.keyUsage.includes("digitalSignature")) add("warning", C.MISSING_DIGITAL_SIGNATURE_KEY_USAGE, "Key usage does not include digitalSignature, which is needed to authenticate the wallet-relying party");
|
|
190
|
+
const acceptedOids = new Set(options.acceptedPolicyOids ?? []);
|
|
191
|
+
const hasAcceptedCustomPolicy = certificate.policies.some((p) => acceptedOids.has(p.oid));
|
|
192
|
+
if (accessCertificate.policies.length === 0 && !hasAcceptedCustomPolicy) add("error", C.MISSING_POLICY, "Certificate does not contain an ETSI TS 119 411-8 certificate policy identifier", "GEN-6.6.1-03");
|
|
193
|
+
if (new Set(accessCertificate.policies.map((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].subjectType)).size > 1) add("error", C.CONFLICTING_POLICIES, `Certificate policies for both natural and legal persons are present: ${accessCertificate.policies.join(", ")}`, "GEN-6.6.1-03");
|
|
194
|
+
if (!certificate.policies.some((p) => p.cpsUris.length > 0)) add("error", C.MISSING_CPS_URI, "Certificate policies do not contain a cpsURI qualifier", "GEN-6.6.1-06");
|
|
195
|
+
const { uris, emails, phoneNumbers } = accessCertificate.contact;
|
|
196
|
+
if (uris.length + emails.length + phoneNumbers.length === 0) add("error", C.MISSING_CONTACT, "Subject alternative name must contain a website (URI), phone number (otherName telephoneNumber) or email address (rfc822Name)", "GEN-6.6.1-07");
|
|
197
|
+
const subject = certificate.subject;
|
|
198
|
+
const subjectType = options.subjectType ?? accessCertificate.subjectType;
|
|
199
|
+
if (!subject.commonName) add("error", C.MISSING_COMMON_NAME, "Subject commonName is missing");
|
|
200
|
+
if (!subject.countryName) add("error", C.MISSING_COUNTRY_NAME, "Subject countryName is missing");
|
|
201
|
+
if (subjectType === "legal") {
|
|
202
|
+
if (!subject.organizationName) add("error", C.MISSING_ORGANIZATION_NAME, "Subject organizationName is missing (ETSI EN 319 412-3)");
|
|
203
|
+
if (!subject.organizationIdentifier) add("error", C.MISSING_ORGANIZATION_IDENTIFIER, "Subject organizationIdentifier is missing", "GEN-6.6.1-05");
|
|
204
|
+
else {
|
|
205
|
+
const identifier = parseSemanticIdentifier(subject.organizationIdentifier);
|
|
206
|
+
if (!identifier) add("error", C.INVALID_ORGANIZATION_IDENTIFIER, `organizationIdentifier "${subject.organizationIdentifier}" is not encoded as specified in ETSI EN 319 412-1 clause 5.1.4`, "GEN-6.6.1-05");
|
|
207
|
+
else if (identifier.countryCode === "GR") add("error", C.INVALID_GREECE_COUNTRY_CODE, "organizationIdentifier must use the country code \"EL\" for Greece", "GEN-6.6.1-05");
|
|
208
|
+
}
|
|
209
|
+
} else if (subjectType === "natural") {
|
|
210
|
+
if (!(subject.givenName || subject.surname) && !subject.pseudonym) add("error", C.MISSING_NATURAL_PERSON_NAME, "Subject must contain givenName and/or surname, or a pseudonym (ETSI EN 319 412-2)");
|
|
211
|
+
if (!subject.serialNumber) add("warning", C.MISSING_SERIAL_NUMBER, "Subject serialNumber is missing; the wallet-relying party has no semantic identifier");
|
|
212
|
+
else if (!parseSemanticIdentifier(subject.serialNumber)) add("warning", C.INVALID_SERIAL_NUMBER, `serialNumber "${subject.serialNumber}" is not a semantic identifier as specified in ETSI EN 319 412-1 clause 5.1.3`);
|
|
213
|
+
} else add("error", C.UNKNOWN_SUBJECT_TYPE, "Unable to determine whether the subject is a natural or a legal person");
|
|
214
|
+
if (accessCertificate.qualified) {
|
|
215
|
+
if (!certificate.qcStatements?.qcCompliance) add("error", C.MISSING_QC_COMPLIANCE, "Qualified access certificates must contain the QcCompliance statement (ETSI EN 319 412-5)", "GEN-6.6.1-02");
|
|
216
|
+
const expectedType = subjectType === "natural" ? "esign" : subjectType === "legal" ? "eseal" : void 0;
|
|
217
|
+
const qcTypes = certificate.qcStatements?.qcTypes ?? [];
|
|
218
|
+
if (expectedType && !qcTypes.includes(expectedType)) add("warning", C.QC_TYPE_MISMATCH, `Expected QcType ${expectedType} for a ${subjectType} person, found ${qcTypes.length ? qcTypes.join(", ") : "none"}`, "GEN-6.6.1-02");
|
|
219
|
+
}
|
|
220
|
+
const errors = issues.filter((i) => i.severity === "error");
|
|
221
|
+
return {
|
|
222
|
+
valid: errors.length === 0,
|
|
223
|
+
errors,
|
|
224
|
+
warnings: issues.filter((i) => i.severity === "warning")
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Parse and validate an access certificate, throwing when it does not conform.
|
|
229
|
+
*
|
|
230
|
+
* @throws AccessCertificateException with the validation errors as details
|
|
231
|
+
*/
|
|
232
|
+
function parseAndValidateAccessCertificate(input, options) {
|
|
233
|
+
const accessCertificate = parseAccessCertificate(input);
|
|
234
|
+
assertValidAccessCertificate(accessCertificate, options);
|
|
235
|
+
return accessCertificate;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @throws AccessCertificateException with the validation errors as details
|
|
239
|
+
*/
|
|
240
|
+
function assertValidAccessCertificate(accessCertificate, options) {
|
|
241
|
+
const result = validateAccessCertificate(accessCertificate, options);
|
|
242
|
+
if (!result.valid) throw new AccessCertificateException(`Invalid access certificate: ${result.errors.map((e) => e.message).join("; ")}`, result.errors);
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/create.ts
|
|
246
|
+
function isLegalPerson(options) {
|
|
247
|
+
return ACCESS_CERTIFICATE_POLICY_INFO[options.policy]?.subjectType === "legal";
|
|
248
|
+
}
|
|
249
|
+
function subjectAttributes(options) {
|
|
250
|
+
const ous = (options.subject.organizationalUnitNames ?? []).map((ou) => ["organizationalUnitName", ou]);
|
|
251
|
+
if (isLegalPerson(options)) {
|
|
252
|
+
const s = options.subject;
|
|
253
|
+
return [
|
|
254
|
+
["countryName", s.countryName],
|
|
255
|
+
["stateOrProvinceName", s.stateOrProvinceName],
|
|
256
|
+
["localityName", s.localityName],
|
|
257
|
+
["organizationName", s.organizationName],
|
|
258
|
+
...ous,
|
|
259
|
+
["organizationIdentifier", s.organizationIdentifier],
|
|
260
|
+
["commonName", s.commonName]
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
const s = options.subject;
|
|
264
|
+
return [
|
|
265
|
+
["countryName", s.countryName],
|
|
266
|
+
...ous,
|
|
267
|
+
["givenName", s.givenName],
|
|
268
|
+
["surname", s.surname],
|
|
269
|
+
["pseudonym", s.pseudonym],
|
|
270
|
+
["serialNumber", s.serialNumber],
|
|
271
|
+
["commonName", s.commonName]
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
function assertInput(options) {
|
|
275
|
+
if (!ACCESS_CERTIFICATE_POLICIES[options.policy]) throw new AccessCertificateException(`Unknown access certificate policy: ${options.policy}`);
|
|
276
|
+
if (!options.cpsUri) throw new AccessCertificateException("cpsUri is required (GEN-6.6.1-06)");
|
|
277
|
+
const { uris = [], emails = [], phoneNumbers = [] } = options.contact;
|
|
278
|
+
if (uris.length + emails.length + phoneNumbers.length === 0) throw new AccessCertificateException("At least one contact website, email address or phone number is required (GEN-6.6.1-07)");
|
|
279
|
+
if (!/^[A-Z]{2}$/.test(options.subject.countryName)) throw new AccessCertificateException("countryName must be an ISO 3166-1 alpha-2 country code");
|
|
280
|
+
if (isLegalPerson(options)) {
|
|
281
|
+
const identifier = parseSemanticIdentifier(options.subject.organizationIdentifier);
|
|
282
|
+
if (!identifier) throw new AccessCertificateException("organizationIdentifier must be encoded as specified in ETSI EN 319 412-1 clause 5.1.4 (GEN-6.6.1-05)");
|
|
283
|
+
if (identifier.countryCode === "GR") throw new AccessCertificateException("organizationIdentifier must use the country code \"EL\" for Greece");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/** Map access certificate options to a generic `@owf/x509` certificate template. */
|
|
287
|
+
function toCertificateTemplate(options) {
|
|
288
|
+
assertInput(options);
|
|
289
|
+
const policyInfo = ACCESS_CERTIFICATE_POLICY_INFO[options.policy];
|
|
290
|
+
const cpsUris = [options.cpsUri];
|
|
291
|
+
const { uris = [], emails = [], phoneNumbers = [] } = options.contact;
|
|
292
|
+
return {
|
|
293
|
+
subject: subjectAttributes(options),
|
|
294
|
+
subjectPublicKey: options.subjectPublicKey,
|
|
295
|
+
issuerCertificate: options.issuerCertificate,
|
|
296
|
+
serialNumber: options.serialNumber,
|
|
297
|
+
notBefore: options.notBefore,
|
|
298
|
+
notAfter: options.notAfter,
|
|
299
|
+
signatureAlgorithm: options.signatureAlgorithm,
|
|
300
|
+
basicConstraints: { cA: false },
|
|
301
|
+
keyUsage: options.keyUsage ?? ["digitalSignature"],
|
|
302
|
+
extendedKeyUsage: options.extendedKeyUsage,
|
|
303
|
+
certificatePolicies: [{
|
|
304
|
+
oid: ACCESS_CERTIFICATE_POLICIES[options.policy],
|
|
305
|
+
cpsUris
|
|
306
|
+
}, ...(options.additionalPolicyOids ?? []).map((oid) => ({
|
|
307
|
+
oid,
|
|
308
|
+
cpsUris
|
|
309
|
+
}))],
|
|
310
|
+
subjectAlternativeNames: {
|
|
311
|
+
dnsNames: options.dnsNames,
|
|
312
|
+
uris,
|
|
313
|
+
emails,
|
|
314
|
+
otherNames: phoneNumbers.map((phone) => (0, _owf_x509.stringOtherName)(_owf_x509.ATTRIBUTE_TYPES.telephoneNumber, phone))
|
|
315
|
+
},
|
|
316
|
+
crlDistributionPoints: options.crlDistributionPoints,
|
|
317
|
+
ocspUrls: options.ocspUrls,
|
|
318
|
+
caIssuersUrls: options.caIssuersUrls,
|
|
319
|
+
qcStatements: policyInfo.qualified ? {
|
|
320
|
+
...options.qcStatements,
|
|
321
|
+
qcTypes: [policyInfo.subjectType === "legal" ? "eseal" : "esign"]
|
|
322
|
+
} : void 0,
|
|
323
|
+
hasher: options.hasher
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Build the TBSCertificate of an access certificate per ETSI TS 119 411-8 clause 6.6.1.
|
|
328
|
+
*
|
|
329
|
+
* Sign the returned `tbs` bytes with the issuing CA key wherever that key lives and pass the
|
|
330
|
+
* signature to {@link assembleAccessCertificate}. {@link createAccessCertificate} wraps both
|
|
331
|
+
* steps around a signer callback.
|
|
332
|
+
*/
|
|
333
|
+
function prepareAccessCertificate(options) {
|
|
334
|
+
return (0, _owf_x509.prepareCertificate)(toCertificateTemplate(options));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Combine a prepared TBSCertificate with the signature of the issuing CA.
|
|
338
|
+
*
|
|
339
|
+
* @param signatureEncoding Encoding of ECDSA signatures; WebCrypto produces `ieee-p1363` (default)
|
|
340
|
+
*/
|
|
341
|
+
function assembleAccessCertificate(prepared, signature, signatureEncoding) {
|
|
342
|
+
return toAccessCertificate((0, _owf_x509.assembleCertificate)(prepared, signature, signatureEncoding));
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Create a wallet-relying party access certificate per ETSI TS 119 411-8.
|
|
346
|
+
*
|
|
347
|
+
* The issuing CA key is never passed in: the `signer` callback receives the DER encoded
|
|
348
|
+
* TBSCertificate and returns the signature, so the key can stay in WebCrypto, a KMS or an HSM.
|
|
349
|
+
* Likewise only the public key of the wallet-relying party is needed; a JWK that contains
|
|
350
|
+
* private key material is rejected.
|
|
351
|
+
*
|
|
352
|
+
* @throws AccessCertificateException when the input or the resulting certificate does not
|
|
353
|
+
* satisfy the certificate profile
|
|
354
|
+
*/
|
|
355
|
+
async function createAccessCertificate(options) {
|
|
356
|
+
const prepared = await prepareAccessCertificate(options);
|
|
357
|
+
const accessCertificate = assembleAccessCertificate(prepared, await options.signer(prepared.tbs), options.signatureEncoding);
|
|
358
|
+
const result = validateAccessCertificate(accessCertificate, { now: false });
|
|
359
|
+
if (!result.valid) throw new AccessCertificateException(`Created access certificate does not conform: ${result.errors.map((e) => e.message).join("; ")}`, result.errors);
|
|
360
|
+
return accessCertificate;
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
exports.ACCESS_CERTIFICATE_POLICIES = ACCESS_CERTIFICATE_POLICIES;
|
|
364
|
+
exports.ACCESS_CERTIFICATE_POLICY_INFO = ACCESS_CERTIFICATE_POLICY_INFO;
|
|
365
|
+
exports.ACCESS_CERTIFICATE_VALIDATION_CODES = ACCESS_CERTIFICATE_VALIDATION_CODES;
|
|
366
|
+
exports.AccessCertificateException = AccessCertificateException;
|
|
367
|
+
exports.LEGAL_PERSON_IDENTIFIER_TYPES = LEGAL_PERSON_IDENTIFIER_TYPES;
|
|
368
|
+
exports.NATURAL_PERSON_IDENTIFIER_TYPES = NATURAL_PERSON_IDENTIFIER_TYPES;
|
|
369
|
+
exports.assembleAccessCertificate = assembleAccessCertificate;
|
|
370
|
+
exports.assertValidAccessCertificate = assertValidAccessCertificate;
|
|
371
|
+
exports.createAccessCertificate = createAccessCertificate;
|
|
372
|
+
exports.getAccessCertificateSubjectIdentifier = getAccessCertificateSubjectIdentifier;
|
|
373
|
+
exports.parseAccessCertificate = parseAccessCertificate;
|
|
374
|
+
exports.parseAndValidateAccessCertificate = parseAndValidateAccessCertificate;
|
|
375
|
+
exports.parseSemanticIdentifier = parseSemanticIdentifier;
|
|
376
|
+
exports.prepareAccessCertificate = prepareAccessCertificate;
|
|
377
|
+
exports.toAccessCertificate = toAccessCertificate;
|
|
378
|
+
exports.toCertificateTemplate = toCertificateTemplate;
|
|
379
|
+
exports.validateAccessCertificate = validateAccessCertificate;
|
|
380
|
+
|
|
381
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["IdentityException","telephoneNumbers","parseCertificate","stringOtherName","ATTRIBUTE_TYPES","prepareCertificate","assembleCertificate"],"sources":["../src/access-certificate-exception.ts","../src/constants.ts","../src/semantic-identifier.ts","../src/profile.ts","../src/validate.ts","../src/create.ts"],"sourcesContent":["import { IdentityException } from '@owf/identity-common'\n\n/**\n * AccessCertificateException is thrown when an access certificate cannot be\n * parsed, fails validation in an assert helper, or cannot be created.\n */\nexport class AccessCertificateException extends IdentityException {\n constructor(message: string, details?: unknown) {\n super(message, details)\n Object.setPrototypeOf(this, AccessCertificateException.prototype)\n this.name = 'AccessCertificateException'\n }\n}\n","/**\n * Certificate policy identifiers defined in ETSI TS 119 411-8 clause 5.3.\n *\n * `{ itu-t(0) identified-organization(4) etsi(0) eudiwrp(194118) policy-identifiers(1) }`\n */\nexport const ACCESS_CERTIFICATE_POLICIES = {\n /** Normalized certificate policy for access certificates issued to natural persons */\n 'NCP-n-eudiwrp': '0.4.0.194118.1.1',\n /** Normalized certificate policy for access certificates issued to legal persons */\n 'NCP-l-eudiwrp': '0.4.0.194118.1.2',\n /** Qualified certificate policy for access certificates issued to natural persons */\n 'QCP-n-eudiwrp': '0.4.0.194118.1.3',\n /** Qualified certificate policy for access certificates issued to legal persons */\n 'QCP-l-eudiwrp': '0.4.0.194118.1.4',\n} as const\n\nexport type AccessCertificatePolicy = keyof typeof ACCESS_CERTIFICATE_POLICIES\n\n/** Whether an access certificate is issued to a natural or a legal person */\nexport type AccessCertificateSubjectType = 'natural' | 'legal'\n\nexport const ACCESS_CERTIFICATE_POLICY_INFO: Record<\n AccessCertificatePolicy,\n { subjectType: AccessCertificateSubjectType; qualified: boolean }\n> = {\n 'NCP-n-eudiwrp': { subjectType: 'natural', qualified: false },\n 'NCP-l-eudiwrp': { subjectType: 'legal', qualified: false },\n 'QCP-n-eudiwrp': { subjectType: 'natural', qualified: true },\n 'QCP-l-eudiwrp': { subjectType: 'legal', qualified: true },\n}\n","import type { SemanticIdentifier } from './types'\n\nconst SEMANTIC_IDENTIFIER = /^([A-Z]{3}|[A-Z]{2}:)([A-Z]{2})(?:\\+([A-Z0-9]{1,3}))?-(.+)$/\n\n/**\n * Parse a semantic identifier per ETSI EN 319 412-1 clauses 5.1.3 and 5.1.4\n * (`<type><country>[+<subdivision>]-<identifier>`). Returns `undefined` when the\n * value does not follow that structure.\n */\nexport function parseSemanticIdentifier(value: string): SemanticIdentifier | undefined {\n const match = value.match(SEMANTIC_IDENTIFIER)\n if (!match) return undefined\n const [, type, countryCode, subdivision, identifier] = match\n return { value, type, countryCode, subdivision, identifier }\n}\n\n/** Identity type references for legal persons (ETSI EN 319 412-1 clause 5.1.4) */\nexport const LEGAL_PERSON_IDENTIFIER_TYPES = ['VAT', 'NTR', 'PSD', 'LEI'] as const\n\n/** Identity type references for natural persons (ETSI EN 319 412-1 clause 5.1.3) */\nexport const NATURAL_PERSON_IDENTIFIER_TYPES = ['PAS', 'IDC', 'PNO', 'TAX', 'TIN'] as const\n","import { type Certificate, type CertificateInput, parseCertificate, telephoneNumbers } from '@owf/x509'\nimport {\n ACCESS_CERTIFICATE_POLICIES,\n ACCESS_CERTIFICATE_POLICY_INFO,\n type AccessCertificatePolicy,\n type AccessCertificateSubjectType,\n} from './constants'\nimport { parseSemanticIdentifier } from './semantic-identifier'\nimport type { AccessCertificate } from './types'\n\nconst POLICY_BY_OID = new Map<string, AccessCertificatePolicy>(\n Object.entries(ACCESS_CERTIFICATE_POLICIES).map(([name, oid]) => [oid, name as AccessCertificatePolicy])\n)\n\nfunction deriveSubjectType(\n policies: AccessCertificatePolicy[],\n certificate: Certificate\n): AccessCertificateSubjectType | undefined {\n const types = new Set(policies.map((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].subjectType))\n if (types.size === 1) return [...types][0]\n if (types.size > 1) return undefined\n const { subject } = certificate\n if (subject.organizationIdentifier) return 'legal'\n if (subject.givenName || subject.surname || subject.pseudonym) return 'natural'\n return undefined\n}\n\n/**\n * Interpret a parsed X.509 certificate as a wallet-relying party access certificate\n * (ETSI TS 119 411-8). This does not check conformance; use {@link validateAccessCertificate}.\n */\nexport function toAccessCertificate(certificate: Certificate): AccessCertificate {\n const policies = certificate.policies\n .map((p) => POLICY_BY_OID.get(p.oid))\n .filter((p): p is AccessCertificatePolicy => p !== undefined)\n const subjectType = deriveSubjectType(policies, certificate)\n const identifier =\n subjectType === 'natural' ? certificate.subject.serialNumber : certificate.subject.organizationIdentifier\n const san = certificate.subjectAlternativeNames\n\n return {\n certificate,\n policies,\n subjectType,\n qualified: policies.some((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].qualified),\n subjectIdentifier: identifier ? parseSemanticIdentifier(identifier) : undefined,\n contact: { uris: san.uris, emails: san.emails, phoneNumbers: telephoneNumbers(san) },\n }\n}\n\n/**\n * Parse a wallet-relying party access certificate (ETSI TS 119 411-8).\n *\n * Shorthand for `toAccessCertificate(parseCertificate(input))`. Parsing only decodes the\n * certificate; it does not check it against the profile or verify its signature.\n *\n * @param input DER bytes, base64 encoded DER, or PEM\n * @throws X509Exception when the input is not a well-formed X.509 certificate\n */\nexport function parseAccessCertificate(input: CertificateInput): AccessCertificate {\n return toAccessCertificate(parseCertificate(input))\n}\n\n/**\n * The semantic identifier of the wallet-relying party, i.e. the `organizationIdentifier`\n * for legal persons or the `serialNumber` for natural persons. This is the value a\n * registration certificate (ETSI TS 119 475) is bound to via its `sub` claim.\n */\nexport function getAccessCertificateSubjectIdentifier(accessCertificate: AccessCertificate): string | undefined {\n const { subject } = accessCertificate.certificate\n return accessCertificate.subjectType === 'natural' ? subject.serialNumber : subject.organizationIdentifier\n}\n","import type { CertificateInput } from '@owf/x509'\nimport { AccessCertificateException } from './access-certificate-exception'\nimport { ACCESS_CERTIFICATE_POLICY_INFO } from './constants'\nimport { parseAccessCertificate } from './profile'\nimport { parseSemanticIdentifier } from './semantic-identifier'\nimport type {\n AccessCertificate,\n AccessCertificateValidationIssue,\n AccessCertificateValidationOptions,\n AccessCertificateValidationSeverity,\n} from './types'\n\nexport const ACCESS_CERTIFICATE_VALIDATION_CODES = {\n UNSUPPORTED_VERSION: 'UNSUPPORTED_VERSION',\n NOT_YET_VALID: 'NOT_YET_VALID',\n EXPIRED: 'EXPIRED',\n CA_CERTIFICATE: 'CA_CERTIFICATE',\n MISSING_DIGITAL_SIGNATURE_KEY_USAGE: 'MISSING_DIGITAL_SIGNATURE_KEY_USAGE',\n MISSING_POLICY: 'MISSING_POLICY',\n CONFLICTING_POLICIES: 'CONFLICTING_POLICIES',\n MISSING_CPS_URI: 'MISSING_CPS_URI',\n MISSING_CONTACT: 'MISSING_CONTACT',\n UNKNOWN_SUBJECT_TYPE: 'UNKNOWN_SUBJECT_TYPE',\n MISSING_COMMON_NAME: 'MISSING_COMMON_NAME',\n MISSING_COUNTRY_NAME: 'MISSING_COUNTRY_NAME',\n MISSING_ORGANIZATION_NAME: 'MISSING_ORGANIZATION_NAME',\n MISSING_ORGANIZATION_IDENTIFIER: 'MISSING_ORGANIZATION_IDENTIFIER',\n INVALID_ORGANIZATION_IDENTIFIER: 'INVALID_ORGANIZATION_IDENTIFIER',\n INVALID_GREECE_COUNTRY_CODE: 'INVALID_GREECE_COUNTRY_CODE',\n MISSING_NATURAL_PERSON_NAME: 'MISSING_NATURAL_PERSON_NAME',\n MISSING_SERIAL_NUMBER: 'MISSING_SERIAL_NUMBER',\n INVALID_SERIAL_NUMBER: 'INVALID_SERIAL_NUMBER',\n MISSING_QC_COMPLIANCE: 'MISSING_QC_COMPLIANCE',\n QC_TYPE_MISMATCH: 'QC_TYPE_MISMATCH',\n} as const\n\nexport type AccessCertificateValidationCode =\n (typeof ACCESS_CERTIFICATE_VALIDATION_CODES)[keyof typeof ACCESS_CERTIFICATE_VALIDATION_CODES]\n\nexport type AccessCertificateIssue = AccessCertificateValidationIssue<AccessCertificateValidationCode>\n\nexport interface AccessCertificateValidationResult {\n /** `true` when there are no errors; warnings do not affect validity */\n valid: boolean\n errors: AccessCertificateIssue[]\n warnings: AccessCertificateIssue[]\n}\n\nconst C = ACCESS_CERTIFICATE_VALIDATION_CODES\n\n/**\n * Check a parsed access certificate against the certificate profile of ETSI TS 119 411-8\n * clause 6.6.1 and the profiles it references (ETSI EN 319 412-2 / 412-3 / 412-5).\n *\n * This checks the certificate content only. Signature, chain and revocation checks\n * against the trusted list of access certificate providers are out of scope.\n */\nexport function validateAccessCertificate(\n accessCertificate: AccessCertificate,\n options: AccessCertificateValidationOptions = {}\n): AccessCertificateValidationResult {\n const { certificate } = accessCertificate\n const issues: AccessCertificateIssue[] = []\n const add = (\n severity: AccessCertificateValidationSeverity,\n code: AccessCertificateValidationCode,\n message: string,\n requirement?: string\n ) => issues.push({ severity, code, message, requirement })\n\n // X.509 basics\n if (certificate.version !== 3) {\n add('error', C.UNSUPPORTED_VERSION, `Expected an X.509 v3 certificate, got v${certificate.version}`)\n }\n if (options.now !== false) {\n const now = options.now ?? new Date()\n if (now < certificate.notBefore) {\n add('error', C.NOT_YET_VALID, `Certificate is not valid before ${certificate.notBefore.toISOString()}`)\n }\n if (now > certificate.notAfter) {\n add('error', C.EXPIRED, `Certificate expired at ${certificate.notAfter.toISOString()}`)\n }\n }\n if (certificate.basicConstraints?.cA) {\n add('error', C.CA_CERTIFICATE, 'An access certificate must be an end-entity certificate (cA is true)')\n }\n if (certificate.keyUsage && !certificate.keyUsage.includes('digitalSignature')) {\n add(\n 'warning',\n C.MISSING_DIGITAL_SIGNATURE_KEY_USAGE,\n 'Key usage does not include digitalSignature, which is needed to authenticate the wallet-relying party'\n )\n }\n\n // GEN-6.6.1-03: policy identifiers\n const acceptedOids = new Set(options.acceptedPolicyOids ?? [])\n const hasAcceptedCustomPolicy = certificate.policies.some((p) => acceptedOids.has(p.oid))\n if (accessCertificate.policies.length === 0 && !hasAcceptedCustomPolicy) {\n add(\n 'error',\n C.MISSING_POLICY,\n 'Certificate does not contain an ETSI TS 119 411-8 certificate policy identifier',\n 'GEN-6.6.1-03'\n )\n }\n const policySubjectTypes = new Set(\n accessCertificate.policies.map((p) => ACCESS_CERTIFICATE_POLICY_INFO[p].subjectType)\n )\n if (policySubjectTypes.size > 1) {\n add(\n 'error',\n C.CONFLICTING_POLICIES,\n `Certificate policies for both natural and legal persons are present: ${accessCertificate.policies.join(', ')}`,\n 'GEN-6.6.1-03'\n )\n }\n\n // GEN-6.6.1-06: CPS URI\n if (!certificate.policies.some((p) => p.cpsUris.length > 0)) {\n add('error', C.MISSING_CPS_URI, 'Certificate policies do not contain a cpsURI qualifier', 'GEN-6.6.1-06')\n }\n\n // GEN-6.6.1-07: contact information in the SAN\n const { uris, emails, phoneNumbers } = accessCertificate.contact\n if (uris.length + emails.length + phoneNumbers.length === 0) {\n add(\n 'error',\n C.MISSING_CONTACT,\n 'Subject alternative name must contain a website (URI), phone number (otherName telephoneNumber) or email address (rfc822Name)',\n 'GEN-6.6.1-07'\n )\n }\n\n // Subject naming\n const subject = certificate.subject\n const subjectType = options.subjectType ?? accessCertificate.subjectType\n if (!subject.commonName) add('error', C.MISSING_COMMON_NAME, 'Subject commonName is missing')\n if (!subject.countryName) add('error', C.MISSING_COUNTRY_NAME, 'Subject countryName is missing')\n\n if (subjectType === 'legal') {\n if (!subject.organizationName) {\n add('error', C.MISSING_ORGANIZATION_NAME, 'Subject organizationName is missing (ETSI EN 319 412-3)')\n }\n if (!subject.organizationIdentifier) {\n add('error', C.MISSING_ORGANIZATION_IDENTIFIER, 'Subject organizationIdentifier is missing', 'GEN-6.6.1-05')\n } else {\n const identifier = parseSemanticIdentifier(subject.organizationIdentifier)\n if (!identifier) {\n add(\n 'error',\n C.INVALID_ORGANIZATION_IDENTIFIER,\n `organizationIdentifier \"${subject.organizationIdentifier}\" is not encoded as specified in ETSI EN 319 412-1 clause 5.1.4`,\n 'GEN-6.6.1-05'\n )\n } else if (identifier.countryCode === 'GR') {\n add(\n 'error',\n C.INVALID_GREECE_COUNTRY_CODE,\n 'organizationIdentifier must use the country code \"EL\" for Greece',\n 'GEN-6.6.1-05'\n )\n }\n }\n } else if (subjectType === 'natural') {\n if (!(subject.givenName || subject.surname) && !subject.pseudonym) {\n add(\n 'error',\n C.MISSING_NATURAL_PERSON_NAME,\n 'Subject must contain givenName and/or surname, or a pseudonym (ETSI EN 319 412-2)'\n )\n }\n if (!subject.serialNumber) {\n add(\n 'warning',\n C.MISSING_SERIAL_NUMBER,\n 'Subject serialNumber is missing; the wallet-relying party has no semantic identifier'\n )\n } else if (!parseSemanticIdentifier(subject.serialNumber)) {\n add(\n 'warning',\n C.INVALID_SERIAL_NUMBER,\n `serialNumber \"${subject.serialNumber}\" is not a semantic identifier as specified in ETSI EN 319 412-1 clause 5.1.3`\n )\n }\n } else {\n add('error', C.UNKNOWN_SUBJECT_TYPE, 'Unable to determine whether the subject is a natural or a legal person')\n }\n\n // GEN-6.6.1-02: qualified certificates follow ETSI EN 319 412-5\n if (accessCertificate.qualified) {\n if (!certificate.qcStatements?.qcCompliance) {\n add(\n 'error',\n C.MISSING_QC_COMPLIANCE,\n 'Qualified access certificates must contain the QcCompliance statement (ETSI EN 319 412-5)',\n 'GEN-6.6.1-02'\n )\n }\n const expectedType = subjectType === 'natural' ? 'esign' : subjectType === 'legal' ? 'eseal' : undefined\n const qcTypes = certificate.qcStatements?.qcTypes ?? []\n if (expectedType && !qcTypes.includes(expectedType)) {\n add(\n 'warning',\n C.QC_TYPE_MISMATCH,\n `Expected QcType ${expectedType} for a ${subjectType} person, found ${qcTypes.length ? qcTypes.join(', ') : 'none'}`,\n 'GEN-6.6.1-02'\n )\n }\n }\n\n const errors = issues.filter((i) => i.severity === 'error')\n return { valid: errors.length === 0, errors, warnings: issues.filter((i) => i.severity === 'warning') }\n}\n\n/**\n * Parse and validate an access certificate, throwing when it does not conform.\n *\n * @throws AccessCertificateException with the validation errors as details\n */\nexport function parseAndValidateAccessCertificate(\n input: CertificateInput,\n options?: AccessCertificateValidationOptions\n): AccessCertificate {\n const accessCertificate = parseAccessCertificate(input)\n assertValidAccessCertificate(accessCertificate, options)\n return accessCertificate\n}\n\n/**\n * @throws AccessCertificateException with the validation errors as details\n */\nexport function assertValidAccessCertificate(\n accessCertificate: AccessCertificate,\n options?: AccessCertificateValidationOptions\n): void {\n const result = validateAccessCertificate(accessCertificate, options)\n if (!result.valid) {\n throw new AccessCertificateException(\n `Invalid access certificate: ${result.errors.map((e) => e.message).join('; ')}`,\n result.errors\n )\n }\n}\n","import {\n ATTRIBUTE_TYPES,\n assembleCertificate,\n type CertificateTemplate,\n type NameAttributeInput,\n prepareCertificate,\n type SignatureEncoding,\n stringOtherName,\n} from '@owf/x509'\nimport { AccessCertificateException } from './access-certificate-exception'\nimport { ACCESS_CERTIFICATE_POLICIES, ACCESS_CERTIFICATE_POLICY_INFO } from './constants'\nimport { toAccessCertificate } from './profile'\nimport { parseSemanticIdentifier } from './semantic-identifier'\nimport type {\n AccessCertificate,\n CreateAccessCertificateOptions,\n LegalPersonAccessCertificateOptions,\n NaturalPersonSubjectInput,\n PrepareAccessCertificateOptions,\n PreparedAccessCertificate,\n} from './types'\nimport { validateAccessCertificate } from './validate'\n\nfunction isLegalPerson(options: PrepareAccessCertificateOptions): options is LegalPersonAccessCertificateOptions {\n return ACCESS_CERTIFICATE_POLICY_INFO[options.policy]?.subjectType === 'legal'\n}\n\nfunction subjectAttributes(options: PrepareAccessCertificateOptions): NameAttributeInput[] {\n const ous = (options.subject.organizationalUnitNames ?? []).map(\n (ou): NameAttributeInput => ['organizationalUnitName', ou]\n )\n if (isLegalPerson(options)) {\n const s = options.subject\n return [\n ['countryName', s.countryName],\n ['stateOrProvinceName', s.stateOrProvinceName],\n ['localityName', s.localityName],\n ['organizationName', s.organizationName],\n ...ous,\n ['organizationIdentifier', s.organizationIdentifier],\n ['commonName', s.commonName],\n ]\n }\n const s = options.subject as NaturalPersonSubjectInput\n return [\n ['countryName', s.countryName],\n ...ous,\n ['givenName', s.givenName],\n ['surname', s.surname],\n ['pseudonym', s.pseudonym],\n ['serialNumber', s.serialNumber],\n ['commonName', s.commonName],\n ]\n}\n\nfunction assertInput(options: PrepareAccessCertificateOptions): void {\n if (!ACCESS_CERTIFICATE_POLICIES[options.policy]) {\n throw new AccessCertificateException(`Unknown access certificate policy: ${options.policy}`)\n }\n if (!options.cpsUri) {\n throw new AccessCertificateException('cpsUri is required (GEN-6.6.1-06)')\n }\n const { uris = [], emails = [], phoneNumbers = [] } = options.contact\n if (uris.length + emails.length + phoneNumbers.length === 0) {\n throw new AccessCertificateException(\n 'At least one contact website, email address or phone number is required (GEN-6.6.1-07)'\n )\n }\n if (!/^[A-Z]{2}$/.test(options.subject.countryName)) {\n throw new AccessCertificateException('countryName must be an ISO 3166-1 alpha-2 country code')\n }\n if (isLegalPerson(options)) {\n const identifier = parseSemanticIdentifier(options.subject.organizationIdentifier)\n if (!identifier) {\n throw new AccessCertificateException(\n 'organizationIdentifier must be encoded as specified in ETSI EN 319 412-1 clause 5.1.4 (GEN-6.6.1-05)'\n )\n }\n if (identifier.countryCode === 'GR') {\n throw new AccessCertificateException('organizationIdentifier must use the country code \"EL\" for Greece')\n }\n }\n}\n\n/** Map access certificate options to a generic `@owf/x509` certificate template. */\nexport function toCertificateTemplate(options: PrepareAccessCertificateOptions): CertificateTemplate {\n assertInput(options)\n const policyInfo = ACCESS_CERTIFICATE_POLICY_INFO[options.policy]\n const cpsUris = [options.cpsUri]\n const { uris = [], emails = [], phoneNumbers = [] } = options.contact\n\n return {\n subject: subjectAttributes(options),\n subjectPublicKey: options.subjectPublicKey,\n issuerCertificate: options.issuerCertificate,\n serialNumber: options.serialNumber,\n notBefore: options.notBefore,\n notAfter: options.notAfter,\n signatureAlgorithm: options.signatureAlgorithm,\n basicConstraints: { cA: false },\n keyUsage: options.keyUsage ?? ['digitalSignature'],\n extendedKeyUsage: options.extendedKeyUsage,\n certificatePolicies: [\n { oid: ACCESS_CERTIFICATE_POLICIES[options.policy], cpsUris },\n ...(options.additionalPolicyOids ?? []).map((oid) => ({ oid, cpsUris })),\n ],\n subjectAlternativeNames: {\n dnsNames: options.dnsNames,\n uris,\n emails,\n otherNames: phoneNumbers.map((phone) => stringOtherName(ATTRIBUTE_TYPES.telephoneNumber, phone)),\n },\n crlDistributionPoints: options.crlDistributionPoints,\n ocspUrls: options.ocspUrls,\n caIssuersUrls: options.caIssuersUrls,\n qcStatements: policyInfo.qualified\n ? { ...options.qcStatements, qcTypes: [policyInfo.subjectType === 'legal' ? 'eseal' : 'esign'] }\n : undefined,\n hasher: options.hasher,\n }\n}\n\n/**\n * Build the TBSCertificate of an access certificate per ETSI TS 119 411-8 clause 6.6.1.\n *\n * Sign the returned `tbs` bytes with the issuing CA key wherever that key lives and pass the\n * signature to {@link assembleAccessCertificate}. {@link createAccessCertificate} wraps both\n * steps around a signer callback.\n */\nexport function prepareAccessCertificate(options: PrepareAccessCertificateOptions): Promise<PreparedAccessCertificate> {\n return prepareCertificate(toCertificateTemplate(options))\n}\n\n/**\n * Combine a prepared TBSCertificate with the signature of the issuing CA.\n *\n * @param signatureEncoding Encoding of ECDSA signatures; WebCrypto produces `ieee-p1363` (default)\n */\nexport function assembleAccessCertificate(\n prepared: PreparedAccessCertificate,\n signature: Uint8Array,\n signatureEncoding?: SignatureEncoding\n): AccessCertificate {\n return toAccessCertificate(assembleCertificate(prepared, signature, signatureEncoding))\n}\n\n/**\n * Create a wallet-relying party access certificate per ETSI TS 119 411-8.\n *\n * The issuing CA key is never passed in: the `signer` callback receives the DER encoded\n * TBSCertificate and returns the signature, so the key can stay in WebCrypto, a KMS or an HSM.\n * Likewise only the public key of the wallet-relying party is needed; a JWK that contains\n * private key material is rejected.\n *\n * @throws AccessCertificateException when the input or the resulting certificate does not\n * satisfy the certificate profile\n */\nexport async function createAccessCertificate(options: CreateAccessCertificateOptions): Promise<AccessCertificate> {\n const prepared = await prepareAccessCertificate(options)\n const signature = await options.signer(prepared.tbs)\n const accessCertificate = assembleAccessCertificate(prepared, signature, options.signatureEncoding)\n\n const result = validateAccessCertificate(accessCertificate, { now: false })\n if (!result.valid) {\n throw new AccessCertificateException(\n `Created access certificate does not conform: ${result.errors.map((e) => e.message).join('; ')}`,\n result.errors\n )\n }\n return accessCertificate\n}\n"],"mappings":";;;;;;;;AAMA,IAAa,6BAAb,MAAa,mCAAmCA,qBAAAA,kBAAkB;CAChE,YAAY,SAAiB,SAAmB;EAC9C,MAAM,SAAS,OAAO;EACtB,OAAO,eAAe,MAAM,2BAA2B,SAAS;EAChE,KAAK,OAAO;CACd;AACF;;;;;;;;ACPA,MAAa,8BAA8B;;CAEzC,iBAAiB;;CAEjB,iBAAiB;;CAEjB,iBAAiB;;CAEjB,iBAAiB;AACnB;AAOA,MAAa,iCAGT;CACF,iBAAiB;EAAE,aAAa;EAAW,WAAW;CAAM;CAC5D,iBAAiB;EAAE,aAAa;EAAS,WAAW;CAAM;CAC1D,iBAAiB;EAAE,aAAa;EAAW,WAAW;CAAK;CAC3D,iBAAiB;EAAE,aAAa;EAAS,WAAW;CAAK;AAC3D;;;AC3BA,MAAM,sBAAsB;;;;;;AAO5B,SAAgB,wBAAwB,OAA+C;CACrF,MAAM,QAAQ,MAAM,MAAM,mBAAmB;CAC7C,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,MAAM,GAAG,MAAM,aAAa,aAAa,cAAc;CACvD,OAAO;EAAE;EAAO;EAAM;EAAa;EAAa;CAAW;AAC7D;;AAGA,MAAa,gCAAgC;CAAC;CAAO;CAAO;CAAO;AAAK;;AAGxE,MAAa,kCAAkC;CAAC;CAAO;CAAO;CAAO;CAAO;AAAK;;;ACVjF,MAAM,gBAAgB,IAAI,IACxB,OAAO,QAAQ,2BAA2B,CAAC,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,KAAK,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