Debian Codegraph @

node_modules/@sigstore/sign/dist/signer/fulcio/ca.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.CAClient = void 0;
4 /*
5 Copyright 2023 The Sigstore Authors.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 */
19 const error_1 = require("../../error");
20 const fulcio_1 = require("../../external/fulcio");
21 class CAClient {
22 fulcio;
23 constructor(options) {
24 this.fulcio = new fulcio_1.Fulcio({
25 baseURL: options.fulcioBaseURL,
26 retry: options.retry,
27 timeout: options.timeout,
28 });
29 }
30 async createSigningCertificate(identityToken, publicKey, challenge) {
31 const request = toCertificateRequest(identityToken, publicKey, challenge);
32 try {
33 const resp = await this.fulcio.createSigningCertificate(request);
34 // Account for the fact that the response may contain either a
35 // signedCertificateEmbeddedSct or a signedCertificateDetachedSct.
36 const cert = resp.signedCertificateEmbeddedSct
37 ? resp.signedCertificateEmbeddedSct
38 : resp.signedCertificateDetachedSct;
39 return cert.chain.certificates;
40 }
41 catch (err) {
42 (0, error_1.internalError)(err, 'CA_CREATE_SIGNING_CERTIFICATE_ERROR', 'error creating signing certificate');
43 }
44 }
45 }
46 exports.CAClient = CAClient;
47 function toCertificateRequest(identityToken, publicKey, challenge) {
48 return {
49 credentials: {
50 oidcIdentityToken: identityToken,
51 },
52 publicKeyRequest: {
53 publicKey: {
54 algorithm: 'ECDSA',
55 content: publicKey,
56 },
57 proofOfPossession: challenge.toString('base64'),
58 },
59 };
60 }