MCPcopy Index your code
hub / github.com/RustPython/RustPython / getpeercert

Method getpeercert

crates/stdlib/src/openssl.rs:2534–2567  ·  view source on GitHub ↗
(
            &self,
            args: GetCertArgs,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

2532
2533 #[pymethod]
2534 fn getpeercert(
2535 &self,
2536 args: GetCertArgs,
2537 vm: &VirtualMachine,
2538 ) -> PyResult<Option<PyObjectRef>> {
2539 let binary = args.binary_form.unwrap_or(false);
2540 let stream = self.connection.read();
2541 if !stream.ssl().is_init_finished() {
2542 return Err(vm.new_value_error("handshake not done yet"));
2543 }
2544
2545 let peer_cert = stream.ssl().peer_certificate();
2546 let Some(cert) = peer_cert else {
2547 return Ok(None);
2548 };
2549
2550 if binary {
2551 // Return DER-encoded certificate
2552 cert_to_py(vm, &cert, true).map(Some)
2553 } else {
2554 // Check verify_mode
2555 unsafe {
2556 let ssl_ctx = sys::SSL_get_SSL_CTX(stream.ssl().as_ptr());
2557 let verify_mode = sys::SSL_CTX_get_verify_mode(ssl_ctx);
2558 if (verify_mode & sys::SSL_VERIFY_PEER as libc::c_int) == 0 {
2559 // Return empty dict when SSL_VERIFY_PEER is not set
2560 Ok(Some(vm.ctx.new_dict().into()))
2561 } else {
2562 // Return decoded certificate
2563 cert_to_py(vm, &cert, false).map(Some)
2564 }
2565 }
2566 }
2567 }
2568
2569 #[pymethod]
2570 fn get_unverified_chain(&self, vm: &VirtualMachine) -> PyResult<Option<PyListRef>> {

Callers

nothing calls this directly

Calls 8

cert_to_pyFunction · 0.85
sslMethod · 0.80
new_dictMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
readMethod · 0.45
mapMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected