From ede2d9ed1613bbf4a0337949474e86829a4cfca0 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Wed, 17 Feb 2021 21:16:19 -0600 Subject: [PATCH] Add SSLSocket.cipher --- vm/src/stdlib/ssl.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vm/src/stdlib/ssl.rs b/vm/src/stdlib/ssl.rs index d37e698e6..cf1f0220c 100644 --- a/vm/src/stdlib/ssl.rs +++ b/vm/src/stdlib/ssl.rs @@ -686,6 +686,15 @@ impl PySslSocket { } } + #[pymethod] + fn cipher(&self) -> Option { + self.stream + .read() + .ssl() + .current_cipher() + .map(cipher_to_tuple) + } + #[pymethod] fn do_handshake(&self, vm: &VirtualMachine) -> PyResult<()> { let mut stream = self.stream.write(); @@ -807,6 +816,12 @@ fn convert_ssl_error( vm.new_exception_msg(cls, msg.to_owned()) } +type CipherTuple = (&'static str, &'static str, i32); + +fn cipher_to_tuple(cipher: &ssl::SslCipherRef) -> CipherTuple { + (cipher.name(), cipher.version(), cipher.bits().secret) +} + fn cert_to_py(vm: &VirtualMachine, cert: &X509Ref, binary: bool) -> PyResult { if binary { cert.to_der()