@@ -3025,7 +3025,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
3025
3025
/*[clinic end generated code: output=2cf0d7a0741b6bd1 input=8d58a805b95fc534]*/
3026
3026
{
3027
3027
PySSLContext * self ;
3028
- long options ;
3028
+ uint64_t options ;
3029
3029
const SSL_METHOD * method = NULL ;
3030
3030
SSL_CTX * ctx = NULL ;
3031
3031
X509_VERIFY_PARAM * params ;
@@ -3618,20 +3618,32 @@ PyDoc_STRVAR(PySSLContext_security_level_doc, "The current security level");
3618
3618
static PyObject *
3619
3619
get_options (PySSLContext * self , void * c )
3620
3620
{
3621
- return PyLong_FromLong (SSL_CTX_get_options (self -> ctx ));
3621
+ uint64_t options = SSL_CTX_get_options (self -> ctx );
3622
+ Py_BUILD_ASSERT (sizeof (unsigned long long ) >= sizeof (options ));
3623
+ return PyLong_FromUnsignedLongLong (options );
3622
3624
}
3623
3625
3624
3626
static int
3625
3627
set_options (PySSLContext * self , PyObject * arg , void * c )
3626
3628
{
3627
- long new_opts , opts , set , clear ;
3628
- long opt_no = (
3629
+ PyObject * new_opts_obj ;
3630
+ unsigned long long new_opts_arg ;
3631
+ uint64_t new_opts , opts , clear , set ;
3632
+ uint64_t opt_no = (
3629
3633
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
3630
3634
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3
3631
3635
);
3632
3636
3633
- if (!PyArg_Parse (arg , "l " , & new_opts ))
3637
+ if (!PyArg_Parse (arg , "O! " , & PyLong_Type , & new_opts_obj )) {
3634
3638
return -1 ;
3639
+ }
3640
+ new_opts_arg = PyLong_AsUnsignedLongLong (new_opts_obj );
3641
+ if (new_opts_arg == (unsigned long long )-1 && PyErr_Occurred ()) {
3642
+ return -1 ;
3643
+ }
3644
+ Py_BUILD_ASSERT (sizeof (new_opts ) >= sizeof (new_opts_arg ));
3645
+ new_opts = (uint64_t )new_opts_arg ;
3646
+
3635
3647
opts = SSL_CTX_get_options (self -> ctx );
3636
3648
clear = opts & ~new_opts ;
3637
3649
set = ~opts & new_opts ;
@@ -3645,8 +3657,9 @@ set_options(PySSLContext *self, PyObject *arg, void *c)
3645
3657
if (clear ) {
3646
3658
SSL_CTX_clear_options (self -> ctx , clear );
3647
3659
}
3648
- if (set )
3660
+ if (set ) {
3649
3661
SSL_CTX_set_options (self -> ctx , set );
3662
+ }
3650
3663
return 0 ;
3651
3664
}
3652
3665
@@ -5754,10 +5767,24 @@ sslmodule_init_socketapi(PyObject *module)
5754
5767
return 0 ;
5755
5768
}
5756
5769
5770
+
5757
5771
static int
5758
- sslmodule_init_constants (PyObject * m )
5772
+ sslmodule_add_option (PyObject * m , const char * name , uint64_t value )
5759
5773
{
5774
+ Py_BUILD_ASSERT (sizeof (unsigned long long ) >= sizeof (value ));
5775
+ PyObject * obj = PyLong_FromUnsignedLongLong (value );
5776
+ if (obj == NULL ) {
5777
+ return -1 ;
5778
+ }
5779
+ int res = PyModule_AddObjectRef (m , name , obj );
5780
+ Py_DECREF (obj );
5781
+ return res ;
5782
+ }
5783
+
5760
5784
5785
+ static int
5786
+ sslmodule_init_constants (PyObject * m )
5787
+ {
5761
5788
PyModule_AddStringConstant (m , "_DEFAULT_CIPHERS" ,
5762
5789
PY_SSL_DEFAULT_CIPHER_STRING );
5763
5790
@@ -5877,46 +5904,47 @@ sslmodule_init_constants(PyObject *m)
5877
5904
PyModule_AddIntConstant (m , "PROTOCOL_TLSv1_2" ,
5878
5905
PY_SSL_VERSION_TLS1_2 );
5879
5906
5907
+ #define ADD_OPTION (NAME , VALUE ) if (sslmodule_add_option(m, NAME, (VALUE)) < 0) return -1
5908
+
5880
5909
/* protocol options */
5881
- PyModule_AddIntConstant (m , "OP_ALL" ,
5882
- SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS );
5883
- PyModule_AddIntConstant (m , "OP_NO_SSLv2" , SSL_OP_NO_SSLv2 );
5884
- PyModule_AddIntConstant (m , "OP_NO_SSLv3" , SSL_OP_NO_SSLv3 );
5885
- PyModule_AddIntConstant (m , "OP_NO_TLSv1" , SSL_OP_NO_TLSv1 );
5886
- PyModule_AddIntConstant (m , "OP_NO_TLSv1_1" , SSL_OP_NO_TLSv1_1 );
5887
- PyModule_AddIntConstant (m , "OP_NO_TLSv1_2" , SSL_OP_NO_TLSv1_2 );
5910
+ ADD_OPTION ("OP_ALL" , SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS );
5911
+ ADD_OPTION ("OP_NO_SSLv2" , SSL_OP_NO_SSLv2 );
5912
+ ADD_OPTION ("OP_NO_SSLv3" , SSL_OP_NO_SSLv3 );
5913
+ ADD_OPTION ("OP_NO_TLSv1" , SSL_OP_NO_TLSv1 );
5914
+ ADD_OPTION ("OP_NO_TLSv1_1" , SSL_OP_NO_TLSv1_1 );
5915
+ ADD_OPTION ("OP_NO_TLSv1_2" , SSL_OP_NO_TLSv1_2 );
5888
5916
#ifdef SSL_OP_NO_TLSv1_3
5889
- PyModule_AddIntConstant ( m , "OP_NO_TLSv1_3" , SSL_OP_NO_TLSv1_3 );
5917
+ ADD_OPTION ( "OP_NO_TLSv1_3" , SSL_OP_NO_TLSv1_3 );
5890
5918
#else
5891
- PyModule_AddIntConstant ( m , "OP_NO_TLSv1_3" , 0 );
5919
+ ADD_OPTION ( "OP_NO_TLSv1_3" , 0 );
5892
5920
#endif
5893
- PyModule_AddIntConstant ( m , "OP_CIPHER_SERVER_PREFERENCE" ,
5921
+ ADD_OPTION ( "OP_CIPHER_SERVER_PREFERENCE" ,
5894
5922
SSL_OP_CIPHER_SERVER_PREFERENCE );
5895
- PyModule_AddIntConstant ( m , "OP_SINGLE_DH_USE" , SSL_OP_SINGLE_DH_USE );
5896
- PyModule_AddIntConstant ( m , "OP_NO_TICKET" , SSL_OP_NO_TICKET );
5897
- PyModule_AddIntConstant ( m , "OP_LEGACY_SERVER_CONNECT" ,
5923
+ ADD_OPTION ( "OP_SINGLE_DH_USE" , SSL_OP_SINGLE_DH_USE );
5924
+ ADD_OPTION ( "OP_NO_TICKET" , SSL_OP_NO_TICKET );
5925
+ ADD_OPTION ( "OP_LEGACY_SERVER_CONNECT" ,
5898
5926
SSL_OP_LEGACY_SERVER_CONNECT );
5899
5927
#ifdef SSL_OP_SINGLE_ECDH_USE
5900
- PyModule_AddIntConstant ( m , "OP_SINGLE_ECDH_USE" , SSL_OP_SINGLE_ECDH_USE );
5928
+ ADD_OPTION ( "OP_SINGLE_ECDH_USE" , SSL_OP_SINGLE_ECDH_USE );
5901
5929
#endif
5902
5930
#ifdef SSL_OP_NO_COMPRESSION
5903
- PyModule_AddIntConstant ( m , "OP_NO_COMPRESSION" ,
5931
+ ADD_OPTION ( "OP_NO_COMPRESSION" ,
5904
5932
SSL_OP_NO_COMPRESSION );
5905
5933
#endif
5906
5934
#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT
5907
- PyModule_AddIntConstant ( m , "OP_ENABLE_MIDDLEBOX_COMPAT" ,
5935
+ ADD_OPTION ( "OP_ENABLE_MIDDLEBOX_COMPAT" ,
5908
5936
SSL_OP_ENABLE_MIDDLEBOX_COMPAT );
5909
5937
#endif
5910
5938
#ifdef SSL_OP_NO_RENEGOTIATION
5911
- PyModule_AddIntConstant ( m , "OP_NO_RENEGOTIATION" ,
5939
+ ADD_OPTION ( "OP_NO_RENEGOTIATION" ,
5912
5940
SSL_OP_NO_RENEGOTIATION );
5913
5941
#endif
5914
5942
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
5915
- PyModule_AddIntConstant ( m , "OP_IGNORE_UNEXPECTED_EOF" ,
5943
+ ADD_OPTION ( "OP_IGNORE_UNEXPECTED_EOF" ,
5916
5944
SSL_OP_IGNORE_UNEXPECTED_EOF );
5917
5945
#endif
5918
5946
#ifdef SSL_OP_ENABLE_KTLS
5919
- PyModule_AddIntConstant ( m , "OP_ENABLE_KTLS" , SSL_OP_ENABLE_KTLS );
5947
+ ADD_OPTION ( "OP_ENABLE_KTLS" , SSL_OP_ENABLE_KTLS );
5920
5948
#endif
5921
5949
5922
5950
#ifdef X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT
0 commit comments