88#endif
99
1010using System . Security . Authentication ;
11+ using System . Security . Cryptography . X509Certificates ;
1112
1213namespace Mono . Unity
1314{
@@ -102,6 +103,30 @@ public static MonoSslPolicyErrors VerifyResultToPolicyErrror (UnityTls.unitytls_
102103 error |= MonoSslPolicyErrors . RemoteCertificateChainErrors ;
103104 return error ;
104105 }
106+
107+ public static X509ChainStatusFlags VerifyResultToChainStatus ( UnityTls . unitytls_x509verify_result verifyResult )
108+ {
109+ // First, check "non-flags"
110+ if ( verifyResult == UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_SUCCESS )
111+ return X509ChainStatusFlags . NoError ;
112+ else if ( verifyResult == UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FATAL_ERROR )
113+ return X509ChainStatusFlags . UntrustedRoot ; // Inaccurate, throw exception instead?
114+
115+ // Yes, we ignore user error flags here. They still affect if a chain is accepted, but they are not status flags of the chain!
116+ X509ChainStatusFlags error = X509ChainStatusFlags . NoError ;
117+ if ( verifyResult . HasFlag ( UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FLAG_EXPIRED ) )
118+ error |= X509ChainStatusFlags . NotTimeValid ;
119+ if ( verifyResult . HasFlag ( UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FLAG_REVOKED ) )
120+ error |= X509ChainStatusFlags . Revoked ;
121+ if ( verifyResult . HasFlag ( UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FLAG_CN_MISMATCH ) )
122+ // Unclear what to return, behaving like Mono's BTLS impl
123+ // https://github.com/mono/mono/blob/1553889bc54f87060158febca7e6b8b9910975f8/mcs/class/System/Mono.Btls/MonoBtlsProvider.cs#L312
124+ error |= X509ChainStatusFlags . UntrustedRoot ;
125+ if ( verifyResult . HasFlag ( UnityTls . unitytls_x509verify_result . UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED ) )
126+ error |= X509ChainStatusFlags . UntrustedRoot ;
127+
128+ return error ;
129+ }
105130 }
106131}
107132#endif
0 commit comments