@@ -69,9 +69,6 @@ internal override bool ValidateCertificate (
6969 errors |= MonoSslPolicyErrors . RemoteCertificateNotAvailable ;
7070 return false ;
7171 }
72-
73- if ( wantsChain )
74- chain = MNS . SystemCertificateValidator . CreateX509Chain ( certificates ) ;
7572 }
7673 else
7774 {
@@ -92,8 +89,7 @@ internal override bool ValidateCertificate (
9289 // convert cert to native or extract from unityTlsChainImpl.
9390 var result = UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_NOT_DONE ;
9491 UnityTls . unitytls_x509list * certificatesNative = null ;
95- UnityTls . unitytls_x509list * finalCertificateChainNative =
96- chain == null ? null : UnityTls . NativeInterface . unitytls_x509list_create ( & errorState ) ;
92+ UnityTls . unitytls_x509list * finalCertificateChainNative = UnityTls . NativeInterface . unitytls_x509list_create ( & errorState ) ;
9793 try
9894 {
9995 // Things the validator provides that we might want to make use of here:
@@ -145,21 +141,20 @@ internal override bool ValidateCertificate (
145141 UnityTls . NativeInterface . unitytls_x509list_free ( certificatesNative ) ;
146142 }
147143
148- if ( finalCertificateChainNative != null ) {
149- chain ? . Dispose ( ) ;
150- chain = new X509Chain ( new X509ChainImplUnityTls (
151- UnityTls . NativeInterface . unitytls_x509list_get_ref ( finalCertificateChainNative , & errorState ) ,
152- reverseOrder : true // the verify callback starts with the root and ends with the leaf. That's the opposite of chain ordering.
153- ) ) ;
154- }
144+ chain ? . Dispose ( ) ;
145+ var chainImpl = new X509ChainImplUnityTls (
146+ UnityTls . NativeInterface . unitytls_x509list_get_ref ( finalCertificateChainNative , & errorState ) ,
147+ reverseOrder : true // the verify callback starts with the root and ends with the leaf. That's the opposite of chain ordering.
148+ ) ;
149+ chain = new X509Chain ( chainImpl ) ;
155150
156151 errors = UnityTlsConversions . VerifyResultToPolicyErrror ( result ) ;
157152 // There should be a status per certificate, but once again we're following closely the BTLS implementation
158153 // https://github.com/mono/mono/blob/1553889bc54f87060158febca7e6b8b9910975f8/mcs/class/System/Mono.Btls/MonoBtlsProvider.cs#L180
159154 // which also provides only a single status for the entire chain.
160155 // It is notoriously tricky to implement in OpenSSL to get a status for all invididual certificates without finishing the handshake in the process.
161156 // This is partially the reason why unitytls_x509verify_X doesn't expose it (TODO!) and likely the reason Mono's BTLS impl ignores this.
162- unityTlsChainImpl ? . AddStatus ( UnityTlsConversions . VerifyResultToChainStatus ( result ) ) ;
157+ chainImpl . AddStatus ( UnityTlsConversions . VerifyResultToChainStatus ( result ) ) ;
163158 return result == UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_SUCCESS &&
164159 errorState . code == UnityTls . unitytls_error_code . UNITYTLS_SUCCESS ;
165160 }
0 commit comments