1 //
2 // BtlsProvider.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2016 Xamarin Inc. (http://www.xamarin.com)
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 using System;
27 using Mono.Security.Interface;
28 using System.Security.Cryptography.X509Certificates;
29 using MNS = Mono.Net.Security;
30 
31 namespace Mono.Btls.Interface
32 {
33 	public static class BtlsProvider
34 	{
IsSupported()35 		public static bool IsSupported ()
36 		{
37 			return MNS.MonoTlsProviderFactory.IsBtlsSupported ();
38 		}
39 
GetProvider()40 		public static MonoTlsProvider GetProvider ()
41 		{
42 			return new MonoBtlsProvider ();
43 		}
44 
CreateNative(byte[] data, BtlsX509Format format)45 		public static BtlsX509 CreateNative (byte[] data, BtlsX509Format format)
46 		{
47 			var x509 = MonoBtlsX509.LoadFromData (data, (MonoBtlsX509Format)format);
48 			return new BtlsX509 (x509);
49 		}
50 
CreateCertificate(byte[] data, BtlsX509Format format, bool disallowFallback = false)51 		public static X509Certificate CreateCertificate (byte[] data, BtlsX509Format format, bool disallowFallback = false)
52 		{
53 			return MonoBtlsProvider.CreateCertificate (data, (MonoBtlsX509Format)format, disallowFallback);
54 		}
55 
CreateCertificate2(byte[] data, BtlsX509Format format, bool disallowFallback = false)56 		public static X509Certificate2 CreateCertificate2 (byte[] data, BtlsX509Format format, bool disallowFallback = false)
57 		{
58 			return MonoBtlsProvider.CreateCertificate2 (data, (MonoBtlsX509Format)format, disallowFallback);
59 		}
60 
CreateCertificate2(byte[] data, string password, bool disallowFallback = false)61 		public static X509Certificate2 CreateCertificate2 (byte[] data, string password, bool disallowFallback = false)
62 		{
63 			return MonoBtlsProvider.CreateCertificate2 (data, password, disallowFallback);
64 		}
65 
CreateNativeChain()66 		public static BtlsX509Chain CreateNativeChain ()
67 		{
68 			return new BtlsX509Chain (new MonoBtlsX509Chain ());
69 		}
70 
CreateNativeStore()71 		public static BtlsX509Store CreateNativeStore ()
72 		{
73 			return new BtlsX509Store (new MonoBtlsX509Store ());
74 		}
75 
CreateNativeStoreCtx()76 		public static BtlsX509StoreCtx CreateNativeStoreCtx ()
77 		{
78 			return new BtlsX509StoreCtx (new MonoBtlsX509StoreCtx ());
79 		}
80 
CreateChain()81 		public static X509Chain CreateChain ()
82 		{
83 			return MonoBtlsProvider.CreateChain ();
84 		}
85 
GetSystemStoreLocation()86 		public static string GetSystemStoreLocation ()
87 		{
88 			return MonoBtlsProvider.GetSystemStoreLocation ();
89 		}
90 
GetVerifyParam_SslClient()91 		public static BtlsX509VerifyParam GetVerifyParam_SslClient ()
92 		{
93 			return new BtlsX509VerifyParam (MonoBtlsX509VerifyParam.GetSslClient ());
94 		}
95 
GetVerifyParam_SslServer()96 		public static BtlsX509VerifyParam GetVerifyParam_SslServer ()
97 		{
98 			return new BtlsX509VerifyParam (MonoBtlsX509VerifyParam.GetSslServer ());
99 		}
100 
GetManagedChain(BtlsX509Chain chain)101 		public static X509Chain GetManagedChain (BtlsX509Chain chain)
102 		{
103 			return MonoBtlsProvider.GetManagedChain (chain.Instance);
104 		}
105 	}
106 }
107 
108