[Mono.Security]: Cleanup Mono.Security.Interface.CertificateValidationHelper.
[mono.git] / mcs / class / System / Mono.Net.Security / NoReflectionHelper.cs
1 //
2 // NoReflectionHelper.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2015 Xamarin, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27 #if SECURITY_DEP
28 #if MONO_SECURITY_ALIAS
29 extern alias MonoSecurity;
30 using MSI = MonoSecurity::Mono.Security.Interface;
31 using MX = MonoSecurity::Mono.Security.X509;
32 #else
33 using MSI = Mono.Security.Interface;
34 using MX = Mono.Security.X509;
35 #endif
36 using System.Security.Cryptography.X509Certificates;
37 #endif
38
39 using System;
40 using System.Net;
41 using System.Net.Security;
42
43 namespace Mono.Net.Security
44 {
45         //
46         // Internal APIs which are used by Mono.Security.dll to avoid using reflection.
47         //
48         internal static class NoReflectionHelper
49         {
50                 internal static object GetInternalValidator (object provider, object settings)
51                 {
52                         #if SECURITY_DEP
53                         return ChainValidationHelper.GetInternalValidator ((MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
54                         #else
55                         throw new NotSupportedException ();
56                         #endif
57                 }
58
59                 internal static object GetDefaultValidator (object settings)
60                 {
61                         #if SECURITY_DEP
62                         return ChainValidationHelper.GetDefaultValidator ((MSI.MonoTlsSettings)settings);
63                         #else
64                         throw new NotSupportedException ();
65                         #endif
66                 }
67
68                 internal static object GetProvider ()
69                 {
70                         #if SECURITY_DEP
71                         return MonoTlsProviderFactory.GetProvider ();
72                         #else
73                         throw new NotSupportedException ();
74                         #endif
75                 }
76
77                 internal static object GetDefaultProvider ()
78                 {
79                         #if SECURITY_DEP
80                         return MonoTlsProviderFactory.GetDefaultProvider ();
81                         #else
82                         throw new NotSupportedException ();
83                         #endif
84                 }
85
86                 internal static bool HasProvider {
87                         get {
88                                 #if SECURITY_DEP
89                                 return MonoTlsProviderFactory.HasProvider;
90                                 #else
91                                 throw new NotSupportedException ();
92                                 #endif
93                         }
94                 }
95
96                 internal static void SetDefaultProvider (string name)
97                 {
98                         #if SECURITY_DEP
99                         MonoTlsProviderFactory.SetDefaultProvider (name);
100                         #else
101                         throw new NotSupportedException ();
102                         #endif
103                 }
104
105                 internal static HttpWebRequest CreateHttpsRequest (Uri requestUri, object provider, object settings)
106                 {
107                         #if SECURITY_DEP
108                         return MonoTlsProviderFactory.CreateHttpsRequest (requestUri, (MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
109                         #else
110                         throw new NotSupportedException ();
111                         #endif
112                 }
113
114                 internal static object CreateHttpListener (object certificate, object provider, object settings)
115                 {
116                         #if SECURITY_DEP
117                         return MonoTlsProviderFactory.CreateHttpListener ((X509Certificate)certificate, (MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
118                         #else
119                         throw new NotSupportedException ();
120                         #endif
121                 }
122
123                 internal static object GetMonoSslStream (SslStream stream)
124                 {
125                         #if SECURITY_DEP
126                         return stream.Impl;
127                         #else
128                         throw new NotSupportedException ();
129                         #endif
130                 }
131
132                 internal static object GetProvider (string name)
133                 {
134                         #if SECURITY_DEP
135                         return MonoTlsProviderFactory.GetProvider (name);
136                         #else
137                         throw new NotSupportedException ();
138                         #endif
139                 }
140         }
141 }