Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
show cert metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Condurache committed Nov 3, 2023
1 parent a48d204 commit 18fe30a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ fn load_native_certs(mut cx: FunctionContext) -> JsResult<JsString> {
certs
.into_iter()
.map(|cert| {
X509Certificate::from_der(&cert.0)
.expect("Could not import to DER")
.encode_pem()
.expect("could not encode to PEM")
let der = X509Certificate::from_der(&cert.0).expect("Could not import to DER");
let subject = der.subject_common_name().unwrap_or_else(|| String::new());
let issuer = der.issuer_common_name().unwrap_or_else(|| String::new());
let pem = der.encode_pem().expect("could not encode to PEM");
format!("# Subject: {subject}\n# Issuer: {issuer}\n{pem}\n")
})
.collect()
});
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const nativeCerts = require(".")
const ca = nativeCerts.load_native_certs()
assert(ca.length > 0)

https.get({ca, host: "google.com", path: "/"}) // should not fail
// console.log(ca) // uncomment to print the certs for debugging
// https.get({ca, host: "google.com", path: "/"}) // should not fail
console.log(ca) // uncomment to print the certs for debugging

0 comments on commit 18fe30a

Please sign in to comment.