Primeiro commit do projeto Angular
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
import type { Bundle } from '@sigstore/bundle';
|
||||
import type { Signature, Signer } from '../signer';
|
||||
import type { Witness } from '../witness';
|
||||
export interface BundleBuilderOptions {
|
||||
signer: Signer;
|
||||
witnesses: Witness[];
|
||||
}
|
||||
export interface Artifact {
|
||||
data: Buffer;
|
||||
type?: string;
|
||||
}
|
||||
export interface BundleBuilder {
|
||||
create: (artifact: Artifact) => Promise<Bundle>;
|
||||
}
|
||||
export declare abstract class BaseBundleBuilder<T extends Bundle> implements BundleBuilder {
|
||||
protected signer: Signer;
|
||||
private witnesses;
|
||||
constructor(options: BundleBuilderOptions);
|
||||
create(artifact: Artifact): Promise<T>;
|
||||
protected prepare(artifact: Artifact): Promise<Buffer>;
|
||||
protected abstract package(artifact: Artifact, signature: Signature): Promise<T>;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaseBundleBuilder = void 0;
|
||||
// BaseBundleBuilder is a base class for BundleBuilder implementations. It
|
||||
// provides a the basic wokflow for signing and witnessing an artifact.
|
||||
// Subclasses must implement the `package` method to assemble a valid bundle
|
||||
// with the generated signature and verification material.
|
||||
class BaseBundleBuilder {
|
||||
signer;
|
||||
witnesses;
|
||||
constructor(options) {
|
||||
this.signer = options.signer;
|
||||
this.witnesses = options.witnesses;
|
||||
}
|
||||
// Executes the signing/witnessing process for the given artifact.
|
||||
async create(artifact) {
|
||||
const signature = await this.prepare(artifact).then((blob) => this.signer.sign(blob));
|
||||
const bundle = await this.package(artifact, signature);
|
||||
// Invoke all of the witnesses in parallel
|
||||
const verificationMaterials = await Promise.all(this.witnesses.map((witness) => witness.testify(bundle.content, publicKey(signature.key))));
|
||||
// Collect the verification material from all of the witnesses
|
||||
const tlogEntryList = [];
|
||||
const timestampList = [];
|
||||
verificationMaterials.forEach(({ tlogEntries, rfc3161Timestamps }) => {
|
||||
tlogEntryList.push(...(tlogEntries ?? []));
|
||||
timestampList.push(...(rfc3161Timestamps ?? []));
|
||||
});
|
||||
// Merge the collected verification material into the bundle
|
||||
bundle.verificationMaterial.tlogEntries = tlogEntryList;
|
||||
bundle.verificationMaterial.timestampVerificationData = {
|
||||
rfc3161Timestamps: timestampList,
|
||||
};
|
||||
return bundle;
|
||||
}
|
||||
// Override this function to apply any pre-signing transformations to the
|
||||
// artifact. The returned buffer will be signed by the signer. The default
|
||||
// implementation simply returns the artifact data.
|
||||
async prepare(artifact) {
|
||||
return artifact.data;
|
||||
}
|
||||
}
|
||||
exports.BaseBundleBuilder = BaseBundleBuilder;
|
||||
// Extracts the public key from a KeyMaterial. Returns either the public key
|
||||
// or the certificate, depending on the type of key material.
|
||||
function publicKey(key) {
|
||||
switch (key.$case) {
|
||||
case 'publicKey':
|
||||
return key.publicKey;
|
||||
case 'x509Certificate':
|
||||
return key.certificate;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import * as sigstore from '@sigstore/bundle';
|
||||
import type { Signature } from '../signer';
|
||||
import type { Artifact } from './base';
|
||||
export declare function toMessageSignatureBundle(artifact: Artifact, signature: Signature): sigstore.BundleWithMessageSignature;
|
||||
export declare function toDSSEBundle(artifact: Required<Artifact>, signature: Signature, certificateChain?: boolean): sigstore.BundleWithDsseEnvelope;
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toMessageSignatureBundle = toMessageSignatureBundle;
|
||||
exports.toDSSEBundle = toDSSEBundle;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const sigstore = __importStar(require("@sigstore/bundle"));
|
||||
const util_1 = require("../util");
|
||||
// Helper functions for assembling the parts of a Sigstore bundle
|
||||
// Message signature bundle - $case: 'messageSignature'
|
||||
function toMessageSignatureBundle(artifact, signature) {
|
||||
const digest = util_1.crypto.digest('sha256', artifact.data);
|
||||
return sigstore.toMessageSignatureBundle({
|
||||
digest,
|
||||
signature: signature.signature,
|
||||
certificate: signature.key.$case === 'x509Certificate'
|
||||
? util_1.pem.toDER(signature.key.certificate)
|
||||
: undefined,
|
||||
keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined,
|
||||
certificateChain: true,
|
||||
});
|
||||
}
|
||||
// DSSE envelope bundle - $case: 'dsseEnvelope'
|
||||
function toDSSEBundle(artifact, signature, certificateChain) {
|
||||
return sigstore.toDSSEBundle({
|
||||
artifact: artifact.data,
|
||||
artifactType: artifact.type,
|
||||
signature: signature.signature,
|
||||
certificate: signature.key.$case === 'x509Certificate'
|
||||
? util_1.pem.toDER(signature.key.certificate)
|
||||
: undefined,
|
||||
keyHint: signature.key.$case === 'publicKey' ? signature.key.hint : undefined,
|
||||
certificateChain,
|
||||
});
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { Artifact, BaseBundleBuilder, BundleBuilderOptions } from './base';
|
||||
import type { BundleWithDsseEnvelope } from '@sigstore/bundle';
|
||||
import type { Signature } from '../signer';
|
||||
type DSSEBundleBuilderOptions = BundleBuilderOptions & {
|
||||
certificateChain?: boolean;
|
||||
};
|
||||
export declare class DSSEBundleBuilder extends BaseBundleBuilder<BundleWithDsseEnvelope> {
|
||||
private certificateChain?;
|
||||
constructor(options: DSSEBundleBuilderOptions);
|
||||
protected prepare(artifact: Artifact): Promise<Buffer>;
|
||||
protected package(artifact: Artifact, signature: Signature): Promise<BundleWithDsseEnvelope>;
|
||||
}
|
||||
export {};
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DSSEBundleBuilder = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const util_1 = require("../util");
|
||||
const base_1 = require("./base");
|
||||
const bundle_1 = require("./bundle");
|
||||
// BundleBuilder implementation for DSSE wrapped attestations
|
||||
class DSSEBundleBuilder extends base_1.BaseBundleBuilder {
|
||||
certificateChain;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.certificateChain = options.certificateChain ?? false;
|
||||
}
|
||||
// DSSE requires the artifact to be pre-encoded with the payload type
|
||||
// before the signature is generated.
|
||||
async prepare(artifact) {
|
||||
const a = artifactDefaults(artifact);
|
||||
return util_1.dsse.preAuthEncoding(a.type, a.data);
|
||||
}
|
||||
// Packages the artifact and signature into a DSSE bundle
|
||||
async package(artifact, signature) {
|
||||
return (0, bundle_1.toDSSEBundle)(artifactDefaults(artifact), signature, this.certificateChain);
|
||||
}
|
||||
}
|
||||
exports.DSSEBundleBuilder = DSSEBundleBuilder;
|
||||
// Defaults the artifact type to an empty string if not provided
|
||||
function artifactDefaults(artifact) {
|
||||
return {
|
||||
...artifact,
|
||||
type: artifact.type ?? '',
|
||||
};
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export type { Artifact, BundleBuilder, BundleBuilderOptions } from './base';
|
||||
export { DSSEBundleBuilder } from './dsse';
|
||||
export { MessageSignatureBundleBuilder } from './message';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MessageSignatureBundleBuilder = exports.DSSEBundleBuilder = void 0;
|
||||
var dsse_1 = require("./dsse");
|
||||
Object.defineProperty(exports, "DSSEBundleBuilder", { enumerable: true, get: function () { return dsse_1.DSSEBundleBuilder; } });
|
||||
var message_1 = require("./message");
|
||||
Object.defineProperty(exports, "MessageSignatureBundleBuilder", { enumerable: true, get: function () { return message_1.MessageSignatureBundleBuilder; } });
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Artifact, BaseBundleBuilder, BundleBuilderOptions } from './base';
|
||||
import type { BundleWithMessageSignature } from '@sigstore/bundle';
|
||||
import type { Signature } from '../signer';
|
||||
export declare class MessageSignatureBundleBuilder extends BaseBundleBuilder<BundleWithMessageSignature> {
|
||||
constructor(options: BundleBuilderOptions);
|
||||
protected package(artifact: Artifact, signature: Signature): Promise<BundleWithMessageSignature>;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MessageSignatureBundleBuilder = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const base_1 = require("./base");
|
||||
const bundle_1 = require("./bundle");
|
||||
// BundleBuilder implementation for raw message signatures
|
||||
class MessageSignatureBundleBuilder extends base_1.BaseBundleBuilder {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
async package(artifact, signature) {
|
||||
return (0, bundle_1.toMessageSignatureBundle)(artifact, signature);
|
||||
}
|
||||
}
|
||||
exports.MessageSignatureBundleBuilder = MessageSignatureBundleBuilder;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { SigningConfig } from '@sigstore/protobuf-specs';
|
||||
import { BundleBuilder } from './bundler/base';
|
||||
import { IdentityProvider } from './identity';
|
||||
import type { MakeFetchHappenOptions } from 'make-fetch-happen';
|
||||
type Retry = MakeFetchHappenOptions['retry'];
|
||||
type BundleType = 'messageSignature' | 'dsseEnvelope';
|
||||
type FetchOptions = {
|
||||
retry?: Retry;
|
||||
timeout?: number | undefined;
|
||||
};
|
||||
type Options = {
|
||||
signingConfig: SigningConfig;
|
||||
identityProvider: IdentityProvider;
|
||||
bundleType: BundleType;
|
||||
fetchOptions?: FetchOptions;
|
||||
};
|
||||
export declare function bundleBuilderFromSigningConfig(options: Options): BundleBuilder;
|
||||
export {};
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bundleBuilderFromSigningConfig = bundleBuilderFromSigningConfig;
|
||||
/*
|
||||
Copyright 2025 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const protobuf_specs_1 = require("@sigstore/protobuf-specs");
|
||||
const dsse_1 = require("./bundler/dsse");
|
||||
const message_1 = require("./bundler/message");
|
||||
const signer_1 = require("./signer");
|
||||
const witness_1 = require("./witness");
|
||||
const MAX_CA_API_VERSION = 1;
|
||||
const MAX_TLOG_API_VERSION = 2;
|
||||
const MAX_TSA_API_VERSION = 1;
|
||||
const DEFAULT_TIMEOUT = 5000;
|
||||
const DEFAULT_REKORV2_TIMEOUT = 20000;
|
||||
const DEFAULT_RETRY = { retries: 2 };
|
||||
// Creates a BundleBuilder based on the provided SigningConfig
|
||||
function bundleBuilderFromSigningConfig(options) {
|
||||
const { signingConfig, identityProvider, bundleType } = options;
|
||||
const fetchOptions = options.fetchOptions || {
|
||||
timeout: DEFAULT_TIMEOUT,
|
||||
retry: DEFAULT_RETRY,
|
||||
};
|
||||
const signer = fulcioSignerFromConfig(signingConfig, identityProvider, fetchOptions);
|
||||
const witnesses = witnessesFromConfig(signingConfig, fetchOptions);
|
||||
switch (bundleType) {
|
||||
case 'messageSignature':
|
||||
return new message_1.MessageSignatureBundleBuilder({ signer, witnesses });
|
||||
case 'dsseEnvelope':
|
||||
return new dsse_1.DSSEBundleBuilder({ signer, witnesses });
|
||||
}
|
||||
}
|
||||
function fulcioSignerFromConfig(signingConfig, identityProvider, fetchOptions) {
|
||||
const service = certAuthorityService(signingConfig);
|
||||
return new signer_1.FulcioSigner({
|
||||
fulcioBaseURL: service.url,
|
||||
identityProvider: identityProvider,
|
||||
timeout: fetchOptions.timeout,
|
||||
retry: fetchOptions.retry,
|
||||
});
|
||||
}
|
||||
function witnessesFromConfig(signingConfig, fetchOptions) {
|
||||
const witnesses = [];
|
||||
if (signingConfig.rekorTlogConfig) {
|
||||
if (signingConfig.rekorTlogConfig.selector !== protobuf_specs_1.ServiceSelector.ANY) {
|
||||
throw new Error('Unsupported Rekor TLog selector in signing configuration');
|
||||
}
|
||||
const tlog = tlogService(signingConfig);
|
||||
witnesses.push(new witness_1.RekorWitness({
|
||||
rekorBaseURL: tlog.url,
|
||||
majorApiVersion: tlog.majorApiVersion,
|
||||
retry: fetchOptions.retry,
|
||||
timeout:
|
||||
// Ensure Rekor V2 has at least a 20 second timeout
|
||||
tlog.majorApiVersion === 1
|
||||
? fetchOptions.timeout
|
||||
: Math.min(fetchOptions.timeout ||
|
||||
/* istanbul ignore next */ DEFAULT_TIMEOUT, DEFAULT_REKORV2_TIMEOUT),
|
||||
}));
|
||||
}
|
||||
if (signingConfig.tsaConfig) {
|
||||
if (signingConfig.tsaConfig.selector !== protobuf_specs_1.ServiceSelector.ANY) {
|
||||
throw new Error('Unsupported TSA selector in signing configuration');
|
||||
}
|
||||
const tsa = tsaService(signingConfig);
|
||||
witnesses.push(new witness_1.TSAWitness({
|
||||
tsaBaseURL: tsa.url,
|
||||
retry: fetchOptions.retry,
|
||||
timeout: fetchOptions.timeout,
|
||||
}));
|
||||
}
|
||||
return witnesses;
|
||||
}
|
||||
// Returns the first valid CA service from the signing configuration
|
||||
function certAuthorityService(signingConfig) {
|
||||
const compatibleCAs = filterServicesByMaxAPIVersion(signingConfig.caUrls, MAX_CA_API_VERSION);
|
||||
const sortedCAs = sortServicesByStartDate(compatibleCAs);
|
||||
if (sortedCAs.length === 0) {
|
||||
throw new Error('No valid CA services found in signing configuration');
|
||||
}
|
||||
return sortedCAs[0];
|
||||
}
|
||||
// Returns the first valid TLog service from the signing configuration
|
||||
function tlogService(signingConfig) {
|
||||
const compatibleTLogs = filterServicesByMaxAPIVersion(signingConfig.rekorTlogUrls, MAX_TLOG_API_VERSION);
|
||||
const sortedTLogs = sortServicesByStartDate(compatibleTLogs);
|
||||
if (sortedTLogs.length === 0) {
|
||||
throw new Error('No valid TLogs found in signing configuration');
|
||||
}
|
||||
return sortedTLogs[0];
|
||||
}
|
||||
// Returns the first valid TSA service from the signing configuration
|
||||
function tsaService(signingConfig) {
|
||||
const compatibleTSAs = filterServicesByMaxAPIVersion(signingConfig.tsaUrls, MAX_TSA_API_VERSION);
|
||||
const sortedTSAs = sortServicesByStartDate(compatibleTSAs);
|
||||
if (sortedTSAs.length === 0) {
|
||||
throw new Error('No valid TSAs found in signing configuration');
|
||||
}
|
||||
return sortedTSAs[0];
|
||||
}
|
||||
// Returns the services sorted by start date (most recent first), filtering out
|
||||
// any services that have an end date in the past
|
||||
function sortServicesByStartDate(services) {
|
||||
const now = new Date();
|
||||
// Filter out any services that have an end date in the past
|
||||
const validServices = services.filter((service) => {
|
||||
// If there's no end date, the service is still valid
|
||||
if (!service.validFor?.end) {
|
||||
return true;
|
||||
}
|
||||
// Keep services whose end date is in the future or present
|
||||
return service.validFor.end >= now;
|
||||
});
|
||||
return validServices.sort((a, b) => {
|
||||
/* istanbul ignore next */
|
||||
const aStart = a.validFor?.start?.getTime() ?? 0;
|
||||
/* istanbul ignore next */
|
||||
const bStart = b.validFor?.start?.getTime() ?? 0;
|
||||
// Sort descending (most recent first)
|
||||
return bStart - aStart;
|
||||
});
|
||||
}
|
||||
// Returns a filtered list of services whose major API version is less than or
|
||||
// equal to the specified version
|
||||
function filterServicesByMaxAPIVersion(services, apiVersion) {
|
||||
// Filter out any services with a major API version greater than the specified version
|
||||
return services.filter((service) => {
|
||||
return service.majorApiVersion <= apiVersion;
|
||||
});
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
type InternalErrorCode = 'TLOG_FETCH_ENTRY_ERROR' | 'TLOG_CREATE_ENTRY_ERROR' | 'CA_CREATE_SIGNING_CERTIFICATE_ERROR' | 'TSA_CREATE_TIMESTAMP_ERROR' | 'IDENTITY_TOKEN_READ_ERROR' | 'IDENTITY_TOKEN_PARSE_ERROR';
|
||||
export declare class InternalError extends Error {
|
||||
code: InternalErrorCode;
|
||||
cause: any | undefined;
|
||||
constructor({ code, message, cause, }: {
|
||||
code: InternalErrorCode;
|
||||
message: string;
|
||||
cause?: any;
|
||||
});
|
||||
}
|
||||
export declare function internalError(err: unknown, code: InternalErrorCode, message: string): never;
|
||||
export {};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InternalError = void 0;
|
||||
exports.internalError = internalError;
|
||||
const error_1 = require("./external/error");
|
||||
class InternalError extends Error {
|
||||
code;
|
||||
cause;
|
||||
constructor({ code, message, cause, }) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
this.cause = cause;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
exports.InternalError = InternalError;
|
||||
function internalError(err, code, message) {
|
||||
if (err instanceof error_1.HTTPError) {
|
||||
message += ` - ${err.message}`;
|
||||
}
|
||||
throw new InternalError({
|
||||
code: code,
|
||||
message: message,
|
||||
cause: err,
|
||||
});
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
export declare class HTTPError extends Error {
|
||||
statusCode: number;
|
||||
location?: string;
|
||||
constructor({ status, message, location, }: {
|
||||
status: number;
|
||||
message: string;
|
||||
location?: string;
|
||||
});
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HTTPError = void 0;
|
||||
class HTTPError extends Error {
|
||||
statusCode;
|
||||
location;
|
||||
constructor({ status, message, location, }) {
|
||||
super(`(${status}) ${message}`);
|
||||
this.statusCode = status;
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
exports.HTTPError = HTTPError;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import fetch, { FetchOptions } from 'make-fetch-happen';
|
||||
type Response = Awaited<ReturnType<typeof fetch>>;
|
||||
export declare function fetchWithRetry(url: string, options: FetchOptions): Promise<Response>;
|
||||
export {};
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fetchWithRetry = fetchWithRetry;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const http2_1 = require("http2");
|
||||
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
|
||||
const proc_log_1 = require("proc-log");
|
||||
const promise_retry_1 = __importDefault(require("promise-retry"));
|
||||
const util_1 = require("../util");
|
||||
const error_1 = require("./error");
|
||||
const { HTTP2_HEADER_LOCATION, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_USER_AGENT, HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_REQUEST_TIMEOUT, } = http2_1.constants;
|
||||
async function fetchWithRetry(url, options) {
|
||||
return (0, promise_retry_1.default)(async (retry, attemptNum) => {
|
||||
const method = options.method || 'POST';
|
||||
const headers = {
|
||||
[HTTP2_HEADER_USER_AGENT]: util_1.ua.getUserAgent(),
|
||||
...options.headers,
|
||||
};
|
||||
const response = await (0, make_fetch_happen_1.default)(url, {
|
||||
method,
|
||||
headers,
|
||||
body: options.body,
|
||||
timeout: options.timeout,
|
||||
retry: false, // We're handling retries ourselves
|
||||
}).catch((reason) => {
|
||||
proc_log_1.log.http('fetch', `${method} ${url} attempt ${attemptNum} failed with ${reason}`);
|
||||
return retry(reason);
|
||||
});
|
||||
if (response.ok) {
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
const error = await errorFromResponse(response);
|
||||
proc_log_1.log.http('fetch', `${method} ${url} attempt ${attemptNum} failed with ${response.status}`);
|
||||
if (retryable(response.status)) {
|
||||
return retry(error);
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}, retryOpts(options.retry));
|
||||
}
|
||||
// Translate a Response into an HTTPError instance. This will attempt to parse
|
||||
// the response body for a message, but will default to the statusText if none
|
||||
// is found.
|
||||
const errorFromResponse = async (response) => {
|
||||
let message = response.statusText;
|
||||
const location = response.headers.get(HTTP2_HEADER_LOCATION) || undefined;
|
||||
const contentType = response.headers.get(HTTP2_HEADER_CONTENT_TYPE);
|
||||
// If response type is JSON, try to parse the body for a message
|
||||
if (contentType?.includes('application/json')) {
|
||||
try {
|
||||
const body = await response.json();
|
||||
message = body.message || message;
|
||||
}
|
||||
catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return new error_1.HTTPError({
|
||||
status: response.status,
|
||||
message: message,
|
||||
location: location,
|
||||
});
|
||||
};
|
||||
// Determine if a status code is retryable. This includes 5xx errors, 408, and
|
||||
// 429.
|
||||
const retryable = (status) => [HTTP_STATUS_REQUEST_TIMEOUT, HTTP_STATUS_TOO_MANY_REQUESTS].includes(status) || status >= HTTP_STATUS_INTERNAL_SERVER_ERROR;
|
||||
// Normalize the retry options to the format expected by promise-retry
|
||||
const retryOpts = (retry) => {
|
||||
if (typeof retry === 'boolean') {
|
||||
return { retries: retry ? 1 : 0 };
|
||||
}
|
||||
else if (typeof retry === 'number') {
|
||||
return { retries: retry };
|
||||
}
|
||||
else {
|
||||
return { retries: 0, ...retry };
|
||||
}
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import type { FetchOptions } from '../types/fetch';
|
||||
export type FulcioOptions = {
|
||||
baseURL: string;
|
||||
} & FetchOptions;
|
||||
export interface SigningCertificateRequest {
|
||||
credentials: {
|
||||
oidcIdentityToken: string;
|
||||
};
|
||||
publicKeyRequest: {
|
||||
publicKey: {
|
||||
algorithm: string;
|
||||
content: string;
|
||||
};
|
||||
proofOfPossession: string;
|
||||
};
|
||||
}
|
||||
export interface SigningCertificateResponse {
|
||||
signedCertificateEmbeddedSct?: {
|
||||
chain: {
|
||||
certificates: string[];
|
||||
};
|
||||
};
|
||||
signedCertificateDetachedSct?: {
|
||||
chain: {
|
||||
certificates: string[];
|
||||
};
|
||||
signedCertificateTimestamp: string;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Fulcio API client.
|
||||
*/
|
||||
export declare class Fulcio {
|
||||
private options;
|
||||
constructor(options: FulcioOptions);
|
||||
createSigningCertificate(request: SigningCertificateRequest): Promise<SigningCertificateResponse>;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Fulcio = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const fetch_1 = require("./fetch");
|
||||
/**
|
||||
* Fulcio API client.
|
||||
*/
|
||||
class Fulcio {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
async createSigningCertificate(request) {
|
||||
const { baseURL, retry, timeout } = this.options;
|
||||
const url = `${baseURL}/api/v2/signingCert`;
|
||||
const response = await (0, fetch_1.fetchWithRetry)(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
timeout,
|
||||
retry,
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
}
|
||||
exports.Fulcio = Fulcio;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { TransparencyLogEntry } from '@sigstore/protobuf-specs';
|
||||
import { CreateEntryRequest } from '@sigstore/protobuf-specs/rekor/v2';
|
||||
import type { FetchOptions } from '../types/fetch';
|
||||
export type RekorOptions = {
|
||||
baseURL: string;
|
||||
} & FetchOptions;
|
||||
/**
|
||||
* Rekor API client.
|
||||
*/
|
||||
export declare class RekorV2 {
|
||||
private options;
|
||||
constructor(options: RekorOptions);
|
||||
createEntry(proposedEntry: CreateEntryRequest): Promise<TransparencyLogEntry>;
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RekorV2 = void 0;
|
||||
/*
|
||||
Copyright 2025 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const fetch_1 = require("./fetch");
|
||||
const protobuf_specs_1 = require("@sigstore/protobuf-specs");
|
||||
const v2_1 = require("@sigstore/protobuf-specs/rekor/v2");
|
||||
/**
|
||||
* Rekor API client.
|
||||
*/
|
||||
class RekorV2 {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
async createEntry(proposedEntry) {
|
||||
const { baseURL, timeout, retry } = this.options;
|
||||
const url = `${baseURL}/api/v2/log/entries`;
|
||||
const response = await (0, fetch_1.fetchWithRetry)(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify(v2_1.CreateEntryRequest.toJSON(proposedEntry)),
|
||||
timeout,
|
||||
retry,
|
||||
});
|
||||
return response.json().then((data) => protobuf_specs_1.TransparencyLogEntry.fromJSON(data));
|
||||
}
|
||||
}
|
||||
exports.RekorV2 = RekorV2;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import type { LogEntry, ProposedDSSEEntry, ProposedEntry, ProposedHashedRekordEntry, ProposedIntotoEntry } from '@sigstore/rekor-types';
|
||||
import type { FetchOptions } from '../types/fetch';
|
||||
export type { ProposedDSSEEntry, ProposedEntry, ProposedHashedRekordEntry, ProposedIntotoEntry, };
|
||||
export type Entry = {
|
||||
uuid: string;
|
||||
} & LogEntry[string];
|
||||
export type RekorOptions = {
|
||||
baseURL: string;
|
||||
} & FetchOptions;
|
||||
/**
|
||||
* Rekor API client.
|
||||
*/
|
||||
export declare class Rekor {
|
||||
private options;
|
||||
constructor(options: RekorOptions);
|
||||
/**
|
||||
* Create a new entry in the Rekor log.
|
||||
* @param propsedEntry {ProposedEntry} Data to create a new entry
|
||||
* @returns {Promise<Entry>} The created entry
|
||||
*/
|
||||
createEntry(propsedEntry: ProposedEntry): Promise<Entry>;
|
||||
/**
|
||||
* Get an entry from the Rekor log.
|
||||
* @param uuid {string} The UUID of the entry to retrieve
|
||||
* @returns {Promise<Entry>} The retrieved entry
|
||||
*/
|
||||
getEntry(uuid: string): Promise<Entry>;
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Rekor = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const fetch_1 = require("./fetch");
|
||||
/**
|
||||
* Rekor API client.
|
||||
*/
|
||||
class Rekor {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
/**
|
||||
* Create a new entry in the Rekor log.
|
||||
* @param propsedEntry {ProposedEntry} Data to create a new entry
|
||||
* @returns {Promise<Entry>} The created entry
|
||||
*/
|
||||
async createEntry(propsedEntry) {
|
||||
const { baseURL, timeout, retry } = this.options;
|
||||
const url = `${baseURL}/api/v1/log/entries`;
|
||||
const response = await (0, fetch_1.fetchWithRetry)(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify(propsedEntry),
|
||||
timeout,
|
||||
retry,
|
||||
});
|
||||
const data = await response.json();
|
||||
return entryFromResponse(data);
|
||||
}
|
||||
/**
|
||||
* Get an entry from the Rekor log.
|
||||
* @param uuid {string} The UUID of the entry to retrieve
|
||||
* @returns {Promise<Entry>} The retrieved entry
|
||||
*/
|
||||
async getEntry(uuid) {
|
||||
const { baseURL, timeout, retry } = this.options;
|
||||
const url = `${baseURL}/api/v1/log/entries/${uuid}`;
|
||||
const response = await (0, fetch_1.fetchWithRetry)(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
timeout,
|
||||
retry,
|
||||
});
|
||||
const data = await response.json();
|
||||
return entryFromResponse(data);
|
||||
}
|
||||
}
|
||||
exports.Rekor = Rekor;
|
||||
// Unpack the response from the Rekor API into a more convenient format.
|
||||
function entryFromResponse(data) {
|
||||
const entries = Object.entries(data);
|
||||
if (entries.length != 1) {
|
||||
throw new Error('Received multiple entries in Rekor response');
|
||||
}
|
||||
// Grab UUID and entry data from the response
|
||||
const [uuid, entry] = entries[0];
|
||||
return {
|
||||
...entry,
|
||||
uuid,
|
||||
};
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import type { FetchOptions } from '../types/fetch';
|
||||
export interface TimestampRequest {
|
||||
artifactHash: string;
|
||||
hashAlgorithm: string;
|
||||
certificates?: boolean;
|
||||
nonce?: number;
|
||||
tsaPolicyOID?: string;
|
||||
}
|
||||
export type TimestampAuthorityOptions = {
|
||||
baseURL: string;
|
||||
} & FetchOptions;
|
||||
export declare class TimestampAuthority {
|
||||
private options;
|
||||
constructor(options: TimestampAuthorityOptions);
|
||||
createTimestamp(request: TimestampRequest): Promise<Buffer>;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TimestampAuthority = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const fetch_1 = require("./fetch");
|
||||
class TimestampAuthority {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
async createTimestamp(request) {
|
||||
const { baseURL, timeout, retry } = this.options;
|
||||
// Account for the fact that the TSA URL may already include the full
|
||||
// path if the client was initalized from a `SigningConfig` service entry
|
||||
// (which always uses the full URL).
|
||||
const url = new URL(baseURL).pathname === '/'
|
||||
? `${baseURL}/api/v1/timestamp`
|
||||
: baseURL;
|
||||
const response = await (0, fetch_1.fetchWithRetry)(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
timeout,
|
||||
retry,
|
||||
});
|
||||
return response.buffer();
|
||||
}
|
||||
}
|
||||
exports.TimestampAuthority = TimestampAuthority;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import type { IdentityProvider } from './provider';
|
||||
/**
|
||||
* CIContextProvider is a composite identity provider which will iterate
|
||||
* over all of the CI-specific providers and return the token from the first
|
||||
* one that resolves.
|
||||
*/
|
||||
export declare class CIContextProvider implements IdentityProvider {
|
||||
private audience;
|
||||
constructor(audience?: string);
|
||||
getToken(): Promise<string>;
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CIContextProvider = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
|
||||
// Collection of all the CI-specific providers we have implemented
|
||||
const providers = [getGHAToken, getEnv];
|
||||
/**
|
||||
* CIContextProvider is a composite identity provider which will iterate
|
||||
* over all of the CI-specific providers and return the token from the first
|
||||
* one that resolves.
|
||||
*/
|
||||
class CIContextProvider {
|
||||
audience;
|
||||
/* istanbul ignore next */
|
||||
constructor(audience = 'sigstore') {
|
||||
this.audience = audience;
|
||||
}
|
||||
// Invoke all registered ProviderFuncs and return the value of whichever one
|
||||
// resolves first.
|
||||
async getToken() {
|
||||
return Promise.any(providers.map((getToken) => getToken(this.audience))).catch(() => Promise.reject('CI: no tokens available'));
|
||||
}
|
||||
}
|
||||
exports.CIContextProvider = CIContextProvider;
|
||||
/**
|
||||
* getGHAToken can retrieve an OIDC token when running in a GitHub Actions
|
||||
* workflow
|
||||
*/
|
||||
async function getGHAToken(audience) {
|
||||
// Check to see if we're running in GitHub Actions
|
||||
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_URL ||
|
||||
!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) {
|
||||
return Promise.reject('no token available');
|
||||
}
|
||||
// Construct URL to request token w/ appropriate audience
|
||||
const url = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
|
||||
url.searchParams.append('audience', audience);
|
||||
const response = await (0, make_fetch_happen_1.default)(url.href, {
|
||||
retry: 2,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`,
|
||||
},
|
||||
});
|
||||
return response.json().then((data) => data.value);
|
||||
}
|
||||
/**
|
||||
* getEnv can retrieve an OIDC token from an environment variable.
|
||||
* This matches the behavior of https://github.com/sigstore/cosign/tree/main/pkg/providers/envvar
|
||||
*/
|
||||
async function getEnv() {
|
||||
if (!process.env.SIGSTORE_ID_TOKEN) {
|
||||
return Promise.reject('no token available');
|
||||
}
|
||||
return process.env.SIGSTORE_ID_TOKEN;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { CIContextProvider } from './ci';
|
||||
export type { IdentityProvider } from './provider';
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CIContextProvider = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
var ci_1 = require("./ci");
|
||||
Object.defineProperty(exports, "CIContextProvider", { enumerable: true, get: function () { return ci_1.CIContextProvider; } });
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export interface IdentityProvider {
|
||||
getToken: () => Promise<string>;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export type { Bundle } from '@sigstore/bundle';
|
||||
export { DSSEBundleBuilder, MessageSignatureBundleBuilder } from './bundler';
|
||||
export type { Artifact, BundleBuilder, BundleBuilderOptions } from './bundler';
|
||||
export { bundleBuilderFromSigningConfig } from './config';
|
||||
export { InternalError } from './error';
|
||||
export { CIContextProvider } from './identity';
|
||||
export type { IdentityProvider } from './identity';
|
||||
export { DEFAULT_FULCIO_URL, FulcioSigner } from './signer';
|
||||
export type { FulcioSignerOptions, Signature, Signer } from './signer';
|
||||
export { DEFAULT_REKOR_URL, RekorWitness, TSAWitness } from './witness';
|
||||
export type { RekorWitnessOptions, SignatureBundle, TSAWitnessOptions, VerificationMaterial, Witness, } from './witness';
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TSAWitness = exports.RekorWitness = exports.DEFAULT_REKOR_URL = exports.FulcioSigner = exports.DEFAULT_FULCIO_URL = exports.CIContextProvider = exports.InternalError = exports.bundleBuilderFromSigningConfig = exports.MessageSignatureBundleBuilder = exports.DSSEBundleBuilder = void 0;
|
||||
var bundler_1 = require("./bundler");
|
||||
Object.defineProperty(exports, "DSSEBundleBuilder", { enumerable: true, get: function () { return bundler_1.DSSEBundleBuilder; } });
|
||||
Object.defineProperty(exports, "MessageSignatureBundleBuilder", { enumerable: true, get: function () { return bundler_1.MessageSignatureBundleBuilder; } });
|
||||
var config_1 = require("./config");
|
||||
Object.defineProperty(exports, "bundleBuilderFromSigningConfig", { enumerable: true, get: function () { return config_1.bundleBuilderFromSigningConfig; } });
|
||||
var error_1 = require("./error");
|
||||
Object.defineProperty(exports, "InternalError", { enumerable: true, get: function () { return error_1.InternalError; } });
|
||||
var identity_1 = require("./identity");
|
||||
Object.defineProperty(exports, "CIContextProvider", { enumerable: true, get: function () { return identity_1.CIContextProvider; } });
|
||||
var signer_1 = require("./signer");
|
||||
Object.defineProperty(exports, "DEFAULT_FULCIO_URL", { enumerable: true, get: function () { return signer_1.DEFAULT_FULCIO_URL; } });
|
||||
Object.defineProperty(exports, "FulcioSigner", { enumerable: true, get: function () { return signer_1.FulcioSigner; } });
|
||||
var witness_1 = require("./witness");
|
||||
Object.defineProperty(exports, "DEFAULT_REKOR_URL", { enumerable: true, get: function () { return witness_1.DEFAULT_REKOR_URL; } });
|
||||
Object.defineProperty(exports, "RekorWitness", { enumerable: true, get: function () { return witness_1.RekorWitness; } });
|
||||
Object.defineProperty(exports, "TSAWitness", { enumerable: true, get: function () { return witness_1.TSAWitness; } });
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import type { FetchOptions } from '../../types/fetch';
|
||||
export interface CA {
|
||||
createSigningCertificate: (identityToken: string, publicKey: string, challenge: Buffer) => Promise<string[]>;
|
||||
}
|
||||
export type CAClientOptions = {
|
||||
fulcioBaseURL: string;
|
||||
} & FetchOptions;
|
||||
export declare class CAClient implements CA {
|
||||
private fulcio;
|
||||
constructor(options: CAClientOptions);
|
||||
createSigningCertificate(identityToken: string, publicKey: string, challenge: Buffer): Promise<string[]>;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CAClient = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const error_1 = require("../../error");
|
||||
const fulcio_1 = require("../../external/fulcio");
|
||||
class CAClient {
|
||||
fulcio;
|
||||
constructor(options) {
|
||||
this.fulcio = new fulcio_1.Fulcio({
|
||||
baseURL: options.fulcioBaseURL,
|
||||
retry: options.retry,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
}
|
||||
async createSigningCertificate(identityToken, publicKey, challenge) {
|
||||
const request = toCertificateRequest(identityToken, publicKey, challenge);
|
||||
try {
|
||||
const resp = await this.fulcio.createSigningCertificate(request);
|
||||
// Account for the fact that the response may contain either a
|
||||
// signedCertificateEmbeddedSct or a signedCertificateDetachedSct.
|
||||
const cert = resp.signedCertificateEmbeddedSct
|
||||
? resp.signedCertificateEmbeddedSct
|
||||
: resp.signedCertificateDetachedSct;
|
||||
return cert.chain.certificates;
|
||||
}
|
||||
catch (err) {
|
||||
(0, error_1.internalError)(err, 'CA_CREATE_SIGNING_CERTIFICATE_ERROR', 'error creating signing certificate');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.CAClient = CAClient;
|
||||
function toCertificateRequest(identityToken, publicKey, challenge) {
|
||||
return {
|
||||
credentials: {
|
||||
oidcIdentityToken: identityToken,
|
||||
},
|
||||
publicKeyRequest: {
|
||||
publicKey: {
|
||||
algorithm: 'ECDSA',
|
||||
content: publicKey,
|
||||
},
|
||||
proofOfPossession: challenge.toString('base64'),
|
||||
},
|
||||
};
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { Signature, Signer } from '../signer';
|
||||
export declare class EphemeralSigner implements Signer {
|
||||
private keypair;
|
||||
constructor();
|
||||
sign(data: Buffer): Promise<Signature>;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EphemeralSigner = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const crypto_1 = require("crypto");
|
||||
const EC_KEYPAIR_TYPE = 'ec';
|
||||
const P256_CURVE = 'P-256';
|
||||
// Signer implementation which uses an ephemeral keypair to sign artifacts.
|
||||
// The private key lives only in memory and is tied to the lifetime of the
|
||||
// EphemeralSigner instance.
|
||||
class EphemeralSigner {
|
||||
keypair;
|
||||
constructor() {
|
||||
this.keypair = (0, crypto_1.generateKeyPairSync)(EC_KEYPAIR_TYPE, {
|
||||
namedCurve: P256_CURVE,
|
||||
});
|
||||
}
|
||||
async sign(data) {
|
||||
const signature = (0, crypto_1.sign)('sha256', data, this.keypair.privateKey);
|
||||
const publicKey = this.keypair.publicKey
|
||||
.export({ format: 'pem', type: 'spki' })
|
||||
.toString('ascii');
|
||||
return {
|
||||
signature: signature,
|
||||
key: { $case: 'publicKey', publicKey },
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.EphemeralSigner = EphemeralSigner;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { CAClientOptions } from './ca';
|
||||
import type { IdentityProvider } from '../../identity';
|
||||
import type { Signature, Signer } from '../signer';
|
||||
export declare const DEFAULT_FULCIO_URL = "https://fulcio.sigstore.dev";
|
||||
export type FulcioSignerOptions = {
|
||||
identityProvider: IdentityProvider;
|
||||
keyHolder?: Signer;
|
||||
} & Partial<CAClientOptions>;
|
||||
export declare class FulcioSigner implements Signer {
|
||||
private ca;
|
||||
private identityProvider;
|
||||
private keyHolder;
|
||||
constructor(options: FulcioSignerOptions);
|
||||
sign(data: Buffer): Promise<Signature>;
|
||||
private getIdentityToken;
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FulcioSigner = exports.DEFAULT_FULCIO_URL = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const error_1 = require("../../error");
|
||||
const util_1 = require("../../util");
|
||||
const ca_1 = require("./ca");
|
||||
const ephemeral_1 = require("./ephemeral");
|
||||
exports.DEFAULT_FULCIO_URL = 'https://fulcio.sigstore.dev';
|
||||
// Signer implementation which can be used to decorate another signer
|
||||
// with a Fulcio-issued signing certificate for the signer's public key.
|
||||
// Must be instantiated with an identity provider which can provide a JWT
|
||||
// which represents the identity to be bound to the signing certificate.
|
||||
class FulcioSigner {
|
||||
ca;
|
||||
identityProvider;
|
||||
keyHolder;
|
||||
constructor(options) {
|
||||
this.ca = new ca_1.CAClient({
|
||||
...options,
|
||||
fulcioBaseURL: options.fulcioBaseURL || /* istanbul ignore next */ exports.DEFAULT_FULCIO_URL,
|
||||
});
|
||||
this.identityProvider = options.identityProvider;
|
||||
this.keyHolder = options.keyHolder || new ephemeral_1.EphemeralSigner();
|
||||
}
|
||||
async sign(data) {
|
||||
// Retrieve identity token from the supplied identity provider
|
||||
const identityToken = await this.getIdentityToken();
|
||||
// Extract challenge claim from OIDC token
|
||||
let subject;
|
||||
try {
|
||||
subject = util_1.oidc.extractJWTSubject(identityToken);
|
||||
}
|
||||
catch (err) {
|
||||
throw new error_1.InternalError({
|
||||
code: 'IDENTITY_TOKEN_PARSE_ERROR',
|
||||
message: `invalid identity token: ${identityToken}`,
|
||||
cause: err,
|
||||
});
|
||||
}
|
||||
// Construct challenge value by signing the subject claim
|
||||
const challenge = await this.keyHolder.sign(Buffer.from(subject));
|
||||
if (challenge.key.$case !== 'publicKey') {
|
||||
throw new error_1.InternalError({
|
||||
code: 'CA_CREATE_SIGNING_CERTIFICATE_ERROR',
|
||||
message: 'unexpected format for signing key',
|
||||
});
|
||||
}
|
||||
// Create signing certificate
|
||||
const certificates = await this.ca.createSigningCertificate(identityToken, challenge.key.publicKey, challenge.signature);
|
||||
// Generate artifact signature
|
||||
const signature = await this.keyHolder.sign(data);
|
||||
// Specifically returning only the first certificate in the chain
|
||||
// as the key.
|
||||
return {
|
||||
signature: signature.signature,
|
||||
key: {
|
||||
$case: 'x509Certificate',
|
||||
certificate: certificates[0],
|
||||
},
|
||||
};
|
||||
}
|
||||
async getIdentityToken() {
|
||||
try {
|
||||
return await this.identityProvider.getToken();
|
||||
}
|
||||
catch (err) {
|
||||
throw new error_1.InternalError({
|
||||
code: 'IDENTITY_TOKEN_READ_ERROR',
|
||||
message: 'error retrieving identity token',
|
||||
cause: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.FulcioSigner = FulcioSigner;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { DEFAULT_FULCIO_URL, FulcioSigner, FulcioSignerOptions, } from './fulcio';
|
||||
export type { KeyMaterial, Signature, Signer } from './signer';
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
/* istanbul ignore file */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FulcioSigner = exports.DEFAULT_FULCIO_URL = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
var fulcio_1 = require("./fulcio");
|
||||
Object.defineProperty(exports, "DEFAULT_FULCIO_URL", { enumerable: true, get: function () { return fulcio_1.DEFAULT_FULCIO_URL; } });
|
||||
Object.defineProperty(exports, "FulcioSigner", { enumerable: true, get: function () { return fulcio_1.FulcioSigner; } });
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export type KeyMaterial = {
|
||||
$case: 'x509Certificate';
|
||||
certificate: string;
|
||||
} | {
|
||||
$case: 'publicKey';
|
||||
publicKey: string;
|
||||
hint?: string;
|
||||
};
|
||||
export type Signature = {
|
||||
signature: Buffer;
|
||||
key: KeyMaterial;
|
||||
};
|
||||
export interface Signer {
|
||||
sign: (data: Buffer) => Promise<Signature>;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { MakeFetchHappenOptions } from 'make-fetch-happen';
|
||||
export type Retry = MakeFetchHappenOptions['retry'];
|
||||
export type FetchOptions = {
|
||||
retry?: Retry;
|
||||
timeout?: number | undefined;
|
||||
};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { crypto, dsse, encoding, json, pem } from '@sigstore/core';
|
||||
export * as oidc from './oidc';
|
||||
export * as ua from './ua';
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ua = exports.oidc = exports.pem = exports.json = exports.encoding = exports.dsse = exports.crypto = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
var core_1 = require("@sigstore/core");
|
||||
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return core_1.crypto; } });
|
||||
Object.defineProperty(exports, "dsse", { enumerable: true, get: function () { return core_1.dsse; } });
|
||||
Object.defineProperty(exports, "encoding", { enumerable: true, get: function () { return core_1.encoding; } });
|
||||
Object.defineProperty(exports, "json", { enumerable: true, get: function () { return core_1.json; } });
|
||||
Object.defineProperty(exports, "pem", { enumerable: true, get: function () { return core_1.pem; } });
|
||||
exports.oidc = __importStar(require("./oidc"));
|
||||
exports.ua = __importStar(require("./ua"));
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function extractJWTSubject(jwt: string): string;
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.extractJWTSubject = extractJWTSubject;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const core_1 = require("@sigstore/core");
|
||||
function extractJWTSubject(jwt) {
|
||||
const parts = jwt.split('.', 3);
|
||||
const payload = JSON.parse(core_1.encoding.base64Decode(parts[1]));
|
||||
if (payload.email) {
|
||||
if (!payload.email_verified) {
|
||||
throw new Error('JWT email not verified by issuer');
|
||||
}
|
||||
return payload.email;
|
||||
}
|
||||
if (payload.sub) {
|
||||
return payload.sub;
|
||||
}
|
||||
else {
|
||||
throw new Error('JWT subject not found');
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare const getUserAgent: () => string;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getUserAgent = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const os_1 = __importDefault(require("os"));
|
||||
// Format User-Agent: <product> / <product-version> (<platform>)
|
||||
// source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
|
||||
const getUserAgent = () => {
|
||||
const packageVersion = require('../../package.json').version;
|
||||
const nodeVersion = process.version;
|
||||
const platformName = os_1.default.platform();
|
||||
const archName = os_1.default.arch();
|
||||
return `sigstore-js/${packageVersion} (Node ${nodeVersion}) (${platformName}/${archName})`;
|
||||
};
|
||||
exports.getUserAgent = getUserAgent;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { DEFAULT_REKOR_URL, RekorWitness, RekorWitnessOptions } from './tlog';
|
||||
export { TSAWitness, TSAWitnessOptions } from './tsa';
|
||||
export type { SignatureBundle, VerificationMaterial, Witness } from './witness';
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
/* istanbul ignore file */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TSAWitness = exports.RekorWitness = exports.DEFAULT_REKOR_URL = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
var tlog_1 = require("./tlog");
|
||||
Object.defineProperty(exports, "DEFAULT_REKOR_URL", { enumerable: true, get: function () { return tlog_1.DEFAULT_REKOR_URL; } });
|
||||
Object.defineProperty(exports, "RekorWitness", { enumerable: true, get: function () { return tlog_1.RekorWitness; } });
|
||||
var tsa_1 = require("./tsa");
|
||||
Object.defineProperty(exports, "TSAWitness", { enumerable: true, get: function () { return tsa_1.TSAWitness; } });
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import type { TransparencyLogEntry } from '@sigstore/bundle';
|
||||
import type { CreateEntryRequest } from '@sigstore/protobuf-specs/rekor/v2';
|
||||
import type { Entry, ProposedEntry } from '../../external/rekor';
|
||||
import type { FetchOptions } from '../../types/fetch';
|
||||
export type { Entry, ProposedEntry };
|
||||
export interface TLog {
|
||||
createEntry: (proposedEntry: ProposedEntry) => Promise<Entry>;
|
||||
}
|
||||
export type TLogClientOptions = {
|
||||
rekorBaseURL: string;
|
||||
fetchOnConflict?: boolean;
|
||||
} & FetchOptions;
|
||||
export declare class TLogClient implements TLog {
|
||||
private rekor;
|
||||
private fetchOnConflict;
|
||||
constructor(options: TLogClientOptions);
|
||||
createEntry(proposedEntry: ProposedEntry): Promise<Entry>;
|
||||
}
|
||||
export interface TLogV2 {
|
||||
createEntry: (createEntryRequest: CreateEntryRequest) => Promise<TransparencyLogEntry>;
|
||||
}
|
||||
export type TLogV2ClientOptions = {
|
||||
rekorBaseURL: string;
|
||||
} & FetchOptions;
|
||||
export declare class TLogV2Client implements TLogV2 {
|
||||
private rekor;
|
||||
constructor(options: TLogV2ClientOptions);
|
||||
createEntry(createEntryRequest: CreateEntryRequest): Promise<TransparencyLogEntry>;
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TLogV2Client = exports.TLogClient = void 0;
|
||||
/*
|
||||
Copyright 2025 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const error_1 = require("../../error");
|
||||
const error_2 = require("../../external/error");
|
||||
const rekor_1 = require("../../external/rekor");
|
||||
const rekor_v2_1 = require("../../external/rekor-v2");
|
||||
class TLogClient {
|
||||
rekor;
|
||||
fetchOnConflict;
|
||||
constructor(options) {
|
||||
this.fetchOnConflict = options.fetchOnConflict ?? false;
|
||||
this.rekor = new rekor_1.Rekor({
|
||||
baseURL: options.rekorBaseURL,
|
||||
retry: options.retry,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
}
|
||||
async createEntry(proposedEntry) {
|
||||
let entry;
|
||||
try {
|
||||
entry = await this.rekor.createEntry(proposedEntry);
|
||||
}
|
||||
catch (err) {
|
||||
// If the entry already exists, fetch it (if enabled)
|
||||
if (entryExistsError(err) && this.fetchOnConflict) {
|
||||
// Grab the UUID of the existing entry from the location header
|
||||
/* istanbul ignore next */
|
||||
const uuid = err.location.split('/').pop() || '';
|
||||
try {
|
||||
entry = await this.rekor.getEntry(uuid);
|
||||
}
|
||||
catch (err) {
|
||||
(0, error_1.internalError)(err, 'TLOG_FETCH_ENTRY_ERROR', 'error fetching tlog entry');
|
||||
}
|
||||
}
|
||||
else {
|
||||
(0, error_1.internalError)(err, 'TLOG_CREATE_ENTRY_ERROR', 'error creating tlog entry');
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
exports.TLogClient = TLogClient;
|
||||
function entryExistsError(value) {
|
||||
return (value instanceof error_2.HTTPError &&
|
||||
value.statusCode === 409 &&
|
||||
value.location !== undefined);
|
||||
}
|
||||
class TLogV2Client {
|
||||
rekor;
|
||||
constructor(options) {
|
||||
this.rekor = new rekor_v2_1.RekorV2({
|
||||
baseURL: options.rekorBaseURL,
|
||||
retry: options.retry,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
}
|
||||
async createEntry(createEntryRequest) {
|
||||
let entry;
|
||||
try {
|
||||
entry = await this.rekor.createEntry(createEntryRequest);
|
||||
}
|
||||
catch (err) {
|
||||
(0, error_1.internalError)(err, 'TLOG_CREATE_ENTRY_ERROR', 'error creating tlog entry');
|
||||
}
|
||||
if (entry.logId === undefined || entry.kindVersion === undefined) {
|
||||
(0, error_1.internalError)(new Error('invalid tlog entry'), 'TLOG_CREATE_ENTRY_ERROR', 'error creating tlog entry');
|
||||
}
|
||||
return {
|
||||
...entry,
|
||||
logId: entry.logId,
|
||||
kindVersion: entry.kindVersion,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.TLogV2Client = TLogV2Client;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { CreateEntryRequest } from '@sigstore/protobuf-specs/rekor/v2';
|
||||
import type { ProposedEntry } from '../../external/rekor';
|
||||
import type { SignatureBundle } from '../witness';
|
||||
export declare function toProposedEntry(content: SignatureBundle, publicKey: string, entryType?: 'dsse' | 'intoto'): ProposedEntry;
|
||||
export declare function toCreateEntryRequest(content: SignatureBundle, publicKey: string): CreateEntryRequest;
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toProposedEntry = toProposedEntry;
|
||||
exports.toCreateEntryRequest = toCreateEntryRequest;
|
||||
/*
|
||||
Copyright 2025 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const bundle_1 = require("@sigstore/bundle");
|
||||
const protobuf_specs_1 = require("@sigstore/protobuf-specs");
|
||||
const util_1 = require("../../util");
|
||||
const SHA256_ALGORITHM = 'sha256';
|
||||
function toProposedEntry(content, publicKey,
|
||||
// TODO: Remove this parameter once have completely switched to 'dsse' entries
|
||||
entryType = 'dsse') {
|
||||
switch (content.$case) {
|
||||
case 'dsseEnvelope':
|
||||
// TODO: Remove this conditional once have completely ditched "intoto" entries
|
||||
if (entryType === 'intoto') {
|
||||
return toProposedIntotoEntry(content.dsseEnvelope, publicKey);
|
||||
}
|
||||
return toProposedDSSEEntry(content.dsseEnvelope, publicKey);
|
||||
case 'messageSignature':
|
||||
return toProposedHashedRekordEntry(content.messageSignature, publicKey);
|
||||
}
|
||||
}
|
||||
// Returns a properly formatted Rekor "hashedrekord" entry for the given digest
|
||||
// and signature
|
||||
function toProposedHashedRekordEntry(messageSignature, publicKey) {
|
||||
const hexDigest = messageSignature.messageDigest.digest.toString('hex');
|
||||
const b64Signature = messageSignature.signature.toString('base64');
|
||||
const b64Key = util_1.encoding.base64Encode(publicKey);
|
||||
return {
|
||||
apiVersion: '0.0.1',
|
||||
kind: 'hashedrekord',
|
||||
spec: {
|
||||
data: {
|
||||
hash: {
|
||||
algorithm: SHA256_ALGORITHM,
|
||||
value: hexDigest,
|
||||
},
|
||||
},
|
||||
signature: {
|
||||
content: b64Signature,
|
||||
publicKey: {
|
||||
content: b64Key,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
// Returns a properly formatted Rekor "dsse" entry for the given DSSE envelope
|
||||
// and signature
|
||||
function toProposedDSSEEntry(envelope, publicKey) {
|
||||
const envelopeJSON = JSON.stringify((0, bundle_1.envelopeToJSON)(envelope));
|
||||
const encodedKey = util_1.encoding.base64Encode(publicKey);
|
||||
return {
|
||||
apiVersion: '0.0.1',
|
||||
kind: 'dsse',
|
||||
spec: {
|
||||
proposedContent: {
|
||||
envelope: envelopeJSON,
|
||||
verifiers: [encodedKey],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
// Returns a properly formatted Rekor "intoto" entry for the given DSSE
|
||||
// envelope and signature
|
||||
function toProposedIntotoEntry(envelope, publicKey) {
|
||||
// Calculate the value for the payloadHash field in the Rekor entry
|
||||
const payloadHash = util_1.crypto
|
||||
.digest(SHA256_ALGORITHM, envelope.payload)
|
||||
.toString('hex');
|
||||
// Calculate the value for the hash field in the Rekor entry
|
||||
const envelopeHash = calculateDSSEHash(envelope, publicKey);
|
||||
// Collect values for re-creating the DSSE envelope.
|
||||
// Double-encode payload and signature cause that's what Rekor expects
|
||||
const payload = util_1.encoding.base64Encode(envelope.payload.toString('base64'));
|
||||
const sig = util_1.encoding.base64Encode(envelope.signatures[0].sig.toString('base64'));
|
||||
const keyid = envelope.signatures[0].keyid;
|
||||
const encodedKey = util_1.encoding.base64Encode(publicKey);
|
||||
// Create the envelope portion of the entry. Note the inclusion of the
|
||||
// publicKey in the signature struct is not a standard part of a DSSE
|
||||
// envelope, but is required by Rekor.
|
||||
const dsse = {
|
||||
payloadType: envelope.payloadType,
|
||||
payload: payload,
|
||||
signatures: [{ sig, publicKey: encodedKey }],
|
||||
};
|
||||
// If the keyid is an empty string, Rekor seems to remove it altogether. We
|
||||
// need to do the same here so that we can properly recreate the entry for
|
||||
// verification.
|
||||
if (keyid.length > 0) {
|
||||
dsse.signatures[0].keyid = keyid;
|
||||
}
|
||||
return {
|
||||
apiVersion: '0.0.2',
|
||||
kind: 'intoto',
|
||||
spec: {
|
||||
content: {
|
||||
envelope: dsse,
|
||||
hash: { algorithm: SHA256_ALGORITHM, value: envelopeHash },
|
||||
payloadHash: { algorithm: SHA256_ALGORITHM, value: payloadHash },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
// Calculates the hash of a DSSE envelope for inclusion in a Rekor entry.
|
||||
// There is no standard way to do this, so the scheme we're using as as
|
||||
// follows:
|
||||
// * payload is base64 encoded
|
||||
// * signature is base64 encoded (only the first signature is used)
|
||||
// * keyid is included ONLY if it is NOT an empty string
|
||||
// * The resulting JSON is canonicalized and hashed to a hex string
|
||||
function calculateDSSEHash(envelope, publicKey) {
|
||||
const dsse = {
|
||||
payloadType: envelope.payloadType,
|
||||
payload: envelope.payload.toString('base64'),
|
||||
signatures: [
|
||||
{ sig: envelope.signatures[0].sig.toString('base64'), publicKey },
|
||||
],
|
||||
};
|
||||
// If the keyid is an empty string, Rekor seems to remove it altogether.
|
||||
if (envelope.signatures[0].keyid.length > 0) {
|
||||
dsse.signatures[0].keyid = envelope.signatures[0].keyid;
|
||||
}
|
||||
return util_1.crypto
|
||||
.digest(SHA256_ALGORITHM, util_1.json.canonicalize(dsse))
|
||||
.toString('hex');
|
||||
}
|
||||
function toCreateEntryRequest(content, publicKey) {
|
||||
switch (content.$case) {
|
||||
case 'dsseEnvelope':
|
||||
return toCreateEntryRequestDSSE(content.dsseEnvelope, publicKey);
|
||||
case 'messageSignature':
|
||||
return toCreateEntryRequestMessageSignature(content.messageSignature, publicKey);
|
||||
}
|
||||
}
|
||||
function toCreateEntryRequestDSSE(envelope, publicKey) {
|
||||
return {
|
||||
spec: {
|
||||
$case: 'dsseRequestV002',
|
||||
dsseRequestV002: {
|
||||
envelope: envelope,
|
||||
verifiers: [
|
||||
{
|
||||
// TODO: We need to add support of passing the key details in the
|
||||
// signature bundle. For now we're hardcoding the key details here.
|
||||
keyDetails: protobuf_specs_1.PublicKeyDetails.PKIX_ECDSA_P256_SHA_256,
|
||||
verifier: {
|
||||
$case: 'x509Certificate',
|
||||
x509Certificate: {
|
||||
rawBytes: util_1.pem.toDER(publicKey),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
function toCreateEntryRequestMessageSignature(messageSignature, publicKey) {
|
||||
return {
|
||||
spec: {
|
||||
$case: 'hashedRekordRequestV002',
|
||||
hashedRekordRequestV002: {
|
||||
digest: messageSignature.messageDigest.digest,
|
||||
signature: {
|
||||
content: messageSignature.signature,
|
||||
verifier: {
|
||||
// TODO: We need to add support of passing the key details in the
|
||||
// signature bundle. For now we're hardcoding the key details here.
|
||||
keyDetails: protobuf_specs_1.PublicKeyDetails.PKIX_ECDSA_P256_SHA_256,
|
||||
verifier: {
|
||||
$case: 'x509Certificate',
|
||||
x509Certificate: {
|
||||
rawBytes: util_1.pem.toDER(publicKey),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { TLogClientOptions } from './client';
|
||||
import type { TransparencyLogEntry } from '@sigstore/bundle';
|
||||
import type { SignatureBundle, Witness } from '../witness';
|
||||
export declare const DEFAULT_REKOR_URL = "https://rekor.sigstore.dev";
|
||||
type TransparencyLogEntries = {
|
||||
tlogEntries: TransparencyLogEntry[];
|
||||
};
|
||||
export type RekorWitnessOptions = Partial<TLogClientOptions> & {
|
||||
entryType?: 'dsse' | 'intoto';
|
||||
majorApiVersion?: number;
|
||||
};
|
||||
export declare class RekorWitness implements Witness {
|
||||
private tlogV1;
|
||||
private tlogV2;
|
||||
private entryType?;
|
||||
private majorApiVersion;
|
||||
constructor(options: RekorWitnessOptions);
|
||||
testify(content: SignatureBundle, publicKey: string): Promise<TransparencyLogEntries>;
|
||||
}
|
||||
export {};
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RekorWitness = exports.DEFAULT_REKOR_URL = void 0;
|
||||
/*
|
||||
Copyright 2025 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const util_1 = require("../../util");
|
||||
const client_1 = require("./client");
|
||||
const entry_1 = require("./entry");
|
||||
exports.DEFAULT_REKOR_URL = 'https://rekor.sigstore.dev';
|
||||
class RekorWitness {
|
||||
tlogV1;
|
||||
tlogV2;
|
||||
entryType;
|
||||
majorApiVersion;
|
||||
constructor(options) {
|
||||
this.entryType = options.entryType;
|
||||
this.majorApiVersion = options.majorApiVersion || 1;
|
||||
this.tlogV1 = new client_1.TLogClient({
|
||||
...options,
|
||||
rekorBaseURL: options.rekorBaseURL || /* istanbul ignore next */ exports.DEFAULT_REKOR_URL,
|
||||
});
|
||||
this.tlogV2 = new client_1.TLogV2Client({
|
||||
...options,
|
||||
rekorBaseURL: options.rekorBaseURL || /* istanbul ignore next */ exports.DEFAULT_REKOR_URL,
|
||||
});
|
||||
}
|
||||
async testify(content, publicKey) {
|
||||
let tlogEntry;
|
||||
if (this.majorApiVersion === 2) {
|
||||
const request = (0, entry_1.toCreateEntryRequest)(content, publicKey);
|
||||
tlogEntry = await this.tlogV2.createEntry(request);
|
||||
}
|
||||
else {
|
||||
const proposedEntry = (0, entry_1.toProposedEntry)(content, publicKey, this.entryType);
|
||||
const entry = await this.tlogV1.createEntry(proposedEntry);
|
||||
tlogEntry = toTransparencyLogEntry(entry);
|
||||
}
|
||||
return { tlogEntries: [tlogEntry] };
|
||||
}
|
||||
}
|
||||
exports.RekorWitness = RekorWitness;
|
||||
function toTransparencyLogEntry(entry) {
|
||||
const logID = Buffer.from(entry.logID, 'hex');
|
||||
// Parse entry body so we can extract the kind and version.
|
||||
const bodyJSON = util_1.encoding.base64Decode(entry.body);
|
||||
const entryBody = JSON.parse(bodyJSON);
|
||||
const promise = entry?.verification?.signedEntryTimestamp
|
||||
? inclusionPromise(entry.verification.signedEntryTimestamp)
|
||||
: undefined;
|
||||
const proof = entry?.verification?.inclusionProof
|
||||
? inclusionProof(entry.verification.inclusionProof)
|
||||
: undefined;
|
||||
const tlogEntry = {
|
||||
logIndex: entry.logIndex.toString(),
|
||||
logId: {
|
||||
keyId: logID,
|
||||
},
|
||||
integratedTime: entry.integratedTime.toString(),
|
||||
kindVersion: {
|
||||
kind: entryBody.kind,
|
||||
version: entryBody.apiVersion,
|
||||
},
|
||||
inclusionPromise: promise,
|
||||
inclusionProof: proof,
|
||||
canonicalizedBody: Buffer.from(entry.body, 'base64'),
|
||||
};
|
||||
return tlogEntry;
|
||||
}
|
||||
function inclusionPromise(promise) {
|
||||
return {
|
||||
signedEntryTimestamp: Buffer.from(promise, 'base64'),
|
||||
};
|
||||
}
|
||||
function inclusionProof(proof) {
|
||||
return {
|
||||
logIndex: proof.logIndex.toString(),
|
||||
treeSize: proof.treeSize.toString(),
|
||||
rootHash: Buffer.from(proof.rootHash, 'hex'),
|
||||
hashes: proof.hashes.map((h) => Buffer.from(h, 'hex')),
|
||||
checkpoint: {
|
||||
envelope: proof.checkpoint,
|
||||
},
|
||||
};
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import type { FetchOptions } from '../../types/fetch';
|
||||
export interface TSA {
|
||||
createTimestamp: (signature: Buffer) => Promise<Buffer>;
|
||||
}
|
||||
export type TSAClientOptions = {
|
||||
tsaBaseURL: string;
|
||||
} & FetchOptions;
|
||||
export declare class TSAClient implements TSA {
|
||||
private tsa;
|
||||
constructor(options: TSAClientOptions);
|
||||
createTimestamp(signature: Buffer): Promise<Buffer>;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TSAClient = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const error_1 = require("../../error");
|
||||
const tsa_1 = require("../../external/tsa");
|
||||
const util_1 = require("../../util");
|
||||
const SHA256_ALGORITHM = 'sha256';
|
||||
class TSAClient {
|
||||
tsa;
|
||||
constructor(options) {
|
||||
this.tsa = new tsa_1.TimestampAuthority({
|
||||
baseURL: options.tsaBaseURL,
|
||||
retry: options.retry,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
}
|
||||
async createTimestamp(signature) {
|
||||
const request = {
|
||||
artifactHash: util_1.crypto
|
||||
.digest(SHA256_ALGORITHM, signature)
|
||||
.toString('base64'),
|
||||
hashAlgorithm: SHA256_ALGORITHM,
|
||||
};
|
||||
try {
|
||||
return await this.tsa.createTimestamp(request);
|
||||
}
|
||||
catch (err) {
|
||||
(0, error_1.internalError)(err, 'TSA_CREATE_TIMESTAMP_ERROR', 'error creating timestamp');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TSAClient = TSAClient;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { TSAClientOptions } from './client';
|
||||
import type { RFC3161SignedTimestamp } from '@sigstore/bundle';
|
||||
import type { SignatureBundle, Witness } from '../witness';
|
||||
type RFC3161SignedTimestamps = {
|
||||
rfc3161Timestamps: RFC3161SignedTimestamp[];
|
||||
};
|
||||
export type TSAWitnessOptions = TSAClientOptions;
|
||||
export declare class TSAWitness implements Witness {
|
||||
private tsa;
|
||||
constructor(options: TSAWitnessOptions);
|
||||
testify(content: SignatureBundle): Promise<RFC3161SignedTimestamps>;
|
||||
}
|
||||
export {};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TSAWitness = void 0;
|
||||
/*
|
||||
Copyright 2023 The Sigstore Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const client_1 = require("./client");
|
||||
class TSAWitness {
|
||||
tsa;
|
||||
constructor(options) {
|
||||
this.tsa = new client_1.TSAClient({
|
||||
tsaBaseURL: options.tsaBaseURL,
|
||||
retry: options.retry,
|
||||
timeout: options.timeout,
|
||||
});
|
||||
}
|
||||
async testify(content) {
|
||||
const signature = extractSignature(content);
|
||||
const timestamp = await this.tsa.createTimestamp(signature);
|
||||
return {
|
||||
rfc3161Timestamps: [{ signedTimestamp: timestamp }],
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.TSAWitness = TSAWitness;
|
||||
function extractSignature(content) {
|
||||
switch (content.$case) {
|
||||
case 'dsseEnvelope':
|
||||
return content.dsseEnvelope.signatures[0].sig;
|
||||
case 'messageSignature':
|
||||
return content.messageSignature.signature;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import type { Bundle, RFC3161SignedTimestamp, TransparencyLogEntry } from '@sigstore/bundle';
|
||||
export type SignatureBundle = Bundle['content'];
|
||||
export type VerificationMaterial = {
|
||||
tlogEntries?: TransparencyLogEntry[];
|
||||
rfc3161Timestamps?: RFC3161SignedTimestamp[];
|
||||
};
|
||||
export interface Witness {
|
||||
testify: (signature: SignatureBundle, publicKey: string) => Promise<VerificationMaterial>;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Reference in New Issue
Block a user