Imported Upstream version 5.18.0.142

Former-commit-id: 7467d4b717762eeaf652d77f1486dd11ffb1ff1f
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-09 08:20:59 +00:00
parent e52655b4dc
commit 0abdbe5a7d
1547 changed files with 93792 additions and 47893 deletions

View File

@@ -1,140 +0,0 @@
//
// AlgorithmIdentifierTest.cs - NUnit tests for AlgorithmIdentifier
//
// 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 NUnit.Framework;
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Pkcs;
namespace MonoTests.System.Security.Cryptography.Pkcs {
[TestFixture]
public class AlgorithmIdentifierTest {
static string defaultOid = "1.2.840.113549.3.7";
static string defaultName = "3des";
static string validOid = "1.2.840.113549.1.1.1";
[Test]
public void ConstructorEmpty ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier ();
Assert.AreEqual (0, ai.KeyLength, "KeyLength");
Assert.AreEqual (defaultName, ai.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (defaultOid, ai.Oid.Value, "Oid.Value");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
public void ConstructorOid ()
{
Oid o = new Oid (validOid);
AlgorithmIdentifier ai = new AlgorithmIdentifier (o);
Assert.AreEqual (0, ai.KeyLength, "KeyLength");
Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
//BUG [ExpectedException (typeof (ArgumentNullException))]
public void ConstructorOidNull ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier (null);
Assert.IsNull (ai.Oid, "Oid");
Assert.AreEqual (0, ai.KeyLength, "KeyLength");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
public void ConstructorOidKeyLength ()
{
Oid o = new Oid (validOid);
AlgorithmIdentifier ai = new AlgorithmIdentifier (o, 128);
Assert.AreEqual (128, ai.KeyLength, "KeyLength");
Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
//BUG [ExpectedException (typeof (ArgumentNullException))]
public void ConstructorOidNullKeyLength ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier (null, 128);
Assert.IsNull (ai.Oid, "Oid");
Assert.AreEqual (128, ai.KeyLength, "KeyLength");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
//BUG [ExpectedException (typeof (ArgumentOutOfRangeException))]
public void ConstructorOidKeyLengthNegative ()
{
Oid o = new Oid (validOid);
AlgorithmIdentifier ai = new AlgorithmIdentifier (o, -1);
Assert.AreEqual (-1, ai.KeyLength, "KeyLength");
Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
}
[Test]
public void KeyLength ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier ();
ai.KeyLength = Int32.MaxValue;
Assert.AreEqual (Int32.MaxValue, ai.KeyLength, "KeyLength-Max");
ai.KeyLength = 0;
Assert.AreEqual (0, ai.KeyLength, "KeyLength-Zero");
ai.KeyLength = Int32.MinValue;
Assert.AreEqual (Int32.MinValue, ai.KeyLength, "KeyLength-Min");
}
[Test]
public void Oid ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier ();
ai.Oid = new Oid (validOid);
Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
ai.Oid = null;
Assert.IsNull (ai.Oid, "Oid-Null");
}
[Test]
public void Parameters ()
{
AlgorithmIdentifier ai = new AlgorithmIdentifier ();
ai.Parameters = new byte[2] { 0x05, 0x00 }; // ASN.1 NULL
Assert.AreEqual ("05-00", BitConverter.ToString (ai.Parameters), "Parameters");
ai.Parameters = null;
Assert.IsNull (ai.Parameters, "Parameters-Null");
}
}
}

View File

@@ -149,10 +149,9 @@ namespace MonoTests.System.Security.Cryptography.Pkcs {
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void GetContentType_signedAndEnvelopedData ()
{
// Note: signedAndEnvelopedData isn't defined in RFC2630
// Note: signedAndEnvelopedData isn't defined in RFC2630, but it is supported by the CMS classes
byte[] signedAndEnvelopedData = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x04, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E,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x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
Oid o = ContentInfo.GetContentType (signedAndEnvelopedData);
Assert.AreEqual ("1.2.840.113549.1.7.4", o.Value, "GetContentType");

View File

@@ -75,14 +75,14 @@ namespace MonoTests.System.Security.Cryptography.Pkcs {
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
[ExpectedException (typeof (CryptographicException))]
public void Constructor_DateTime_MinValue ()
{
Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.MinValue);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
[ExpectedException (typeof (CryptographicException))]
public void Constructor_DateTime_1600 ()
{
DateTime dt = new DateTime (1600, 12, 31, 11, 59, 59);
@@ -104,54 +104,6 @@ namespace MonoTests.System.Security.Cryptography.Pkcs {
Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.MaxValue);
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void Constructor_DateTime_Before1950 ()
{
DateTime dt = new DateTime (1949, 12, 31, 11, 59, 59);
// UTCTIME (0x17), i.e. 2 digits years, limited to 1950-2050
Pkcs9SigningTime st = new Pkcs9SigningTime (dt);
}
[Test]
public void Constructor_DateTime_After1950 ()
{
DateTime dt = new DateTime (1950, 01, 01, 00, 00, 00);
// UTCTIME (0x17), i.e. 2 digits years, limited to 1950-2050
Pkcs9SigningTime st = new Pkcs9SigningTime (dt);
Assert.AreEqual (signingTimeName, st.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (signingTimeOid, st.Oid.Value, "Oid.Value");
Assert.AreEqual (15, st.RawData.Length, "RawData.Length");
Assert.AreEqual ("17-0D-35-30-30-31-30-31-30-30-30-30-30-30-5A", BitConverter.ToString (st.RawData));
Assert.AreEqual (dt, st.SigningTime, "st.SigningTime");
Assert.AreEqual ("17 0d 35 30 30 31 30 31 30 30 30 30 30 30 5a", st.Format (true), "Format(true)");
Assert.AreEqual ("17 0d 35 30 30 31 30 31 30 30 30 30 30 30 5a", st.Format (false), "Format(false)");
}
[Test]
public void Constructor_DateTime_Before2050 ()
{
DateTime dt = new DateTime (2049, 12, 31, 11, 59, 59);
// up to 2050 encoding should stay with UTCTIME (0x17), i.e. 2 digits years
Pkcs9SigningTime st = new Pkcs9SigningTime (dt);
Assert.AreEqual (signingTimeName, st.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (signingTimeOid, st.Oid.Value, "Oid.Value");
Assert.AreEqual (15, st.RawData.Length, "RawData.Length");
Assert.AreEqual ("17-0D-34-39-31-32-33-31-31-31-35-39-35-39-5A", BitConverter.ToString (st.RawData));
Assert.AreEqual (dt, st.SigningTime, "st.SigningTime");
Assert.AreEqual ("17 0d 34 39 31 32 33 31 31 31 35 39 35 39 5a", st.Format (true), "Format(true)");
Assert.AreEqual ("17 0d 34 39 31 32 33 31 31 31 35 39 35 39 5a", st.Format (false), "Format(false)");
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void Constructor_DateTime_After2050 ()
{
DateTime dt = new DateTime (2050, 01, 01, 00, 00, 00);
// in 2050 encoding should switch to GENERALIZEDTIME (0x18), i.e. 4 digits years
Pkcs9SigningTime st = new Pkcs9SigningTime (dt);
}
[Test]
public void Constructor_DateTime ()
{

View File

@@ -374,7 +374,7 @@ namespace MonoTests.System.Security.Cryptography.Pkcs {
}
[Test]
[ExpectedException (typeof (CryptographicException))]
[ExpectedException (typeof (PlatformNotSupportedException))]
public void ComputeEmptySignature ()
{
SignedCms sp = new SignedCms ();

View File

@@ -110,14 +110,14 @@ namespace MonoTests.System.Security.Cryptography.Pkcs {
SignerInfo si = GetSignerInfo (data);
// default properties
Assert.AreEqual (0, si.SignedAttributes.Count, "SignedAttributes");
Assert.AreEqual (5, si.SignedAttributes.Count, "SignedAttributes");
Assert.IsNotNull (si.Certificate, "Certificate");
Assert.AreEqual (0, si.CounterSignerInfos.Count, "CounterSignerInfos");
Assert.AreEqual ("sha256", si.DigestAlgorithm.FriendlyName, "DigestAlgorithm.FriendlyName");
Assert.AreEqual ("2.16.840.1.101.3.4.2.1", si.DigestAlgorithm.Value, "DigestAlgorithm.Value");
Assert.AreEqual (SubjectIdentifierType.SubjectKeyIdentifier, si.SignerIdentifier.Type, "SignerIdentifier.Type");
Assert.AreEqual ("F1CC7184EBDA537140C1A57416017810DF133020", (string)si.SignerIdentifier.Value, "SignerIdentifier.Value");
Assert.AreEqual (0, si.UnsignedAttributes.Count, "UnsignedAttributes");
Assert.AreEqual (1, si.UnsignedAttributes.Count, "UnsignedAttributes");
Assert.AreEqual (3, si.Version, "Version");
}
}

View File

@@ -116,22 +116,6 @@ namespace MonoTests.System.Security.Cryptography {
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[Category ("NotDotNet")]
public void Protect_InvalidDataProtectionScope ()
{
try {
byte[] data = new byte[16];
ProtectedData.Protect (data, notMuchEntropy, (DataProtectionScope) Int32.MinValue);
// MS doesn't throw an ArgumentException but returning from
// this method will throw an UnhandledException in NUnit
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ProtectNull ()
@@ -148,7 +132,6 @@ namespace MonoTests.System.Security.Cryptography {
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void UnprotectNotProtectedData ()
{
try {
@@ -158,23 +141,9 @@ namespace MonoTests.System.Security.Cryptography {
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[Category ("NotDotNet")]
public void Unprotect_InvalidDataProtectionScope ()
{
try {
byte[] data = new byte[16];
byte[] encdata = ProtectedData.Protect (data, notMuchEntropy, DataProtectionScope.CurrentUser);
ProtectedData.Unprotect (encdata, notMuchEntropy, (DataProtectionScope) Int32.MinValue);
// MS doesn't throw an ArgumentException but returning from
// this method will throw an UnhandledException in NUnit
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
catch (CryptographicException) {
Assert.Pass ();
}
}
[Test]
@@ -184,5 +153,4 @@ namespace MonoTests.System.Security.Cryptography {
ProtectedData.Unprotect (null, notMuchEntropy, DataProtectionScope.CurrentUser);
}
}
}
}