@@ -252,7 +252,9 @@ public void load_verify_locations(CodeContext context, object cafile = null, str
252252 using IPythonBuffer buf = cabuf . GetBuffer ( ) ;
253253 var contents = buf . AsReadOnlySpan ( ) ;
254254 while ( contents . Length > 0 ) {
255- #if NET
255+ #if NET10_0_OR_GREATER
256+ var cert = X509CertificateLoader . LoadCertificate ( contents ) ;
257+ #elif NET
256258 var cert = new X509Certificate2 ( contents ) ;
257259#else
258260 var cert = new X509Certificate2 ( contents . ToArray ( ) ) ;
@@ -449,7 +451,12 @@ public void do_handshake() {
449451 if ( _serverSide ) {
450452 var _cert = context . _cert ;
451453 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) {
452- _cert = new X509Certificate2 ( _cert . Export ( X509ContentType . Pkcs12 ) ) ;
454+ byte [ ] certData = _cert . Export ( X509ContentType . Pkcs12 ) ;
455+ #if NET10_0_OR_GREATER
456+ _cert = X509CertificateLoader . LoadCertificate ( certData ) ;
457+ #else
458+ _cert = new X509Certificate2 ( certData ) ;
459+ #endif
453460 }
454461 _sslStream . AuthenticateAsServer ( _cert , _certsMode == PythonSsl . CERT_REQUIRED , enabledSslProtocols , false ) ;
455462 } else {
@@ -527,6 +534,8 @@ private static SslProtocols GetProtocolType(int protocol, int options) {
527534#pragma warning restore CS0618 // Type or member is obsolete
528535#pragma warning restore CA5397 // Do not use deprecated SslProtocols values
529536
537+ #pragma warning disable SYSLIB0058 // Certain SslStream properties are obsolete
538+
530539 public PythonTuple cipher ( ) {
531540 if ( _sslStream != null && _sslStream . IsAuthenticated ) {
532541 return PythonTuple . MakeTuple (
@@ -540,6 +549,8 @@ public PythonTuple cipher() {
540549
541550 public object compression ( ) => null ; // TODO
542551
552+ #pragma warning restore SYSLIB0058 // Certain SslStream properties are obsolete
553+
543554#pragma warning disable CA5397 // Do not use deprecated SslProtocols values
544555#pragma warning disable CS0618 // Type or member is obsolete
545556#pragma warning disable SYSLIB0039 // Type or member is obsolete
@@ -876,7 +887,14 @@ public static PythonDictionary _test_decode_cert(CodeContext context, string pat
876887 private static PythonDictionary CertificateToPython ( CodeContext context , X509Certificate cert ) {
877888 if ( cert is X509Certificate2 cert2 )
878889 return CertificateToPython ( context , cert2 ) ;
879- return CertificateToPython ( context , new X509Certificate2 ( cert . GetRawCertData ( ) ) ) ;
890+
891+ byte [ ] certData = cert . GetRawCertData ( ) ;
892+ #if NET10_0_OR_GREATER
893+ cert2 = X509CertificateLoader . LoadCertificate ( certData ) ;
894+ #else
895+ cert2 = new X509Certificate2 ( certData ) ;
896+ #endif
897+ return CertificateToPython ( context , cert2 ) ;
880898 }
881899
882900 private static PythonDictionary CertificateToPython ( CodeContext context , X509Certificate2 cert ) {
@@ -1030,7 +1048,12 @@ private static X509Certificate2 ReadCertificate(CodeContext context, string file
10301048 var certStr = ReadToEnd ( lines , ref i , "-----END CERTIFICATE-----" ) ;
10311049
10321050 try {
1033- cert = new X509Certificate2 ( Convert . FromBase64String ( certStr . ToString ( ) ) ) ;
1051+ byte [ ] certData = Convert . FromBase64String ( certStr . ToString ( ) ) ;
1052+ #if NET10_0_OR_GREATER
1053+ cert = X509CertificateLoader . LoadCertificate ( certData ) ;
1054+ #else
1055+ cert = new X509Certificate2 ( certData ) ;
1056+ #endif
10341057 } catch ( Exception e ) {
10351058 throw ErrorDecoding ( context , filename , e ) ;
10361059 }
0 commit comments