马宇豪
2024-07-16 f591c27b57e2418c9495bc02ae8cfff84d35bc18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.signatureContent = exports.toSignedEntity = void 0;
const core_1 = require("@sigstore/core");
const dsse_1 = require("./dsse");
const message_1 = require("./message");
function toSignedEntity(bundle, artifact) {
    const { tlogEntries, timestampVerificationData } = bundle.verificationMaterial;
    const timestamps = [];
    for (const entry of tlogEntries) {
        timestamps.push({
            $case: 'transparency-log',
            tlogEntry: entry,
        });
    }
    for (const ts of timestampVerificationData?.rfc3161Timestamps ?? []) {
        timestamps.push({
            $case: 'timestamp-authority',
            timestamp: core_1.RFC3161Timestamp.parse(ts.signedTimestamp),
        });
    }
    return {
        signature: signatureContent(bundle, artifact),
        key: key(bundle),
        tlogEntries,
        timestamps,
    };
}
exports.toSignedEntity = toSignedEntity;
function signatureContent(bundle, artifact) {
    switch (bundle.content.$case) {
        case 'dsseEnvelope':
            return new dsse_1.DSSESignatureContent(bundle.content.dsseEnvelope);
        case 'messageSignature':
            return new message_1.MessageSignatureContent(bundle.content.messageSignature, artifact);
    }
}
exports.signatureContent = signatureContent;
function key(bundle) {
    switch (bundle.verificationMaterial.content.$case) {
        case 'publicKey':
            return {
                $case: 'public-key',
                hint: bundle.verificationMaterial.content.publicKey.hint,
            };
        case 'x509CertificateChain':
            return {
                $case: 'certificate',
                certificate: core_1.X509Certificate.parse(bundle.verificationMaterial.content.x509CertificateChain
                    .certificates[0].rawBytes),
            };
        case 'certificate':
            return {
                $case: 'certificate',
                certificate: core_1.X509Certificate.parse(bundle.verificationMaterial.content.certificate.rawBytes),
            };
    }
}