|
1 | 1 | import { Constrained, Uint16 } from "../src/dep.ts"; |
2 | 2 | import { Enum } from "../src/enum.js"; |
| 3 | +import { sha256, sha384, sha512 } from "@noble/hashes/sha2"; |
3 | 4 |
|
4 | 5 | /** |
5 | 6 | * Enumeration of signature schemes as defined in RFC 8446. |
6 | 7 | * @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.3 |
7 | 8 | */ |
8 | | -export class SignatureScheme extends Enum { |
9 | | - /** RSASSA-PKCS1-v1_5 algorithms */ |
| 9 | +export declare class SignatureScheme extends Enum { |
10 | 10 | static RSA_PKCS1_SHA256: SignatureScheme; |
11 | 11 | static RSA_PKCS1_SHA384: SignatureScheme; |
12 | 12 | static RSA_PKCS1_SHA512: SignatureScheme; |
13 | | - |
14 | | - /** ECDSA algorithms */ |
15 | 13 | static ECDSA_SECP256R1_SHA256: SignatureScheme; |
16 | 14 | static ECDSA_SECP384R1_SHA384: SignatureScheme; |
17 | 15 | static ECDSA_SECP521R1_SHA512: SignatureScheme; |
18 | | - |
19 | | - /** RSASSA-PSS algorithms with public key OID rsaEncryption */ |
20 | 16 | static RSA_PSS_RSAE_SHA256: SignatureScheme; |
21 | 17 | static RSA_PSS_RSAE_SHA384: SignatureScheme; |
22 | 18 | static RSA_PSS_RSAE_SHA512: SignatureScheme; |
23 | | - |
24 | | - /** EdDSA algorithms */ |
25 | 19 | static ED25519: SignatureScheme; |
26 | 20 | static ED448: SignatureScheme; |
27 | | - |
28 | | - /** RSASSA-PSS algorithms with public key OID RSASSA-PSS */ |
29 | 21 | static RSA_PSS_PSS_SHA256: SignatureScheme; |
30 | 22 | static RSA_PSS_PSS_SHA384: SignatureScheme; |
31 | 23 | static RSA_PSS_PSS_SHA512: SignatureScheme; |
32 | | - |
33 | | - /** Legacy algorithms */ |
34 | 24 | static RSA_PKCS1_SHA1: SignatureScheme; |
35 | 25 | static ECDSA_SHA1: SignatureScheme; |
36 | | - |
37 | | - /** Reserved Code Points */ |
38 | 26 | static dsa_sha1_RESERVED: SignatureScheme; |
39 | 27 | static dsa_sha256_RESERVED: SignatureScheme; |
40 | 28 | static dsa_sha384_RESERVED: SignatureScheme; |
41 | 29 | static dsa_sha512_RESERVED: SignatureScheme; |
42 | 30 |
|
43 | 31 | /** |
44 | 32 | * Parses an octet array and returns a valid SignatureScheme. |
45 | | - * @param {Uint8Array} octet - The octet array to parse. |
46 | | - * @returns {SignatureScheme} The corresponding SignatureScheme instance. |
| 33 | + * @param octet The octet array to parse. |
| 34 | + * @returns The corresponding SignatureScheme instance. |
47 | 35 | * @throws {Error} If the octet does not correspond to a known SignatureScheme. |
48 | 36 | */ |
49 | 37 | static from(octet: Uint8Array): SignatureScheme; |
50 | 38 |
|
51 | 39 | /** |
52 | | - * Returns the bit length of the SignatureScheme. |
53 | | - * @returns {number} The bit length, which is always 16. |
| 40 | + * The bit length of the SignatureScheme. |
| 41 | + * @returns The bit length, which is always 16. |
54 | 42 | */ |
55 | 43 | get bit(): number; |
56 | 44 |
|
57 | 45 | /** |
58 | 46 | * Converts the SignatureScheme to a Uint16 representation. |
59 | | - * @returns {Uint16} The Uint16 representation of the SignatureScheme. |
| 47 | + * @returns The Uint16 representation of the SignatureScheme. |
60 | 48 | */ |
61 | 49 | get Uint16(): Uint16; |
62 | 50 |
|
63 | 51 | /** |
64 | | - * Creates a CertificateVerify handshake instance. |
65 | | - * @param clientHelloMsg The ClientHello message. |
66 | | - * @param serverHelloMsg The ServerHello message. |
67 | | - * @param encryptedExtensionsMsg The EncryptedExtensions message. |
68 | | - * @param certificateMsg The Certificate message. |
69 | | - * @param RSAprivateKey The RSA private key. |
70 | | - * @param sha The SHA variant (256, 384, or 512). |
| 52 | + * Retrieves the algorithm details for the SignatureScheme. |
| 53 | + * @returns An object describing the algorithm and hash details. |
| 54 | + */ |
| 55 | + get algo(): { name: string; hash?: string; saltLength?: number }; |
| 56 | + |
| 57 | + /** |
| 58 | + * Verifies a certificate using the provided messages and private key. |
| 59 | + * @param clientHelloMsg The client hello message. |
| 60 | + * @param serverHelloMsg The server hello message. |
| 61 | + * @param encryptedExtensionsMsg The encrypted extensions message. |
| 62 | + * @param certificateMsg The certificate message. |
| 63 | + * @param RSAprivateKey The private RSA key. |
| 64 | + * @returns A promise that resolves to a CertificateVerify instance. |
71 | 65 | */ |
72 | 66 | certificateVerify( |
73 | 67 | clientHelloMsg: Uint8Array, |
74 | 68 | serverHelloMsg: Uint8Array, |
75 | 69 | encryptedExtensionsMsg: Uint8Array, |
76 | 70 | certificateMsg: Uint8Array, |
77 | | - RSAprivateKey: CryptoKey, |
78 | | - sha: number, |
| 71 | + RSAprivateKey: CryptoKey |
79 | 72 | ): Promise<CertificateVerify>; |
80 | 73 | } |
81 | 74 |
|
82 | | -/** |
83 | | - * Represents a CertificateVerify message. |
84 | | - */ |
85 | 75 | export declare class CertificateVerify extends Uint8Array { |
86 | | - /** |
87 | | - * Creates a CertificateVerify instance from an array. |
88 | | - * @param array The input array. |
89 | | - */ |
90 | 76 | static fromMsg(array: Uint8Array): CertificateVerify; |
91 | | - |
92 | 77 | constructor(signatureScheme: SignatureScheme, signature: Uint8Array); |
93 | | - |
94 | 78 | algorithm: SignatureScheme; |
95 | 79 | signature: Uint8Array; |
96 | 80 | } |
97 | 81 |
|
98 | | -/** |
99 | | - * Represents a constrained Signature. |
100 | | - */ |
101 | 82 | export declare class Signature extends Constrained { |
102 | | - /** |
103 | | - * Creates a Signature instance from an array. |
104 | | - * @param array The input array. |
105 | | - */ |
106 | 83 | static from(array: Uint8Array): Signature; |
107 | | - |
108 | 84 | constructor(opaque: Uint8Array); |
109 | | - |
110 | 85 | opaque: Uint8Array; |
111 | 86 | } |
112 | 87 |
|
113 | 88 | /** |
114 | | - * Generates a signature for the CertificateVerify message. |
| 89 | + * Generates a signature from the provided messages and key. |
| 90 | + * @param clientHelloMsg The client hello message. |
| 91 | + * @param serverHelloMsg The server hello message. |
| 92 | + * @param encryptedExtensionsMsg The encrypted extensions message. |
| 93 | + * @param certificateMsg The certificate message. |
| 94 | + * @param RSAprivateKey The private RSA key. |
| 95 | + * @param algo The algorithm to use for signing. |
| 96 | + * @returns A promise that resolves to the generated signature as a Uint8Array. |
115 | 97 | */ |
116 | 98 | export declare function signatureFrom( |
117 | 99 | clientHelloMsg: Uint8Array, |
118 | 100 | serverHelloMsg: Uint8Array, |
119 | 101 | encryptedExtensionsMsg: Uint8Array, |
120 | 102 | certificateMsg: Uint8Array, |
121 | 103 | RSAprivateKey: CryptoKey, |
122 | | - sha?: number, |
| 104 | + algo: { name: string; hash?: string; saltLength?: number } |
123 | 105 | ): Promise<Uint8Array>; |
124 | 106 |
|
125 | 107 | /** |
126 | | - * Generates a Finished message. |
| 108 | + * Computes the hash function based on the provided algorithm. |
| 109 | + * @param algo The algorithm details. |
| 110 | + * @returns The appropriate hash instance. |
| 111 | + */ |
| 112 | +export declare function hashFromAlgo( |
| 113 | + algo: { hash?: string; saltLength?: number } |
| 114 | +): ReturnType<typeof sha256.create | typeof sha384.create | typeof sha512.create>; |
| 115 | + |
| 116 | +/** |
| 117 | + * Creates a Finished instance from the provided key and messages. |
| 118 | + * @param finishedKey The HMAC key used for the finished computation. |
| 119 | + * @param sha The SHA variant to use (256, 384, etc.). |
| 120 | + * @param messages The messages to include in the transcript. |
| 121 | + * @returns A promise that resolves to a Finished instance. |
127 | 122 | */ |
128 | 123 | export declare function finished( |
129 | 124 | finishedKey: Uint8Array, |
130 | 125 | sha: number, |
131 | 126 | ...messages: Uint8Array[] |
132 | 127 | ): Promise<Finished>; |
133 | 128 |
|
134 | | -/** |
135 | | - * Represents a Finished handshake message. |
136 | | - */ |
137 | 129 | export declare class Finished extends Uint8Array { |
138 | | - /** |
139 | | - * Creates a Finished instance from a message. |
140 | | - * @param message The input message. |
141 | | - */ |
142 | 130 | static fromMsg(message: Uint8Array): Finished; |
143 | | - |
144 | 131 | constructor(verify_data: Uint8Array); |
145 | | - |
146 | 132 | verify_data: Uint8Array; |
147 | 133 | } |
0 commit comments