@pagopa/io-react-native-wallet 2.0.0-next.0 → 2.0.0-next.1
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/lib/commonjs/trust/README.md +147 -0
- package/lib/commonjs/trust/chain.js +47 -10
- package/lib/commonjs/trust/chain.js.map +1 -1
- package/lib/commonjs/trust/errors.js +24 -1
- package/lib/commonjs/trust/errors.js.map +1 -1
- package/lib/commonjs/trust/index.js +11 -5
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/trust/utils.js +30 -1
- package/lib/commonjs/trust/utils.js.map +1 -1
- package/lib/module/trust/README.md +147 -0
- package/lib/module/trust/chain.js +49 -12
- package/lib/module/trust/chain.js.map +1 -1
- package/lib/module/trust/errors.js +23 -2
- package/lib/module/trust/errors.js.map +1 -1
- package/lib/module/trust/index.js +11 -5
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/trust/utils.js +27 -0
- package/lib/module/trust/utils.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +12 -12
- package/lib/typescript/credential/presentation/types.d.ts +4 -4
- package/lib/typescript/credential/status/types.d.ts +6 -6
- package/lib/typescript/sd-jwt/index.d.ts +12 -12
- package/lib/typescript/sd-jwt/types.d.ts +6 -6
- package/lib/typescript/trust/chain.d.ts +8 -6
- package/lib/typescript/trust/chain.d.ts.map +1 -1
- package/lib/typescript/trust/errors.d.ts +22 -0
- package/lib/typescript/trust/errors.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +208 -206
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +559 -559
- package/lib/typescript/trust/utils.d.ts +10 -0
- package/lib/typescript/trust/utils.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +25 -25
- package/package.json +2 -2
- package/src/trust/README.md +147 -0
- package/src/trust/chain.ts +91 -15
- package/src/trust/errors.ts +32 -1
- package/src/trust/index.ts +11 -4
- package/src/trust/utils.ts +35 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
# Trust Chain Validation
|
2
|
+
|
3
|
+
This module implements **Trust Chain validation** for Entity Configurations and Entity Statements in line with the [IT Wallet Federation Specifications](https://italia.github.io/eid-wallet-it-docs/). It ensures that an entity's metadata is trusted by validating a chain of signed JWTs up to a known Trust Anchor.
|
4
|
+
|
5
|
+
The validation covers:
|
6
|
+
|
7
|
+
* JWT signature verification (using the next entity's JWKS)
|
8
|
+
* Trust chain ordering (leaf → parent → Trust Anchor)
|
9
|
+
* Optional X.509 CRL-based certificate validation
|
10
|
+
|
11
|
+
## Sequence Diagram
|
12
|
+
|
13
|
+
```mermaid
|
14
|
+
sequenceDiagram
|
15
|
+
autonumber
|
16
|
+
participant A as Leaf Entity
|
17
|
+
participant B as Intermediate (Federation Authority)
|
18
|
+
participant C as Trust Anchor
|
19
|
+
|
20
|
+
A->>A: Self-issued Entity Configuration (JWT)
|
21
|
+
B->>A: Signed Entity Statement (JWT)
|
22
|
+
C->>B: Signed Entity Statement (JWT or self-issued EC)
|
23
|
+
|
24
|
+
Note over A,C: Each JWT is validated with the next issuer's public keys
|
25
|
+
```
|
26
|
+
|
27
|
+
## Errors
|
28
|
+
|
29
|
+
| Error | Description |
|
30
|
+
| ----------------------------- | ------------------------------------------------------------------ |
|
31
|
+
| `TrustChainEmptyError` | The input chain is empty. |
|
32
|
+
| `TrustChainTokenMissingError` | One of the JWTs in the chain is missing. |
|
33
|
+
| `X509ValidationError` | X.509 certificate validation failed (e.g. revocation, expiration). |
|
34
|
+
| `FederationError` | Generic federation processing error. |
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
### Validate a trust chain
|
39
|
+
|
40
|
+
```ts
|
41
|
+
import { validateTrustChain } from "./trust";
|
42
|
+
import { trustAnchorEntityConfiguration } from "./your-data";
|
43
|
+
import { chain } from "./your-data"; // array of JWTs, starting from leaf
|
44
|
+
|
45
|
+
const result = await validateTrustChain(trustAnchorEntityConfiguration, chain, {
|
46
|
+
connectTimeout: 3000,
|
47
|
+
readTimeout: 3000,
|
48
|
+
requireCrl: false,
|
49
|
+
});
|
50
|
+
```
|
51
|
+
|
52
|
+
* The `chain` must be an array of signed JWT strings.
|
53
|
+
* The first JWT must be a self-issued `EntityConfiguration`.
|
54
|
+
* The last JWT must be an `EntityStatement` or a self-issued Trust Anchor `EntityConfiguration`.
|
55
|
+
|
56
|
+
### Renew a trust chain
|
57
|
+
|
58
|
+
```ts
|
59
|
+
import { renewTrustChain } from "./trust";
|
60
|
+
|
61
|
+
const newChain = await renewTrustChain(chain);
|
62
|
+
```
|
63
|
+
|
64
|
+
This will fetch updated JWTs from each authority in the chain.
|
65
|
+
|
66
|
+
### Build a trust chain
|
67
|
+
|
68
|
+
```ts
|
69
|
+
import { buildTrustChain } from "./trust";
|
70
|
+
|
71
|
+
const chain = await buildTrustChain({
|
72
|
+
leaf: "https://example-leaf",
|
73
|
+
trustAnchor: trustAnchorEntityConfiguration,
|
74
|
+
});
|
75
|
+
```
|
76
|
+
|
77
|
+
* **leaf**: the entity URL of the subject to be trusted.
|
78
|
+
* **trustAnchor**: the known trust anchor configuration.
|
79
|
+
* Returns a list of JWT strings ordered from leaf to trust anchor.
|
80
|
+
|
81
|
+
|
82
|
+
## Trust Chain Structure
|
83
|
+
|
84
|
+
| Position | JWT Type | Requirements |
|
85
|
+
| -------- | ----------------------------------- |-------------------------------|
|
86
|
+
| First | Entity Configuration | `iss === sub` (self-issued) |
|
87
|
+
| Middle | Entity Statement | `iss ≠ sub`, signed by parent |
|
88
|
+
| Last | Entity Statement or Trust Anchor EC | Trust Anchor must be known |
|
89
|
+
|
90
|
+
### Build and Validate Example
|
91
|
+
|
92
|
+
```ts
|
93
|
+
import {
|
94
|
+
buildTrustChain,
|
95
|
+
validateTrustChain,
|
96
|
+
} from "./trust";
|
97
|
+
import { trustAnchorEntityConfiguration } from "./your-data";
|
98
|
+
|
99
|
+
const chain = await buildTrustChain({
|
100
|
+
leaf: "https://example-leaf",
|
101
|
+
trustAnchor: trustAnchorEntityConfiguration,
|
102
|
+
});
|
103
|
+
|
104
|
+
const result = await validateTrustChain(trustAnchorEntityConfiguration, chain, {
|
105
|
+
connectTimeout: 3000,
|
106
|
+
readTimeout: 3000,
|
107
|
+
requireCrl: true,
|
108
|
+
});
|
109
|
+
```
|
110
|
+
|
111
|
+
* This example fetches and builds the full trust chain dynamically, then validates it end-to-end.
|
112
|
+
|
113
|
+
## Example Trust Chain
|
114
|
+
|
115
|
+
```ts
|
116
|
+
[
|
117
|
+
{
|
118
|
+
header: { alg: "ES256", kid: "leaf-kid" },
|
119
|
+
payload: { iss: "https://leaf", sub: "https://leaf", jwks: { keys: [...] } }
|
120
|
+
},
|
121
|
+
{
|
122
|
+
header: { alg: "ES256", kid: "intermediate-kid" },
|
123
|
+
payload: { iss: "https://intermediate", sub: "https://leaf", jwks: { keys: [...] } }
|
124
|
+
},
|
125
|
+
{
|
126
|
+
header: { alg: "ES256", kid: "ta-kid" },
|
127
|
+
payload: { iss: "https://ta", sub: "https://ta", jwks: { keys: [...] } }
|
128
|
+
}
|
129
|
+
]
|
130
|
+
```
|
131
|
+
|
132
|
+
## Mocking in Tests
|
133
|
+
|
134
|
+
If you're testing in Node (not in React Native), you need to mock X.509 and crypto-native dependencies:
|
135
|
+
|
136
|
+
```ts
|
137
|
+
jest.mock("@pagopa/io-react-native-crypto", () => ({
|
138
|
+
verifyCertificateChain: jest.fn().mockResolvedValue({
|
139
|
+
isValid: true,
|
140
|
+
validationStatus: "VALID",
|
141
|
+
errorMessage: undefined,
|
142
|
+
}),
|
143
|
+
generate: jest.fn().mockResolvedValue({ ... }),
|
144
|
+
}));
|
145
|
+
```
|
146
|
+
|
147
|
+
Ensure mocked `JWK`s contain an `x5c` array to trigger certificate validation logic during tests.
|
@@ -10,6 +10,7 @@ var z = _interopRequireWildcard(require("zod"));
|
|
10
10
|
var _ = require(".");
|
11
11
|
var _utils = require("./utils");
|
12
12
|
var _errors = require("./errors");
|
13
|
+
var _ioReactNativeCrypto = require("@pagopa/io-react-native-crypto");
|
13
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
14
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15
16
|
// The first element of the chain is supposed to be the Entity Configuration for the document issuer
|
@@ -21,14 +22,15 @@ const MiddleElementShape = _types.EntityStatement;
|
|
21
22
|
const LastElementShape = z.union([_types.EntityStatement, _types.TrustAnchorEntityConfiguration]);
|
22
23
|
|
23
24
|
/**
|
24
|
-
* Validates a provided trust chain against a known trust
|
25
|
+
* Validates a provided trust chain against a known trust anchor, including X.509 certificate checks.
|
25
26
|
*
|
26
|
-
* @param trustAnchorEntity The entity configuration of the known trust anchor
|
27
|
-
* @param chain The chain of statements to be validated
|
28
|
-
* @
|
29
|
-
* @
|
27
|
+
* @param trustAnchorEntity The entity configuration of the known trust anchor (for JWT validation).
|
28
|
+
* @param chain The chain of statements to be validated.
|
29
|
+
* @param x509Options Options for X.509 certificate validation.
|
30
|
+
* @returns The list of parsed tokens representing the chain.
|
31
|
+
* @throws {FederationError} If the chain is not valid (JWT or X.509). Specific errors like TrustChainEmptyError, X509ValidationError may be thrown.
|
30
32
|
*/
|
31
|
-
async function validateTrustChain(trustAnchorEntity, chain) {
|
33
|
+
async function validateTrustChain(trustAnchorEntity, chain, x509Options) {
|
32
34
|
// If the chain is empty, fail
|
33
35
|
if (chain.length === 0) {
|
34
36
|
throw new _errors.TrustChainEmptyError("Cannot verify empty trust chain.");
|
@@ -37,7 +39,7 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
37
39
|
// Select the expected token shape
|
38
40
|
const selectTokenShape = elementIndex => elementIndex === 0 ? FirstElementShape : elementIndex === chain.length - 1 ? LastElementShape : MiddleElementShape;
|
39
41
|
|
40
|
-
//
|
42
|
+
// Select the kid from the current index
|
41
43
|
const selectKid = currentIndex => {
|
42
44
|
const token = chain[currentIndex];
|
43
45
|
if (!token) {
|
@@ -49,8 +51,8 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
49
51
|
return shape.parse((0, _utils.decode)(token)).header.kid;
|
50
52
|
};
|
51
53
|
|
52
|
-
//
|
53
|
-
//
|
54
|
+
// Select keys from the next token
|
55
|
+
// If the current token is the last, keys from trust anchor will be used
|
54
56
|
const selectKeys = currentIndex => {
|
55
57
|
if (currentIndex === chain.length - 1) {
|
56
58
|
return trustAnchorEntity.payload.jwks.keys;
|
@@ -65,10 +67,45 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
65
67
|
const shape = selectTokenShape(nextIndex);
|
66
68
|
return shape.parse((0, _utils.decode)(nextToken)).payload.jwks.keys;
|
67
69
|
};
|
70
|
+
const x509TrustAnchorCertBase64 = (0, _utils.getTrustAnchorX509Certificate)(trustAnchorEntity);
|
68
71
|
|
69
72
|
// Iterate the chain and validate each element's signature against the public keys of its next
|
70
73
|
// If there is no next, hence it's the end of the chain, and it must be verified by the Trust Anchor
|
71
|
-
|
74
|
+
const validationPromises = chain.map(async (tokenString, i) => {
|
75
|
+
const kidFromTokenHeader = selectKid(i);
|
76
|
+
const signerJwks = selectKeys(i);
|
77
|
+
|
78
|
+
// Step 1: Verify JWT signature
|
79
|
+
const parsedToken = await (0, _utils.verify)(tokenString, kidFromTokenHeader, signerJwks);
|
80
|
+
|
81
|
+
// Step 2: X.509 Certificate Chain Validation
|
82
|
+
const jwkUsedForVerification = signerJwks.find(k => k.kid === kidFromTokenHeader);
|
83
|
+
if (!jwkUsedForVerification) {
|
84
|
+
throw new _errors.FederationError(`JWK with kid '${kidFromTokenHeader}' was not found in signer's JWKS for token at index ${i}, though JWT verification passed.`, {
|
85
|
+
tokenIndex: i,
|
86
|
+
kid: kidFromTokenHeader
|
87
|
+
});
|
88
|
+
}
|
89
|
+
if (!jwkUsedForVerification.x5c || jwkUsedForVerification.x5c.length === 0) {
|
90
|
+
throw new _errors.MissingX509CertsError(`JWK with kid '${kidFromTokenHeader}' does not contain an X.509 certificate chain (x5c) for token at index ${i}.`);
|
91
|
+
}
|
92
|
+
|
93
|
+
// If the chain has more than one certificate AND
|
94
|
+
// the last certificate in the x5c chain is the same as the trust anchor,
|
95
|
+
// remove the anchor from the chain being passed, as it's supplied separately.
|
96
|
+
const certChainBase64 = jwkUsedForVerification.x5c.length > 1 && jwkUsedForVerification.x5c.at(-1) === x509TrustAnchorCertBase64 ? jwkUsedForVerification.x5c.slice(0, -1) : jwkUsedForVerification.x5c;
|
97
|
+
const x509ValidationResult = await (0, _ioReactNativeCrypto.verifyCertificateChain)(certChainBase64, x509TrustAnchorCertBase64, x509Options);
|
98
|
+
if (!x509ValidationResult.isValid) {
|
99
|
+
throw new _errors.X509ValidationError(`X.509 certificate chain validation failed for token at index ${i} (kid: ${kidFromTokenHeader}). Status: ${x509ValidationResult.validationStatus}. Error: ${x509ValidationResult.errorMessage}`, {
|
100
|
+
tokenIndex: i,
|
101
|
+
kid: kidFromTokenHeader,
|
102
|
+
x509ValidationStatus: x509ValidationResult.validationStatus,
|
103
|
+
x509ErrorMessage: x509ValidationResult.errorMessage
|
104
|
+
});
|
105
|
+
}
|
106
|
+
return parsedToken;
|
107
|
+
});
|
108
|
+
return Promise.all(validationPromises);
|
72
109
|
}
|
73
110
|
|
74
111
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_types","require","z","_interopRequireWildcard","_","_utils","_errors","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FirstElementShape","EntityConfiguration","MiddleElementShape","EntityStatement","LastElementShape","union","TrustAnchorEntityConfiguration","validateTrustChain","trustAnchorEntity","chain","length","TrustChainEmptyError","selectTokenShape","elementIndex","selectKid","currentIndex","token","TrustChainTokenMissingError","index","shape","parse","decode","header","kid","selectKeys","payload","jwks","keys","nextIndex","nextToken","
|
1
|
+
{"version":3,"names":["_types","require","z","_interopRequireWildcard","_","_utils","_errors","_ioReactNativeCrypto","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FirstElementShape","EntityConfiguration","MiddleElementShape","EntityStatement","LastElementShape","union","TrustAnchorEntityConfiguration","validateTrustChain","trustAnchorEntity","chain","x509Options","length","TrustChainEmptyError","selectTokenShape","elementIndex","selectKid","currentIndex","token","TrustChainTokenMissingError","index","shape","parse","decode","header","kid","selectKeys","payload","jwks","keys","nextIndex","nextToken","x509TrustAnchorCertBase64","getTrustAnchorX509Certificate","validationPromises","map","tokenString","i","kidFromTokenHeader","signerJwks","parsedToken","verify","jwkUsedForVerification","find","k","FederationError","tokenIndex","x5c","MissingX509CertsError","certChainBase64","at","slice","x509ValidationResult","verifyCertificateChain","isValid","X509ValidationError","validationStatus","errorMessage","x509ValidationStatus","x509ErrorMessage","Promise","all","renewTrustChain","appFetch","arguments","undefined","fetch","decoded","entityStatementResult","safeParse","entityConfigurationResult","success","getSignedEntityConfiguration","data","iss","entityStatement","parentBaseUrl","parentECJwt","parentEC","federationFetchEndpoint","metadata","federation_entity","federation_fetch_endpoint","MissingFederationFetchEndpointError","sub","entityBaseUrl","missingInEntityUrl","getSignedEntityStatement","TrustChainRenewalError","originalChain"],"sourceRoot":"../../../src","sources":["trust/chain.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,CAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,CAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAMA,IAAAK,OAAA,GAAAL,OAAA;AASA,IAAAM,oBAAA,GAAAN,OAAA;AAIwC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAN,wBAAAU,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cA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yD,GAAG,EAC3B;QAAErB;MAAS,CACb,CAAC;IACH;IACA,MAAM,IAAIyB,8BAAsB,CAC7B,iDAAgDpE,KAAM,mBAAkB,EACzE;MAAEqE,aAAa,EAAE/E;IAAM,CACzB,CAAC;EACH,CAAC,CACH,CAAC;AACH"}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.TrustChainTokenMissingError = exports.TrustChainRenewalError = exports.TrustChainEmptyError = exports.TrustAnchorKidMissingError = exports.RelyingPartyNotAuthorizedError = exports.MissingFederationFetchEndpointError = exports.FederationListParseError = exports.FederationError = exports.BuildTrustChainError = void 0;
|
6
|
+
exports.X509ValidationError = exports.TrustChainTokenMissingError = exports.TrustChainRenewalError = exports.TrustChainEmptyError = exports.TrustAnchorKidMissingError = exports.RelyingPartyNotAuthorizedError = exports.MissingX509CertsError = exports.MissingFederationFetchEndpointError = exports.FederationListParseError = exports.FederationError = exports.BuildTrustChainError = void 0;
|
7
7
|
var _errors = require("../utils/errors");
|
8
8
|
// Ensure this path is correct
|
9
9
|
|
@@ -106,5 +106,28 @@ class MissingFederationFetchEndpointError extends FederationError {
|
|
106
106
|
super(message, details);
|
107
107
|
}
|
108
108
|
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Error thrown when the X.509 certificate chain is missing in an entity's configuration.
|
112
|
+
*/
|
109
113
|
exports.MissingFederationFetchEndpointError = MissingFederationFetchEndpointError;
|
114
|
+
class MissingX509CertsError extends FederationError {
|
115
|
+
code = "ERR_FED_MISSING_X509_CERTS";
|
116
|
+
constructor(message) {
|
117
|
+
super(message, undefined);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Error thrown when an X.509 certificate validation fails.
|
123
|
+
* This is used to indicate issues with the certificate chain or signature verification.
|
124
|
+
*/
|
125
|
+
exports.MissingX509CertsError = MissingX509CertsError;
|
126
|
+
class X509ValidationError extends FederationError {
|
127
|
+
code = "ERR_FED_X509_VALIDATION_FAILED";
|
128
|
+
constructor(message, details) {
|
129
|
+
super(message, details);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
exports.X509ValidationError = X509ValidationError;
|
110
133
|
//# sourceMappingURL=errors.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_errors","require","FederationError","IoWalletError","constructor","message","details","serializeAttrs","name","exports","TrustChainEmptyError","code","arguments","length","undefined","TrustChainTokenMissingError","TrustChainRenewalError","FederationListParseError","BuildTrustChainError","TrustAnchorKidMissingError","RelyingPartyNotAuthorizedError","MissingFederationFetchEndpointError"],"sourceRoot":"../../../src","sources":["trust/errors.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;
|
1
|
+
{"version":3,"names":["_errors","require","FederationError","IoWalletError","constructor","message","details","serializeAttrs","name","exports","TrustChainEmptyError","code","arguments","length","undefined","TrustChainTokenMissingError","TrustChainRenewalError","FederationListParseError","BuildTrustChainError","TrustAnchorKidMissingError","RelyingPartyNotAuthorizedError","MissingFederationFetchEndpointError","MissingX509CertsError","X509ValidationError"],"sourceRoot":"../../../src","sources":["trust/errors.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACmF;;AAEnF;AACA;AACA;AACO,MAAMC,eAAe,SAASC,qBAAa,CAAC;EACjDC,WAAWA,CAACC,OAAe,EAAEC,OAAiC,EAAE;IAC9D,KAAK,CAACA,OAAO,GAAG,IAAAC,sBAAc,EAAC;MAAEF,OAAO;MAAE,GAAGC;IAAQ,CAAC,CAAC,GAAGD,OAAO,CAAC;IAClE,IAAI,CAACG,IAAI,GAAG,IAAI,CAACJ,WAAW,CAACI,IAAI;EACnC;AACF;;AAEA;AACA;AACA;AAFAC,OAAA,CAAAP,eAAA,GAAAA,eAAA;AAGO,MAAMQ,oBAAoB,SAASR,eAAe,CAAC;EACxDS,IAAI,GAAG,2BAA2B;EAClCP,WAAWA,CAAA,EAA2C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O,GAAAO,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,6CAA6C;IACjE,KAAK,CAACP,OAAO,EAAES,SAAS,CAAC;EAC3B;AACF;;AAEA;AACA;AACA;AAFAL,OAAA,CAAAU,0BAAA,GAAAA,0BAAA;AAGO,MAAMC,8BAA8B,SAASlB,eAAe,CAAC;EAClES,IAAI,GAAG,sCAAsC;EAC7CP,WAAWA,CACTC,OAAe,EACfC,OAAqE,EACrE;IACA,KAAK,CAACD,OAAO,EAAEC,OAAO,CAAC;EACzB;AACF;;AAEA;AACA;AACA;AAFAG,OAAA,CAAAW,8BAAA,GAAAA,8BAAA;AAGO,MAAMC,mCAAmC,SAASnB,eAAe,CAAC;EACvES,IAAI,GAAG,2CAA2C;EAClDP,WAAWA,CACTC,OAAe,EACfC,OAA8D,EAC9D;IACA,KAAK,CAACD,OAAO,EAAEC,OAAO,CAAC;EACzB;AACF;;AAEA;AACA;AACA;AAFAG,OAAA,CAAAY,mCAAA,GAAAA,mCAAA;AAGO,MAAMC,qBAAqB,SAASpB,eAAe,CAAC;EACzDS,IAAI,GAAG,4BAA4B;EACnCP,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,EAAES,SAAS,CAAC;EAC3B;AACF;;AAEA;AACA;AACA;AACA;AAHAL,OAAA,CAAAa,qBAAA,GAAAA,qBAAA;AAIO,MAAMC,mBAAmB,SAASrB,eAAe,CAAC;EACvDS,IAAI,GAAG,gCAAgC;EACvCP,WAAWA,CACTC,OAAe,EACfC,OAMC,EACD;IACA,KAAK,CAACD,OAAO,EAAEC,OAAO,CAAC;EACzB;AACF;AAACG,OAAA,CAAAc,mBAAA,GAAAA,mBAAA"}
|
@@ -24,22 +24,28 @@ var _errors = require("./errors");
|
|
24
24
|
*
|
25
25
|
* @param trustAnchorEntity The entity configuration of the known trust anchor
|
26
26
|
* @param chain The chain of statements to be validated
|
27
|
-
* @param
|
28
|
-
* @param appFetch
|
27
|
+
* @param x509Options Options for the verification process
|
28
|
+
* @param appFetch (optional) fetch api implementation
|
29
|
+
* @param renewOnFail Whether to attempt to renew the trust chain if the initial validation fails
|
29
30
|
* @returns The result of the chain validation
|
30
31
|
* @throws {FederationError} If the chain is not valid
|
31
32
|
*/
|
32
33
|
async function verifyTrustChain(trustAnchorEntity, chain) {
|
34
|
+
let x509Options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
35
|
+
connectTimeout: 10000,
|
36
|
+
readTimeout: 10000,
|
37
|
+
requireCrl: true
|
38
|
+
};
|
33
39
|
let {
|
34
40
|
appFetch = fetch,
|
35
41
|
renewOnFail = true
|
36
|
-
} = arguments.length >
|
42
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
37
43
|
try {
|
38
|
-
return (0, _chain.validateTrustChain)(trustAnchorEntity, chain);
|
44
|
+
return (0, _chain.validateTrustChain)(trustAnchorEntity, chain, x509Options);
|
39
45
|
} catch (error) {
|
40
46
|
if (renewOnFail) {
|
41
47
|
const renewedChain = await (0, _chain.renewTrustChain)(chain, appFetch);
|
42
|
-
return (0, _chain.validateTrustChain)(trustAnchorEntity, renewedChain);
|
48
|
+
return (0, _chain.validateTrustChain)(trustAnchorEntity, renewedChain, x509Options);
|
43
49
|
} else {
|
44
50
|
throw error;
|
45
51
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_utils","require","_ioReactNativeJwt","_types","_chain","_misc","_errors","verifyTrustChain","trustAnchorEntity","chain","
|
1
|
+
{"version":3,"names":["_utils","require","_ioReactNativeJwt","_types","_chain","_misc","_errors","verifyTrustChain","trustAnchorEntity","chain","x509Options","arguments","length","undefined","connectTimeout","readTimeout","requireCrl","appFetch","fetch","renewOnFail","validateTrustChain","error","renewedChain","renewTrustChain","getSignedEntityConfiguration","entityBaseUrl","wellKnownUrl","method","then","hasStatusOrThrow","res","text","fetchAndParseEntityConfiguration","schema","responseText","responseJwt","decodeJwt","parse","header","protectedHeader","payload","getWalletProviderEntityConfiguration","options","WalletProviderEntityConfiguration","exports","getCredentialIssuerEntityConfiguration","CredentialIssuerEntityConfiguration","getTrustAnchorEntityConfiguration","TrustAnchorEntityConfiguration","getRelyingPartyEntityConfiguration","RelyingPartyEntityConfiguration","getEntityConfiguration","EntityConfiguration","getEntityStatement","accreditationBodyBaseUrl","subordinatedEntityBaseUrl","getSignedEntityStatement","EntityStatement","federationFetchEndpoint","url","URL","searchParams","set","toString","getFederationList","federationListEndpoint","json","result","FederationListResponse","safeParse","success","FederationListParseError","message","parseError","data","buildTrustChain","relyingPartyEntityBaseUrl","trustAnchorKey","trustChain","gatherTrustChain","trustAnchorJwt","BuildTrustChainError","relyingPartyUrl","kid","TrustAnchorKidMissingError","verify","trustAnchorConfig","decode","metadata","federation_entity","federation_list_endpoint","federationList","includes","RelyingPartyNotAuthorizedError","isLeaf","entityECJwt","entityEC","push","authorityHints","authority_hints","parentEntityBaseUrl","parentECJwt","parentEC","federation_fetch_endpoint","MissingFederationFetchEndpointError","missingInEntityUrl","entityStatementJwt","parentChain","concat"],"sourceRoot":"../../../src","sources":["trust/index.ts"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeM,gBAAgBA,CACpCC,iBAAiD,EACjDC,KAAe,EAUiC;EAAA,IAThDC,WAAmC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACpCG,cAAc,EAAE,KAAK;IACrBC,WAAW,EAAE,KAAK;IAClBC,UAAU,EAAE;EACd,CAAC;EAAA,IACD;IACEC,Q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,MAAM,KAAK,CAAC,EAAE;IAC/B;IACA,IAAI,CAACkF,MAAM,EAAE;MACXrF,KAAK,CAACwF,IAAI,CAACF,WAAW,CAAC;IACzB;IACA,OAAOtF,KAAK;EACd;EAEA,MAAM2F,mBAAmB,GAAGF,cAAc,CAAC,CAAC,CAAE;;EAE9C;EACA,MAAMG,WAAW,GAAG,MAAM7E,4BAA4B,CAAC4E,mBAAmB,EAAE;IAC1EnF;EACF,CAAC,CAAC;EACF,MAAMqF,QAAQ,GAAGlD,0BAAmB,CAACf,KAAK,CAAC,IAAAkD,aAAM,EAACc,WAAW,CAAC,CAAC;;EAE/D;EACA,MAAM3C,uBAAuB,GAC3B4C,QAAQ,CAAC9D,OAAO,CAACgD,QAAQ,CAACC,iBAAiB,CAACc,yBAAyB;EACvE,IAAI,CAAC7C,uBAAuB,EAAE;IAC5B,MAAM,IAAI8C,2CAAmC,CAC1C,kDAAiDJ,mBAAoB,4CAA2C3E,aAAc,GAAE,EACjI;MAAEA,aAAa;MAAEgF,kBAAkB,EAAEL;IAAoB,CAC3D,CAAC;EACH;EAEA,MAAMM,kBAAkB,GAAG,MAAMlD,wBAAwB,CACvDE,uBAAuB,EACvBjC,aAAa,EACb;IAAER;EAAS,CACb,CAAC;EACD;EACAwC,sBAAe,CAACpB,KAAK,CAAC,IAAAkD,aAAM,EAACmB,kBAAkB,CAAC,CAAC;;EAEjD;EACAjG,KAAK,CAACwF,IAAI,CAACS,kBAAkB,CAAC;;EAE9B;EACA,MAAMC,WAAW,GAAG,MAAM5B,gBAAgB,CACxCqB,mBAAmB,EACnBnF,QAAQ,EACR,KACF,CAAC;EAED,OAAOR,KAAK,CAACmG,MAAM,CAACD,WAAW,CAAC;AAClC"}
|
@@ -3,8 +3,11 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.decode = void 0;
|
7
|
+
exports.getTrustAnchorX509Certificate = getTrustAnchorX509Certificate;
|
8
|
+
exports.verify = void 0;
|
7
9
|
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
10
|
+
var _errors = require("./errors");
|
8
11
|
// Verify a token signature
|
9
12
|
// The kid is extracted from the token header
|
10
13
|
const verify = async (token, kid, jwks) => {
|
@@ -37,5 +40,31 @@ const decode = token => {
|
|
37
40
|
payload
|
38
41
|
};
|
39
42
|
};
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Extracts the X.509 Trust Anchor certificate (Base64 encoded) from the
|
46
|
+
* Trust Anchor's Entity Configuration.
|
47
|
+
*
|
48
|
+
* @param trustAnchorEntity The entity configuration of the known trust anchor.
|
49
|
+
* @returns The Base64 encoded X.509 certificate string.
|
50
|
+
* @throws {FederationError} If the certificate cannot be derived.
|
51
|
+
*/
|
40
52
|
exports.decode = decode;
|
53
|
+
function getTrustAnchorX509Certificate(trustAnchorEntity) {
|
54
|
+
const taHeaderKid = trustAnchorEntity.header.kid;
|
55
|
+
const taSigningJwk = trustAnchorEntity.payload.jwks.keys.find(key => key.kid === taHeaderKid);
|
56
|
+
if (!taSigningJwk) {
|
57
|
+
throw new _errors.FederationError(`Cannot derive X.509 Trust Anchor certificate: JWK with kid '${taHeaderKid}' not found in Trust Anchor's JWKS.`, {
|
58
|
+
trustAnchorKid: taHeaderKid,
|
59
|
+
reason: "JWK not found for header kid"
|
60
|
+
});
|
61
|
+
}
|
62
|
+
if (taSigningJwk.x5c && taSigningJwk.x5c.length > 0 && taSigningJwk.x5c[0]) {
|
63
|
+
return taSigningJwk.x5c[0];
|
64
|
+
}
|
65
|
+
throw new _errors.FederationError(`Cannot derive X.509 Trust Anchor certificate: JWK with kid '${taHeaderKid}' does not contain a valid 'x5c' certificate array.`, {
|
66
|
+
trustAnchorKid: taHeaderKid,
|
67
|
+
reason: "Missing or empty x5c in JWK"
|
68
|
+
});
|
69
|
+
}
|
41
70
|
//# sourceMappingURL=utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_ioReactNativeJwt","require","verify","token","kid","jwks","jwk","find","k","Error","protectedHeader","header","payload","verifyJwt","exports","decode","decodeJwt"],"sourceRoot":"../../../src","sources":["trust/utils.ts"],"mappings":"
|
1
|
+
{"version":3,"names":["_ioReactNativeJwt","require","_errors","verify","token","kid","jwks","jwk","find","k","Error","protectedHeader","header","payload","verifyJwt","exports","decode","decodeJwt","getTrustAnchorX509Certificate","trustAnchorEntity","taHeaderKid","taSigningJwk","keys","key","FederationError","trustAnchorKid","reason","x5c","length"],"sourceRoot":"../../../src","sources":["trust/utils.ts"],"mappings":";;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAD,OAAA;AAQA;AACA;AACO,MAAME,MAAM,GAAG,MAAAA,CACpBC,KAAa,EACbC,GAAW,EACXC,IAAW,KACc;EACzB,MAAMC,GAAG,GAAGD,IAAI,CAACE,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACJ,GAAG,KAAKA,GAAG,CAAC;EAC3C,IAAI,CAACE,GAAG,EAAE;IACR,MAAM,IAAIG,KAAK,CAAE,gBAAeL,GAAI,YAAWD,KAAM,EAAC,CAAC;EACzD;EACA,MAAM;IAAEO,eAAe,EAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAG,MAAM,IAAAC,wBAAS,EAACV,KAAK,EAAEG,GAAG,CAAC;EACxE,OAAO;IAAEK,MAAM;IAAEC;EAAQ,CAAC;AAC5B,CAAC;;AAED;AACA;AACA;AACA;AAHAE,OAAA,CAAAZ,MAAA,GAAAA,MAAA;AAIO,MAAMa,MAAM,GAAIZ,KAAa,IAAkB;EACpD,MAAM;IAAEO,eAAe,EAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAG,IAAAI,wBAAS,EAACb,KAAK,CAAC;EAC7D,OAAO;IAAEQ,MAAM;IAAEC;EAAQ,CAAC;AAC5B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAE,OAAA,CAAAC,MAAA,GAAAA,MAAA;AAQO,SAASE,6BAA6BA,CAC3CC,iBAAiD,EACzC;EACR,MAAMC,WAAW,GAAGD,iBAAiB,CAACP,MAAM,CAACP,GAAG;EAChD,MAAMgB,YAAY,GAAGF,iBAAiB,CAACN,OAAO,CAACP,IAAI,CAACgB,IAAI,CAACd,IAAI,CAC1De,GAAG,IAAKA,GAAG,CAAClB,GAAG,KAAKe,WACvB,CAAC;EAED,IAAI,CAACC,YAAY,EAAE;IACjB,MAAM,IAAIG,uBAAe,CACtB,+DAA8DJ,WAAY,qCAAoC,EAC/G;MAAEK,cAAc,EAAEL,WAAW;MAAEM,MAAM,EAAE;IAA+B,CACxE,CAAC;EACH;EAEA,IAAIL,YAAY,CAACM,GAAG,IAAIN,YAAY,CAACM,GAAG,CAACC,MAAM,GAAG,CAAC,IAAIP,YAAY,CAACM,GAAG,CAAC,CAAC,CAAC,EAAE;IAC1E,OAAON,YAAY,CAACM,GAAG,CAAC,CAAC,CAAC;EAC5B;EAEA,MAAM,IAAIH,uBAAe,CACtB,+DAA8DJ,WAAY,qDAAoD,EAC/H;IAAEK,cAAc,EAAEL,WAAW;IAAEM,MAAM,EAAE;EAA8B,CACvE,CAAC;AACH"}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# Trust Chain Validation
|
2
|
+
|
3
|
+
This module implements **Trust Chain validation** for Entity Configurations and Entity Statements in line with the [IT Wallet Federation Specifications](https://italia.github.io/eid-wallet-it-docs/). It ensures that an entity's metadata is trusted by validating a chain of signed JWTs up to a known Trust Anchor.
|
4
|
+
|
5
|
+
The validation covers:
|
6
|
+
|
7
|
+
* JWT signature verification (using the next entity's JWKS)
|
8
|
+
* Trust chain ordering (leaf → parent → Trust Anchor)
|
9
|
+
* Optional X.509 CRL-based certificate validation
|
10
|
+
|
11
|
+
## Sequence Diagram
|
12
|
+
|
13
|
+
```mermaid
|
14
|
+
sequenceDiagram
|
15
|
+
autonumber
|
16
|
+
participant A as Leaf Entity
|
17
|
+
participant B as Intermediate (Federation Authority)
|
18
|
+
participant C as Trust Anchor
|
19
|
+
|
20
|
+
A->>A: Self-issued Entity Configuration (JWT)
|
21
|
+
B->>A: Signed Entity Statement (JWT)
|
22
|
+
C->>B: Signed Entity Statement (JWT or self-issued EC)
|
23
|
+
|
24
|
+
Note over A,C: Each JWT is validated with the next issuer's public keys
|
25
|
+
```
|
26
|
+
|
27
|
+
## Errors
|
28
|
+
|
29
|
+
| Error | Description |
|
30
|
+
| ----------------------------- | ------------------------------------------------------------------ |
|
31
|
+
| `TrustChainEmptyError` | The input chain is empty. |
|
32
|
+
| `TrustChainTokenMissingError` | One of the JWTs in the chain is missing. |
|
33
|
+
| `X509ValidationError` | X.509 certificate validation failed (e.g. revocation, expiration). |
|
34
|
+
| `FederationError` | Generic federation processing error. |
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
### Validate a trust chain
|
39
|
+
|
40
|
+
```ts
|
41
|
+
import { validateTrustChain } from "./trust";
|
42
|
+
import { trustAnchorEntityConfiguration } from "./your-data";
|
43
|
+
import { chain } from "./your-data"; // array of JWTs, starting from leaf
|
44
|
+
|
45
|
+
const result = await validateTrustChain(trustAnchorEntityConfiguration, chain, {
|
46
|
+
connectTimeout: 3000,
|
47
|
+
readTimeout: 3000,
|
48
|
+
requireCrl: false,
|
49
|
+
});
|
50
|
+
```
|
51
|
+
|
52
|
+
* The `chain` must be an array of signed JWT strings.
|
53
|
+
* The first JWT must be a self-issued `EntityConfiguration`.
|
54
|
+
* The last JWT must be an `EntityStatement` or a self-issued Trust Anchor `EntityConfiguration`.
|
55
|
+
|
56
|
+
### Renew a trust chain
|
57
|
+
|
58
|
+
```ts
|
59
|
+
import { renewTrustChain } from "./trust";
|
60
|
+
|
61
|
+
const newChain = await renewTrustChain(chain);
|
62
|
+
```
|
63
|
+
|
64
|
+
This will fetch updated JWTs from each authority in the chain.
|
65
|
+
|
66
|
+
### Build a trust chain
|
67
|
+
|
68
|
+
```ts
|
69
|
+
import { buildTrustChain } from "./trust";
|
70
|
+
|
71
|
+
const chain = await buildTrustChain({
|
72
|
+
leaf: "https://example-leaf",
|
73
|
+
trustAnchor: trustAnchorEntityConfiguration,
|
74
|
+
});
|
75
|
+
```
|
76
|
+
|
77
|
+
* **leaf**: the entity URL of the subject to be trusted.
|
78
|
+
* **trustAnchor**: the known trust anchor configuration.
|
79
|
+
* Returns a list of JWT strings ordered from leaf to trust anchor.
|
80
|
+
|
81
|
+
|
82
|
+
## Trust Chain Structure
|
83
|
+
|
84
|
+
| Position | JWT Type | Requirements |
|
85
|
+
| -------- | ----------------------------------- |-------------------------------|
|
86
|
+
| First | Entity Configuration | `iss === sub` (self-issued) |
|
87
|
+
| Middle | Entity Statement | `iss ≠ sub`, signed by parent |
|
88
|
+
| Last | Entity Statement or Trust Anchor EC | Trust Anchor must be known |
|
89
|
+
|
90
|
+
### Build and Validate Example
|
91
|
+
|
92
|
+
```ts
|
93
|
+
import {
|
94
|
+
buildTrustChain,
|
95
|
+
validateTrustChain,
|
96
|
+
} from "./trust";
|
97
|
+
import { trustAnchorEntityConfiguration } from "./your-data";
|
98
|
+
|
99
|
+
const chain = await buildTrustChain({
|
100
|
+
leaf: "https://example-leaf",
|
101
|
+
trustAnchor: trustAnchorEntityConfiguration,
|
102
|
+
});
|
103
|
+
|
104
|
+
const result = await validateTrustChain(trustAnchorEntityConfiguration, chain, {
|
105
|
+
connectTimeout: 3000,
|
106
|
+
readTimeout: 3000,
|
107
|
+
requireCrl: true,
|
108
|
+
});
|
109
|
+
```
|
110
|
+
|
111
|
+
* This example fetches and builds the full trust chain dynamically, then validates it end-to-end.
|
112
|
+
|
113
|
+
## Example Trust Chain
|
114
|
+
|
115
|
+
```ts
|
116
|
+
[
|
117
|
+
{
|
118
|
+
header: { alg: "ES256", kid: "leaf-kid" },
|
119
|
+
payload: { iss: "https://leaf", sub: "https://leaf", jwks: { keys: [...] } }
|
120
|
+
},
|
121
|
+
{
|
122
|
+
header: { alg: "ES256", kid: "intermediate-kid" },
|
123
|
+
payload: { iss: "https://intermediate", sub: "https://leaf", jwks: { keys: [...] } }
|
124
|
+
},
|
125
|
+
{
|
126
|
+
header: { alg: "ES256", kid: "ta-kid" },
|
127
|
+
payload: { iss: "https://ta", sub: "https://ta", jwks: { keys: [...] } }
|
128
|
+
}
|
129
|
+
]
|
130
|
+
```
|
131
|
+
|
132
|
+
## Mocking in Tests
|
133
|
+
|
134
|
+
If you're testing in Node (not in React Native), you need to mock X.509 and crypto-native dependencies:
|
135
|
+
|
136
|
+
```ts
|
137
|
+
jest.mock("@pagopa/io-react-native-crypto", () => ({
|
138
|
+
verifyCertificateChain: jest.fn().mockResolvedValue({
|
139
|
+
isValid: true,
|
140
|
+
validationStatus: "VALID",
|
141
|
+
errorMessage: undefined,
|
142
|
+
}),
|
143
|
+
generate: jest.fn().mockResolvedValue({ ... }),
|
144
|
+
}));
|
145
|
+
```
|
146
|
+
|
147
|
+
Ensure mocked `JWK`s contain an `x5c` array to trigger certificate validation logic during tests.
|