2004-12-23 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 23 Dec 2004 13:50:47 +0000 (13:50 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 23 Dec 2004 13:50:47 +0000 (13:50 -0000)
* System.Security.dll.sources: Added System.Security.Cryptography/
ProtectedData.cs, ProtectedMemory.cs, DataProtectionScope.cs and
MemoryProtectionScope.cs as they been moved from mscorlib to here.
* System.Security_test.dll.sources : Added Test/System.Security.
Cryptography/ProtectedDataTest.cs and ProtectedMemoryTest.cs for the
same reason.

svn path=/trunk/mcs/; revision=38060

1  2 
mcs/class/System.Security/ChangeLog
mcs/class/System.Security/System.Security.Cryptography/DataProtectionScope.cs
mcs/class/System.Security/System.Security.Cryptography/MemoryProtectionScope.cs
mcs/class/System.Security/System.Security.Cryptography/ProtectedData.cs
mcs/class/System.Security/System.Security.Cryptography/ProtectedMemory.cs
mcs/class/System.Security/System.Security.dll.sources
mcs/class/System.Security/System.Security_test.dll.sources
mcs/class/System.Security/Test/System.Security.Cryptography/ProtectedDataTest.cs
mcs/class/System.Security/Test/System.Security.Cryptography/ProtectedMemoryTest.cs

index af39e934f885246799097045daaa930e948d8665,af39e934f885246799097045daaa930e948d8665..5e5ae81ba8f0a3ac55a8ff9622b2cdbfbea757e9
@@@ -1,3 -1,3 +1,12 @@@
++2004-12-23  Sebastien Pouliot  <sebastien@ximian.com>
++
++      * System.Security.dll.sources: Added System.Security.Cryptography/
++      ProtectedData.cs, ProtectedMemory.cs, DataProtectionScope.cs and
++      MemoryProtectionScope.cs as they been moved from mscorlib to here.
++      * System.Security_test.dll.sources : Added Test/System.Security.
++      Cryptography/ProtectedDataTest.cs and ProtectedMemoryTest.cs for the 
++      same reason.
++
  2004-09-04  Tim Coleman <tim@timcoleman.com>
        * System.Security.dll.sources:
                Add new System.Security.Cryptography.Pkcs classes.
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..0e592b198a42c0d3558e2de2cfa65c4aca331d66
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,45 @@@
++//
++// DataProtectionScope.cs: Scope for ProtectData
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.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 NET_2_0
++
++using System;
++
++namespace System.Security.Cryptography {
++
++      public enum DataProtectionScope {
++              CurrentUser,
++              LocalMachine
++      }
++}
++
++#endif
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ac36dd779e9a83cc61ce2eaa016d9f23e2a0bbd5
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,46 @@@
++//
++// MemoryProtectionScope.cs: Scope for ProtectMemory
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.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 NET_2_0
++
++using System;
++
++namespace System.Security.Cryptography {
++
++      public enum MemoryProtectionScope {
++              SameProcess,
++              CrossProcess,
++              SameLogon
++      } 
++}
++
++#endif
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..fcc07f0b4206e32f2e703b9ebad7af86b259e38a
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,71 @@@
++//
++// ProtectedData.cs: Protect (encrypt) data without (user involved) key management
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.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 NET_2_0
++
++using System;
++
++namespace System.Security.Cryptography {
++
++      // References:
++      // a.   Windows Data Protection
++      //      http://msdn.microsoft.com/library/en-us/dnsecure/html/windataprotection-dpapi.asp?frame=true
++
++      public sealed class ProtectedData {
++
++              private ProtectedData ()
++              {
++              }
++
++              // FIXME: interop could be important under windows - if one application protect some data using
++              // mono and another one unprotects it using ms.net
++
++              [MonoTODO ("interop with MS implementation ?")]
++              public static byte[] Protect (byte[] userData, byte[] optionalEntropy, DataProtectionScope scope) 
++              {
++                      if (userData == null)
++                              throw new ArgumentNullException ("userData");
++
++                      // on Windows this is supported only under 2000 and later OS
++                      throw new PlatformNotSupportedException ();
++              }
++
++              [MonoTODO ("interop with MS implementation ?")]
++              public static byte[] Unprotect (byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope) 
++              {
++                      if (encryptedData == null)
++                              throw new ArgumentNullException ("encryptedData");
++
++                      // on Windows this is supported only under 2000 and later OS
++                      throw new PlatformNotSupportedException ();
++              }
++      } 
++}
++
++#endif
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..2b1dfab08ec349a2e4633dd6d9fb2c5f8239511a
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,72 @@@
++//
++// ProtectedMemory.cs: Protect (encrypt) memory without (user involved) key management
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.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 NET_2_0
++
++using System;
++
++namespace System.Security.Cryptography {
++
++      // References:
++      // a.   Windows Data Protection
++      //      http://msdn.microsoft.com/library/en-us/dnsecure/html/windataprotection-dpapi.asp?frame=true
++
++      public sealed class ProtectedMemory {
++
++              private ProtectedMemory ()
++              {
++              }
++
++              [MonoTODO]
++              public static void Protect (byte[] userData, MemoryProtectionScope scope) 
++              {
++                      if (userData == null)
++                              throw new ArgumentNullException ("userData");
++                      if (userData.Length % 16 != 0)
++                              throw new CryptographicException ("not a multiple of 16 bytes");
++
++                      // on Windows this is supported only under XP and later OS
++                      throw new PlatformNotSupportedException ();
++              }
++
++              [MonoTODO]
++              public static void Unprotect (byte[] encryptedData, MemoryProtectionScope scope) 
++              {
++                      if (encryptedData == null)
++                              throw new ArgumentNullException ("encryptedData");
++                      if (encryptedData.Length % 16 != 0)
++                              throw new CryptographicException ("not a multiple of 16 bytes");
++
++                      // on Windows this is supported only under XP and later OS
++                      throw new PlatformNotSupportedException ();
++              }
++      } 
++}
++
++#endif
index 5d965982bf8f6e4ddd7109e91ad8113364c1c77b,5d965982bf8f6e4ddd7109e91ad8113364c1c77b..a98f70adee2d334a65125ef74edb9d218ddc7d1f
@@@ -7,9 -7,9 +7,13 @@@ System.Security.Cryptography/AsnEncoded
  System.Security.Cryptography/CryptographicAttribute.cs
  System.Security.Cryptography/CryptographicAttributeCollection.cs
  System.Security.Cryptography/CryptographicAttributeEnumerator.cs
++System.Security.Cryptography/DataProtectionScope.cs
++System.Security.Cryptography/MemoryProtectionScope.cs
  System.Security.Cryptography/Oid.cs
  System.Security.Cryptography/OidCollection.cs
  System.Security.Cryptography/OidEnumerator.cs
++System.Security.Cryptography/ProtectedData.cs
++System.Security.Cryptography/ProtectedMemory.cs
  System.Security.Cryptography.Pkcs/AlgorithmIdentifier.cs
  System.Security.Cryptography.Pkcs/ContentInfo.cs
  System.Security.Cryptography.Pkcs/EnvelopedCms.cs
index 2c4eba53a96a2144630e32469c8c315598391edc,2c4eba53a96a2144630e32469c8c315598391edc..4e06fe47816e2855b1bf9442ca51a6f84888d03d
@@@ -3,6 -3,6 +3,8 @@@ System.Security.Cryptography/Cryptograp
  System.Security.Cryptography/OidCollectionTest.cs
  System.Security.Cryptography/OidEnumeratorTest.cs
  System.Security.Cryptography/OidTest.cs
++System.Security.Cryptography/ProtectedDataTest.cs
++System.Security.Cryptography/ProtectedMemoryTest.cs
  System.Security.Cryptography.Pkcs/AlgorithmIdentifierTest.cs
  System.Security.Cryptography.Pkcs/CmsRecipientTest.cs
  System.Security.Cryptography.Pkcs/CmsSignerTest.cs
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..27e2d5bb23764be7b95721492d266b44902a7b05
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,109 @@@
++//
++// ProtectedDataTest.cs - NUnit Test Cases for ProtectedData
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.com)
++//
++// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
++//
++
++#if NET_2_0
++
++using NUnit.Framework;
++
++using System;
++using System.Security.Cryptography;
++
++namespace MonoTests.System.Security.Cryptography {
++
++      // References:
++      // a.   
++
++      [TestFixture]
++      public class ProtectedDataTest : Assertion {
++
++              private void ProtectUnprotect (byte[] entropy, DataProtectionScope scope) 
++              {
++                      byte[] data = new byte [16];
++                      byte[] encdata = ProtectedData.Protect (data, entropy, scope);
++                      int total = 0;
++                      for (int i=0; i < 16; i++)
++                              total += encdata [i];
++                      Assert ("Protect", (total != 0));
++
++                      byte[] decdata = ProtectedData.Unprotect (encdata, entropy, scope);
++                      total = 0;
++                      for (int i=0; i < 16; i++)
++                              total += decdata [i];
++                      Assert ("Unprotect", (total == 0));
++              }
++
++              [Test]
++              public void ProtectCurrentUser () 
++              {
++                      try {
++                              byte[] notMuchEntropy = new byte [16];
++                              // we're testing the DataProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (notMuchEntropy, DataProtectionScope.CurrentUser);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows 2000 and later");
++                      }
++              }
++
++              [Test]
++              public void ProtectLocalMachine () 
++              {
++                      try {
++                              byte[] notMuchEntropy = new byte [16];
++                              // we're testing the DataProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (notMuchEntropy, DataProtectionScope.LocalMachine);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows 2000 and later");
++                      }
++              }
++
++              [Test]
++              [ExpectedException (typeof (ArgumentNullException))]
++              public void ProtectNull () 
++              {
++                      byte[] notMuchEntropy = new byte [16];
++                      ProtectedData.Protect (null, notMuchEntropy, DataProtectionScope.CurrentUser);
++              }
++
++              [Test]
++              public void ProtectNullEntropy () 
++              {
++                      try {
++                              // we're testing the DataProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (null, DataProtectionScope.LocalMachine);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows 2000 and later");
++                      }
++              }
++
++              [Test]
++              [ExpectedException (typeof (CryptographicException))]
++              public void UnprotectNotProtectedData () 
++              {
++                      byte[] baddata = new byte [16];
++                      byte[] notMuchEntropy = new byte [16];
++                      ProtectedData.Unprotect (baddata, notMuchEntropy, DataProtectionScope.CurrentUser);
++              }
++
++              [Test]
++              [ExpectedException (typeof (ArgumentNullException))]
++              public void UnprotectNull () 
++              {
++                      byte[] notMuchEntropy = new byte [16];
++                      ProtectedData.Unprotect (null, notMuchEntropy, DataProtectionScope.CurrentUser);
++              }
++      }
++}
++
++#endif
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a8827ff41f1ed2cffd7b21037cf8c318650998a8
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,112 @@@
++//
++// ProtectedMemoryTest.cs - NUnit Test Cases for ProtectedMemory
++//
++// Author:
++//    Sebastien Pouliot (spouliot@motus.com)
++//
++// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
++//
++
++#if NET_2_0
++
++using NUnit.Framework;
++
++using System;
++using System.Security.Cryptography;
++
++namespace MonoTests.System.Security.Cryptography {
++
++      // References:
++      // a.   
++
++      [TestFixture]
++      public class ProtectedMemoryTest : Assertion {
++
++              private void ProtectUnprotect (MemoryProtectionScope scope) 
++              {
++                      byte[] data = new byte [16];
++                      ProtectedMemory.Protect (data, scope);
++                      int total = 0;
++                      for (int i=0; i < 16; i++)
++                              total += data [i];
++                      Assert ("Protect", (total != 0));
++
++                      ProtectedMemory.Unprotect (data, scope);
++                      total = 0;
++                      for (int i=0; i < 16; i++)
++                              total += data [i];
++                      Assert ("Unprotect", (total == 0));
++              }
++
++              [Test]
++              public void ProtectSameProcess () 
++              {
++                      try {
++                              // we're testing the MemoryProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (MemoryProtectionScope.SameProcess);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows XP and later");
++                      }
++              }
++
++              [Test]
++              public void ProtectSameLogon () 
++              {
++                      try {
++                              // we're testing the MemoryProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (MemoryProtectionScope.SameLogon);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows XP and later");
++                      }
++              }
++
++              [Test]
++              public void ProtectCrossProcess () 
++              {
++                      try {
++                              // we're testing the MemoryProtectionScope definition but
++                              // not if it's really limited to the scope specified
++                              ProtectUnprotect (MemoryProtectionScope.CrossProcess);
++                      }
++                      catch (PlatformNotSupportedException) {
++                              Console.WriteLine ("Only supported under Windows XP and later");
++                      }
++              }
++
++              [Test]
++              [ExpectedException (typeof (CryptographicException))]
++              public void ProtectBadDataLength () 
++              {
++                      byte[] data = new byte [15];
++                      ProtectedMemory.Protect (data, MemoryProtectionScope.SameProcess);
++              }
++
++              [Test]
++              [ExpectedException (typeof (ArgumentNullException))]
++              public void ProtectNull () 
++              {
++                      ProtectedMemory.Protect (null, MemoryProtectionScope.SameProcess);
++              }
++
++              [Test]
++              [ExpectedException (typeof (CryptographicException))]
++              public void UnprotectBadDataLength () 
++              {
++                      byte[] data = new byte [15];
++                      ProtectedMemory.Unprotect (data, MemoryProtectionScope.SameProcess);
++              }
++
++              [Test]
++              [ExpectedException (typeof (ArgumentNullException))]
++              public void UnprotectNull () 
++              {
++                      ProtectedMemory.Unprotect (null, MemoryProtectionScope.SameProcess);
++              }
++      }
++}
++
++#endif