PKI¶
Certificates from a PKI secrets engine (client.pki(mount = "pki")).
| Function | What it does |
|---|---|
issueCertificate(role, commonName, options?) |
new key pair + certificate: certificate, issuingCa, caChain, privateKey (redacted), privateKeyType, serialNumber, expiration; options altNames, ipSans, uriSans, ttl, format, privateKeyFormat, excludeCnFromSans; a name the role does not allow → VALIDATION |
signCsr(role, csr, options?) |
signs a PEM CSR (same result without the private key); a bad CSR → VALIDATION |
revokeCertificate(serial) |
revocationTime; unknown serial → VALIDATION |
readCaChain() |
PEM text of the CA chain |
readCertificate(serial) |
PEM certificate and revocation time (empty when not revoked); unknown → NOT_FOUND |
listCertificates() |
serial numbers (colon hex) |
tidy(options?) / tidyStatus() |
starts the asynchronous tidy (tidyCertStore, tidyRevokedCerts, safetyBuffer) / polls its state (Running, Finished) |
Issue, inspect and revoke a certificate¶
const pki = client.pki();
const cert = await pki.issueCertificate("web", "app.example.test", {
altNames: ["www.example.test"],
ttlMs: 3_600_000,
});
console.log(cert.serialNumber, cert.certificate);
const chain = await pki.readCaChain();
await pki.revokeCertificate(cert.serialNumber);
console.log((await pki.readCertificate(cert.serialNumber)).revocationTime); // a Date
use grow_hashicorp_vault::IssueOptions;
let pki = client.pki();
let cert = pki
.issue_certificate(
"web",
"app.example.test",
Some(&IssueOptions {
alt_names: vec!["www.example.test".into()],
ttl: Some(Duration::from_secs(3600)),
..Default::default()
}),
)
.await?;
let chain = pki.read_ca_chain().await?;
pki.revoke_certificate(&cert.serial_number).await?;