formacao
This commit is contained in:
+1
@@ -3,3 +3,4 @@ export { PolicyError, VerificationError } from './error';
|
||||
export { KeyFinderFunc, TrustMaterial, toTrustMaterial } from './trust';
|
||||
export { Verifier, VerifierOptions } from './verifier';
|
||||
export type { SignedEntity, Signer, VerificationPolicy } from './shared.types';
|
||||
export type { ObjectIdentifierValuePair } from '@sigstore/protobuf-specs';
|
||||
|
||||
+8
@@ -56,9 +56,17 @@ function getSigner(cert) {
|
||||
else {
|
||||
issuer = cert.extension(OID_FULCIO_ISSUER_V1)?.value.toString('ascii');
|
||||
}
|
||||
const oids = cert.extensions.map((ext) => {
|
||||
const oid = ext.subs[0].toOID();
|
||||
return {
|
||||
oid: { id: oid.split('.').map(Number) },
|
||||
value: ext.subs[ext.subs.length - 1].value,
|
||||
};
|
||||
});
|
||||
const identity = {
|
||||
extensions: { issuer },
|
||||
subjectAlternativeName: cert.subjectAltName,
|
||||
oids,
|
||||
};
|
||||
return {
|
||||
key: core_1.crypto.createPublicKey(cert.publicKey),
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
import { CertificateExtensions } from './shared.types';
|
||||
import type { ObjectIdentifierValuePair } from '@sigstore/protobuf-specs';
|
||||
export declare function verifySubjectAlternativeName(policyIdentity: string, signerIdentity: string | undefined): void;
|
||||
export declare function verifyExtensions(policyExtensions: CertificateExtensions, signerExtensions?: CertificateExtensions): void;
|
||||
export declare function verifyOIDs(policyOIDs: ObjectIdentifierValuePair[], signerOIDs?: ObjectIdentifierValuePair[]): void;
|
||||
|
||||
+26
@@ -2,7 +2,12 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.verifySubjectAlternativeName = verifySubjectAlternativeName;
|
||||
exports.verifyExtensions = verifyExtensions;
|
||||
exports.verifyOIDs = verifyOIDs;
|
||||
const error_1 = require("./error");
|
||||
// Verifies that the signer's SAN matches the policy identity. The
|
||||
// policyIdentity is treated as a JavaScript regular expression pattern and
|
||||
// tested against the full signerIdentity string. For exact matching, use
|
||||
// anchored patterns (e.g. '^user@example\\.com$').
|
||||
function verifySubjectAlternativeName(policyIdentity, signerIdentity) {
|
||||
if (signerIdentity === undefined || !signerIdentity.match(policyIdentity)) {
|
||||
throw new error_1.PolicyError({
|
||||
@@ -22,3 +27,24 @@ function verifyExtensions(policyExtensions, signerExtensions = {}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function verifyOIDs(policyOIDs, signerOIDs = []) {
|
||||
for (const policyOID of policyOIDs) {
|
||||
const match = signerOIDs.find((signerOID) => oidEquals(policyOID.oid?.id, signerOID.oid?.id) &&
|
||||
policyOID.value.equals(signerOID.value));
|
||||
if (!match) {
|
||||
/* istanbul ignore next */
|
||||
const oid = policyOID.oid?.id.join('.') ?? '<unknown>';
|
||||
throw new error_1.PolicyError({
|
||||
code: 'UNTRUSTED_SIGNER_ERROR',
|
||||
message: `invalid certificate extension - missing OID ${oid}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function oidEquals(a, b) {
|
||||
/* istanbul ignore if */
|
||||
if (a === undefined || b === undefined) {
|
||||
return false;
|
||||
}
|
||||
return a.length === b.length && a.every((v, i) => v === b[i]);
|
||||
}
|
||||
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
import type { TransparencyLogEntry } from '@sigstore/bundle';
|
||||
import type { RFC3161Timestamp, X509Certificate, crypto } from '@sigstore/core';
|
||||
import type { ObjectIdentifierValuePair } from '@sigstore/protobuf-specs';
|
||||
export type CertificateExtensionName = 'issuer';
|
||||
export type CertificateExtensions = {
|
||||
[key in CertificateExtensionName]?: string;
|
||||
@@ -7,6 +8,7 @@ export type CertificateExtensions = {
|
||||
export type CertificateIdentity = {
|
||||
subjectAlternativeName?: string;
|
||||
extensions?: CertificateExtensions;
|
||||
oids?: ObjectIdentifierValuePair[];
|
||||
};
|
||||
export type VerificationPolicy = CertificateIdentity;
|
||||
export type Signer = {
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ export type TimestampVerificationResult = {
|
||||
timestamp: Date;
|
||||
};
|
||||
export declare function getTSATimestamp(timestamp: RFC3161Timestamp, data: Buffer, timestampAuthorities: CertAuthority[]): TimestampVerificationResult;
|
||||
export declare function getTLogTimestamp(entry: TransparencyLogEntry): TimestampVerificationResult;
|
||||
export declare function getTLogTimestamp(entry: TransparencyLogEntry): TimestampVerificationResult | undefined;
|
||||
|
||||
+4
@@ -12,6 +12,10 @@ function getTSATimestamp(timestamp, data, timestampAuthorities) {
|
||||
};
|
||||
}
|
||||
function getTLogTimestamp(entry) {
|
||||
// Only entries with an inclusion promise provide a verifiable timestamp
|
||||
if (!entry.inclusionPromise) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
type: 'transparency-log',
|
||||
logID: entry.logId.keyId,
|
||||
|
||||
+20
-10
@@ -46,17 +46,22 @@ class Verifier {
|
||||
}
|
||||
// Checks that all of the timestamps in the entity are valid and returns them
|
||||
verifyTimestamps(entity) {
|
||||
let timestampCount = 0;
|
||||
const timestamps = entity.timestamps.map((timestamp) => {
|
||||
const timestamps = [];
|
||||
for (const timestamp of entity.timestamps) {
|
||||
switch (timestamp.$case) {
|
||||
case 'timestamp-authority':
|
||||
timestampCount++;
|
||||
return (0, timestamp_1.getTSATimestamp)(timestamp.timestamp, entity.signature.signature, this.trustMaterial.timestampAuthorities);
|
||||
case 'transparency-log':
|
||||
timestampCount++;
|
||||
return (0, timestamp_1.getTLogTimestamp)(timestamp.tlogEntry);
|
||||
timestamps.push((0, timestamp_1.getTSATimestamp)(timestamp.timestamp, entity.signature.signature, this.trustMaterial.timestampAuthorities));
|
||||
break;
|
||||
case 'transparency-log': {
|
||||
const result = (0, timestamp_1.getTLogTimestamp)(timestamp.tlogEntry);
|
||||
/* istanbul ignore else */
|
||||
if (result) {
|
||||
timestamps.push(result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Check for duplicate timestamps
|
||||
if (containsDupes(timestamps)) {
|
||||
throw new error_1.VerificationError({
|
||||
@@ -64,10 +69,10 @@ class Verifier {
|
||||
message: 'duplicate timestamp',
|
||||
});
|
||||
}
|
||||
if (timestampCount < this.options.timestampThreshold) {
|
||||
if (timestamps.length < this.options.timestampThreshold) {
|
||||
throw new error_1.VerificationError({
|
||||
code: 'TIMESTAMP_ERROR',
|
||||
message: `expected ${this.options.timestampThreshold} timestamps, got ${timestampCount}`,
|
||||
message: `expected ${this.options.timestampThreshold} timestamps, got ${timestamps.length}`,
|
||||
});
|
||||
}
|
||||
return timestamps.map((t) => t.timestamp);
|
||||
@@ -133,6 +138,11 @@ class Verifier {
|
||||
if (policy.extensions) {
|
||||
(0, policy_1.verifyExtensions)(policy.extensions, identity.extensions);
|
||||
}
|
||||
// Check that the OIDs of the signer match the policy
|
||||
/* istanbul ignore if */
|
||||
if (policy.oids) {
|
||||
(0, policy_1.verifyOIDs)(policy.oids, identity.oids);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Verifier = Verifier;
|
||||
|
||||
Reference in New Issue
Block a user