@@ -135,7 +135,15 @@ public _SSLContext(CodeContext context, int protocol) {
135135 }
136136
137137 public void set_ciphers ( CodeContext context , string ciphers ) {
138+ // TODO
139+ }
140+
141+ public void _set_alpn_protocols ( CodeContext context , IBufferProtocol protos ) {
142+ // TODO
143+ }
138144
145+ public void _set_npn_protocols ( CodeContext context , IBufferProtocol protos ) {
146+ // TODO
139147 }
140148
141149 public int options {
@@ -270,23 +278,28 @@ public class _SSLSocket {
270278 private SslStream _sslStream ;
271279 private readonly PythonSocket . socket _socket ;
272280 private readonly X509Certificate2Collection _certCollection ;
273- private readonly int _protocol , _certsMode ;
281+ private readonly int _certsMode ;
274282 private readonly bool _validate , _serverSide ;
275283 private readonly CodeContext _context ;
276284 private readonly RemoteCertificateValidationCallback _callback ;
277285 private Exception _validationFailure ;
278- internal string _serverHostName ;
279286
280287 public _SSLContext context { get ; }
281288
289+ public object owner { get ; set ; } // TODO
290+
291+ public string server_hostname { get ; }
292+
293+ public string version ( ) => ProtocolToPython ( ) ;
294+
282295 internal _SSLSocket ( CodeContext context , _SSLContext sslcontext , PythonSocket . socket sock , bool server_side , string server_hostname ) {
283296 if ( sock == null ) {
284297 throw PythonOps . TypeError ( "expected socket object, got None" ) ;
285298 }
286299
287300 this . context = sslcontext ;
288301 _serverSide = server_side ;
289- _serverHostName = server_hostname ;
302+ this . server_hostname = server_hostname ;
290303
291304 _certsMode = sslcontext . verify_mode ;
292305
@@ -319,7 +332,6 @@ internal _SSLSocket(CodeContext context, _SSLContext sslcontext, PythonSocket.so
319332
320333 EnsureSslStream ( false ) ;
321334
322- _protocol = sslcontext . protocol | sslcontext . options ;
323335 _validate = validate ;
324336 _context = context ;
325337 }
@@ -429,7 +441,7 @@ public void do_handshake() {
429441
430442 EnsureSslStream ( true ) ;
431443
432- var enabledSslProtocols = GetProtocolType ( _protocol ) ;
444+ var enabledSslProtocols = GetProtocolType ( context . protocol , context . options ) ;
433445
434446 try {
435447 if ( _serverSide ) {
@@ -439,7 +451,7 @@ public void do_handshake() {
439451 }
440452 _sslStream . AuthenticateAsServer ( _cert , _certsMode == PythonSsl . CERT_REQUIRED , enabledSslProtocols , false ) ;
441453 } else {
442- _sslStream . AuthenticateAsClient ( _serverHostName ?? _socket . _hostName , context . _cert_store , enabledSslProtocols , false ) ;
454+ _sslStream . AuthenticateAsClient ( server_hostname ?? _socket . _hostName , context . _cert_store , enabledSslProtocols , false ) ;
443455 }
444456 } catch ( AuthenticationException e ) {
445457 ( ( IDisposable ) _socket . _socket ) . Dispose ( ) ;
@@ -467,10 +479,10 @@ TLSv1.1 no no yes no yes no
467479 TLSv1.2 no no yes no no yes
468480 */
469481
470- private static SslProtocols GetProtocolType ( int type ) {
482+ private static SslProtocols GetProtocolType ( int protocol , int options ) {
471483 SslProtocols result = SslProtocols . None ;
472484
473- switch ( type & ~ PythonSsl . OP_NO_ALL ) {
485+ switch ( protocol ) {
474486#pragma warning disable CA5397 // Do not use deprecated SslProtocols values
475487#pragma warning disable CS0618 // Type or member is obsolete
476488 case PythonSsl . PROTOCOL_SSLv2 :
@@ -494,17 +506,17 @@ private static SslProtocols GetProtocolType(int type) {
494506 result = SslProtocols . Tls12 ;
495507 break ;
496508 default :
497- throw new InvalidOperationException ( "bad ssl protocol type: " + type ) ;
509+ throw new InvalidOperationException ( "bad ssl protocol type: " + protocol ) ;
498510 }
499511 // Filter out requested protocol exclusions:
500512#pragma warning disable CA5397 // Do not use deprecated SslProtocols values
501513#pragma warning disable CS0618 // Type or member is obsolete
502- result &= ( type & PythonSsl . OP_NO_SSLv3 ) != 0 ? ~ SslProtocols . Ssl3 : ~ SslProtocols . None ;
503- result &= ( type & PythonSsl . OP_NO_SSLv2 ) != 0 ? ~ SslProtocols . Ssl2 : ~ SslProtocols . None ;
514+ result &= ( options & PythonSsl . OP_NO_SSLv3 ) != 0 ? ~ SslProtocols . Ssl3 : ~ SslProtocols . None ;
515+ result &= ( options & PythonSsl . OP_NO_SSLv2 ) != 0 ? ~ SslProtocols . Ssl2 : ~ SslProtocols . None ;
504516#pragma warning restore CS0618 // Type or member is obsolete
505- result &= ( type & PythonSsl . OP_NO_TLSv1 ) != 0 ? ~ SslProtocols . Tls : ~ SslProtocols . None ;
506- result &= ( type & PythonSsl . OP_NO_TLSv1_1 ) != 0 ? ~ SslProtocols . Tls11 : ~ SslProtocols . None ;
507- result &= ( type & PythonSsl . OP_NO_TLSv1_2 ) != 0 ? ~ SslProtocols . Tls12 : ~ SslProtocols . None ;
517+ result &= ( options & PythonSsl . OP_NO_TLSv1 ) != 0 ? ~ SslProtocols . Tls : ~ SslProtocols . None ;
518+ result &= ( options & PythonSsl . OP_NO_TLSv1_1 ) != 0 ? ~ SslProtocols . Tls11 : ~ SslProtocols . None ;
519+ result &= ( options & PythonSsl . OP_NO_TLSv1_2 ) != 0 ? ~ SslProtocols . Tls12 : ~ SslProtocols . None ;
508520#pragma warning restore CA5397 // Do not use deprecated SslProtocols values
509521 return result ;
510522 }
@@ -1179,6 +1191,7 @@ private static Exception ErrorDecoding(CodeContext context, params object[] args
11791191 private const int PROTOCOL_SSLv2 = 0 ;
11801192 private const int PROTOCOL_SSLv3 = 1 ;
11811193 public const int PROTOCOL_SSLv23 = 2 ;
1194+ public const int PROTOCOL_TLS = 2 ;
11821195 public const int PROTOCOL_TLSv1 = 3 ;
11831196 public const int PROTOCOL_TLSv1_1 = 4 ;
11841197 public const int PROTOCOL_TLSv1_2 = 5 ;
0 commit comments