@@ -999,6 +999,25 @@ static PyObject *PySSL_cipher (PySSLSocket *self) {
999999 return NULL ;
10001000}
10011001
1002+ static PyObject * PySSL_compression (PySSLSocket * self ) {
1003+ #ifdef OPENSSL_NO_COMP
1004+ Py_RETURN_NONE ;
1005+ #else
1006+ const COMP_METHOD * comp_method ;
1007+ const char * short_name ;
1008+
1009+ if (self -> ssl == NULL )
1010+ Py_RETURN_NONE ;
1011+ comp_method = SSL_get_current_compression (self -> ssl );
1012+ if (comp_method == NULL || comp_method -> type == NID_undef )
1013+ Py_RETURN_NONE ;
1014+ short_name = OBJ_nid2sn (comp_method -> type );
1015+ if (short_name == NULL )
1016+ Py_RETURN_NONE ;
1017+ return PyUnicode_DecodeFSDefault (short_name );
1018+ #endif
1019+ }
1020+
10021021static void PySSL_dealloc (PySSLSocket * self )
10031022{
10041023 if (self -> peer_cert ) /* Possible not to have one? */
@@ -1452,6 +1471,7 @@ static PyMethodDef PySSLMethods[] = {
14521471 {"peer_certificate" , (PyCFunction )PySSL_peercert , METH_VARARGS ,
14531472 PySSL_peercert_doc },
14541473 {"cipher" , (PyCFunction )PySSL_cipher , METH_NOARGS },
1474+ {"compression" , (PyCFunction )PySSL_compression , METH_NOARGS },
14551475 {"shutdown" , (PyCFunction )PySSL_SSLshutdown , METH_NOARGS ,
14561476 PySSL_SSLshutdown_doc },
14571477#if HAVE_OPENSSL_FINISHED
@@ -2482,6 +2502,10 @@ PyInit__ssl(void)
24822502 PyModule_AddIntConstant (m , "OP_CIPHER_SERVER_PREFERENCE" ,
24832503 SSL_OP_CIPHER_SERVER_PREFERENCE );
24842504 PyModule_AddIntConstant (m , "OP_SINGLE_ECDH_USE" , SSL_OP_SINGLE_ECDH_USE );
2505+ #ifdef SSL_OP_NO_COMPRESSION
2506+ PyModule_AddIntConstant (m , "OP_NO_COMPRESSION" ,
2507+ SSL_OP_NO_COMPRESSION );
2508+ #endif
24852509
24862510#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
24872511 r = Py_True ;
0 commit comments