micro509 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +130 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/internal/jose/base64url.js +40 -0
- package/dist/internal/jose/base64url.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +9 -0
- package/dist/internal/jose/strict-json.js +155 -0
- package/dist/internal/jose/strict-json.js.map +1 -0
- package/dist/internal/verify/spki-distrust.js +23 -0
- package/dist/internal/verify/spki-distrust.js.map +1 -0
- package/dist/internal/verify/verify-path.js +77 -60
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/jose/errors.d.ts +44 -0
- package/dist/jose/errors.js +11 -0
- package/dist/jose/errors.js.map +1 -0
- package/dist/jose/jwks.d.ts +93 -0
- package/dist/jose/jwks.js +193 -0
- package/dist/jose/jwks.js.map +1 -0
- package/dist/jose/jws.d.ts +158 -0
- package/dist/jose/jws.js +362 -0
- package/dist/jose/jws.js.map +1 -0
- package/dist/jose/jwt.d.ts +91 -0
- package/dist/jose/jwt.js +187 -0
- package/dist/jose/jwt.js.map +1 -0
- package/dist/jose/remote-jwks.d.ts +95 -0
- package/dist/jose/remote-jwks.js +298 -0
- package/dist/jose/remote-jwks.js.map +1 -0
- package/dist/jose.d.ts +7 -0
- package/dist/jose.js +5 -0
- package/dist/kdf/argon2.d.ts +78 -0
- package/dist/kdf/argon2.js +167 -0
- package/dist/kdf/argon2.js.map +1 -0
- package/dist/kdf.d.ts +2 -0
- package/dist/kdf.js +1 -0
- package/dist/keys/keys.d.ts +11 -8
- package/dist/keys/keys.js.map +1 -1
- package/dist/revocation/crl.js +2 -7
- package/dist/revocation/crl.js.map +1 -1
- package/dist/ssh/ssh.d.ts +200 -0
- package/dist/ssh/ssh.js +648 -0
- package/dist/ssh/ssh.js.map +1 -0
- package/dist/ssh/wire.d.ts +3 -0
- package/dist/ssh/wire.js +105 -0
- package/dist/ssh/wire.js.map +1 -0
- package/dist/ssh.d.ts +3 -0
- package/dist/ssh.js +1 -0
- package/dist/verify/verify.d.ts +32 -1
- package/dist/verify/verify.js +100 -58
- package/dist/verify/verify.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +11 -0
- package/dist/x509/fingerprint.js +19 -1
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509.d.ts +2 -2
- package/dist/x509.js +3 -3
- package/package.json +20 -6
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
|
+
import { EcNamedCurve, RsaHash, RsaSignatureScheme } from "../keys/keys.js";
|
|
3
|
+
import { SshErrorCode } from "./wire.js";
|
|
4
|
+
/** SSH public-key type names (RFC 4253 §6.6, RFC 5656 §6.2, RFC 8709 §4) this module reads and writes. */
|
|
5
|
+
export type SshKeyType = "ssh-rsa" | "ssh-ed25519" | "ecdsa-sha2-nistp256" | "ecdsa-sha2-nistp384" | "ecdsa-sha2-nistp521";
|
|
6
|
+
/** Algorithm family of an SSH key, discriminated by `kind`. */
|
|
7
|
+
export type SshKeyAlgorithm = {
|
|
8
|
+
/** RSA. */
|
|
9
|
+
readonly kind: "rsa";
|
|
10
|
+
/** Modulus size in bits. */
|
|
11
|
+
readonly modulusBits: number;
|
|
12
|
+
} | {
|
|
13
|
+
/** ECDSA. */
|
|
14
|
+
readonly kind: "ecdsa";
|
|
15
|
+
/** NIST curve. */
|
|
16
|
+
readonly curve: EcNamedCurve;
|
|
17
|
+
} | {
|
|
18
|
+
/** Ed25519. */
|
|
19
|
+
readonly kind: "ed25519";
|
|
20
|
+
};
|
|
21
|
+
/** Structured failure payload of the SSH key import functions. */
|
|
22
|
+
export interface SshFailure extends Micro509Error<SshErrorCode> {
|
|
23
|
+
/** Always `false` for failures. */
|
|
24
|
+
readonly ok: false;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Success-or-failure result of the SSH key import functions.
|
|
28
|
+
*
|
|
29
|
+
* `code` is `'malformed'` for structurally invalid input, `'unsupported'` for a
|
|
30
|
+
* valid construct this module does not read (encrypted keys, multi-key files,
|
|
31
|
+
* other key types, RSA below the minimum size, compressed points unless
|
|
32
|
+
* accepted), `'limit_exceeded'` for an implementation bound, and
|
|
33
|
+
* `'key_mismatch'` when the declared key types or the embedded public and
|
|
34
|
+
* private keys disagree. No message contains private key material.
|
|
35
|
+
*/
|
|
36
|
+
export type SshResult<T> = {
|
|
37
|
+
readonly ok: true;
|
|
38
|
+
readonly value: T;
|
|
39
|
+
} | ErrorResult<SshErrorCode, Record<never, never>, SshFailure>;
|
|
40
|
+
/** Policy options of the SSH key import functions. */
|
|
41
|
+
export interface SshImportOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Smallest accepted RSA modulus in bits, an integer from 1 to 16384. Default: `2048`.
|
|
44
|
+
*
|
|
45
|
+
* The standards leave key strength to the relying party. RFC 8332 §5.1 calls
|
|
46
|
+
* 2048 bits prudent; OpenSSH itself accepts 1024.
|
|
47
|
+
*/
|
|
48
|
+
readonly minRsaModulusBits?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Accept SEC 1 compressed ECDSA points. Default: `false`.
|
|
51
|
+
*
|
|
52
|
+
* RFC 5656 §3.1 allows point compression; OpenSSH reads and writes only
|
|
53
|
+
* uncompressed points.
|
|
54
|
+
*/
|
|
55
|
+
readonly acceptCompressedEcPoints?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* WebCrypto parameters of an imported RSA key. Default: PKCS#1 v1.5 with
|
|
58
|
+
* SHA-256. These choose how the `CryptoKey` signs; they do not change the
|
|
59
|
+
* `ssh-rsa` key encoding.
|
|
60
|
+
*/
|
|
61
|
+
readonly rsa?: {
|
|
62
|
+
/** Signature padding scheme. */
|
|
63
|
+
readonly scheme?: RsaSignatureScheme;
|
|
64
|
+
/** Signature hash. */
|
|
65
|
+
readonly hash?: RsaHash;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Public key read from an OpenSSH public-key line. */
|
|
69
|
+
export interface ImportedSshPublicKey {
|
|
70
|
+
/** SSH key type name. */
|
|
71
|
+
readonly keyType: SshKeyType;
|
|
72
|
+
/** Algorithm family and size. */
|
|
73
|
+
readonly algorithm: SshKeyAlgorithm;
|
|
74
|
+
/** Extractable WebCrypto key with `verify` usage. */
|
|
75
|
+
readonly publicKey: CryptoKey;
|
|
76
|
+
/** The line's trailing comment; empty when absent. */
|
|
77
|
+
readonly comment: string;
|
|
78
|
+
/** `SHA256:` fingerprint of the public-key blob. */
|
|
79
|
+
readonly fingerprint: string;
|
|
80
|
+
}
|
|
81
|
+
/** Key pair read from an `openssh-key-v1` private-key file. */
|
|
82
|
+
export interface ImportedOpenSshPrivateKey extends ImportedSshPublicKey {
|
|
83
|
+
/** Extractable WebCrypto private key with `sign` usage. */
|
|
84
|
+
readonly privateKey: CryptoKey;
|
|
85
|
+
}
|
|
86
|
+
/** Options of {@linkcode exportSshPublicKey} and {@linkcode exportOpenSshPrivateKey}. */
|
|
87
|
+
export interface SshExportOptions {
|
|
88
|
+
/** Comment to attach, at most 8192 UTF-8 bytes. Must be well-formed Unicode without CR, LF or NUL. Default: empty. */
|
|
89
|
+
readonly comment?: string;
|
|
90
|
+
}
|
|
91
|
+
/** Machine-readable failure reason of the SSH key export functions. */
|
|
92
|
+
export type SshExportErrorCode = "invalid_key" | "unsupported_algorithm" | "not_extractable" | "invalid_comment";
|
|
93
|
+
/**
|
|
94
|
+
* Import an OpenSSH public-key line (`<type> <base64> [comment]`).
|
|
95
|
+
*
|
|
96
|
+
* Reads `ssh-rsa`, `ssh-ed25519`, and `ecdsa-sha2-nistp256/384/521` keys as
|
|
97
|
+
* written by `ssh-keygen` into `.pub` files. The line key type must equal the
|
|
98
|
+
* type inside the blob (RFC 4253 §6.6), an ECDSA curve identifier must equal
|
|
99
|
+
* its key type suffix (RFC 5656 §3.1), and trailing data after the blob is
|
|
100
|
+
* rejected. Fields are separated by spaces or tabs, one trailing line break
|
|
101
|
+
* is allowed, and everything after the base64 field is the comment.
|
|
102
|
+
* `authorized_keys` options and SSH certificate types are not read.
|
|
103
|
+
*
|
|
104
|
+
* Input is capped at 16 KiB and RSA moduli at 16384 bits. `input` is never
|
|
105
|
+
* modified.
|
|
106
|
+
*
|
|
107
|
+
* @param input - The line as text or UTF-8 bytes
|
|
108
|
+
* @param options - Policy options; see {@linkcode SshImportOptions}
|
|
109
|
+
* @returns The WebCrypto verification key, its comment and its SHA-256 fingerprint
|
|
110
|
+
*
|
|
111
|
+
* @see {@linkcode importSshPublicKeyOrThrow} for the throwing variant
|
|
112
|
+
* @see {@linkcode exportSshPublicKey} for the inverse operation
|
|
113
|
+
*/
|
|
114
|
+
export declare function importSshPublicKey(input: string | Uint8Array, options?: SshImportOptions): Promise<SshResult<ImportedSshPublicKey>>;
|
|
115
|
+
/**
|
|
116
|
+
* Throwing variant of {@linkcode importSshPublicKey}.
|
|
117
|
+
*
|
|
118
|
+
* @throws {ResultError} Carrying an {@linkcode SshErrorCode} as `code`
|
|
119
|
+
*/
|
|
120
|
+
export declare function importSshPublicKeyOrThrow(input: string | Uint8Array, options?: SshImportOptions): Promise<ImportedSshPublicKey>;
|
|
121
|
+
/**
|
|
122
|
+
* Import an unencrypted single-key `openssh-key-v1` private key file.
|
|
123
|
+
*
|
|
124
|
+
* Accepts the `-----BEGIN OPENSSH PRIVATE KEY-----` PEM that `ssh-keygen`
|
|
125
|
+
* writes for RSA, Ed25519 and ECDSA P-256/P-384/P-521 keys. The cipher and
|
|
126
|
+
* KDF must both be `none` with empty KDF options; any other value returns
|
|
127
|
+
* `unsupported`, as does a file holding several keys. The check integers,
|
|
128
|
+
* the `1, 2, 3, ...` padding, the block alignment, and the absence of trailing
|
|
129
|
+
* bytes are verified, and RSA integers must be canonical positive `mpint`s.
|
|
130
|
+
*
|
|
131
|
+
* The public key embedded in the file must equal the public half of the
|
|
132
|
+
* private section and its key type, or the result is `key_mismatch`. The
|
|
133
|
+
* private material is then checked cryptographically: for RSA, `p·q = n`,
|
|
134
|
+
* `d·e ≡ 1` modulo both `p-1` and `q-1`, and `iqmp·q ≡ 1 (mod p)`; for every
|
|
135
|
+
* key, a signature made with the private key must verify under the embedded
|
|
136
|
+
* public key. For Ed25519 the 32-byte suffix of the private field must equal
|
|
137
|
+
* the public key.
|
|
138
|
+
*
|
|
139
|
+
* Both keys are returned extractable. The decoded binary copy of the file is
|
|
140
|
+
* zeroed before returning. JavaScript strings, including the PEM text and the
|
|
141
|
+
* JWK members used for the import, cannot be zeroed, and `input` is never
|
|
142
|
+
* modified.
|
|
143
|
+
*
|
|
144
|
+
* @param input - The PEM file as text or UTF-8 bytes, at most 32 KiB
|
|
145
|
+
* @param options - Policy options; see {@linkcode SshImportOptions}
|
|
146
|
+
*
|
|
147
|
+
* @see {@linkcode importOpenSshPrivateKeyOrThrow} for the throwing variant
|
|
148
|
+
* @see {@linkcode exportOpenSshPrivateKey} for the inverse operation
|
|
149
|
+
*/
|
|
150
|
+
export declare function importOpenSshPrivateKey(input: string | Uint8Array, options?: SshImportOptions): Promise<SshResult<ImportedOpenSshPrivateKey>>;
|
|
151
|
+
/**
|
|
152
|
+
* Throwing variant of {@linkcode importOpenSshPrivateKey}.
|
|
153
|
+
*
|
|
154
|
+
* @throws {ResultError} Carrying an {@linkcode SshErrorCode} as `code`
|
|
155
|
+
*/
|
|
156
|
+
export declare function importOpenSshPrivateKeyOrThrow(input: string | Uint8Array, options?: SshImportOptions): Promise<ImportedOpenSshPrivateKey>;
|
|
157
|
+
/**
|
|
158
|
+
* Export a public key as an OpenSSH public-key line.
|
|
159
|
+
*
|
|
160
|
+
* Writes `<type> <base64> [comment]` with padded base64 and no trailing line
|
|
161
|
+
* break, the form `ssh-keygen` puts in `.pub` files. ECDSA points are written
|
|
162
|
+
* uncompressed. The key must be an extractable RSA, ECDSA (P-256, P-384,
|
|
163
|
+
* P-521) or Ed25519 public `CryptoKey`.
|
|
164
|
+
*
|
|
165
|
+
* @throws {ResultError} Carrying an {@linkcode SshExportErrorCode} as `code`
|
|
166
|
+
*
|
|
167
|
+
* @see {@linkcode importSshPublicKey} for the inverse operation
|
|
168
|
+
*/
|
|
169
|
+
export declare function exportSshPublicKey(publicKey: CryptoKey, options?: SshExportOptions): Promise<string>;
|
|
170
|
+
/**
|
|
171
|
+
* Export a private key as an unencrypted `openssh-key-v1` PEM file.
|
|
172
|
+
*
|
|
173
|
+
* The file holds one key, cipher `none` and KDF `none`, with the check
|
|
174
|
+
* integers drawn from the WebCrypto random source and the public key derived
|
|
175
|
+
* from the private key. `ssh-keygen` reads it directly. Check integers are
|
|
176
|
+
* random, so compare keys, not file bytes, between two exports.
|
|
177
|
+
*
|
|
178
|
+
* The private `CryptoKey` must be extractable. The binary encoding is zeroed
|
|
179
|
+
* after the PEM text is built; the returned string and the JWK used for the
|
|
180
|
+
* export cannot be zeroed.
|
|
181
|
+
*
|
|
182
|
+
* @throws {ResultError} Carrying an {@linkcode SshExportErrorCode} as `code`
|
|
183
|
+
*
|
|
184
|
+
* @see {@linkcode importOpenSshPrivateKey} for the inverse operation
|
|
185
|
+
*/
|
|
186
|
+
export declare function exportOpenSshPrivateKey(privateKey: CryptoKey, options?: SshExportOptions): Promise<string>;
|
|
187
|
+
/**
|
|
188
|
+
* The `SHA256:` fingerprint `ssh-keygen -l -E sha256` prints for a key.
|
|
189
|
+
*
|
|
190
|
+
* It is the SHA-256 digest of the SSH public-key blob (RFC 4253 §6.6 layout),
|
|
191
|
+
* base64-encoded without padding and prefixed with `SHA256:`. It differs from a
|
|
192
|
+
* certificate fingerprint and from a digest of the SPKI encoding. Pass a
|
|
193
|
+
* public or private `CryptoKey`, or the raw blob bytes (the decoded base64
|
|
194
|
+
* field of a public-key line). A private key must be extractable.
|
|
195
|
+
*
|
|
196
|
+
* @throws {ResultError} Carrying an {@linkcode SshExportErrorCode} when a `CryptoKey` cannot be encoded
|
|
197
|
+
*/
|
|
198
|
+
export declare function sshFingerprintSha256(key: CryptoKey | Uint8Array): Promise<string>;
|
|
199
|
+
export type { SshErrorCode };
|
|
200
|
+
//# sourceMappingURL=ssh.d.ts.map
|