@parmana/crypto 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +16 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/ApprovalArtifactCrypto.d.ts +33 -0
- package/dist/ApprovalArtifactCrypto.d.ts.map +1 -0
- package/dist/ApprovalArtifactCrypto.js +54 -0
- package/dist/ApprovalArtifactCrypto.js.map +1 -0
- package/dist/ArtifactSigner.d.ts +22 -0
- package/dist/ArtifactSigner.d.ts.map +1 -0
- package/dist/ArtifactSigner.js +29 -0
- package/dist/ArtifactSigner.js.map +1 -0
- package/dist/AuditEventCrypto.d.ts +39 -0
- package/dist/AuditEventCrypto.d.ts.map +1 -0
- package/dist/AuditEventCrypto.js +57 -0
- package/dist/AuditEventCrypto.js.map +1 -0
- package/dist/AuthorizationSigner.d.ts +56 -0
- package/dist/AuthorizationSigner.d.ts.map +1 -0
- package/dist/AuthorizationSigner.js +103 -0
- package/dist/AuthorizationSigner.js.map +1 -0
- package/dist/AuthorizationVerifier.d.ts +53 -0
- package/dist/AuthorizationVerifier.d.ts.map +1 -0
- package/dist/AuthorizationVerifier.js +66 -0
- package/dist/AuthorizationVerifier.js.map +1 -0
- package/dist/CallerAuditChainVerifier.d.ts +62 -0
- package/dist/CallerAuditChainVerifier.d.ts.map +1 -0
- package/dist/CallerAuditChainVerifier.js +97 -0
- package/dist/CallerAuditChainVerifier.js.map +1 -0
- package/dist/CanonicalSerializer.d.ts +26 -0
- package/dist/CanonicalSerializer.d.ts.map +1 -0
- package/dist/CanonicalSerializer.js +78 -0
- package/dist/CanonicalSerializer.js.map +1 -0
- package/dist/CryptoBootstrap.d.ts +27 -0
- package/dist/CryptoBootstrap.d.ts.map +1 -0
- package/dist/CryptoBootstrap.js +70 -0
- package/dist/CryptoBootstrap.js.map +1 -0
- package/dist/CryptoBuilder.d.ts +27 -0
- package/dist/CryptoBuilder.d.ts.map +1 -0
- package/dist/CryptoBuilder.js +42 -0
- package/dist/CryptoBuilder.js.map +1 -0
- package/dist/ExecutableContentHasher.d.ts +22 -0
- package/dist/ExecutableContentHasher.d.ts.map +1 -0
- package/dist/ExecutableContentHasher.js +25 -0
- package/dist/ExecutableContentHasher.js.map +1 -0
- package/dist/ExecutionChainCrypto.d.ts +78 -0
- package/dist/ExecutionChainCrypto.d.ts.map +1 -0
- package/dist/ExecutionChainCrypto.js +165 -0
- package/dist/ExecutionChainCrypto.js.map +1 -0
- package/dist/ExecutionChainHasher.d.ts +10 -0
- package/dist/ExecutionChainHasher.d.ts.map +1 -0
- package/dist/ExecutionChainHasher.js +13 -0
- package/dist/ExecutionChainHasher.js.map +1 -0
- package/dist/ExecutionIntentCanonicalView.d.ts +28 -0
- package/dist/ExecutionIntentCanonicalView.d.ts.map +1 -0
- package/dist/ExecutionIntentCanonicalView.js +29 -0
- package/dist/ExecutionIntentCanonicalView.js.map +1 -0
- package/dist/ExecutionIntentCrypto.d.ts +21 -0
- package/dist/ExecutionIntentCrypto.d.ts.map +1 -0
- package/dist/ExecutionIntentCrypto.js +47 -0
- package/dist/ExecutionIntentCrypto.js.map +1 -0
- package/dist/ExecutionTrustRecordCanonicalView.d.ts +89 -0
- package/dist/ExecutionTrustRecordCanonicalView.d.ts.map +1 -0
- package/dist/ExecutionTrustRecordCanonicalView.js +106 -0
- package/dist/ExecutionTrustRecordCanonicalView.js.map +1 -0
- package/dist/HybridSignatureProvider.d.ts +48 -0
- package/dist/HybridSignatureProvider.d.ts.map +1 -0
- package/dist/HybridSignatureProvider.js +90 -0
- package/dist/HybridSignatureProvider.js.map +1 -0
- package/dist/KeyBootstrap.d.ts +23 -0
- package/dist/KeyBootstrap.d.ts.map +1 -0
- package/dist/KeyBootstrap.js +37 -0
- package/dist/KeyBootstrap.js.map +1 -0
- package/dist/KeyExpiry.d.ts +34 -0
- package/dist/KeyExpiry.d.ts.map +1 -0
- package/dist/KeyExpiry.js +66 -0
- package/dist/KeyExpiry.js.map +1 -0
- package/dist/KeyPair.d.ts +25 -0
- package/dist/KeyPair.d.ts.map +1 -0
- package/dist/KeyPair.js +37 -0
- package/dist/KeyPair.js.map +1 -0
- package/dist/KeyProvider.d.ts +98 -0
- package/dist/KeyProvider.d.ts.map +1 -0
- package/dist/KeyProvider.js +57 -0
- package/dist/KeyProvider.js.map +1 -0
- package/dist/KeyStore.d.ts +35 -0
- package/dist/KeyStore.d.ts.map +1 -0
- package/dist/KeyStore.js +2 -0
- package/dist/KeyStore.js.map +1 -0
- package/dist/OfflineVerifier.d.ts +80 -0
- package/dist/OfflineVerifier.d.ts.map +1 -0
- package/dist/OfflineVerifier.js +271 -0
- package/dist/OfflineVerifier.js.map +1 -0
- package/dist/PolicyChangeCrypto.d.ts +44 -0
- package/dist/PolicyChangeCrypto.d.ts.map +1 -0
- package/dist/PolicyChangeCrypto.js +79 -0
- package/dist/PolicyChangeCrypto.js.map +1 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts +55 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts.map +1 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.js +107 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.js.map +1 -0
- package/dist/ReceiptCrypto.d.ts +44 -0
- package/dist/ReceiptCrypto.d.ts.map +1 -0
- package/dist/ReceiptCrypto.js +84 -0
- package/dist/ReceiptCrypto.js.map +1 -0
- package/dist/ReceiptHasher.d.ts +10 -0
- package/dist/ReceiptHasher.d.ts.map +1 -0
- package/dist/ReceiptHasher.js +13 -0
- package/dist/ReceiptHasher.js.map +1 -0
- package/dist/RefusalCrypto.d.ts +35 -0
- package/dist/RefusalCrypto.d.ts.map +1 -0
- package/dist/RefusalCrypto.js +73 -0
- package/dist/RefusalCrypto.js.map +1 -0
- package/dist/SignatureCommitment.d.ts +33 -0
- package/dist/SignatureCommitment.d.ts.map +1 -0
- package/dist/SignatureCommitment.js +42 -0
- package/dist/SignatureCommitment.js.map +1 -0
- package/dist/SignatureVerifier.d.ts +20 -0
- package/dist/SignatureVerifier.d.ts.map +1 -0
- package/dist/SignatureVerifier.js +25 -0
- package/dist/SignatureVerifier.js.map +1 -0
- package/dist/Signer.d.ts +49 -0
- package/dist/Signer.d.ts.map +1 -0
- package/dist/Signer.js +2 -0
- package/dist/Signer.js.map +1 -0
- package/dist/SignerBootstrap.d.ts +37 -0
- package/dist/SignerBootstrap.d.ts.map +1 -0
- package/dist/SignerBootstrap.js +52 -0
- package/dist/SignerBootstrap.js.map +1 -0
- package/dist/TrustRecordHasher.d.ts +18 -0
- package/dist/TrustRecordHasher.d.ts.map +1 -0
- package/dist/TrustRecordHasher.js +23 -0
- package/dist/TrustRecordHasher.js.map +1 -0
- package/dist/VerificationCrypto.d.ts +132 -0
- package/dist/VerificationCrypto.d.ts.map +1 -0
- package/dist/VerificationCrypto.js +229 -0
- package/dist/VerificationCrypto.js.map +1 -0
- package/dist/errors/CryptoError.d.ts +14 -0
- package/dist/errors/CryptoError.d.ts.map +1 -0
- package/dist/errors/CryptoError.js +18 -0
- package/dist/errors/CryptoError.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/models/HybridCryptoProvider.d.ts +9 -0
- package/dist/models/HybridCryptoProvider.d.ts.map +1 -0
- package/dist/models/HybridCryptoProvider.js +2 -0
- package/dist/models/HybridCryptoProvider.js.map +1 -0
- package/dist/providers/CryptoProvider.d.ts +15 -0
- package/dist/providers/CryptoProvider.d.ts.map +1 -0
- package/dist/providers/CryptoProvider.js +2 -0
- package/dist/providers/CryptoProvider.js.map +1 -0
- package/dist/providers/HashProvider.d.ts +17 -0
- package/dist/providers/HashProvider.d.ts.map +1 -0
- package/dist/providers/HashProvider.js +2 -0
- package/dist/providers/HashProvider.js.map +1 -0
- package/dist/providers/HashRegistry.d.ts +11 -0
- package/dist/providers/HashRegistry.d.ts.map +1 -0
- package/dist/providers/HashRegistry.js +18 -0
- package/dist/providers/HashRegistry.js.map +1 -0
- package/dist/providers/ProviderFactory.d.ts +11 -0
- package/dist/providers/ProviderFactory.d.ts.map +1 -0
- package/dist/providers/ProviderFactory.js +13 -0
- package/dist/providers/ProviderFactory.js.map +1 -0
- package/dist/providers/SignatureProvider.d.ts +25 -0
- package/dist/providers/SignatureProvider.d.ts.map +1 -0
- package/dist/providers/SignatureProvider.js +2 -0
- package/dist/providers/SignatureProvider.js.map +1 -0
- package/dist/providers/SignatureRegistry.d.ts +11 -0
- package/dist/providers/SignatureRegistry.d.ts.map +1 -0
- package/dist/providers/SignatureRegistry.js +18 -0
- package/dist/providers/SignatureRegistry.js.map +1 -0
- package/dist/providers/SignerKeyProviderAdapter.d.ts +50 -0
- package/dist/providers/SignerKeyProviderAdapter.d.ts.map +1 -0
- package/dist/providers/SignerKeyProviderAdapter.js +66 -0
- package/dist/providers/SignerKeyProviderAdapter.js.map +1 -0
- package/dist/providers/hash/SHA256HashProvider.d.ts +10 -0
- package/dist/providers/hash/SHA256HashProvider.d.ts.map +1 -0
- package/dist/providers/hash/SHA256HashProvider.js +12 -0
- package/dist/providers/hash/SHA256HashProvider.js.map +1 -0
- package/dist/providers/key/FileKeyProvider.d.ts +85 -0
- package/dist/providers/key/FileKeyProvider.d.ts.map +1 -0
- package/dist/providers/key/FileKeyProvider.js +163 -0
- package/dist/providers/key/FileKeyProvider.js.map +1 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.d.ts +23 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.d.ts.map +1 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.js +33 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.js.map +1 -0
- package/dist/providers/signature/Ed25519SignatureProvider.d.ts +17 -0
- package/dist/providers/signature/Ed25519SignatureProvider.d.ts.map +1 -0
- package/dist/providers/signature/Ed25519SignatureProvider.js +40 -0
- package/dist/providers/signature/Ed25519SignatureProvider.js.map +1 -0
- package/dist/providers/signature/assertKeyType.d.ts +14 -0
- package/dist/providers/signature/assertKeyType.d.ts.map +1 -0
- package/dist/providers/signature/assertKeyType.js +19 -0
- package/dist/providers/signature/assertKeyType.js.map +1 -0
- package/dist/providers/signer/KmsSigner.d.ts +71 -0
- package/dist/providers/signer/KmsSigner.d.ts.map +1 -0
- package/dist/providers/signer/KmsSigner.js +270 -0
- package/dist/providers/signer/KmsSigner.js.map +1 -0
- package/dist/providers/signer/LocalFileSigner.d.ts +28 -0
- package/dist/providers/signer/LocalFileSigner.d.ts.map +1 -0
- package/dist/providers/signer/LocalFileSigner.js +38 -0
- package/dist/providers/signer/LocalFileSigner.js.map +1 -0
- package/dist/support/MlDsaSupport.d.ts +9 -0
- package/dist/support/MlDsaSupport.d.ts.map +1 -0
- package/dist/support/MlDsaSupport.js +23 -0
- package/dist/support/MlDsaSupport.js.map +1 -0
- package/package.json +45 -4
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { createPublicKey } from "node:crypto";
|
|
2
|
+
import { canonicalExecutionIntent } from "./ExecutionIntentCanonicalView.js";
|
|
3
|
+
import { canonicalExecutionTrustRecord, hybridSignedCanonicalView, isAtOrAfterCutover, SUPPORTED_HYBRID_SCHEMA_VERSIONS, WHOLE_RECORD_SCHEMA_VERSION, } from "./ExecutionTrustRecordCanonicalView.js";
|
|
4
|
+
import { SHA256HashProvider } from "./providers/hash/SHA256HashProvider.js";
|
|
5
|
+
import { Ed25519SignatureProvider } from "./providers/signature/Ed25519SignatureProvider.js";
|
|
6
|
+
import { Dilithium3SignatureProvider } from "./providers/signature/Dilithium3SignatureProvider.js";
|
|
7
|
+
import { SignatureVerifier } from "./SignatureVerifier.js";
|
|
8
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
9
|
+
/**
|
|
10
|
+
* Standalone, offline verification of an Execution Trust Record
|
|
11
|
+
* (PQC audit RED-1, docs/VERIFICATION-GAPS.md).
|
|
12
|
+
*
|
|
13
|
+
* Zero network calls, zero disk reads, zero environment variables.
|
|
14
|
+
* Callers supply the exact public key material for every keyId a
|
|
15
|
+
* record references; everything else this module needs
|
|
16
|
+
* (CanonicalSerializer, the canonical Execution Trust Record field
|
|
17
|
+
* mapping, the Ed25519/ML-DSA-65 SignatureProvider implementations)
|
|
18
|
+
* is the same code the real, online VerificationCrypto uses --
|
|
19
|
+
* ExecutionTrustRecordCanonicalView.ts is shared between them so there
|
|
20
|
+
* is exactly one definition of "which fields participate in the
|
|
21
|
+
* signature," not two implementations that could silently drift apart.
|
|
22
|
+
*
|
|
23
|
+
* This is the reference this repository's own VerificationCrypto is
|
|
24
|
+
* built on. A separately published verifier ports this
|
|
25
|
+
* module as of v0.2.0: the same canonical field mappings, the hybrid
|
|
26
|
+
* `signatures`/`schemaVersion` envelope, and the Ed25519 large-message
|
|
27
|
+
* commitment, checked against fixtures signed by this repository's
|
|
28
|
+
* code. Any change to what is signed here must be mirrored there, or
|
|
29
|
+
* third-party verification of new records will fail.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Registry of the signature algorithms this module can actually
|
|
33
|
+
* verify. Deliberately the same two this repository's
|
|
34
|
+
* SignatureRegistry (CryptoBootstrap.ts) registers -- "ecdsa-p256",
|
|
35
|
+
* "dilithium5", and "sphincs-plus" are declared as valid
|
|
36
|
+
* PRIMARY_SIGNATURE_PROVIDER config values elsewhere in this codebase
|
|
37
|
+
* but have no real implementation anywhere (see docs/REMAINING-WORK.md, section D);
|
|
38
|
+
* an offline verifier claiming to support them would be worse than
|
|
39
|
+
* refusing outright.
|
|
40
|
+
*/
|
|
41
|
+
function signatureProviderFor(algorithm) {
|
|
42
|
+
switch (algorithm) {
|
|
43
|
+
case "ed25519":
|
|
44
|
+
return new Ed25519SignatureProvider();
|
|
45
|
+
case "dilithium3":
|
|
46
|
+
return new Dilithium3SignatureProvider();
|
|
47
|
+
default:
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `publicKeys` maps keyId -> PEM-encoded public key (SPKI). Supply an
|
|
53
|
+
* entry for every keyId the record's `signature.keyId` and (if
|
|
54
|
+
* present) each `signatures[].keyId` reference -- typically fetched
|
|
55
|
+
* once from a key-discovery endpoint (see the `/keys` and
|
|
56
|
+
* `/.well-known/jwks.json` routes) and cached by the caller, not
|
|
57
|
+
* re-fetched per verification.
|
|
58
|
+
*/
|
|
59
|
+
export async function verifyExecutionTrustRecordOffline(trustRecord, publicKeys, options = {}) {
|
|
60
|
+
const malformed = malformedArtifact(trustRecord, "trustRecordHash");
|
|
61
|
+
if (malformed !== undefined) {
|
|
62
|
+
return malformed;
|
|
63
|
+
}
|
|
64
|
+
const errors = [];
|
|
65
|
+
const algorithmsChecked = [];
|
|
66
|
+
const hasher = new TrustRecordHasher({
|
|
67
|
+
hash: new SHA256HashProvider(),
|
|
68
|
+
signature: new Ed25519SignatureProvider(),
|
|
69
|
+
});
|
|
70
|
+
const expectedHash = await hasher.hash(canonicalExecutionTrustRecord(trustRecord));
|
|
71
|
+
const hashValid = expectedHash === trustRecord.trustRecordHash;
|
|
72
|
+
if (!hashValid) {
|
|
73
|
+
errors.push(`trustRecordHash mismatch: expected ${expectedHash}, got ${trustRecord.trustRecordHash}.`);
|
|
74
|
+
}
|
|
75
|
+
const legacySignatureValid = await verifyOneEntry({
|
|
76
|
+
algorithm: trustRecord.signature.algorithm,
|
|
77
|
+
keyId: trustRecord.signature.keyId,
|
|
78
|
+
signature: trustRecord.signature.value,
|
|
79
|
+
}, canonicalExecutionTrustRecord(trustRecord), publicKeys, algorithmsChecked, errors);
|
|
80
|
+
let hybridSignaturesValid;
|
|
81
|
+
//
|
|
82
|
+
// An auditor may hand this anything: a signatures field that is not
|
|
83
|
+
// an array of { algorithm, keyId, signature } strings is reported as
|
|
84
|
+
// an invalid hybrid envelope, never read as one (and never thrown).
|
|
85
|
+
//
|
|
86
|
+
const signaturesMalformed = trustRecord.signatures !== undefined &&
|
|
87
|
+
trustRecord.signatures !== null &&
|
|
88
|
+
(!Array.isArray(trustRecord.signatures) ||
|
|
89
|
+
!trustRecord.signatures.every(isSignatureEntry));
|
|
90
|
+
const declaredVersion = trustRecord.schemaVersion ?? 2;
|
|
91
|
+
if (signaturesMalformed) {
|
|
92
|
+
errors.push("malformed signatures: expected an array of entries with string algorithm, keyId and signature.");
|
|
93
|
+
hybridSignaturesValid = false;
|
|
94
|
+
}
|
|
95
|
+
else if (!SUPPORTED_HYBRID_SCHEMA_VERSIONS.includes(declaredVersion)) {
|
|
96
|
+
errors.push(`unsupported schemaVersion ${String(declaredVersion)}: expected 2 or 3.`);
|
|
97
|
+
hybridSignaturesValid = false;
|
|
98
|
+
}
|
|
99
|
+
else if (trustRecord.signatures === undefined ||
|
|
100
|
+
trustRecord.signatures === null ||
|
|
101
|
+
trustRecord.signatures.length === 0) {
|
|
102
|
+
//
|
|
103
|
+
// A schema version 3 record declares that it is whole-record signed,
|
|
104
|
+
// so a missing signatures array is a failure, not a legacy-only pass.
|
|
105
|
+
//
|
|
106
|
+
if (declaredVersion === WHOLE_RECORD_SCHEMA_VERSION) {
|
|
107
|
+
errors.push("schemaVersion 3 record has no signatures array: a whole-record signature is required.");
|
|
108
|
+
hybridSignaturesValid = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const hybridArtifact = hybridSignedCanonicalView(trustRecord, declaredVersion);
|
|
113
|
+
const seenAlgorithms = new Set();
|
|
114
|
+
let allValid = trustRecord.signatures.length >= 2;
|
|
115
|
+
if (!allValid) {
|
|
116
|
+
errors.push(`signatures array has ${trustRecord.signatures.length} entr${trustRecord.signatures.length === 1 ? "y" : "ies"}, need at least 2 for a hybrid record.`);
|
|
117
|
+
}
|
|
118
|
+
for (const entry of trustRecord.signatures) {
|
|
119
|
+
if (seenAlgorithms.has(entry.algorithm)) {
|
|
120
|
+
errors.push(`duplicate algorithm in signatures array: ${entry.algorithm}.`);
|
|
121
|
+
allValid = false;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
seenAlgorithms.add(entry.algorithm);
|
|
125
|
+
const entryValid = await verifyOneEntry(entry, hybridArtifact, publicKeys, algorithmsChecked, errors);
|
|
126
|
+
allValid = allValid && entryValid;
|
|
127
|
+
}
|
|
128
|
+
hybridSignaturesValid = allValid;
|
|
129
|
+
}
|
|
130
|
+
//
|
|
131
|
+
// A record with no hybrid envelope is accepted only when the caller
|
|
132
|
+
// allows it: explicitly (allowLegacyOnly), or because the record predates
|
|
133
|
+
// a cutover the caller supplied (ADR-0016). Otherwise it is refused, so a
|
|
134
|
+
// stripped envelope can never pass by default. An envelope that is present
|
|
135
|
+
// has already been judged above.
|
|
136
|
+
//
|
|
137
|
+
const predatesCutover = options.hybridRequiredFrom !== undefined &&
|
|
138
|
+
!isAtOrAfterCutover(trustRecord.createdAt, options.hybridRequiredFrom);
|
|
139
|
+
// With a cutover, the cutover alone decides; allowLegacyOnly applies only when none is given.
|
|
140
|
+
const legacyOnlyAllowed = options.hybridRequiredFrom !== undefined
|
|
141
|
+
? predatesCutover
|
|
142
|
+
: options.allowLegacyOnly === true;
|
|
143
|
+
const hybridOk = hybridSignaturesValid === undefined
|
|
144
|
+
? legacyOnlyAllowed
|
|
145
|
+
: hybridSignaturesValid;
|
|
146
|
+
if (hybridSignaturesValid === undefined && !legacyOnlyAllowed) {
|
|
147
|
+
errors.push(options.hybridRequiredFrom === undefined
|
|
148
|
+
? "record has no hybrid envelope: pass hybridRequiredFrom or allowLegacyOnly to accept a legacy-only record."
|
|
149
|
+
: `record created at or after hybridRequiredFrom (${options.hybridRequiredFrom}) has no valid hybrid envelope.`);
|
|
150
|
+
}
|
|
151
|
+
const valid = hashValid && legacySignatureValid && hybridOk;
|
|
152
|
+
return {
|
|
153
|
+
valid,
|
|
154
|
+
hashValid,
|
|
155
|
+
legacySignatureValid,
|
|
156
|
+
...(hybridSignaturesValid !== undefined ? { hybridSignaturesValid } : {}),
|
|
157
|
+
algorithmsChecked,
|
|
158
|
+
errors,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Verifies an Execution Intent (ADR-0012) with no network call, no database and
|
|
163
|
+
* no key directory: only the intent and the public key(s) are needed. Checks
|
|
164
|
+
* that the recorded hash matches the canonical intent and that the signature
|
|
165
|
+
* verifies against the public key for the intent's keyId.
|
|
166
|
+
*
|
|
167
|
+
* A valid result proves the intent was signed by the holder of that key and has
|
|
168
|
+
* not been altered. It does not prove the action was released, or what the
|
|
169
|
+
* result was: an intent is written BEFORE release. Whether a signed Execution
|
|
170
|
+
* Trust Record exists for the same businessTransactionId is a separate check.
|
|
171
|
+
*/
|
|
172
|
+
export async function verifyExecutionIntentOffline(intent, publicKeys) {
|
|
173
|
+
const malformed = malformedArtifact(intent, "intentHash");
|
|
174
|
+
if (malformed !== undefined) {
|
|
175
|
+
return malformed;
|
|
176
|
+
}
|
|
177
|
+
const errors = [];
|
|
178
|
+
const algorithmsChecked = [];
|
|
179
|
+
const hasher = new TrustRecordHasher({
|
|
180
|
+
hash: new SHA256HashProvider(),
|
|
181
|
+
signature: new Ed25519SignatureProvider(),
|
|
182
|
+
});
|
|
183
|
+
const canonical = canonicalExecutionIntent(intent);
|
|
184
|
+
const expectedHash = await hasher.hash(canonical);
|
|
185
|
+
const hashValid = expectedHash === intent.intentHash;
|
|
186
|
+
if (!hashValid) {
|
|
187
|
+
errors.push(`intentHash mismatch: expected ${expectedHash}, got ${intent.intentHash}.`);
|
|
188
|
+
}
|
|
189
|
+
const legacySignatureValid = await verifyOneEntry({
|
|
190
|
+
algorithm: intent.signature.algorithm,
|
|
191
|
+
keyId: intent.signature.keyId,
|
|
192
|
+
signature: intent.signature.value,
|
|
193
|
+
}, canonical, publicKeys, algorithmsChecked, errors);
|
|
194
|
+
return {
|
|
195
|
+
valid: hashValid && legacySignatureValid,
|
|
196
|
+
hashValid,
|
|
197
|
+
legacySignatureValid,
|
|
198
|
+
algorithmsChecked,
|
|
199
|
+
errors,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The result for input that is not a record of the expected shape: no
|
|
204
|
+
* hash field or no signature object. Returned instead of throwing, so a
|
|
205
|
+
* caller verifying untrusted files always gets `valid: false` and a
|
|
206
|
+
* reason, as OfflineVerificationResult documents.
|
|
207
|
+
*/
|
|
208
|
+
function isSignatureEntry(value) {
|
|
209
|
+
const entry = value;
|
|
210
|
+
return (typeof entry === "object" &&
|
|
211
|
+
entry !== null &&
|
|
212
|
+
typeof entry.algorithm === "string" &&
|
|
213
|
+
typeof entry.keyId === "string" &&
|
|
214
|
+
typeof entry.signature === "string");
|
|
215
|
+
}
|
|
216
|
+
function malformedArtifact(artifact, hashField) {
|
|
217
|
+
const record = artifact;
|
|
218
|
+
const signature = typeof record === "object" && record !== null
|
|
219
|
+
? record.signature
|
|
220
|
+
: undefined;
|
|
221
|
+
const wellFormed = typeof record === "object" &&
|
|
222
|
+
record !== null &&
|
|
223
|
+
typeof record[hashField] === "string" &&
|
|
224
|
+
typeof signature === "object" &&
|
|
225
|
+
signature !== null &&
|
|
226
|
+
typeof signature.algorithm === "string" &&
|
|
227
|
+
typeof signature.keyId === "string" &&
|
|
228
|
+
typeof signature.value === "string";
|
|
229
|
+
if (wellFormed) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
valid: false,
|
|
234
|
+
hashValid: false,
|
|
235
|
+
legacySignatureValid: false,
|
|
236
|
+
algorithmsChecked: [],
|
|
237
|
+
errors: [
|
|
238
|
+
`malformed input: expected an object with a string ${hashField} and a signature with algorithm, keyId and value.`,
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async function verifyOneEntry(entry, artifact, publicKeys, algorithmsChecked, errors) {
|
|
243
|
+
const signatureProvider = signatureProviderFor(entry.algorithm);
|
|
244
|
+
if (!signatureProvider) {
|
|
245
|
+
errors.push(`unsupported algorithm: ${entry.algorithm}.`);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const publicKeyPem = publicKeys[entry.keyId];
|
|
249
|
+
if (!publicKeyPem) {
|
|
250
|
+
errors.push(`no public key supplied for keyId "${entry.keyId}".`);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
algorithmsChecked.push(entry.algorithm);
|
|
254
|
+
try {
|
|
255
|
+
const publicKey = createPublicKey(publicKeyPem);
|
|
256
|
+
const verifier = new SignatureVerifier({
|
|
257
|
+
hash: new SHA256HashProvider(),
|
|
258
|
+
signature: signatureProvider,
|
|
259
|
+
});
|
|
260
|
+
const verified = await verifier.verify(artifact, entry.signature, publicKey);
|
|
261
|
+
if (!verified) {
|
|
262
|
+
errors.push(`signature verification failed for keyId "${entry.keyId}" (${entry.algorithm}).`);
|
|
263
|
+
}
|
|
264
|
+
return verified;
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
errors.push(`error verifying keyId "${entry.keyId}" (${entry.algorithm}): ${error instanceof Error ? error.message : String(error)}`);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=OfflineVerifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfflineVerifier.js","sourceRoot":"","sources":["../src/OfflineVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,gCAAgC,EAChC,2BAA2B,GAC5B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EAAE,MAAM,sDA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GAAG,IAAI,iBAAiB,CAAC;YACrC,IAAI,EAAE,IAAI,kBAAkB,EAAE;YAC9B,SAAS,EAAE,iBAAiB;SAC7B,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CACpC,QAAQ,EACR,KAAK,CAAC,SAAS,EACf,SAAS,CACV,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,CACT,4CAA4C,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,SAAS,IAAI,CACjF,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CACT,0BAA0B,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,SAAS,MACxD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PolicyChangeApprovalRecord, Signature } from "@parmana/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Policy Change cryptographic operations (Policy Governance,
|
|
4
|
+
* maker-checker).
|
|
5
|
+
*
|
|
6
|
+
* Parallel to RefusalCrypto, over PolicyChangeApprovalRecord instead
|
|
7
|
+
* of RefusalRecord. Deliberately reuses the exact same signing stack
|
|
8
|
+
* and DEFAULT_KEY_ID as VerificationCrypto/RefusalCrypto -- see
|
|
9
|
+
* PolicyChangeApprovalRecord's own doc comment: this is the same
|
|
10
|
+
* trust root approvals and refusals already share, not a third key
|
|
11
|
+
* to manage.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PolicyChangeCrypto {
|
|
14
|
+
private readonly crypto;
|
|
15
|
+
private readonly signerPromise;
|
|
16
|
+
private readonly hasher;
|
|
17
|
+
private readonly signer;
|
|
18
|
+
private readonly verifier;
|
|
19
|
+
/**
|
|
20
|
+
* Creates the canonical immutable view of a Policy Change Approval
|
|
21
|
+
* Record used for signing/verification. Excludes the signature
|
|
22
|
+
* itself.
|
|
23
|
+
*/
|
|
24
|
+
private canonicalRecord;
|
|
25
|
+
/**
|
|
26
|
+
* Hashes arbitrary canonicalized policy content -- the same
|
|
27
|
+
* canonicalization and hash algorithm as every other artifact hash
|
|
28
|
+
* in this codebase, used for PolicyChangeApprovalRecord's
|
|
29
|
+
* contentHashBefore/contentHashAfter (the canonicalized policy.json
|
|
30
|
+
* content immediately before/after an approval, not the approval
|
|
31
|
+
* record itself).
|
|
32
|
+
*/
|
|
33
|
+
hashPolicyContent(content: unknown): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a digital signature over the canonical Policy Change
|
|
36
|
+
* Approval Record.
|
|
37
|
+
*/
|
|
38
|
+
sign(record: PolicyChangeApprovalRecord): Promise<Signature>;
|
|
39
|
+
/**
|
|
40
|
+
* Verifies the signature of a Policy Change Approval Record.
|
|
41
|
+
*/
|
|
42
|
+
verify(record: PolicyChangeApprovalRecord): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=PolicyChangeCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyChangeCrypto.d.ts","sourceRoot":"","sources":["../src/PolicyChangeCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS7E;;;;;;;;;;GAUG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAE1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAE7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAE/D;;;;OAIG;IACH,OAAO,CAAC,eAAe;IA0BvB;;;;;;;OAOG;IACG,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAEzD;IAED;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,SAAS,CAAC,CAoBjE;IAED;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,OAAO,CAAC,CAUjE;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { CryptoBootstrap } from "./CryptoBootstrap.js";
|
|
2
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
3
|
+
import { ArtifactSigner } from "./ArtifactSigner.js";
|
|
4
|
+
import { SignatureVerifier } from "./SignatureVerifier.js";
|
|
5
|
+
import { SignerBootstrap } from "./SignerBootstrap.js";
|
|
6
|
+
import { DEFAULT_KEY_ID } from "./KeyProvider.js";
|
|
7
|
+
/**
|
|
8
|
+
* Policy Change cryptographic operations (Policy Governance,
|
|
9
|
+
* maker-checker).
|
|
10
|
+
*
|
|
11
|
+
* Parallel to RefusalCrypto, over PolicyChangeApprovalRecord instead
|
|
12
|
+
* of RefusalRecord. Deliberately reuses the exact same signing stack
|
|
13
|
+
* and DEFAULT_KEY_ID as VerificationCrypto/RefusalCrypto -- see
|
|
14
|
+
* PolicyChangeApprovalRecord's own doc comment: this is the same
|
|
15
|
+
* trust root approvals and refusals already share, not a third key
|
|
16
|
+
* to manage.
|
|
17
|
+
*/
|
|
18
|
+
export class PolicyChangeCrypto {
|
|
19
|
+
crypto = CryptoBootstrap.create();
|
|
20
|
+
signerPromise = SignerBootstrap.create();
|
|
21
|
+
hasher = new TrustRecordHasher(this.crypto);
|
|
22
|
+
signer = new ArtifactSigner(this.crypto);
|
|
23
|
+
verifier = new SignatureVerifier(this.crypto);
|
|
24
|
+
/**
|
|
25
|
+
* Creates the canonical immutable view of a Policy Change Approval
|
|
26
|
+
* Record used for signing/verification. Excludes the signature
|
|
27
|
+
* itself.
|
|
28
|
+
*/
|
|
29
|
+
canonicalRecord(record) {
|
|
30
|
+
return {
|
|
31
|
+
policyChangeApprovalRecordId: record.policyChangeApprovalRecordId,
|
|
32
|
+
pendingPolicyChangeId: record.pendingPolicyChangeId,
|
|
33
|
+
policyName: record.policyName,
|
|
34
|
+
policyVersion: record.policyVersion,
|
|
35
|
+
proposedBy: record.proposedBy,
|
|
36
|
+
approvedBy: record.approvedBy,
|
|
37
|
+
proposedAt: record.proposedAt,
|
|
38
|
+
approvedAt: record.approvedAt,
|
|
39
|
+
contentHashBefore: record.contentHashBefore,
|
|
40
|
+
contentHashAfter: record.contentHashAfter,
|
|
41
|
+
previousRecordHash: record.previousRecordHash,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hashes arbitrary canonicalized policy content -- the same
|
|
46
|
+
* canonicalization and hash algorithm as every other artifact hash
|
|
47
|
+
* in this codebase, used for PolicyChangeApprovalRecord's
|
|
48
|
+
* contentHashBefore/contentHashAfter (the canonicalized policy.json
|
|
49
|
+
* content immediately before/after an approval, not the approval
|
|
50
|
+
* record itself).
|
|
51
|
+
*/
|
|
52
|
+
async hashPolicyContent(content) {
|
|
53
|
+
return this.hasher.hash(content);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a digital signature over the canonical Policy Change
|
|
57
|
+
* Approval Record.
|
|
58
|
+
*/
|
|
59
|
+
async sign(record) {
|
|
60
|
+
const keyId = DEFAULT_KEY_ID;
|
|
61
|
+
const signer = await this.signerPromise;
|
|
62
|
+
const value = await this.signer.signWithSigner(this.canonicalRecord(record), keyId, signer);
|
|
63
|
+
return {
|
|
64
|
+
algorithm: this.crypto.signature.algorithm,
|
|
65
|
+
keyId,
|
|
66
|
+
value,
|
|
67
|
+
signedAt: new Date(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Verifies the signature of a Policy Change Approval Record.
|
|
72
|
+
*/
|
|
73
|
+
async verify(record) {
|
|
74
|
+
const signer = await this.signerPromise;
|
|
75
|
+
const publicKey = await signer.getPublicKey(record.signature.keyId);
|
|
76
|
+
return this.verifier.verify(this.canonicalRecord(record), record.signature.value, publicKey);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=PolicyChangeCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyChangeCrypto.js","sourceRoot":"","sources":["../src/PolicyChangeCrypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IACZ,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAElC,aAAa,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAEzC,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEzC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE/D;;;;OAIG;IACK,eAAe,CAAC,MAAkC;QACxD,OAAO;YACL,4BAA4B,EAAE,MAAM,CAAC,4BAA4B;YAEjE,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;YAEnD,UAAU,EAAE,MAAM,CAAC,UA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KAAK,EACtB,SAAS,CACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { KeyObject } from "node:crypto";
|
|
2
|
+
import type { PolicyChangeStepUpAuthorization } from "@parmana/shared";
|
|
3
|
+
/**
|
|
4
|
+
* Signs a PolicyChangeStepUpAuthorization. Used by
|
|
5
|
+
* scripts/sign-policy-change-step-up.ts, run by a human checker on
|
|
6
|
+
* their own machine against their own private key -- never runs
|
|
7
|
+
* server-side. Mirrors AuthorizationSigner's shape (caller supplies
|
|
8
|
+
* identity/action fields, this method supplies nonce/timestamps, then
|
|
9
|
+
* signs), scoped to the narrower step-up payload.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PolicyChangeStepUpAuthorizationSigner {
|
|
12
|
+
private readonly signer;
|
|
13
|
+
sign(input: {
|
|
14
|
+
readonly pendingPolicyChangeId: string;
|
|
15
|
+
readonly action: "approve" | "reject";
|
|
16
|
+
}, privateKey: KeyObject, keyId: string, ttlSeconds: number): Promise<PolicyChangeStepUpAuthorization>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of verifying a PolicyChangeStepUpAuthorization's
|
|
20
|
+
* side-effect-free properties: payload version, signature, expiry,
|
|
21
|
+
* and binding to the specific (pendingPolicyChangeId, action) the
|
|
22
|
+
* request is for. Never touches a nonce store -- see
|
|
23
|
+
* packages/api/src/auth/PolicyChangeStepUpVerifier.ts for the
|
|
24
|
+
* envelope-level wrapper that adds TTL policy and nonce consumption,
|
|
25
|
+
* mirroring EnvelopeVerifier's own verifyChecks()/consumeNonce()/
|
|
26
|
+
* verify() split for the same reason: nonce consumption is the only
|
|
27
|
+
* side-effecting check, and must run last, only once every other
|
|
28
|
+
* check has independently passed.
|
|
29
|
+
*/
|
|
30
|
+
export interface PolicyChangeStepUpPayloadVerificationResult {
|
|
31
|
+
readonly valid: boolean;
|
|
32
|
+
readonly checks: {
|
|
33
|
+
readonly versionSupported: boolean;
|
|
34
|
+
readonly signatureVerified: boolean;
|
|
35
|
+
readonly notExpired: boolean;
|
|
36
|
+
readonly pendingPolicyChangeIdMatches: boolean;
|
|
37
|
+
readonly actionMatches: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Verifies a PolicyChangeStepUpAuthorization's signature, expiry, and
|
|
42
|
+
* binding to the specific action it is being presented for. Runs
|
|
43
|
+
* server-side, in pending-policy-changes.ts's approve/reject handlers
|
|
44
|
+
* via PolicyChangeStepUpVerifier. Mirrors AuthorizationVerifier's own
|
|
45
|
+
* no-early-return-between-independent-checks discipline (no timing
|
|
46
|
+
* oracle on any one field).
|
|
47
|
+
*/
|
|
48
|
+
export declare class PolicyChangeStepUpAuthorizationVerifier {
|
|
49
|
+
private readonly verifier;
|
|
50
|
+
verify(authorization: PolicyChangeStepUpAuthorization, publicKey: KeyObject, expected: {
|
|
51
|
+
readonly pendingPolicyChangeId: string;
|
|
52
|
+
readonly action: "approve" | "reject";
|
|
53
|
+
}, now?: Date): Promise<PolicyChangeStepUpPayloadVerificationResult>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=PolicyChangeStepUpAuthorizationCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyChangeStepUpAuthorizationCrypto.d.ts","sourceRoot":"","sources":["../src/PolicyChangeStepUpAuthorizationCrypto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,iBAAiB,CAAC;AA4BzB;;;;;;;GAOG;AACH,qBAAa,qCAAqC;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoD;IAErE,IAAI,CACR,KAAK,EAAE;QACL,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;QACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;KACvC,EACD,UAAU,EAAE,SAAS,EACrB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,+BAA+B,CAAC,CAyB1C;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,2CAA2C;IAC1D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;QACnC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACpC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;QAC7B,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC;QAC/C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;KACjC,CAAC;CACH;AAED;;;;;;;GAOG;AACH,qBAAa,uCAAuC;IAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAEvB;IAEI,MAAM,CACV,aAAa,EAAE,+BAA+B,EAC9C,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE;QACR,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;QACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;KACvC,EACD,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,2CAA2C,CAAC,CAuDtD;CACF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ArtifactSigner } from "./ArtifactSigner.js";
|
|
3
|
+
import { SignatureVerifier } from "./SignatureVerifier.js";
|
|
4
|
+
import { SHA256HashProvider } from "./providers/hash/SHA256HashProvider.js";
|
|
5
|
+
import { Ed25519SignatureProvider } from "./providers/signature/Ed25519SignatureProvider.js";
|
|
6
|
+
/** Allowed clock drift when checking authorizedAt against now. */
|
|
7
|
+
const STEP_UP_CLOCK_SKEW_MS = 60_000;
|
|
8
|
+
const SUPPORTED_PAYLOAD_VERSION = 1;
|
|
9
|
+
/**
|
|
10
|
+
* Step-up keys are always Ed25519, independent of whatever this
|
|
11
|
+
* server's own SIGNATURE_PROVIDER is configured to (that setting
|
|
12
|
+
* governs Parmana's own runtime signing key -- gateway attestation,
|
|
13
|
+
* execution authorization -- never an operator-held key like this
|
|
14
|
+
* one). Hardcoded here rather than threaded through CryptoBootstrap so
|
|
15
|
+
* that PolicyChangeStepUpAuthorizationSigner, run by a checker on
|
|
16
|
+
* their own machine via scripts/sign-policy-change-step-up.ts, never
|
|
17
|
+
* depends on the server's environment/config at all.
|
|
18
|
+
*/
|
|
19
|
+
const ED25519_ONLY_CRYPTO_PROVIDER = {
|
|
20
|
+
hash: new SHA256HashProvider(),
|
|
21
|
+
signature: new Ed25519SignatureProvider(),
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Signs a PolicyChangeStepUpAuthorization. Used by
|
|
25
|
+
* scripts/sign-policy-change-step-up.ts, run by a human checker on
|
|
26
|
+
* their own machine against their own private key -- never runs
|
|
27
|
+
* server-side. Mirrors AuthorizationSigner's shape (caller supplies
|
|
28
|
+
* identity/action fields, this method supplies nonce/timestamps, then
|
|
29
|
+
* signs), scoped to the narrower step-up payload.
|
|
30
|
+
*/
|
|
31
|
+
export class PolicyChangeStepUpAuthorizationSigner {
|
|
32
|
+
signer = new ArtifactSigner(ED25519_ONLY_CRYPTO_PROVIDER);
|
|
33
|
+
async sign(input, privateKey, keyId, ttlSeconds) {
|
|
34
|
+
if (!Number.isFinite(ttlSeconds) || ttlSeconds <= 0) {
|
|
35
|
+
throw new Error(`Invalid step-up authorization TTL: ${ttlSeconds}`);
|
|
36
|
+
}
|
|
37
|
+
const authorizedAt = new Date();
|
|
38
|
+
const expiresAt = new Date(authorizedAt.getTime() + ttlSeconds * 1000);
|
|
39
|
+
const payload = {
|
|
40
|
+
version: SUPPORTED_PAYLOAD_VERSION,
|
|
41
|
+
nonce: randomUUID(),
|
|
42
|
+
pendingPolicyChangeId: input.pendingPolicyChangeId,
|
|
43
|
+
action: input.action,
|
|
44
|
+
authorizedAt: authorizedAt.toISOString(),
|
|
45
|
+
expiresAt: expiresAt.toISOString(),
|
|
46
|
+
};
|
|
47
|
+
const signature = await this.signer.sign(payload, privateKey);
|
|
48
|
+
return {
|
|
49
|
+
payload,
|
|
50
|
+
signature,
|
|
51
|
+
keyId,
|
|
52
|
+
algorithm: ED25519_ONLY_CRYPTO_PROVIDER.signature.algorithm,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Verifies a PolicyChangeStepUpAuthorization's signature, expiry, and
|
|
58
|
+
* binding to the specific action it is being presented for. Runs
|
|
59
|
+
* server-side, in pending-policy-changes.ts's approve/reject handlers
|
|
60
|
+
* via PolicyChangeStepUpVerifier. Mirrors AuthorizationVerifier's own
|
|
61
|
+
* no-early-return-between-independent-checks discipline (no timing
|
|
62
|
+
* oracle on any one field).
|
|
63
|
+
*/
|
|
64
|
+
export class PolicyChangeStepUpAuthorizationVerifier {
|
|
65
|
+
verifier = new SignatureVerifier(ED25519_ONLY_CRYPTO_PROVIDER);
|
|
66
|
+
async verify(authorization, publicKey, expected, now = new Date()) {
|
|
67
|
+
const versionSupported = authorization.payload.version === SUPPORTED_PAYLOAD_VERSION;
|
|
68
|
+
if (!versionSupported) {
|
|
69
|
+
return {
|
|
70
|
+
valid: false,
|
|
71
|
+
checks: {
|
|
72
|
+
versionSupported: false,
|
|
73
|
+
signatureVerified: false,
|
|
74
|
+
notExpired: false,
|
|
75
|
+
pendingPolicyChangeIdMatches: false,
|
|
76
|
+
actionMatches: false,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const signatureVerified = await this.verifier.verify(authorization.payload, authorization.signature, publicKey);
|
|
81
|
+
const expiry = Date.parse(authorization.payload.expiresAt);
|
|
82
|
+
const notExpired = Number.isFinite(expiry) && now.getTime() < expiry;
|
|
83
|
+
// An envelope signed for a future window must not be usable now. The
|
|
84
|
+
// skew allowance covers clock drift between the issuer and this check.
|
|
85
|
+
const issued = Date.parse(authorization.payload.authorizedAt);
|
|
86
|
+
const notFromTheFuture = Number.isFinite(issued) &&
|
|
87
|
+
issued <= now.getTime() + STEP_UP_CLOCK_SKEW_MS;
|
|
88
|
+
const pendingPolicyChangeIdMatches = authorization.payload.pendingPolicyChangeId ===
|
|
89
|
+
expected.pendingPolicyChangeId;
|
|
90
|
+
const actionMatches = authorization.payload.action === expected.action;
|
|
91
|
+
return {
|
|
92
|
+
valid: signatureVerified &&
|
|
93
|
+
notExpired &&
|
|
94
|
+
notFromTheFuture &&
|
|
95
|
+
pendingPolicyChangeIdMatches &&
|
|
96
|
+
actionMatches,
|
|
97
|
+
checks: {
|
|
98
|
+
versionSupported,
|
|
99
|
+
signatureVerified,
|
|
100
|
+
notExpired,
|
|
101
|
+
pendingPolicyChangeIdMatches,
|
|
102
|
+
actionMatches,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=PolicyChangeStepUpAuthorizationCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyChangeStepUpAuthorizationCrypto.js","sourceRoot":"","sources":["../src/PolicyChangeStepUpAuthorizationCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAG7F,kEAAkE;AAClE,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAEpC;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAmB;IACnD,IAAI,EAAE,IAAI,kB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BAChB,iBAAiB;gBACjB,UAAU;gBACV,4BAA4B;gBAC5B,aAAa;aACd;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Receipt } from "@parmana/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Receipt cryptographic operations.
|
|
4
|
+
*
|
|
5
|
+
* Owns all receipt-related cryptographic
|
|
6
|
+
* operations for Parmana.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ReceiptCrypto {
|
|
9
|
+
private readonly crypto;
|
|
10
|
+
private readonly config;
|
|
11
|
+
/**
|
|
12
|
+
* Signer (ADR-0009) -- LocalFileSigner or KmsSigner depending on
|
|
13
|
+
* KEY_PROVIDER.
|
|
14
|
+
*/
|
|
15
|
+
private readonly signerPromise;
|
|
16
|
+
/**
|
|
17
|
+
* Hybrid mode's secondary signature stays local-file-backed; see
|
|
18
|
+
* the identical comment in VerificationCrypto.
|
|
19
|
+
*/
|
|
20
|
+
private readonly hybridKeys;
|
|
21
|
+
private readonly trustRecordHasher;
|
|
22
|
+
private readonly receiptHasher;
|
|
23
|
+
private readonly signer;
|
|
24
|
+
/**
|
|
25
|
+
* Computes the canonical receipt hash.
|
|
26
|
+
*/
|
|
27
|
+
hash(trustRecord: unknown): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Signs any canonical object.
|
|
30
|
+
*/
|
|
31
|
+
sign(value: unknown): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a signed Receipt.
|
|
34
|
+
*
|
|
35
|
+
* The legacy `signature`/`algorithm` are unchanged by hybrid mode:
|
|
36
|
+
* always signed by the configured primary provider alone, over
|
|
37
|
+
* exactly the same content as before this milestone (Hybrid
|
|
38
|
+
* Signature Support, Phase A). When CRYPTO_MODE=hybrid, an
|
|
39
|
+
* additional `signatures` array and `schemaVersion` are populated
|
|
40
|
+
* alongside them -- additive, never replacing the legacy fields.
|
|
41
|
+
*/
|
|
42
|
+
createReceipt(payload: Omit<Receipt, "signature" | "algorithm" | "schemaVersion" | "signatures">): Promise<Receipt>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ReceiptCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceiptCrypto.d.ts","sourceRoot":"","sources":["../src/ReceiptCrypto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAmB/C;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAE1D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IAEpD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAsC;IAExE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA6C;IAE3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D;;OAEG;IACG,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhD;IAED;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1C;IAED;;;;;;;;;OASG;IACG,aAAa,CACjB,OAAO,EAAE,IAAI,CACX,OAAO,EACP,WAAW,GAAG,WAAW,GAAG,eAAe,GAAG,YAAY,CAC3D,GACA,OAAO,CAAC,OAAO,CAAC,CAuClB;CACF"}
|