Skip to content

Commit 6abf7f1

Browse files
committed
get_verified_chain
1 parent 5b2b64c commit 6abf7f1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

stdlib/src/ssl.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,37 @@ mod _ssl {
11461146
Some(vm.ctx.new_list(certs).into())
11471147
}
11481148

1149+
#[pymethod]
1150+
fn get_verified_chain(&self, vm: &VirtualMachine) -> Option<PyListRef> {
1151+
let stream = self.stream.read();
1152+
unsafe {
1153+
let chain = sys::SSL_get0_verified_chain(stream.ssl().as_ptr());
1154+
if chain.is_null() {
1155+
return None;
1156+
}
1157+
1158+
let num_certs = sys::OPENSSL_sk_num(chain as *const _);
1159+
let mut certs = Vec::new();
1160+
1161+
for i in 0..num_certs {
1162+
let cert_ptr = sys::OPENSSL_sk_value(chain as *const _, i) as *mut sys::X509;
1163+
if cert_ptr.is_null() {
1164+
continue;
1165+
}
1166+
let cert = X509Ref::from_ptr(cert_ptr);
1167+
if let Ok(der) = cert.to_der() {
1168+
certs.push(vm.ctx.new_bytes(der).into());
1169+
}
1170+
}
1171+
1172+
if certs.is_empty() {
1173+
None
1174+
} else {
1175+
Some(vm.ctx.new_list(certs))
1176+
}
1177+
}
1178+
}
1179+
11491180
#[pymethod]
11501181
fn version(&self) -> Option<&'static str> {
11511182
let v = self.stream.read().ssl().version_str();

0 commit comments

Comments
 (0)