Skip to content

Commit

Permalink
Implement node:crypto X509Certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jun 27, 2024
1 parent 900909e commit 45b8f44
Show file tree
Hide file tree
Showing 16 changed files with 1,870 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/secret_scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ paths-ignore:
- "src/workerd/api/node/crypto_keys-test.js"
- "src/workerd/api/node/crypto_dh-test.js"
- "src/workerd/jsg/url-test-corpus-success.h"
- "src/workerd/api/node/tests/crypto_x509-test.js"
10 changes: 9 additions & 1 deletion src/node/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ import {
createSecretKey,
} from 'node-internal:crypto_keys';

import {
X509Certificate,
} from 'node-internal:crypto_x509';

export {
// DH
DiffieHellman,
Expand Down Expand Up @@ -126,6 +130,8 @@ export {
createPrivateKey,
createPublicKey,
createSecretKey,
// X509
X509Certificate,
}

export function getCiphers() {
Expand Down Expand Up @@ -231,6 +237,8 @@ export default {
// WebCrypto
subtle,
webcrypto,
// X509
X509Certificate,
};

// Classes
Expand All @@ -245,7 +253,7 @@ export default {
// * [ ] crypto.KeyObject
// * [ ] crypto.Sign
// * [ ] crypto.Verify
// * [ ] crypto.X509Certificate
// * [x] crypto.X509Certificate
// * [ ] crypto.constants
// * [ ] crypto.DEFAULT_ENCODING
// * Primes
Expand Down
36 changes: 36 additions & 0 deletions src/node/internal/crypto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@ export function checkPrimeSync(candidate: ArrayBufferView, num_checks: number):
export function randomPrime(size: number, safe: boolean, add?: ArrayBufferView|undefined,
rem?: ArrayBufferView|undefined): ArrayBuffer;

// X509Certificate
export interface CheckOptions {
subject?: string;
wildcards?: boolean;
partialWildcards?: boolean;
multiLabelWildcards?: boolean;
singleLabelSubdomains?: boolean;
}

export class X509Certificate {
public static parse(data: ArrayBuffer|ArrayBufferView): X509Certificate;
public get subject(): string|undefined;
public get subjectAltName(): string|undefined;
public get infoAccess(): string|undefined;
public get issuer(): string|undefined;
public get issuerCert(): X509Certificate|undefined;
public get validFrom(): string|undefined;
public get validTo(): string|undefined;
public get fingerprint(): string|undefined;
public get fingerprint256(): string|undefined;
public get fingerprint512(): string|undefined;
public get keyUsage(): string[]|undefined;
public get serialNumber(): string|undefined;
public get pem(): string|undefined;
public get raw(): ArrayBuffer|undefined;
public get publicKey(): CryptoKey|undefined;
public get isCA(): boolean;
public checkHost(host: string, options?: CheckOptions): string|undefined;
public checkEmail(email: string, options?: CheckOptions): string|undefined;
public checkIp(ip: string, options?: CheckOptions): string|undefined;
public checkIssued(cert: X509Certificate): boolean;
public checkPrivateKey(key: CryptoKey): boolean;
public verify(key: CryptoKey): boolean;
public toLegacyObject(): object;
}

// Hash and Hmac
export class HashHandle {
public constructor(algorithm: string, xofLen: number);
Expand Down
Loading

0 comments on commit 45b8f44

Please sign in to comment.