summaryrefslogtreecommitdiff
path: root/ext/node/ops
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/ops')
-rw-r--r--ext/node/ops/mod.rs1
-rw-r--r--ext/node/ops/tls.rs29
2 files changed, 30 insertions, 0 deletions
diff --git a/ext/node/ops/mod.rs b/ext/node/ops/mod.rs
index d11cc7461..b562261f3 100644
--- a/ext/node/ops/mod.rs
+++ b/ext/node/ops/mod.rs
@@ -11,6 +11,7 @@ pub mod ipc;
pub mod os;
pub mod process;
pub mod require;
+pub mod tls;
pub mod util;
pub mod v8;
pub mod vm;
diff --git a/ext/node/ops/tls.rs b/ext/node/ops/tls.rs
new file mode 100644
index 000000000..86b177960
--- /dev/null
+++ b/ext/node/ops/tls.rs
@@ -0,0 +1,29 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+use base64::Engine;
+use deno_core::op2;
+use webpki_root_certs;
+
+#[op2]
+#[serde]
+pub fn op_get_root_certificates() -> Vec<String> {
+ let certs = webpki_root_certs::TLS_SERVER_ROOT_CERTS
+ .iter()
+ .map(|cert| {
+ let b64 = base64::engine::general_purpose::STANDARD.encode(cert);
+ let pem_lines = b64
+ .chars()
+ .collect::<Vec<char>>()
+ // Node uses 72 characters per line, so we need to follow node even though
+ // it's not spec compliant https://datatracker.ietf.org/doc/html/rfc7468#section-2
+ .chunks(72)
+ .map(|c| c.iter().collect::<String>())
+ .collect::<Vec<String>>()
+ .join("\n");
+ let pem = format!(
+ "-----BEGIN CERTIFICATE-----\n{pem_lines}\n-----END CERTIFICATE-----\n",
+ );
+ pem
+ })
+ .collect::<Vec<String>>();
+ certs
+}