Updating tests to use moq.netcore
This commit is contained in:
parent
7bb3ccf201
commit
ca3e4669dc
|
|
@ -25,3 +25,4 @@ nuget.exe
|
|||
*.ipch
|
||||
*.sln.ide
|
||||
project.lock.json
|
||||
.vs
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNet.Cryptography;
|
|||
using Microsoft.AspNet.Cryptography.Cng;
|
||||
using Microsoft.AspNet.Cryptography.SafeHandles;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.Cng.Internal;
|
||||
using Microsoft.AspNet.DataProtection.SP800_108;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.Cng
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNet.Cryptography;
|
|||
using Microsoft.AspNet.Cryptography.Cng;
|
||||
using Microsoft.AspNet.Cryptography.SafeHandles;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.Cng.Internal;
|
||||
using Microsoft.AspNet.DataProtection.SP800_108;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.Cng
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.Cng
|
||||
namespace Microsoft.AspNet.DataProtection.Cng.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class used for all CNG-related authentication encryption operations.
|
||||
/// </summary>
|
||||
internal unsafe abstract class CngAuthenticatedEncryptorBase : IOptimizedAuthenticatedEncryptor, IDisposable
|
||||
public unsafe abstract class CngAuthenticatedEncryptorBase : IOptimizedAuthenticatedEncryptor, IDisposable
|
||||
{
|
||||
public byte[] Decrypt(ArraySegment<byte> ciphertext, ArraySegment<byte> additionalAuthenticatedData)
|
||||
{
|
||||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNet.DataProtection;
|
|||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.Cng;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.DataProtection.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using Microsoft.AspNet.Cryptography.Cng;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection
|
||||
namespace Microsoft.AspNet.DataProtection.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface into <see cref="Activator.CreateInstance{T}"/> that also supports
|
||||
/// limited dependency injection (of <see cref="IServiceProvider"/>).
|
||||
/// </summary>
|
||||
internal interface IActivator
|
||||
public interface IActivator
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of <paramref name="implementationTypeName"/> and ensures
|
||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.DataProtection.Repositories;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
|
|
@ -15,7 +16,13 @@ namespace Microsoft.AspNet.DataProtection.KeyManagement
|
|||
/// </summary>
|
||||
internal sealed class DeferredKey : KeyBase
|
||||
{
|
||||
public DeferredKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate, IInternalXmlKeyManager keyManager, XElement keyElement)
|
||||
public DeferredKey(
|
||||
Guid keyId,
|
||||
DateTimeOffset creationDate,
|
||||
DateTimeOffset activationDate,
|
||||
DateTimeOffset expirationDate,
|
||||
IInternalXmlKeyManager keyManager,
|
||||
XElement keyElement)
|
||||
: base(keyId, creationDate, activationDate, expirationDate, new Lazy<IAuthenticatedEncryptor>(GetLazyEncryptorDelegate(keyManager, keyElement)))
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps both a keyring and its expiration policy.
|
||||
/// </summary>
|
||||
internal sealed class CacheableKeyRing
|
||||
public sealed class CacheableKeyRing
|
||||
{
|
||||
private readonly CancellationToken _expirationToken;
|
||||
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
internal struct DefaultKeyResolution
|
||||
public struct DefaultKeyResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// The default key, may be null if no key is a good default candidate.
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
internal interface ICacheableKeyRingProvider
|
||||
public interface ICacheableKeyRingProvider
|
||||
{
|
||||
CacheableKeyRing GetCacheableKeyRing(DateTimeOffset now);
|
||||
}
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements policy for resolving the default key from a candidate keyring.
|
||||
/// </summary>
|
||||
internal interface IDefaultKeyResolver
|
||||
public interface IDefaultKeyResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Locates the default key from the keyring.
|
||||
|
|
@ -5,12 +5,12 @@ using System;
|
|||
using Microsoft.AspNet.DataProtection.Repositories;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides default implementations of the services required by an <see cref="IKeyManager"/>.
|
||||
/// </summary>
|
||||
internal interface IDefaultKeyServices
|
||||
public interface IDefaultKeyServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="IXmlEncryptor"/> service (could return null).
|
||||
|
|
@ -5,10 +5,9 @@ using System;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
// Used for unit testing
|
||||
internal interface IInternalXmlKeyManager
|
||||
public interface IInternalXmlKeyManager
|
||||
{
|
||||
IKey CreateNewKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate);
|
||||
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// The basic interface for accessing a read-only keyring.
|
||||
/// </summary>
|
||||
internal interface IKeyRing
|
||||
public interface IKeyRing
|
||||
{
|
||||
/// <summary>
|
||||
/// The authenticated encryptor that shall be used for new encryption operations.
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
|
||||
{
|
||||
internal interface IKeyRingProvider
|
||||
public interface IKeyRingProvider
|
||||
{
|
||||
IKeyRing GetCurrentKeyRing();
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.KeyManagement
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ using System.Xml;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.DataProtection.Repositories;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Linq;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.Cryptography;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.XmlEncryption
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" },
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": {
|
||||
"type": "build",
|
||||
"version": ""
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"keyFile": "../../tools/Key.snk",
|
||||
"warningsAsErrors": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.Cryptography.KeyDerivation": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": "",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Moq": "4.2.1312.1622",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.Cryptography.KeyDerivation": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": "",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,28 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Moq": "4.2.1312.1622",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
"Moq": "4.2.1312.1622"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compile": "..\\common\\**\\*.cs",
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"moq.netcore": "4.4.0-beta8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compile": "../common/**/*.cs",
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Microsoft.AspNet.DataProtection
|
|||
|
||||
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
|
||||
{
|
||||
public bool IsMet => (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null);
|
||||
public bool IsMet => Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%") != null;
|
||||
|
||||
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,31 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" },
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Moq": "4.2.1312.1622",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": {
|
||||
"type": "build",
|
||||
"version": ""
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
"Moq": "4.2.1312.1622"
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"moq.netcore": "4.4.0-beta8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,7 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
},
|
||||
"commands": {
|
||||
|
||||
},
|
||||
"compilationOptions": {
|
||||
},
|
||||
"shared": "**\\*.cs"
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
},
|
||||
"shared": "**/*.cs"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
#if DNX451
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -85,3 +86,4 @@ namespace Microsoft.AspNet.DataProtection
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -74,14 +74,23 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
|
|||
Assert.Equal(plaintext, roundTripPlaintext);
|
||||
}
|
||||
|
||||
public static TheoryData CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementationData
|
||||
=> new TheoryData<EncryptionAlgorithm, ValidationAlgorithm, Func<HMAC>>
|
||||
{
|
||||
{ EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
|
||||
{ EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
|
||||
{ EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
|
||||
{ EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
|
||||
{ EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
|
||||
{ EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA256)]
|
||||
[InlineData(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA256)]
|
||||
[InlineData(EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA256)]
|
||||
[InlineData(EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA512)]
|
||||
[InlineData(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512)]
|
||||
[InlineData(EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA512)]
|
||||
public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(EncryptionAlgorithm encryptionAlgorithm, ValidationAlgorithm validationAlgorithm)
|
||||
[MemberData(nameof(CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementationData))]
|
||||
public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(
|
||||
EncryptionAlgorithm encryptionAlgorithm,
|
||||
ValidationAlgorithm validationAlgorithm,
|
||||
Func<HMAC> validationAlgorithmFactory)
|
||||
{
|
||||
// Parse test input
|
||||
int keyLengthInBits = Int32.Parse(Regex.Match(encryptionAlgorithm.ToString(), @"^AES_(?<keyLength>\d{3})_CBC$").Groups["keyLength"].Value, CultureInfo.InvariantCulture);
|
||||
|
|
@ -90,9 +99,9 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
|
|||
var masterKey = Secret.Random(512 / 8);
|
||||
var control = new ManagedAuthenticatedEncryptor(
|
||||
keyDerivationKey: masterKey,
|
||||
symmetricAlgorithmFactory: () => new AesCryptoServiceProvider(),
|
||||
symmetricAlgorithmFactory: () => Aes.Create(),
|
||||
symmetricAlgorithmKeySizeInBytes: keyLengthInBits / 8,
|
||||
validationAlgorithmFactory: () => KeyedHashAlgorithm.Create(validationAlgorithm.ToString()));
|
||||
validationAlgorithmFactory: validationAlgorithmFactory);
|
||||
var test = CreateDescriptor(encryptionAlgorithm, validationAlgorithm, masterKey).CreateEncryptorInstance();
|
||||
|
||||
// Act & assert - data round trips properly from control to test
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
|
|||
var control = new ManagedAuthenticatedEncryptorDescriptor(
|
||||
new ManagedAuthenticatedEncryptionOptions()
|
||||
{
|
||||
EncryptionAlgorithmType = typeof(AesCryptoServiceProvider),
|
||||
EncryptionAlgorithmType = typeof(Aes),
|
||||
EncryptionAlgorithmKeySize = 192,
|
||||
ValidationAlgorithmType = typeof(HMACSHA384)
|
||||
},
|
||||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
|
|||
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
|
||||
</masterKey>
|
||||
</descriptor>",
|
||||
typeof(AesCryptoServiceProvider).AssemblyQualifiedName, typeof(HMACSHA384).AssemblyQualifiedName);
|
||||
typeof(Aes).AssemblyQualifiedName, typeof(HMACSHA384).AssemblyQualifiedName);
|
||||
var test = new ManagedAuthenticatedEncryptorDescriptorDeserializer().ImportFromXml(XElement.Parse(xml)).CreateEncryptorInstance();
|
||||
|
||||
// Act & assert
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNet.Testing.xunit;
|
|||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.DataProtection.Cng
|
||||
namespace Microsoft.AspNet.DataProtection.Cng.Internal
|
||||
{
|
||||
public unsafe class CngAuthenticatedEncryptorBaseTests
|
||||
{
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.DataProtection.Cng
|
|||
Assert.Equal(new byte[] { 0x20, 0x21, 0x22 }, retVal);
|
||||
}
|
||||
|
||||
internal abstract class MockableEncryptor : CngAuthenticatedEncryptorBase
|
||||
public abstract class MockableEncryptor : CngAuthenticatedEncryptorBase
|
||||
{
|
||||
public override void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ using System;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Globalization;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ using System.Xml;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
|
||||
using Microsoft.AspNet.DataProtection.Repositories;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.AspNet.DataProtection.XmlEncryption;
|
||||
using Moq;
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ namespace Microsoft.AspNet.DataProtection
|
|||
["EncryptionType"] = "managed",
|
||||
["EncryptionAlgorithmType"] = typeof(TripleDES).AssemblyQualifiedName,
|
||||
["EncryptionAlgorithmKeySize"] = 2048,
|
||||
["ValidationAlgorithmType"] = typeof(HMACMD5).AssemblyQualifiedName
|
||||
["ValidationAlgorithmType"] = typeof(HMACSHA1).AssemblyQualifiedName
|
||||
});
|
||||
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
|
|
@ -203,7 +203,7 @@ namespace Microsoft.AspNet.DataProtection
|
|||
{
|
||||
EncryptionAlgorithmType = typeof(TripleDES),
|
||||
EncryptionAlgorithmKeySize = 2048,
|
||||
ValidationAlgorithmType = typeof(HMACMD5)
|
||||
ValidationAlgorithmType = typeof(HMACSHA1)
|
||||
});
|
||||
var actualConfiguration = (ManagedAuthenticatedEncryptorConfiguration)services.GetService<IAuthenticatedEncryptorConfiguration>();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.DataProtection.Repositories
|
|||
|
||||
// Assert
|
||||
Assert.Equal(defaultDirInfo.FullName,
|
||||
new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ASP.NET", "DataProtection-Keys")).FullName);
|
||||
new DirectoryInfo(Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"), "ASP.NET", "DataProtection-Keys")).FullName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.DataProtection.Repositories
|
|||
|
||||
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
|
||||
{
|
||||
public bool IsMet => (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null);
|
||||
public bool IsMet => Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%") != null;
|
||||
|
||||
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
#if !DNXCORE50
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.Xml;
|
||||
|
|
@ -58,3 +59,5 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
|
|||
XmlAssert.Equal(originalXml, roundTrippedElement);
|
||||
}
|
||||
|
||||
#if !DNXCORE50
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails()
|
||||
|
|
@ -51,5 +52,6 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
|
|||
ExceptionAssert2.ThrowsCryptographicException(() =>
|
||||
AnonymousImpersonation.Run(() => decryptor.Decrypt(encryptedXmlInfo.EncryptedElement)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNet.DataProtection.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" },
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||
"Moq": "4.2.1312.1622",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection.Test.Shared": {
|
||||
"type": "build",
|
||||
"version": ""
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
"Moq": "4.2.1312.1622"
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"moq.netcore": "4.4.0-beta8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.aspnet"
|
||||
},
|
||||
"compilationOptions": {
|
||||
"allowUnsafe": true,
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue