Merge pull request #3913 from omwok/master
[mono.git] / mcs / class / System / System / AndroidPlatform.cs
index 45adf27af71cab8fbdc631893eac34ae7266b84a..dc4f4aaa54ec0200a97c579834cc1af691bc7012 100644 (file)
@@ -33,17 +33,24 @@ using System.Net.Security;
 using System.Security.Cryptography.X509Certificates;
 #if SECURITY_DEP
 using MSX = Mono.Security.X509;
+#if MONO_FEATURE_BTLS
+using Mono.Btls;
+#endif
 #endif
 
 namespace System {
 
        internal static class AndroidPlatform {
-
+               delegate int GetInterfaceAddressesDelegate (out IntPtr ifap);
+               delegate void FreeInterfaceAddressesDelegate (IntPtr ifap);
+               
 #if SECURITY_DEP
                static readonly Converter<List <byte[]>, bool> trustEvaluateSsl;
+               static readonly Func<long, bool, byte[]> certStoreLookup;
 #endif  // SECURITY_DEP
                static readonly Func<IWebProxy> getDefaultProxy;
-
+               static readonly GetInterfaceAddressesDelegate getInterfaceAddresses;
+               static readonly FreeInterfaceAddressesDelegate freeInterfaceAddresses;
 
                static AndroidPlatform ()
                {
@@ -55,27 +62,82 @@ namespace System {
                                                        "TrustEvaluateSsl",
                                                        ignoreCase:false,
                                                        throwOnBindFailure:true);
+#if MONO_FEATURE_BTLS
+                       certStoreLookup = (Func<long, bool, byte[]>)
+                               Delegate.CreateDelegate (typeof (Func<long, bool, byte[]>),
+                                                       t,
+                                                       "CertStoreLookup",
+                                                       ignoreCase:false,
+                                                       throwOnBindFailure:true);
+#endif  // MONO_FEATURE_BTLS
 #endif  // SECURITY_DEP
                        getDefaultProxy = (Func<IWebProxy>)Delegate.CreateDelegate (
                                typeof (Func<IWebProxy>), t, "GetDefaultProxy",
                                ignoreCase:false,
                                throwOnBindFailure:true);
+
+                       getInterfaceAddresses = (GetInterfaceAddressesDelegate)Delegate.CreateDelegate (
+                               typeof (GetInterfaceAddressesDelegate), t, "GetInterfaceAddresses",
+                               ignoreCase: false,
+                               throwOnBindFailure: false);
+                       
+                       freeInterfaceAddresses = (FreeInterfaceAddressesDelegate)Delegate.CreateDelegate (
+                               typeof (FreeInterfaceAddressesDelegate), t, "FreeInterfaceAddresses",
+                               ignoreCase: false,
+                               throwOnBindFailure: false);
                }
 
 #if SECURITY_DEP
-               internal static bool TrustEvaluateSsl (MSX.X509CertificateCollection collection, object sender, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors errors)
+               internal static bool TrustEvaluateSsl (X509CertificateCollection collection)
                {
                        var certsRawData = new List <byte[]> (collection.Count);
-                       foreach (MSX.X509Certificate cert in collection)
-                               certsRawData.Add (cert.RawData);
+                       foreach (var cert in collection)
+                               certsRawData.Add (cert.GetRawCertData ());
                        return trustEvaluateSsl (certsRawData);
                }
+
+#if MONO_FEATURE_BTLS
+               internal static MonoBtlsX509 CertStoreLookup (MonoBtlsX509Name name)
+               {
+                       var hash = name.GetHash ();
+                       var hashOld = name.GetHashOld ();
+                       var result = certStoreLookup (hash, false);
+                       if (result == null)
+                               result = certStoreLookup (hashOld, false);
+                       if (result == null)
+                               result = certStoreLookup (hash, true);
+                       if (result == null)
+                               result = certStoreLookup (hashOld, true);
+
+                       if (result == null)
+                               return null;
+
+                       return MonoBtlsX509.LoadFromData (result, MonoBtlsX509Format.DER);
+               }
+#endif  // MONO_FEATURE_BTLS
 #endif  // SECURITY_DEP
 
                internal static IWebProxy GetDefaultProxy ()
                {
                        return getDefaultProxy ();
                }
+
+               internal static int GetInterfaceAddresses (out IntPtr ifap)
+               {
+                       ifap = IntPtr.Zero;
+                       if (getInterfaceAddresses == null)
+                               return -1;
+
+                       return getInterfaceAddresses (out ifap);
+               }
+
+               internal static void FreeInterfaceAddresses (IntPtr ifap)
+               {
+                       if (freeInterfaceAddresses == null)
+                               return;
+
+                       freeInterfaceAddresses (ifap);
+               }
        }
 }
 #endif  // MONODROID