Message callback function called by OpenSSL Called during SSL operations to report protocol messages. debughelpers.c:_PySSL_msg_callback
(
write_p: libc::c_int,
mut version: libc::c_int,
content_type: libc::c_int,
buf: *const libc::c_void,
len: usize,
ssl_ptr: *mut sys::SSL,
_arg:
| 762 | // Called during SSL operations to report protocol messages. |
| 763 | // debughelpers.c:_PySSL_msg_callback |
| 764 | unsafe extern "C" fn _msg_callback( |
| 765 | write_p: libc::c_int, |
| 766 | mut version: libc::c_int, |
| 767 | content_type: libc::c_int, |
| 768 | buf: *const libc::c_void, |
| 769 | len: usize, |
| 770 | ssl_ptr: *mut sys::SSL, |
| 771 | _arg: *mut libc::c_void, |
| 772 | ) { |
| 773 | if ssl_ptr.is_null() { |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | unsafe { |
| 778 | // Get SSL socket from ex_data using the dedicated index |
| 779 | let idx = get_msg_callback_ex_data_index(); |
| 780 | let ssl_socket_ptr = sys::SSL_get_ex_data(ssl_ptr, idx); |
| 781 | if ssl_socket_ptr.is_null() { |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | // ssl_socket_ptr is a pointer to Box<Py<PySslSocket>>, set in _wrap_socket/_wrap_bio |
| 786 | let ssl_socket: &Py<PySslSocket> = &*(ssl_socket_ptr as *const Py<PySslSocket>); |
| 787 | |
| 788 | // Get the callback from the context |
| 789 | let callback_opt = ssl_socket.ctx.read().msg_callback.lock().clone(); |
| 790 | let Some(callback) = callback_opt else { |
| 791 | return; |
| 792 | }; |
| 793 | |
| 794 | // Get VM from thread-local storage (set by HandshakeVmGuard in do_handshake) |
| 795 | let Some(vm_ptr) = HANDSHAKE_VM.with(|cell| cell.get()) else { |
| 796 | // VM not available - this shouldn't happen during handshake |
| 797 | return; |
| 798 | }; |
| 799 | let vm = &*vm_ptr; |
| 800 | |
| 801 | // Get SSL socket owner object |
| 802 | let ssl_socket_obj = ssl_socket |
| 803 | .owner |
| 804 | .read() |
| 805 | .as_ref() |
| 806 | .and_then(|weak| weak.upgrade()) |
| 807 | .unwrap_or_else(|| vm.ctx.none()); |
| 808 | |
| 809 | // Create the message bytes |
| 810 | let buf_slice = std::slice::from_raw_parts(buf as *const u8, len); |
| 811 | let msg_bytes = vm.ctx.new_bytes(buf_slice.to_vec()); |
| 812 | |
| 813 | // Determine direction string |
| 814 | let direction_str = if write_p != 0 { "write" } else { "read" }; |
| 815 | |
| 816 | // Calculate msg_type based on content_type (debughelpers.c behavior) |
| 817 | let msg_type = match content_type { |
| 818 | SSL3_RT_CHANGE_CIPHER_SPEC => SSL3_MT_CHANGE_CIPHER_SPEC, |
| 819 | SSL3_RT_ALERT => { |
| 820 | // byte 1 is alert type |
| 821 | if len >= 2 { buf_slice[1] as i32 } else { -1 } |
nothing calls this directly
no test coverage detected