Add function & interface declarations for CA handling

Namely:
- `pki.createCaStore()`
- `pki.verifyCertificateChain()`
- interface `CAStore`

... and fix a copy&paste error in the APIDoc of `pki.Certificate.setIssuer()`.
This commit is contained in:
Alex D'Andrea
2018-12-04 09:19:42 +01:00
parent 96f1ee52c6
commit 2f0bb90c16
2 changed files with 31 additions and 1 deletions
+12 -1
View File
@@ -67,6 +67,8 @@ declare module "node-forge" {
function privateKeyFromPem(pem: PEM): PrivateKey;
function certificateToPem(cert: Certificate, maxline?: number): PEM;
function certificateFromPem(pem: PEM, computeHash?: boolean, strict?: boolean): Certificate;
function createCaStore(): CAStore;
function verifyCertificateChain(caStore: CAStore, chain: Certificate[], customVerifyCallback?: (verified: boolean | string, depth: number, chain: Certificate[]) => boolean): boolean;
interface oids {
[key: string]: string;
@@ -202,7 +204,7 @@ declare module "node-forge" {
*/
setSubject(attrs: CertificateField[], uniqueId?: string): void;
/**
* Sets the subject of this certificate.
* Sets the issuer of this certificate.
*
* @param attrs the array of subject attributes to use.
* @param uniqueId an optional a unique ID to use.
@@ -244,6 +246,15 @@ declare module "node-forge" {
}
interface CAStore {
addCertificate(cert: Certificate | string): any;
hasCertificate(cert: Certificate | string): boolean;
removeCertificate(cert: Certificate | string): Certificate | null;
listAllCertificates(): pki.Certificate[];
getIssuer(subject: Certificate): Certificate | null;
getBySubject(subject: string): Certificate | null;
}
function certificateFromAsn1(obj: asn1.Asn1, computeHash?: boolean): Certificate;
function decryptRsaPrivateKey(pem: PEM, passphrase?: string): PrivateKey;
+19
View File
@@ -203,3 +203,22 @@ if (forge.util.fillString('1', 5) !== '11111') throw Error('forge.util.fillStrin
throw Error("rsa signature verification fail");
}
}
{
const emptyStore = forge.pki.createCaStore();
const certificate = forge.pki.createCertificate();
const pem = forge.pki.certificateToPem(certificate);
const caStore = forge.pki.createCaStore();
caStore.addCertificate(certificate);
caStore.removeCertificate(certificate);
caStore.listAllCertificates();
caStore.removeCertificate(certificate);
forge.pki.verifyCertificateChain(caStore, [certificate], (verified, depth, chain) => {
return true;
});
}