|
| 1 | +import {Buffer} from 'node:buffer' |
| 2 | + |
| 3 | +declare namespace pem { |
| 4 | + type Callback<T> = (error: Error | null, result: T) => void |
| 5 | + |
| 6 | + interface CreatePrivateKeyOptions { |
| 7 | + cipher?: string |
| 8 | + password?: string |
| 9 | + } |
| 10 | + |
| 11 | + interface PrivateKeyResult { |
| 12 | + key: string |
| 13 | + } |
| 14 | + |
| 15 | + interface CreateDhparamResult { |
| 16 | + dhparam: string |
| 17 | + } |
| 18 | + |
| 19 | + interface CreateEcparamResult { |
| 20 | + ecparam: string |
| 21 | + } |
| 22 | + |
| 23 | + interface CreateCSROptions { |
| 24 | + clientKey?: string | Buffer |
| 25 | + clientKeyPassword?: string |
| 26 | + keyBitsize?: number |
| 27 | + hash?: string |
| 28 | + country?: string |
| 29 | + state?: string |
| 30 | + locality?: string |
| 31 | + organization?: string | string[] |
| 32 | + organizationUnit?: string | string[] |
| 33 | + commonName?: string |
| 34 | + altNames?: Array<string> |
| 35 | + emailAddress?: string |
| 36 | + csrConfigFile?: string |
| 37 | + config?: string |
| 38 | + password?: string |
| 39 | + dc?: string | string[] |
| 40 | + C?: string |
| 41 | + ST?: string |
| 42 | + L?: string |
| 43 | + O?: string | string[] |
| 44 | + OU?: string | string[] |
| 45 | + CN?: string |
| 46 | + } |
| 47 | + |
| 48 | + interface CSRResult { |
| 49 | + csr: string |
| 50 | + clientKey: string |
| 51 | + config: string | null |
| 52 | + } |
| 53 | + |
| 54 | + interface CreateCertificateOptions extends CreateCSROptions { |
| 55 | + serviceCertificate?: string | Buffer |
| 56 | + serviceKey?: string | Buffer |
| 57 | + serviceKeyPassword?: string |
| 58 | + selfSigned?: boolean |
| 59 | + serial?: string | number | Buffer |
| 60 | + serialFile?: string |
| 61 | + days?: number |
| 62 | + extFile?: string |
| 63 | + cipher?: string |
| 64 | + } |
| 65 | + |
| 66 | + interface CertificateCreationResult { |
| 67 | + certificate: string |
| 68 | + csr: string |
| 69 | + clientKey: string |
| 70 | + serviceKey: string |
| 71 | + } |
| 72 | + |
| 73 | + interface CertificateInfo { |
| 74 | + serial?: string |
| 75 | + country?: string | string[] |
| 76 | + state?: string | string[] |
| 77 | + locality?: string | string[] |
| 78 | + organization?: string | string[] |
| 79 | + organizationUnit?: string | string[] |
| 80 | + commonName?: string | string[] |
| 81 | + emailAddress?: string | string[] |
| 82 | + dc?: string | string[] |
| 83 | + san?: { |
| 84 | + dns?: string[] | '' |
| 85 | + ip?: string[] | '' |
| 86 | + email?: string[] | '' |
| 87 | + } |
| 88 | + validity?: { |
| 89 | + start: number |
| 90 | + end: number |
| 91 | + } |
| 92 | + signatureAlgorithm?: string |
| 93 | + publicKeyAlgorithm?: string |
| 94 | + publicKeySize?: string |
| 95 | + issuer: { |
| 96 | + country?: string | string[] |
| 97 | + state?: string | string[] |
| 98 | + locality?: string | string[] |
| 99 | + organization?: string | string[] |
| 100 | + organizationUnit?: string | string[] |
| 101 | + commonName?: string | string[] |
| 102 | + emailAddress?: string | string[] |
| 103 | + dc?: string | string[] |
| 104 | + [key: string]: string | string[] | undefined |
| 105 | + } |
| 106 | + [key: string]: unknown |
| 107 | + } |
| 108 | + |
| 109 | + interface FingerprintResult { |
| 110 | + fingerprint: string |
| 111 | + } |
| 112 | + |
| 113 | + interface PublicKeyResult { |
| 114 | + publicKey: string |
| 115 | + } |
| 116 | + |
| 117 | + interface ModulusResult { |
| 118 | + modulus: string |
| 119 | + } |
| 120 | + |
| 121 | + interface DhparamInfoResult { |
| 122 | + size: number |
| 123 | + prime: string |
| 124 | + } |
| 125 | + |
| 126 | + interface CreatePkcs12Options { |
| 127 | + cipher?: string |
| 128 | + clientKeyPassword?: string |
| 129 | + certFiles?: Array<string> |
| 130 | + } |
| 131 | + |
| 132 | + interface CreatePkcs12Result { |
| 133 | + pkcs12: Buffer |
| 134 | + } |
| 135 | + |
| 136 | + interface ReadPkcs12Options { |
| 137 | + p12Password?: string |
| 138 | + clientKeyPassword?: string |
| 139 | + } |
| 140 | + |
| 141 | + interface ReadPkcs12Result { |
| 142 | + cert?: string |
| 143 | + ca?: string[] |
| 144 | + key?: string |
| 145 | + } |
| 146 | + |
| 147 | + type CertificateInput = string | Buffer |
| 148 | + type CertificateChainInput = string | Buffer | Array<string | Buffer> |
| 149 | + |
| 150 | + interface ConvertCertificateBundle { |
| 151 | + cert: string |
| 152 | + ca?: string | string[] |
| 153 | + } |
| 154 | + |
| 155 | + interface ConvertCertificateKeyBundle extends ConvertCertificateBundle { |
| 156 | + key: string |
| 157 | + } |
| 158 | + |
| 159 | + interface ConvertModule { |
| 160 | + PEM2DER(pathIn: string, pathOut: string, callback: Callback<boolean>): void |
| 161 | + PEM2DER(pathIn: string, pathOut: string, type: string, callback: Callback<boolean>): void |
| 162 | + DER2PEM(pathIn: string, pathOut: string, callback: Callback<boolean>): void |
| 163 | + DER2PEM(pathIn: string, pathOut: string, type: string, callback: Callback<boolean>): void |
| 164 | + PEM2P7B(bundle: ConvertCertificateBundle, pathOut: string, callback: Callback<boolean>): void |
| 165 | + P7B2PEM(pathIn: string, pathOut: string, callback: Callback<boolean>): void |
| 166 | + PEM2PFX(bundle: ConvertCertificateKeyBundle, pathOut: string, password: string, callback: Callback<boolean>): void |
| 167 | + PFX2PEM(pathIn: string, pathOut: string, password: string, callback: Callback<boolean>): void |
| 168 | + } |
| 169 | + |
| 170 | + interface IssueCertificateOptions extends CreateCertificateOptions { |
| 171 | + csr?: string | Buffer |
| 172 | + clientKey?: string | Buffer |
| 173 | + chain?: Array<string | Buffer> |
| 174 | + startDate?: Date | number | string |
| 175 | + endDate?: Date | number | string |
| 176 | + days?: number |
| 177 | + serial?: string | number | Buffer |
| 178 | + } |
| 179 | + |
| 180 | + interface IssuedCertificate { |
| 181 | + csr: string |
| 182 | + clientKey: string |
| 183 | + certificate: string |
| 184 | + caCertificate: string |
| 185 | + caChain: string[] |
| 186 | + serial: string |
| 187 | + validity: { |
| 188 | + start: number |
| 189 | + end: number |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + interface CertificateAuthorityOptions { |
| 194 | + key: string | Buffer |
| 195 | + certificate: string | Buffer |
| 196 | + chain?: Array<string | Buffer> |
| 197 | + keyPassword?: string |
| 198 | + password?: string |
| 199 | + defaultDays?: number |
| 200 | + } |
| 201 | + |
| 202 | + class CA { |
| 203 | + constructor(options: CertificateAuthorityOptions) |
| 204 | + issueCertificate(options?: IssueCertificateOptions): Promise<IssuedCertificate> |
| 205 | + issueCertificate(callback: Callback<IssuedCertificate>): void |
| 206 | + issueCertificate(options: IssueCertificateOptions, callback: Callback<IssuedCertificate>): void |
| 207 | + } |
| 208 | + |
| 209 | + interface Promisified { |
| 210 | + createPrivateKey(): Promise<PrivateKeyResult> |
| 211 | + createPrivateKey(keyBitsize: number): Promise<PrivateKeyResult> |
| 212 | + createPrivateKey(options: CreatePrivateKeyOptions): Promise<PrivateKeyResult> |
| 213 | + createPrivateKey(keyBitsize: number, options: CreatePrivateKeyOptions): Promise<PrivateKeyResult> |
| 214 | + createDhparam(keyBitsize?: number): Promise<CreateDhparamResult> |
| 215 | + createEcparam(keyName?: string, paramEnc?: string, noOut?: boolean): Promise<CreateEcparamResult> |
| 216 | + createCSR(options?: CreateCSROptions): Promise<CSRResult> |
| 217 | + createCertificate(options?: CreateCertificateOptions): Promise<CertificateCreationResult> |
| 218 | + readCertificateInfo(certificate?: CertificateInput): Promise<CertificateInfo> |
| 219 | + getPublicKey(certificate?: CertificateInput): Promise<PublicKeyResult> |
| 220 | + getFingerprint(certificate: CertificateInput, hash?: string): Promise<FingerprintResult> |
| 221 | + getModulus(certificate: CertificateInput, password?: string, hash?: string | false): Promise<ModulusResult> |
| 222 | + getDhparamInfo(dh: CertificateInput): Promise<DhparamInfoResult> |
| 223 | + createPkcs12(key: string | Buffer, certificate: string | Buffer, password: string, options?: CreatePkcs12Options): Promise<CreatePkcs12Result> |
| 224 | + readPkcs12(bufferOrPath: Buffer | string, options?: ReadPkcs12Options): Promise<ReadPkcs12Result> |
| 225 | + verifySigningChain(certificate: CertificateChainInput, ca?: CertificateChainInput): Promise<boolean> |
| 226 | + checkCertificate(certificate: CertificateInput, passphrase?: string): Promise<boolean> |
| 227 | + checkPkcs12(bufferOrPath: Buffer | string, passphrase?: string): Promise<boolean> |
| 228 | + } |
| 229 | + |
| 230 | + interface PemModule { |
| 231 | + createPrivateKey(keyBitsize: number, options: CreatePrivateKeyOptions, callback: Callback<PrivateKeyResult>): void |
| 232 | + createPrivateKey(keyBitsize: number, callback: Callback<PrivateKeyResult>): void |
| 233 | + createPrivateKey(options: CreatePrivateKeyOptions, callback: Callback<PrivateKeyResult>): void |
| 234 | + createPrivateKey(callback: Callback<PrivateKeyResult>): void |
| 235 | + createPrivateKey(keyBitsize?: number, options?: CreatePrivateKeyOptions): Promise<PrivateKeyResult> |
| 236 | + |
| 237 | + createDhparam(keyBitsize: number, callback: Callback<CreateDhparamResult>): void |
| 238 | + createDhparam(callback: Callback<CreateDhparamResult>): void |
| 239 | + createDhparam(keyBitsize?: number): Promise<CreateDhparamResult> |
| 240 | + |
| 241 | + createEcparam(keyName: string, paramEnc: string, noOut: boolean, callback: Callback<CreateEcparamResult>): void |
| 242 | + createEcparam(keyName: string, paramEnc: string, callback: Callback<CreateEcparamResult>): void |
| 243 | + createEcparam(keyName: string, callback: Callback<CreateEcparamResult>): void |
| 244 | + createEcparam(callback: Callback<CreateEcparamResult>): void |
| 245 | + createEcparam(keyName?: string, paramEnc?: string, noOut?: boolean): Promise<CreateEcparamResult> |
| 246 | + |
| 247 | + createCSR(options: CreateCSROptions, callback: Callback<CSRResult>): void |
| 248 | + createCSR(callback: Callback<CSRResult>): void |
| 249 | + createCSR(options?: CreateCSROptions): Promise<CSRResult> |
| 250 | + |
| 251 | + createCertificate(options: CreateCertificateOptions, callback: Callback<CertificateCreationResult>): void |
| 252 | + createCertificate(callback: Callback<CertificateCreationResult>): void |
| 253 | + createCertificate(options?: CreateCertificateOptions): Promise<CertificateCreationResult> |
| 254 | + |
| 255 | + readCertificateInfo(certificate: CertificateInput, callback: Callback<CertificateInfo>): void |
| 256 | + readCertificateInfo(callback: Callback<CertificateInfo>): void |
| 257 | + readCertificateInfo(certificate?: CertificateInput): Promise<CertificateInfo> |
| 258 | + |
| 259 | + getPublicKey(certificate: CertificateInput, callback: Callback<PublicKeyResult>): void |
| 260 | + getPublicKey(callback: Callback<PublicKeyResult>): void |
| 261 | + getPublicKey(certificate?: CertificateInput): Promise<PublicKeyResult> |
| 262 | + |
| 263 | + getFingerprint(certificate: CertificateInput, hash: string, callback: Callback<FingerprintResult>): void |
| 264 | + getFingerprint(certificate: CertificateInput, callback: Callback<FingerprintResult>): void |
| 265 | + getFingerprint(certificate: CertificateInput, hash?: string): Promise<FingerprintResult> |
| 266 | + |
| 267 | + getModulus(certificate: CertificateInput, password: string, hash: string | false, callback: Callback<ModulusResult>): void |
| 268 | + getModulus(certificate: CertificateInput, password: string, callback: Callback<ModulusResult>): void |
| 269 | + getModulus(certificate: CertificateInput, callback: Callback<ModulusResult>): void |
| 270 | + getModulus(certificate: CertificateInput, password?: string, hash?: string | false): Promise<ModulusResult> |
| 271 | + |
| 272 | + getDhparamInfo(dh: CertificateInput, callback: Callback<DhparamInfoResult>): void |
| 273 | + getDhparamInfo(dh: CertificateInput): Promise<DhparamInfoResult> |
| 274 | + |
| 275 | + createPkcs12(key: string | Buffer, certificate: string | Buffer, password: string, options: CreatePkcs12Options, callback: Callback<CreatePkcs12Result>): void |
| 276 | + createPkcs12(key: string | Buffer, certificate: string | Buffer, password: string, callback: Callback<CreatePkcs12Result>): void |
| 277 | + createPkcs12(key: string | Buffer, certificate: string | Buffer, password: string, options?: CreatePkcs12Options): Promise<CreatePkcs12Result> |
| 278 | + |
| 279 | + readPkcs12(bufferOrPath: Buffer | string, options: ReadPkcs12Options, callback: Callback<ReadPkcs12Result>): void |
| 280 | + readPkcs12(bufferOrPath: Buffer | string, callback: Callback<ReadPkcs12Result>): void |
| 281 | + readPkcs12(bufferOrPath: Buffer | string, options?: ReadPkcs12Options): Promise<ReadPkcs12Result> |
| 282 | + |
| 283 | + verifySigningChain(certificate: CertificateChainInput, ca: CertificateChainInput, callback: Callback<boolean>): void |
| 284 | + verifySigningChain(certificate: CertificateChainInput, callback: Callback<boolean>): void |
| 285 | + verifySigningChain(certificate: CertificateChainInput, ca?: CertificateChainInput): Promise<boolean> |
| 286 | + |
| 287 | + checkCertificate(certificate: CertificateInput, passphrase: string, callback: Callback<boolean>): void |
| 288 | + checkCertificate(certificate: CertificateInput, callback: Callback<boolean>): void |
| 289 | + checkCertificate(certificate: CertificateInput, passphrase?: string): Promise<boolean> |
| 290 | + |
| 291 | + checkPkcs12(bufferOrPath: Buffer | string, passphrase: string, callback: Callback<boolean>): void |
| 292 | + checkPkcs12(bufferOrPath: Buffer | string, callback: Callback<boolean>): void |
| 293 | + checkPkcs12(bufferOrPath: Buffer | string, passphrase?: string): Promise<boolean> |
| 294 | + |
| 295 | + config(options: Record<string, string | number | boolean>): void |
| 296 | + |
| 297 | + convert: ConvertModule |
| 298 | + CA: typeof CA |
| 299 | + promisified: Promisified |
| 300 | + } |
| 301 | +} |
| 302 | + |
| 303 | +declare const pem: pem.PemModule |
| 304 | + |
| 305 | +export = pem |
0 commit comments