You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.142
Former-commit-id: 7467d4b717762eeaf652d77f1486dd11ffb1ff1f
This commit is contained in:
parent
e52655b4dc
commit
0abdbe5a7d
@@ -10,7 +10,7 @@ LIBRARY = System.Security.dll
|
||||
API_BIN_REFS := System.Numerics System.Core
|
||||
LIB_REFS = $(MONO_SECURITY) System System.Xml
|
||||
KEYFILE = ../msfinal.pub
|
||||
LIB_MCS_FLAGS = -nowarn:414,618 -d:SECURITY_DEP
|
||||
LIB_MCS_FLAGS = -unsafe -nowarn:414,618 -d:SECURITY_DEP
|
||||
|
||||
LOCAL_MCS_FLAGS =
|
||||
|
||||
@@ -26,8 +26,4 @@ EXTRA_DISTFILES = \
|
||||
Test/System.Security.Cryptography.Pkcs/detached.data \
|
||||
Test/System.Security.Cryptography.Pkcs/detached.p7
|
||||
|
||||
RESX_RESOURCE_STRING = \
|
||||
../../../external/corefx/src/System.Security.Cryptography.Xml/src/Resources/Strings.resx \
|
||||
../../../external/corefx/src/System.Security.Cryptography.Pkcs/src/Resources/Strings.resx
|
||||
|
||||
include ../../build/library.make
|
||||
|
@@ -1,225 +0,0 @@
|
||||
//
|
||||
// NativeDapiProtection.cs -
|
||||
// Protect (encrypt) data without (user involved) key management
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace Mono.Security.Cryptography {
|
||||
|
||||
// DAPI is only available in Windows 2000 and later operating systems
|
||||
// see ManagedProtection for other platforms
|
||||
|
||||
// notes:
|
||||
// * no need to assert KeyContainerPermission here as unmanaged code can
|
||||
// do what it wants;
|
||||
// * which is why we also need the [SuppressUnmanagedCodeSecurity]
|
||||
// attribute on each native function (so we don't require UnmanagedCode)
|
||||
|
||||
internal class NativeDapiProtection {
|
||||
|
||||
private const uint CRYPTPROTECT_UI_FORBIDDEN = 0x1;
|
||||
private const uint CRYPTPROTECT_LOCAL_MACHINE = 0x4;
|
||||
|
||||
[StructLayout (LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
private struct DATA_BLOB {
|
||||
|
||||
private int cbData;
|
||||
private IntPtr pbData;
|
||||
|
||||
public void Alloc (int size)
|
||||
{
|
||||
if (size > 0) {
|
||||
pbData = Marshal.AllocHGlobal (size);
|
||||
cbData = size;
|
||||
}
|
||||
}
|
||||
|
||||
public void Alloc (byte[] managedMemory)
|
||||
{
|
||||
if (managedMemory != null) {
|
||||
int size = managedMemory.Length;
|
||||
pbData = Marshal.AllocHGlobal (size);
|
||||
cbData = size;
|
||||
Marshal.Copy (managedMemory, 0, pbData, cbData);
|
||||
}
|
||||
}
|
||||
|
||||
public void Free ()
|
||||
{
|
||||
if (pbData != IntPtr.Zero) {
|
||||
// clear copied memory!
|
||||
ZeroMemory (pbData, cbData);
|
||||
Marshal.FreeHGlobal (pbData);
|
||||
pbData = IntPtr.Zero;
|
||||
cbData = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ToBytes ()
|
||||
{
|
||||
if (cbData <= 0)
|
||||
return new byte [0];
|
||||
|
||||
byte[] managedMemory = new byte[cbData];
|
||||
Marshal.Copy (pbData, managedMemory, 0, cbData);
|
||||
return managedMemory;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout (LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
private struct CRYPTPROTECT_PROMPTSTRUCT {
|
||||
|
||||
private int cbSize;
|
||||
private uint dwPromptFlags;
|
||||
private IntPtr hwndApp;
|
||||
private string szPrompt;
|
||||
|
||||
public CRYPTPROTECT_PROMPTSTRUCT (uint flags)
|
||||
{
|
||||
cbSize = Marshal.SizeOf (typeof (CRYPTPROTECT_PROMPTSTRUCT));
|
||||
dwPromptFlags = flags;
|
||||
hwndApp = IntPtr.Zero;
|
||||
szPrompt = null;
|
||||
}
|
||||
}
|
||||
|
||||
// http://msdn.microsoft.com/library/en-us/seccrypto/security/cryptprotectdata.asp
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport ("crypt32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
|
||||
private static extern bool CryptProtectData (ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy,
|
||||
IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, uint dwFlags, ref DATA_BLOB pDataOut);
|
||||
|
||||
// http://msdn.microsoft.com/library/en-us/seccrypto/security/cryptunprotectdata.asp
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport ("crypt32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
|
||||
private static extern bool CryptUnprotectData (ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy,
|
||||
IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, uint dwFlags, ref DATA_BLOB pDataOut);
|
||||
|
||||
// http://msdn.microsoft.com/library/en-us/memory/base/zeromemory.asp
|
||||
// note: SecureZeroMemory is an inline function (and can't be used here)
|
||||
// anyway I don't think the CLR will optimize this call away (like a C/C++ compiler could do)
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport ("kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
|
||||
private static extern void ZeroMemory (IntPtr dest, int size);
|
||||
|
||||
|
||||
// managed helpers
|
||||
|
||||
public static byte[] Protect (byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
byte[] encdata = null;
|
||||
int hr = 0;
|
||||
|
||||
DATA_BLOB data = new DATA_BLOB ();
|
||||
DATA_BLOB entropy = new DATA_BLOB ();
|
||||
DATA_BLOB cipher = new DATA_BLOB ();
|
||||
try {
|
||||
CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT (0);
|
||||
data.Alloc (userData);
|
||||
entropy.Alloc (optionalEntropy);
|
||||
|
||||
// note: the scope/flags has already been check by the public caller
|
||||
uint flags = CRYPTPROTECT_UI_FORBIDDEN;
|
||||
if (scope == DataProtectionScope.LocalMachine)
|
||||
flags |= CRYPTPROTECT_LOCAL_MACHINE;
|
||||
|
||||
// note: on Windows 2000 the string parameter *cannot* be null
|
||||
if (CryptProtectData (ref data, String.Empty, ref entropy, IntPtr.Zero,
|
||||
ref prompt, flags, ref cipher)) {
|
||||
// copy encrypted data back to managed codde
|
||||
encdata = cipher.ToBytes ();
|
||||
} else {
|
||||
hr = Marshal.GetLastWin32Error ();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
string msg = Locale.GetText ("Error protecting data.");
|
||||
throw new CryptographicException (msg, ex);
|
||||
}
|
||||
finally {
|
||||
cipher.Free ();
|
||||
data.Free ();
|
||||
entropy.Free ();
|
||||
}
|
||||
|
||||
if ((encdata == null) || (hr != 0)) {
|
||||
throw new CryptographicException (hr);
|
||||
}
|
||||
return encdata;
|
||||
}
|
||||
|
||||
public static byte[] Unprotect (byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
byte[] decdata = null;
|
||||
int hr = 0;
|
||||
|
||||
DATA_BLOB cipher = new DATA_BLOB ();
|
||||
DATA_BLOB entropy = new DATA_BLOB ();
|
||||
DATA_BLOB data = new DATA_BLOB ();
|
||||
try {
|
||||
CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT (0);
|
||||
cipher.Alloc (encryptedData);
|
||||
entropy.Alloc (optionalEntropy);
|
||||
|
||||
// note: the scope/flags has already been check by the public caller
|
||||
uint flags = CRYPTPROTECT_UI_FORBIDDEN;
|
||||
if (scope == DataProtectionScope.LocalMachine)
|
||||
flags |= CRYPTPROTECT_LOCAL_MACHINE;
|
||||
|
||||
if (CryptUnprotectData (ref cipher, null, ref entropy, IntPtr.Zero,
|
||||
ref prompt, flags, ref data)) {
|
||||
// copy decrypted data back to managed codde
|
||||
decdata = data.ToBytes ();
|
||||
} else {
|
||||
hr = Marshal.GetLastWin32Error ();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
string msg = Locale.GetText ("Error protecting data.");
|
||||
throw new CryptographicException (msg, ex);
|
||||
}
|
||||
finally {
|
||||
cipher.Free ();
|
||||
data.Free ();
|
||||
entropy.Free ();
|
||||
}
|
||||
|
||||
if ((decdata == null) || (hr != 0)) {
|
||||
throw new CryptographicException (hr);
|
||||
}
|
||||
return decdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,80 +0,0 @@
|
||||
//
|
||||
// AlgorithmIdentifier.cs - System.Security.Cryptography.Pkcs.AlgorithmIdentifier
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class AlgorithmIdentifier {
|
||||
|
||||
private Oid _oid;
|
||||
private int _length;
|
||||
private byte[] _params;
|
||||
|
||||
// constructors
|
||||
|
||||
public AlgorithmIdentifier ()
|
||||
{
|
||||
_oid = new Oid ("1.2.840.113549.3.7", "3des");
|
||||
_params = new byte [0];
|
||||
}
|
||||
|
||||
public AlgorithmIdentifier (Oid oid)
|
||||
{
|
||||
_oid = oid;
|
||||
_params = new byte [0];
|
||||
}
|
||||
|
||||
public AlgorithmIdentifier (Oid oid, int keyLength)
|
||||
{
|
||||
_oid = oid;
|
||||
_length = keyLength;
|
||||
_params = new byte [0];
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public int KeyLength {
|
||||
get { return _length; }
|
||||
set { _length = value; }
|
||||
}
|
||||
|
||||
public Oid Oid {
|
||||
get { return _oid; }
|
||||
set { _oid = value; }
|
||||
}
|
||||
|
||||
public byte[] Parameters {
|
||||
get { return _params; }
|
||||
set { _params = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,74 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.CmsRecipient class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class CmsRecipient {
|
||||
|
||||
private SubjectIdentifierType _recipient;
|
||||
private X509Certificate2 _certificate;
|
||||
|
||||
// constructor
|
||||
|
||||
public CmsRecipient (X509Certificate2 certificate)
|
||||
{
|
||||
if (certificate == null)
|
||||
throw new ArgumentNullException ("certificate");
|
||||
_recipient = SubjectIdentifierType.IssuerAndSerialNumber;
|
||||
_certificate = certificate;
|
||||
}
|
||||
|
||||
public CmsRecipient (SubjectIdentifierType recipientIdentifierType, X509Certificate2 certificate)
|
||||
{
|
||||
if (certificate == null)
|
||||
throw new ArgumentNullException ("certificate");
|
||||
|
||||
if (recipientIdentifierType == SubjectIdentifierType.Unknown)
|
||||
_recipient = SubjectIdentifierType.IssuerAndSerialNumber;
|
||||
else
|
||||
_recipient = recipientIdentifierType;
|
||||
_certificate = certificate;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public X509Certificate2 Certificate {
|
||||
get { return _certificate; }
|
||||
}
|
||||
|
||||
public SubjectIdentifierType RecipientIdentifierType {
|
||||
get { return _recipient; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,114 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.CmsRecipientCollection class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005, 2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class CmsRecipientCollection : ICollection, IEnumerable {
|
||||
|
||||
private ArrayList _list;
|
||||
|
||||
// constructors
|
||||
|
||||
public CmsRecipientCollection ()
|
||||
{
|
||||
_list = new ArrayList ();
|
||||
}
|
||||
|
||||
public CmsRecipientCollection (CmsRecipient recipient)
|
||||
{
|
||||
_list.Add (recipient);
|
||||
}
|
||||
|
||||
public CmsRecipientCollection (SubjectIdentifierType recipientIdentifierType, X509Certificate2Collection certificates)
|
||||
{
|
||||
// no null check, MS throws a NullReferenceException here
|
||||
foreach (X509Certificate2 x509 in certificates) {
|
||||
CmsRecipient p7r = new CmsRecipient (recipientIdentifierType, x509);
|
||||
_list.Add (p7r);
|
||||
}
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public int Count {
|
||||
get { return _list.Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized {
|
||||
get { return _list.IsSynchronized; }
|
||||
}
|
||||
|
||||
public CmsRecipient this [int index] {
|
||||
get { return (CmsRecipient) _list [index]; }
|
||||
}
|
||||
|
||||
public object SyncRoot {
|
||||
get { return _list.SyncRoot; }
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
public int Add (CmsRecipient recipient)
|
||||
{
|
||||
return _list.Add (recipient);
|
||||
}
|
||||
|
||||
public void CopyTo (Array array, int index)
|
||||
{
|
||||
_list.CopyTo (array, index);
|
||||
}
|
||||
|
||||
public void CopyTo (CmsRecipient[] array, int index)
|
||||
{
|
||||
_list.CopyTo (array, index);
|
||||
}
|
||||
|
||||
public CmsRecipientEnumerator GetEnumerator ()
|
||||
{
|
||||
return new CmsRecipientEnumerator (_list);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return new CmsRecipientEnumerator (_list);
|
||||
}
|
||||
|
||||
public void Remove (CmsRecipient recipient)
|
||||
{
|
||||
_list.Remove (recipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.CmsRecipientEnumerator
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class CmsRecipientEnumerator : IEnumerator {
|
||||
|
||||
private IEnumerator enumerator;
|
||||
|
||||
// constructors
|
||||
|
||||
internal CmsRecipientEnumerator (IEnumerable enumerable)
|
||||
{
|
||||
enumerator = enumerable.GetEnumerator ();
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public CmsRecipient Current {
|
||||
get { return (CmsRecipient) enumerator.Current; }
|
||||
}
|
||||
|
||||
object IEnumerator.Current {
|
||||
get { return enumerator.Current; }
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
public bool MoveNext ()
|
||||
{
|
||||
return enumerator.MoveNext ();
|
||||
}
|
||||
|
||||
public void Reset ()
|
||||
{
|
||||
enumerator.Reset ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.CmsSigner class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class CmsSigner {
|
||||
|
||||
private SubjectIdentifierType _signer;
|
||||
private X509Certificate2 _certificate;
|
||||
private X509Certificate2Collection _coll;
|
||||
private Oid _digest;
|
||||
private X509IncludeOption _options;
|
||||
private CryptographicAttributeObjectCollection _signed;
|
||||
private CryptographicAttributeObjectCollection _unsigned;
|
||||
|
||||
// constructors
|
||||
|
||||
public CmsSigner ()
|
||||
{
|
||||
_signer = SubjectIdentifierType.IssuerAndSerialNumber;
|
||||
_digest = new Oid ("1.3.14.3.2.26");
|
||||
_options = X509IncludeOption.ExcludeRoot;
|
||||
_signed = new CryptographicAttributeObjectCollection ();
|
||||
_unsigned = new CryptographicAttributeObjectCollection ();
|
||||
_coll = new X509Certificate2Collection ();
|
||||
}
|
||||
|
||||
public CmsSigner (SubjectIdentifierType signerIdentifierType) : this ()
|
||||
{
|
||||
if (signerIdentifierType == SubjectIdentifierType.Unknown)
|
||||
_signer = SubjectIdentifierType.IssuerAndSerialNumber;
|
||||
else
|
||||
_signer = signerIdentifierType;
|
||||
}
|
||||
|
||||
public CmsSigner (SubjectIdentifierType signerIdentifierType, X509Certificate2 certificate)
|
||||
: this (signerIdentifierType)
|
||||
{
|
||||
_certificate = certificate;
|
||||
}
|
||||
|
||||
public CmsSigner (X509Certificate2 certificate) : this ()
|
||||
{
|
||||
_certificate = certificate;
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public CmsSigner (CspParameters parameters) : this ()
|
||||
{
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public CryptographicAttributeObjectCollection SignedAttributes {
|
||||
get { return _signed; }
|
||||
}
|
||||
|
||||
public X509Certificate2 Certificate {
|
||||
get { return _certificate; }
|
||||
set { _certificate = value; }
|
||||
}
|
||||
|
||||
public X509Certificate2Collection Certificates {
|
||||
get { return _coll; }
|
||||
}
|
||||
|
||||
public Oid DigestAlgorithm {
|
||||
get { return _digest; }
|
||||
set { _digest = value; }
|
||||
}
|
||||
|
||||
public X509IncludeOption IncludeOption {
|
||||
get { return _options; }
|
||||
set { _options = value; }
|
||||
}
|
||||
|
||||
public SubjectIdentifierType SignerIdentifierType {
|
||||
get { return _signer; }
|
||||
set {
|
||||
if (value == SubjectIdentifierType.Unknown)
|
||||
throw new ArgumentException ("value");
|
||||
|
||||
_signer = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CryptographicAttributeObjectCollection UnsignedAttributes {
|
||||
get { return _unsigned; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,112 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.ContentInfo
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
/*
|
||||
* ContentInfo ::= SEQUENCE {
|
||||
* contentType ContentType,
|
||||
* content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
|
||||
* }
|
||||
* ContentType ::= OBJECT IDENTIFIER
|
||||
*/
|
||||
|
||||
public sealed class ContentInfo {
|
||||
|
||||
private Oid _oid;
|
||||
private byte[] _content;
|
||||
|
||||
// constructors
|
||||
|
||||
public ContentInfo (byte[] content)
|
||||
: this (new Oid ("1.2.840.113549.1.7.1"), content)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentInfo (Oid contentType, byte[] content)
|
||||
{
|
||||
if (contentType == null)
|
||||
throw new ArgumentNullException ("contentType");
|
||||
if (content == null)
|
||||
throw new ArgumentNullException ("content");
|
||||
|
||||
_oid = contentType;
|
||||
_content = content;
|
||||
}
|
||||
|
||||
~ContentInfo ()
|
||||
{
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public byte[] Content {
|
||||
get { return (byte[]) _content.Clone (); }
|
||||
}
|
||||
|
||||
public Oid ContentType {
|
||||
get { return _oid; }
|
||||
}
|
||||
|
||||
// static methods
|
||||
|
||||
[MonoTODO ("MS is stricter than us about the content structure")]
|
||||
public static Oid GetContentType (byte[] encodedMessage)
|
||||
{
|
||||
if (encodedMessage == null)
|
||||
throw new ArgumentNullException ("algorithm");
|
||||
|
||||
try {
|
||||
PKCS7.ContentInfo ci = new PKCS7.ContentInfo (encodedMessage);
|
||||
switch (ci.ContentType) {
|
||||
case PKCS7.Oid.data:
|
||||
case PKCS7.Oid.signedData: // see SignedCms class
|
||||
case PKCS7.Oid.envelopedData: // see EnvelopedCms class
|
||||
case PKCS7.Oid.digestedData:
|
||||
case PKCS7.Oid.encryptedData:
|
||||
return new Oid (ci.ContentType);
|
||||
default:
|
||||
// Note: the constructor will accept any "valid" OID (but that
|
||||
// doesn't mean it's a valid ContentType structure - ASN.1 wise).
|
||||
string msg = Locale.GetText ("Bad ASN1 - invalid OID '{0}'");
|
||||
throw new CryptographicException (String.Format (msg, ci.ContentType));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CryptographicException (Locale.GetText ("Bad ASN1 - invalid structure"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -27,221 +27,25 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Cryptography.Xml;
|
||||
using System.Text;
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
// References
|
||||
// a. PKCS #7: Cryptographic Message Syntax, Version 1.5, Section 10
|
||||
// http://www.faqs.org/rfcs/rfc2315.html
|
||||
|
||||
public sealed class EnvelopedCms {
|
||||
|
||||
private ContentInfo _content;
|
||||
private AlgorithmIdentifier _identifier;
|
||||
private X509Certificate2Collection _certs;
|
||||
private RecipientInfoCollection _recipients;
|
||||
private CryptographicAttributeObjectCollection _uattribs;
|
||||
private SubjectIdentifierType _idType;
|
||||
private int _version;
|
||||
|
||||
// constructors
|
||||
|
||||
public EnvelopedCms ()
|
||||
{
|
||||
_certs = new X509Certificate2Collection ();
|
||||
_recipients = new RecipientInfoCollection ();
|
||||
_uattribs = new CryptographicAttributeObjectCollection ();
|
||||
}
|
||||
|
||||
public EnvelopedCms (ContentInfo contentInfo) : this ()
|
||||
{
|
||||
if (contentInfo == null)
|
||||
throw new ArgumentNullException ("contentInfo");
|
||||
|
||||
_content = contentInfo;
|
||||
}
|
||||
|
||||
public EnvelopedCms (ContentInfo contentInfo, AlgorithmIdentifier encryptionAlgorithm)
|
||||
: this (contentInfo)
|
||||
{
|
||||
if (encryptionAlgorithm == null)
|
||||
throw new ArgumentNullException ("encryptionAlgorithm");
|
||||
|
||||
_identifier = encryptionAlgorithm;
|
||||
}
|
||||
|
||||
public sealed partial class EnvelopedCms {
|
||||
public EnvelopedCms (SubjectIdentifierType recipientIdentifierType, ContentInfo contentInfo)
|
||||
: this (contentInfo)
|
||||
{
|
||||
_idType = recipientIdentifierType;
|
||||
if (_idType == SubjectIdentifierType.SubjectKeyIdentifier)
|
||||
_version = 2;
|
||||
if (recipientIdentifierType == SubjectIdentifierType.SubjectKeyIdentifier)
|
||||
Version = 2;
|
||||
}
|
||||
|
||||
public EnvelopedCms (SubjectIdentifierType recipientIdentifierType, ContentInfo contentInfo, AlgorithmIdentifier encryptionAlgorithm)
|
||||
: this (contentInfo, encryptionAlgorithm)
|
||||
{
|
||||
_idType = recipientIdentifierType;
|
||||
if (_idType == SubjectIdentifierType.SubjectKeyIdentifier)
|
||||
_version = 2;
|
||||
if (recipientIdentifierType == SubjectIdentifierType.SubjectKeyIdentifier)
|
||||
Version = 2;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public X509Certificate2Collection Certificates {
|
||||
get { return _certs; }
|
||||
}
|
||||
|
||||
public AlgorithmIdentifier ContentEncryptionAlgorithm {
|
||||
get {
|
||||
if (_identifier == null)
|
||||
_identifier = new AlgorithmIdentifier ();
|
||||
return _identifier;
|
||||
}
|
||||
}
|
||||
|
||||
public ContentInfo ContentInfo {
|
||||
get {
|
||||
if (_content == null) {
|
||||
Oid oid = new Oid (PKCS7.Oid.data);
|
||||
_content = new ContentInfo (oid, new byte [0]);
|
||||
}
|
||||
return _content;
|
||||
}
|
||||
}
|
||||
|
||||
public RecipientInfoCollection RecipientInfos {
|
||||
get { return _recipients; }
|
||||
}
|
||||
|
||||
public CryptographicAttributeObjectCollection UnprotectedAttributes {
|
||||
get { return _uattribs; }
|
||||
}
|
||||
|
||||
public int Version {
|
||||
get { return _version; }
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
private X509IssuerSerial GetIssuerSerial (string issuer, byte[] serial)
|
||||
{
|
||||
X509IssuerSerial xis = new X509IssuerSerial ();
|
||||
xis.IssuerName = issuer;
|
||||
StringBuilder sb = new StringBuilder ();
|
||||
foreach (byte b in serial)
|
||||
sb.Append (b.ToString ("X2"));
|
||||
xis.SerialNumber = sb.ToString ();
|
||||
return xis;
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Decode (byte[] encodedMessage)
|
||||
{
|
||||
if (encodedMessage == null)
|
||||
throw new ArgumentNullException ("encodedMessage");
|
||||
|
||||
PKCS7.ContentInfo ci = new PKCS7.ContentInfo (encodedMessage);
|
||||
if (ci.ContentType != PKCS7.Oid.envelopedData)
|
||||
throw new Exception ("");
|
||||
|
||||
PKCS7.EnvelopedData ed = new PKCS7.EnvelopedData (ci.Content);
|
||||
|
||||
Oid oid = new Oid (ed.ContentInfo.ContentType);
|
||||
_content = new ContentInfo (oid, new byte [0]); //ed.ContentInfo.Content.Value);
|
||||
|
||||
foreach (PKCS7.RecipientInfo ri in ed.RecipientInfos) {
|
||||
Oid o = new Oid (ri.Oid);
|
||||
AlgorithmIdentifier ai = new AlgorithmIdentifier (o);
|
||||
SubjectIdentifier si = null;
|
||||
if (ri.SubjectKeyIdentifier != null) {
|
||||
si = new SubjectIdentifier (SubjectIdentifierType.SubjectKeyIdentifier, ri.SubjectKeyIdentifier);
|
||||
}
|
||||
else if ((ri.Issuer != null) && (ri.Serial != null)) {
|
||||
X509IssuerSerial xis = GetIssuerSerial (ri.Issuer, ri.Serial);
|
||||
si = new SubjectIdentifier (SubjectIdentifierType.IssuerAndSerialNumber, (object)xis);
|
||||
}
|
||||
|
||||
KeyTransRecipientInfo _keyTrans = new KeyTransRecipientInfo (ri.Key, ai, si, ri.Version);
|
||||
_recipients.Add (_keyTrans);
|
||||
}
|
||||
|
||||
// TODO - Certificates
|
||||
// TODO - UnprotectedAttributes
|
||||
|
||||
_version = ed.Version;
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Decrypt ()
|
||||
{
|
||||
throw new InvalidOperationException ("not encrypted");
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Decrypt (RecipientInfo recipientInfo)
|
||||
{
|
||||
if (recipientInfo == null)
|
||||
throw new ArgumentNullException ("recipientInfo");
|
||||
Decrypt ();
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Decrypt (RecipientInfo recipientInfo, X509Certificate2Collection extraStore)
|
||||
{
|
||||
if (recipientInfo == null)
|
||||
throw new ArgumentNullException ("recipientInfo");
|
||||
if (extraStore == null)
|
||||
throw new ArgumentNullException ("extraStore");
|
||||
Decrypt ();
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Decrypt (X509Certificate2Collection extraStore)
|
||||
{
|
||||
if (extraStore == null)
|
||||
throw new ArgumentNullException ("extraStore");
|
||||
Decrypt ();
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public byte[] Encode ()
|
||||
{
|
||||
throw new InvalidOperationException ("not encrypted");
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Encrypt ()
|
||||
{
|
||||
if ((_content == null) || (_content.Content == null) || (_content.Content.Length == 0))
|
||||
throw new CryptographicException ("no content to encrypt");
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Encrypt (CmsRecipient recipient)
|
||||
{
|
||||
if (recipient == null)
|
||||
throw new ArgumentNullException ("recipient");
|
||||
// TODO
|
||||
Encrypt ();
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public void Encrypt (CmsRecipientCollection recipients)
|
||||
{
|
||||
if (recipients == null)
|
||||
throw new ArgumentNullException ("recipients");
|
||||
// ? foreach on Encrypt CmsRecipient ?
|
||||
Encrypt (new CmsRecipientCollection ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,73 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.KeyAgreeRecipientInfo class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
[MonoTODO]
|
||||
public sealed class KeyAgreeRecipientInfo : RecipientInfo {
|
||||
|
||||
// only accessible from EnvelopedCms.RecipientInfos
|
||||
internal KeyAgreeRecipientInfo ()
|
||||
: base (RecipientInfoType.KeyAgreement)
|
||||
{
|
||||
}
|
||||
|
||||
public DateTime Date {
|
||||
get { return DateTime.MinValue; }
|
||||
}
|
||||
|
||||
public override byte[] EncryptedKey {
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public override AlgorithmIdentifier KeyEncryptionAlgorithm {
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public SubjectIdentifierOrKey OriginatorIdentifierOrKey {
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public CryptographicAttributeObject OtherKeyAttribute {
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public override SubjectIdentifier RecipientIdentifier {
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public override int Version {
|
||||
get { return 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// KeyTransRecipientInfo.cs - System.Security.Cryptography.Pkcs.KeyTransRecipientInfo
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class KeyTransRecipientInfo : RecipientInfo {
|
||||
|
||||
private byte[] _encryptedKey;
|
||||
private AlgorithmIdentifier _keyEncryptionAlgorithm;
|
||||
private SubjectIdentifier _recipientIdentifier;
|
||||
private int _version;
|
||||
|
||||
// only accessible from EnvelopedCms.RecipientInfos
|
||||
internal KeyTransRecipientInfo (byte[] encryptedKey, AlgorithmIdentifier keyEncryptionAlgorithm, SubjectIdentifier recipientIdentifier, int version)
|
||||
: base (RecipientInfoType.KeyTransport)
|
||||
{
|
||||
_encryptedKey = encryptedKey;
|
||||
_keyEncryptionAlgorithm = keyEncryptionAlgorithm;
|
||||
_recipientIdentifier = recipientIdentifier;
|
||||
_version = version;
|
||||
}
|
||||
|
||||
public override byte[] EncryptedKey {
|
||||
get { return _encryptedKey; }
|
||||
}
|
||||
|
||||
public override AlgorithmIdentifier KeyEncryptionAlgorithm {
|
||||
get { return _keyEncryptionAlgorithm; }
|
||||
}
|
||||
|
||||
public override SubjectIdentifier RecipientIdentifier {
|
||||
get { return _recipientIdentifier; }
|
||||
}
|
||||
|
||||
public override int Version {
|
||||
get { return _version; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.Pkcs9AttributeObject class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public class Pkcs9AttributeObject : AsnEncodedData {
|
||||
|
||||
// constructors
|
||||
|
||||
public Pkcs9AttributeObject ()
|
||||
: base ()
|
||||
{
|
||||
}
|
||||
|
||||
public Pkcs9AttributeObject (AsnEncodedData asnEncodedData)
|
||||
: base (asnEncodedData)
|
||||
{
|
||||
}
|
||||
|
||||
public Pkcs9AttributeObject (Oid oid, byte[] encodedData)
|
||||
{
|
||||
if (oid == null)
|
||||
throw new ArgumentNullException ("oid");
|
||||
base.Oid = oid;
|
||||
RawData = encodedData;
|
||||
}
|
||||
|
||||
public Pkcs9AttributeObject (string oid, byte[] encodedData)
|
||||
: base (oid, encodedData)
|
||||
{
|
||||
}
|
||||
|
||||
// this (sadly) removes the "set" accessor
|
||||
public new Oid Oid {
|
||||
get { return base.Oid; }
|
||||
internal set { base.Oid = value; }
|
||||
}
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
if (asnEncodedData == null)
|
||||
throw new ArgumentNullException ("asnEncodedData");
|
||||
|
||||
throw new ArgumentException ("Cannot convert the PKCS#9 attribute.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,111 +0,0 @@
|
||||
//
|
||||
// Pkcs9ContentType.cs - System.Security.Cryptography.Pkcs.Pkcs9ContentType
|
||||
//
|
||||
// Authors:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class Pkcs9ContentType : Pkcs9AttributeObject {
|
||||
|
||||
internal const string oid = "1.2.840.113549.1.9.3";
|
||||
internal const string friendlyName = "Content Type";
|
||||
|
||||
private Oid _contentType;
|
||||
private byte[] _encoded;
|
||||
|
||||
// constructors
|
||||
|
||||
public Pkcs9ContentType ()
|
||||
{
|
||||
// Pkcs9Attribute remove the "set" accessor on Oid :-(
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_encoded = null;
|
||||
}
|
||||
|
||||
internal Pkcs9ContentType (string contentType)
|
||||
{
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_contentType = new Oid (contentType);
|
||||
RawData = Encode ();
|
||||
_encoded = null;
|
||||
}
|
||||
|
||||
internal Pkcs9ContentType (byte[] encodedContentType)
|
||||
{
|
||||
if (encodedContentType == null)
|
||||
throw new ArgumentNullException ("encodedContentType");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
RawData = encodedContentType;
|
||||
Decode (encodedContentType);
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public Oid ContentType {
|
||||
get {
|
||||
if (_encoded != null)
|
||||
Decode (_encoded);
|
||||
return _contentType;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
base.CopyFrom (asnEncodedData);
|
||||
_encoded = asnEncodedData.RawData;
|
||||
}
|
||||
|
||||
// internal stuff
|
||||
|
||||
internal void Decode (byte[] attribute)
|
||||
{
|
||||
if ((attribute == null) || (attribute [0] != 0x06))
|
||||
throw new CryptographicException (Locale.GetText ("Expected an OID."));
|
||||
|
||||
ASN1 oid = new ASN1 (attribute);
|
||||
_contentType = new Oid (ASN1Convert.ToOid (oid));
|
||||
_encoded = null;
|
||||
}
|
||||
|
||||
internal byte[] Encode ()
|
||||
{
|
||||
if (_contentType == null)
|
||||
return null;
|
||||
return ASN1Convert.FromOid (_contentType.Value).GetBytes ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.Pkcs9DocumentDescription class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Text;
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class Pkcs9DocumentDescription : Pkcs9AttributeObject {
|
||||
|
||||
internal const string oid = "1.3.6.1.4.1.311.88.2.2";
|
||||
internal const string friendlyName = null;
|
||||
|
||||
private string _desc;
|
||||
|
||||
public Pkcs9DocumentDescription ()
|
||||
{
|
||||
// Pkcs9Attribute remove the "set" accessor on Oid :-(
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
}
|
||||
|
||||
public Pkcs9DocumentDescription (string documentDescription)
|
||||
{
|
||||
if (documentDescription == null)
|
||||
throw new ArgumentNullException ("documentName");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_desc = documentDescription;
|
||||
RawData = Encode ();
|
||||
}
|
||||
|
||||
public Pkcs9DocumentDescription (byte[] encodedDocumentDescription)
|
||||
{
|
||||
if (encodedDocumentDescription == null)
|
||||
throw new ArgumentNullException ("encodedDocumentDescription");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
RawData = encodedDocumentDescription;
|
||||
Decode (encodedDocumentDescription);
|
||||
}
|
||||
|
||||
public string DocumentDescription {
|
||||
get { return _desc; }
|
||||
}
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
base.CopyFrom (asnEncodedData);
|
||||
Decode (this.RawData);
|
||||
}
|
||||
|
||||
// internal stuff
|
||||
|
||||
internal void Decode (byte[] attribute)
|
||||
{
|
||||
if (attribute [0] != 0x04)
|
||||
return; // throw ?
|
||||
|
||||
ASN1 attr = new ASN1 (attribute);
|
||||
byte[] str = attr.Value;
|
||||
int length = str.Length;
|
||||
if (str [length - 2] == 0x00)
|
||||
length -= 2; // zero-terminated (normal)
|
||||
_desc = Encoding.Unicode.GetString (str, 0, length);
|
||||
}
|
||||
|
||||
internal byte[] Encode ()
|
||||
{
|
||||
// OCTETSTRING (0x04) Of the zero-terminated unicode string
|
||||
ASN1 attr = new ASN1 (0x04, Encoding.Unicode.GetBytes (_desc + (char)0));
|
||||
return attr.GetBytes ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// Pkcs9DocumentName.cs - System.Security.Cryptography.Pkcs.Pkcs9DocumentName
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Text;
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class Pkcs9DocumentName : Pkcs9AttributeObject {
|
||||
|
||||
internal const string oid = "1.3.6.1.4.1.311.88.2.1";
|
||||
internal const string friendlyName = null;
|
||||
|
||||
private string _name;
|
||||
|
||||
public Pkcs9DocumentName ()
|
||||
{
|
||||
// Pkcs9Attribute remove the "set" accessor on Oid :-(
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
}
|
||||
|
||||
public Pkcs9DocumentName (string documentName)
|
||||
{
|
||||
if (documentName == null)
|
||||
throw new ArgumentNullException ("documentName");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_name = documentName;
|
||||
RawData = Encode ();
|
||||
}
|
||||
|
||||
public Pkcs9DocumentName (byte[] encodedDocumentName)
|
||||
{
|
||||
if (encodedDocumentName == null)
|
||||
throw new ArgumentNullException ("encodedDocumentName");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
RawData = encodedDocumentName;
|
||||
Decode (encodedDocumentName);
|
||||
}
|
||||
|
||||
public string DocumentName {
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
base.CopyFrom (asnEncodedData);
|
||||
Decode (this.RawData);
|
||||
}
|
||||
|
||||
// internal stuff
|
||||
|
||||
internal void Decode (byte[] attribute)
|
||||
{
|
||||
if (attribute [0] != 0x04)
|
||||
return; // throw ?
|
||||
|
||||
ASN1 attr = new ASN1 (attribute);
|
||||
byte[] str = attr.Value;
|
||||
int length = str.Length;
|
||||
if (str [length - 2] == 0x00)
|
||||
length -= 2; // zero-terminated (normal)
|
||||
_name = Encoding.Unicode.GetString (str, 0, length);
|
||||
}
|
||||
|
||||
internal byte[] Encode ()
|
||||
{
|
||||
// OCTETSTRING (0x04) Of the zero-terminated unicode string
|
||||
ASN1 attr = new ASN1 (0x04, Encoding.Unicode.GetBytes (_name + (char)0));
|
||||
return attr.GetBytes ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,109 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.Pkcs9MessageDigest class
|
||||
//
|
||||
// Authors:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class Pkcs9MessageDigest : Pkcs9AttributeObject {
|
||||
|
||||
internal const string oid = "1.2.840.113549.1.9.4";
|
||||
internal const string friendlyName = "Message Digest";
|
||||
|
||||
private byte[] _messageDigest;
|
||||
private byte[] _encoded;
|
||||
|
||||
// constructors
|
||||
|
||||
public Pkcs9MessageDigest ()
|
||||
{
|
||||
// Pkcs9Attribute remove the "set" accessor on Oid :-(
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_encoded = null;
|
||||
}
|
||||
|
||||
internal Pkcs9MessageDigest (byte[] messageDigest, bool encoded)
|
||||
{
|
||||
if (messageDigest == null)
|
||||
throw new ArgumentNullException ("messageDigest");
|
||||
|
||||
if (encoded) {
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
RawData = messageDigest;
|
||||
Decode (messageDigest);
|
||||
} else {
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_messageDigest = (byte[]) _messageDigest.Clone ();
|
||||
RawData = Encode ();
|
||||
}
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public byte[] MessageDigest {
|
||||
get {
|
||||
if (_encoded != null)
|
||||
Decode (_encoded);
|
||||
// FIXME: beta2 returns a reference
|
||||
return _messageDigest;
|
||||
}
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
base.CopyFrom (asnEncodedData);
|
||||
_encoded = asnEncodedData.RawData;
|
||||
}
|
||||
|
||||
// internal stuff
|
||||
|
||||
internal void Decode (byte[] attribute)
|
||||
{
|
||||
if ((attribute == null) || (attribute [0] != 0x04))
|
||||
throw new CryptographicException (Locale.GetText ("Expected an OCTETSTRING."));
|
||||
|
||||
ASN1 md = new ASN1 (attribute);
|
||||
_messageDigest = md.Value;
|
||||
_encoded = null;
|
||||
}
|
||||
|
||||
internal byte[] Encode ()
|
||||
{
|
||||
ASN1 md = new ASN1 (0x04, _messageDigest);
|
||||
return md.GetBytes ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,114 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Pkcs.Pkcs9SigningTime class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
using Mono.Security;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class Pkcs9SigningTime : Pkcs9AttributeObject {
|
||||
|
||||
internal const string oid = "1.2.840.113549.1.9.5";
|
||||
internal const string friendlyName = "Signing Time";
|
||||
|
||||
private DateTime _signingTime;
|
||||
|
||||
public Pkcs9SigningTime ()
|
||||
{
|
||||
// Pkcs9Attribute remove the "set" accessor on Oid :-(
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_signingTime = DateTime.Now;
|
||||
RawData = Encode ();
|
||||
}
|
||||
|
||||
public Pkcs9SigningTime (DateTime signingTime)
|
||||
{
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
_signingTime = signingTime;
|
||||
RawData = Encode ();
|
||||
}
|
||||
|
||||
public Pkcs9SigningTime (byte[] encodedSigningTime)
|
||||
{
|
||||
if (encodedSigningTime == null)
|
||||
throw new ArgumentNullException ("encodedSigningTime");
|
||||
|
||||
(this as AsnEncodedData).Oid = new Oid (oid, friendlyName);
|
||||
RawData = encodedSigningTime;
|
||||
Decode (encodedSigningTime);
|
||||
}
|
||||
|
||||
public DateTime SigningTime {
|
||||
get { return _signingTime; }
|
||||
}
|
||||
|
||||
public override void CopyFrom (AsnEncodedData asnEncodedData)
|
||||
{
|
||||
if (asnEncodedData == null)
|
||||
throw new ArgumentNullException ("asnEncodedData");
|
||||
|
||||
Decode (asnEncodedData.RawData);
|
||||
Oid = asnEncodedData.Oid;
|
||||
RawData = asnEncodedData.RawData;
|
||||
}
|
||||
|
||||
// internal stuff
|
||||
|
||||
internal void Decode (byte[] attribute)
|
||||
{
|
||||
// Only UTCTIME is supported by FX 2.0
|
||||
if (attribute [0] != 0x17)
|
||||
throw new CryptographicException (Locale.GetText ("Only UTCTIME is supported."));
|
||||
|
||||
ASN1 attr = new ASN1 (attribute);
|
||||
byte[] value = attr.Value;
|
||||
string date = Encoding.ASCII.GetString (value, 0, value.Length - 1);
|
||||
_signingTime = DateTime.ParseExact (date, "yyMMddHHmmss", null);
|
||||
}
|
||||
|
||||
internal byte[] Encode ()
|
||||
{
|
||||
if (_signingTime.Year <= 1600)
|
||||
throw new ArgumentOutOfRangeException ("<= 1600");
|
||||
// Only UTCTIME is supported by FX 2.0
|
||||
if ((_signingTime.Year < 1950) || (_signingTime.Year >= 2050))
|
||||
throw new CryptographicException ("[1950,2049]");
|
||||
|
||||
string date = _signingTime.ToString ("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z";
|
||||
ASN1 attr = new ASN1 (0x17, Encoding.ASCII.GetBytes (date));
|
||||
return attr.GetBytes ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// PublicKeyInfo.cs - System.Security.Cryptography.Pkcs.PublicKeyInfo
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class PublicKeyInfo {
|
||||
|
||||
private AlgorithmIdentifier _algorithm;
|
||||
private byte[] _key;
|
||||
|
||||
// constructors
|
||||
|
||||
// only used in KeyAgreeRecipientInfo.OriginatorIdentifierOrKey.Value
|
||||
// when SubjectIdentifierOrKeyType == PublicKeyInfo
|
||||
internal PublicKeyInfo (AlgorithmIdentifier algorithm, byte[] key)
|
||||
{
|
||||
_algorithm = algorithm;
|
||||
_key = key;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public AlgorithmIdentifier Algorithm {
|
||||
get { return _algorithm; }
|
||||
}
|
||||
|
||||
public byte[] KeyValue {
|
||||
get { return _key; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// RecipientInfo.cs - System.Security.Cryptography.Pkcs.RecipientInfo
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public abstract class RecipientInfo {
|
||||
|
||||
private RecipientInfoType _type;
|
||||
|
||||
// constructors
|
||||
|
||||
// documented as protected at http://longhorn.msdn.microsoft.com
|
||||
// but not present in the 1.2 beta SDK
|
||||
internal RecipientInfo (RecipientInfoType recipInfoType)
|
||||
{
|
||||
_type = recipInfoType;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public abstract byte[] EncryptedKey { get; }
|
||||
|
||||
public abstract AlgorithmIdentifier KeyEncryptionAlgorithm { get; }
|
||||
|
||||
public abstract SubjectIdentifier RecipientIdentifier { get; }
|
||||
|
||||
public RecipientInfoType Type {
|
||||
get { return _type; }
|
||||
}
|
||||
|
||||
public abstract int Version { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,94 +0,0 @@
|
||||
//
|
||||
// RecipientInfoCollection.cs - System.Security.Cryptography.Pkcs.RecipientInfoCollection
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.Pkcs {
|
||||
|
||||
public sealed class RecipientInfoCollection : ICollection {
|
||||
|
||||
private ArrayList _list;
|
||||
|
||||
// only accessible from EnvelopedPkcs7.RecipientInfos
|
||||
internal RecipientInfoCollection ()
|
||||
{
|
||||
_list = new ArrayList ();
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
public int Count {
|
||||
get { return _list.Count; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized {
|
||||
get { return _list.IsSynchronized; }
|
||||
}
|
||||
|
||||
public RecipientInfo this [int index] {
|
||||
get { return (RecipientInfo) _list [index]; }
|
||||
}
|
||||
|
||||
public object SyncRoot {
|
||||
get { return _list.SyncRoot; }
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
internal int Add (RecipientInfo ri)
|
||||
{
|
||||
return _list.Add (ri);
|
||||
}
|
||||
|
||||
public void CopyTo (Array array, int index)
|
||||
{
|
||||
_list.CopyTo (array, index);
|
||||
}
|
||||
|
||||
public void CopyTo (RecipientInfo[] array, int index)
|
||||
{
|
||||
_list.CopyTo (array, index);
|
||||
}
|
||||
|
||||
public RecipientInfoEnumerator GetEnumerator ()
|
||||
{
|
||||
return new RecipientInfoEnumerator (_list);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return new RecipientInfoEnumerator (_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user