Pass SSL certificate chain, not just collection, to Mono.Android.dll
[mono.git] / mcs / class / System / System / AndroidPlatform.cs
1 //
2 // System.AndroidPlatform.cs
3 //
4 // Author:
5 //   Jonathan Pryor (jonp@xamarin.com)
6 //
7 // Copyright (C) 2012 Xamarin Inc (http://xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if MONODROID
30 using System;
31 using System.Net.Security;
32 using System.Security.Cryptography.X509Certificates;
33
34 using MSX = Mono.Security.X509;
35
36 namespace System {
37
38         internal static class AndroidPlatform {
39
40 #if SECURITY_DEP
41                 static readonly Converter<MSX.X509CertificateCollection, bool> trustEvaluateSsl;
42                 static readonly Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool> trustEvaluateSsl2;
43 #endif  // SECURITY_DEP
44
45
46                 static AndroidPlatform ()
47                 {
48 #if SECURITY_DEP
49                         var t = Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", throwOnError:true);
50                         trustEvaluateSsl2 = (Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool>)
51                                 Delegate.CreateDelegate (
52                                                 typeof (Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool>),
53                                                 t,
54                                                 "TrustEvaluateSsl2",
55                                                 ignoreCase:false,
56                                                 throwOnBindFailure:false);
57                         if (trustEvaluateSsl2 == null)
58                                 trustEvaluateSsl = (Converter<MSX.X509CertificateCollection, bool>)
59                                         Delegate.CreateDelegate (typeof (Converter<MSX.X509CertificateCollection, bool>),
60                                                         t,
61                                                         "TrustEvaluateSsl",
62                                                         ignoreCase:false,
63                                                         throwOnBindFailure:true);
64 #endif  // SECURITY_DEP
65                 }
66
67 #if SECURITY_DEP
68                 internal static bool TrustEvaluateSsl (MSX.X509CertificateCollection collection, object sender, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors errors)
69                 {
70                         if (trustEvaluateSsl2 != null)
71                                 return trustEvaluateSsl2 (collection, sender, certificate, chain, errors);
72                         return trustEvaluateSsl (collection);
73                 }
74 #endif  // SECURITY_DEP
75         }
76 }
77 #endif  // MONODROID