2 // MonoBtlsX509Revoked.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2016 Xamarin Inc. (http://www.xamarin.com)
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
26 #if SECURITY_DEP && MONO_FEATURE_BTLS
30 using System.Threading;
31 using System.Runtime.CompilerServices;
32 using System.Runtime.InteropServices;
33 using System.Security.Cryptography.X509Certificates;
34 using System.Security.Cryptography;
38 class MonoBtlsX509Revoked : MonoBtlsObject
40 internal class BoringX509RevokedHandle : MonoBtlsHandle
42 public BoringX509RevokedHandle (IntPtr handle)
47 protected override bool ReleaseHandle ()
49 if (handle != IntPtr.Zero)
50 mono_btls_x509_revoked_free (handle);
54 public IntPtr StealHandle ()
56 var retval = Interlocked.Exchange (ref handle, IntPtr.Zero);
61 new internal BoringX509RevokedHandle Handle {
62 get { return (BoringX509RevokedHandle)base.Handle; }
65 internal MonoBtlsX509Revoked (BoringX509RevokedHandle handle)
70 [DllImport (BTLS_DYLIB)]
71 extern static int mono_btls_x509_revoked_get_serial_number (IntPtr handle, IntPtr data, int size);
73 [DllImport (BTLS_DYLIB)]
74 extern static long mono_btls_x509_revoked_get_revocation_date (IntPtr handle);
76 [DllImport (BTLS_DYLIB)]
77 extern static int mono_btls_x509_revoked_get_reason (IntPtr handle);
79 [DllImport (BTLS_DYLIB)]
80 extern static int mono_btls_x509_revoked_get_sequence (IntPtr handle);
82 [DllImport (BTLS_DYLIB)]
83 extern static void mono_btls_x509_revoked_free (IntPtr handle);
85 public byte[] GetSerialNumber ()
88 IntPtr data = Marshal.AllocHGlobal (size);
90 var ret = mono_btls_x509_revoked_get_serial_number (
91 Handle.DangerousGetHandle (), data, size);
93 var buffer = new byte[ret];
94 Marshal.Copy (data, buffer, 0, ret);
97 if (data != IntPtr.Zero)
98 Marshal.FreeHGlobal (data);
102 public DateTime GetRevocationDate ()
104 var ticks = mono_btls_x509_revoked_get_revocation_date (
105 Handle.DangerousGetHandle ());
106 return new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds (ticks);
109 public int GetReason ()
111 return mono_btls_x509_revoked_get_reason (Handle.DangerousGetHandle ());
114 public int GetSequence ()
116 return mono_btls_x509_revoked_get_sequence (Handle.DangerousGetHandle ());