@@ -2996,7 +2996,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
2996
2996
/*[clinic end generated code: output=2cf0d7a0741b6bd1 input=8d58a805b95fc534]*/
2997
2997
{
2998
2998
PySSLContext * self ;
2999
- long options ;
2999
+ uint64_t options ;
3000
3000
const SSL_METHOD * method = NULL ;
3001
3001
SSL_CTX * ctx = NULL ;
3002
3002
X509_VERIFY_PARAM * params ;
@@ -3594,20 +3594,32 @@ PyDoc_STRVAR(PySSLContext_security_level_doc, "The current security level");
3594
3594
static PyObject *
3595
3595
get_options (PySSLContext * self , void * c )
3596
3596
{
3597
- return PyLong_FromLong (SSL_CTX_get_options (self -> ctx ));
3597
+ uint64_t options = SSL_CTX_get_options (self -> ctx );
3598
+ Py_BUILD_ASSERT (sizeof (unsigned long long ) >= sizeof (options ));
3599
+ return PyLong_FromUnsignedLongLong (options );
3598
3600
}
3599
3601
3600
3602
static int
3601
3603
set_options (PySSLContext * self , PyObject * arg , void * c )
3602
3604
{
3603
- long new_opts , opts , set , clear ;
3604
- long opt_no = (
3605
+ PyObject * new_opts_obj ;
3606
+ unsigned long long new_opts_arg ;
3607
+ uint64_t new_opts , opts , clear , set ;
3608
+ uint64_t opt_no = (
3605
3609
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
3606
3610
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3
3607
3611
);
3608
3612
3609
- if (!PyArg_Parse (arg , "l " , & new_opts ))
3613
+ if (!PyArg_Parse (arg , "O! " , & PyLong_Type , & new_opts_obj )) {
3610
3614
return -1 ;
3615
+ }
3616
+ new_opts_arg = PyLong_AsUnsignedLongLong (new_opts_obj );
3617
+ if (new_opts_arg == (unsigned long long )-1 && PyErr_Occurred ()) {
3618
+ return -1 ;
3619
+ }
3620
+ Py_BUILD_ASSERT (sizeof (new_opts ) >= sizeof (new_opts_arg ));
3621
+ new_opts = (uint64_t )new_opts_arg ;
3622
+
3611
3623
opts = SSL_CTX_get_options (self -> ctx );
3612
3624
clear = opts & ~new_opts ;
3613
3625
set = ~opts & new_opts ;
@@ -3621,8 +3633,9 @@ set_options(PySSLContext *self, PyObject *arg, void *c)
3621
3633
if (clear ) {
3622
3634
SSL_CTX_clear_options (self -> ctx , clear );
3623
3635
}
3624
- if (set )
3636
+ if (set ) {
3625
3637
SSL_CTX_set_options (self -> ctx , set );
3638
+ }
3626
3639
return 0 ;
3627
3640
}
3628
3641
@@ -5731,10 +5744,24 @@ sslmodule_init_socketapi(PyObject *module)
5731
5744
return 0 ;
5732
5745
}
5733
5746
5747
+
5734
5748
static int
5735
- sslmodule_init_constants (PyObject * m )
5749
+ sslmodule_add_option (PyObject * m , const char * name , uint64_t value )
5736
5750
{
5751
+ Py_BUILD_ASSERT (sizeof (unsigned long long ) >= sizeof (value ));
5752
+ PyObject * obj = PyLong_FromUnsignedLongLong (value );
5753
+ if (obj == NULL ) {
5754
+ return -1 ;
5755
+ }
5756
+ int res = PyModule_AddObjectRef (m , name , obj );
5757
+ Py_DECREF (obj );
5758
+ return res ;
5759
+ }
5760
+
5737
5761
5762
+ static int
5763
+ sslmodule_init_constants (PyObject * m )
5764
+ {
5738
5765
PyModule_AddStringConstant (m , "_DEFAULT_CIPHERS" ,
5739
5766
PY_SSL_DEFAULT_CIPHER_STRING );
5740
5767
@@ -5854,46 +5881,47 @@ sslmodule_init_constants(PyObject *m)
5854
5881
PyModule_AddIntConstant (m , "PROTOCOL_TLSv1_2" ,
5855
5882
PY_SSL_VERSION_TLS1_2 );
5856
5883
5884
+ #define ADD_OPTION (NAME , VALUE ) if (sslmodule_add_option(m, NAME, (VALUE)) < 0) return -1
5885
+
5857
5886
/* protocol options */
5858
- PyModule_AddIntConstant (m , "OP_ALL" ,
5859
- SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS );
5860
- PyModule_AddIntConstant (m , "OP_NO_SSLv2" , SSL_OP_NO_SSLv2 );
5861
- PyModule_AddIntConstant (m , "OP_NO_SSLv3" , SSL_OP_NO_SSLv3 );
5862
- PyModule_AddIntConstant (m , "OP_NO_TLSv1" , SSL_OP_NO_TLSv1 );
5863
- PyModule_AddIntConstant (m , "OP_NO_TLSv1_1" , SSL_OP_NO_TLSv1_1 );
5864
- PyModule_AddIntConstant (m , "OP_NO_TLSv1_2" , SSL_OP_NO_TLSv1_2 );
5887
+ ADD_OPTION ("OP_ALL" , SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS );
5888
+ ADD_OPTION ("OP_NO_SSLv2" , SSL_OP_NO_SSLv2 );
5889
+ ADD_OPTION ("OP_NO_SSLv3" , SSL_OP_NO_SSLv3 );
5890
+ ADD_OPTION ("OP_NO_TLSv1" , SSL_OP_NO_TLSv1 );
5891
+ ADD_OPTION ("OP_NO_TLSv1_1" , SSL_OP_NO_TLSv1_1 );
5892
+ ADD_OPTION ("OP_NO_TLSv1_2" , SSL_OP_NO_TLSv1_2 );
5865
5893
#ifdef SSL_OP_NO_TLSv1_3
5866
- PyModule_AddIntConstant ( m , "OP_NO_TLSv1_3" , SSL_OP_NO_TLSv1_3 );
5894
+ ADD_OPTION ( "OP_NO_TLSv1_3" , SSL_OP_NO_TLSv1_3 );
5867
5895
#else
5868
- PyModule_AddIntConstant ( m , "OP_NO_TLSv1_3" , 0 );
5896
+ ADD_OPTION ( "OP_NO_TLSv1_3" , 0 );
5869
5897
#endif
5870
- PyModule_AddIntConstant ( m , "OP_CIPHER_SERVER_PREFERENCE" ,
5898
+ ADD_OPTION ( "OP_CIPHER_SERVER_PREFERENCE" ,
5871
5899
SSL_OP_CIPHER_SERVER_PREFERENCE );
5872
- PyModule_AddIntConstant ( m , "OP_SINGLE_DH_USE" , SSL_OP_SINGLE_DH_USE );
5873
- PyModule_AddIntConstant ( m , "OP_NO_TICKET" , SSL_OP_NO_TICKET );
5874
- PyModule_AddIntConstant ( m , "OP_LEGACY_SERVER_CONNECT" ,
5900
+ ADD_OPTION ( "OP_SINGLE_DH_USE" , SSL_OP_SINGLE_DH_USE );
5901
+ ADD_OPTION ( "OP_NO_TICKET" , SSL_OP_NO_TICKET );
5902
+ ADD_OPTION ( "OP_LEGACY_SERVER_CONNECT" ,
5875
5903
SSL_OP_LEGACY_SERVER_CONNECT );
5876
5904
#ifdef SSL_OP_SINGLE_ECDH_USE
5877
- PyModule_AddIntConstant ( m , "OP_SINGLE_ECDH_USE" , SSL_OP_SINGLE_ECDH_USE );
5905
+ ADD_OPTION ( "OP_SINGLE_ECDH_USE" , SSL_OP_SINGLE_ECDH_USE );
5878
5906
#endif
5879
5907
#ifdef SSL_OP_NO_COMPRESSION
5880
- PyModule_AddIntConstant ( m , "OP_NO_COMPRESSION" ,
5908
+ ADD_OPTION ( "OP_NO_COMPRESSION" ,
5881
5909
SSL_OP_NO_COMPRESSION );
5882
5910
#endif
5883
5911
#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT
5884
- PyModule_AddIntConstant ( m , "OP_ENABLE_MIDDLEBOX_COMPAT" ,
5912
+ ADD_OPTION ( "OP_ENABLE_MIDDLEBOX_COMPAT" ,
5885
5913
SSL_OP_ENABLE_MIDDLEBOX_COMPAT );
5886
5914
#endif
5887
5915
#ifdef SSL_OP_NO_RENEGOTIATION
5888
- PyModule_AddIntConstant ( m , "OP_NO_RENEGOTIATION" ,
5916
+ ADD_OPTION ( "OP_NO_RENEGOTIATION" ,
5889
5917
SSL_OP_NO_RENEGOTIATION );
5890
5918
#endif
5891
5919
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
5892
- PyModule_AddIntConstant ( m , "OP_IGNORE_UNEXPECTED_EOF" ,
5920
+ ADD_OPTION ( "OP_IGNORE_UNEXPECTED_EOF" ,
5893
5921
SSL_OP_IGNORE_UNEXPECTED_EOF );
5894
5922
#endif
5895
5923
#ifdef SSL_OP_ENABLE_KTLS
5896
- PyModule_AddIntConstant ( m , "OP_ENABLE_KTLS" , SSL_OP_ENABLE_KTLS );
5924
+ ADD_OPTION ( "OP_ENABLE_KTLS" , SSL_OP_ENABLE_KTLS );
5897
5925
#endif
5898
5926
5899
5927
#ifdef X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT