Beispiel #1
0
        public void VerifySignatureTestSetup()
        {
            file = new Mock <FileWrapper>();
            file.Setup(f => f.ReadAllBytes(It.IsAny <string>()))
            .Returns <string>(givenFile => files[givenFile]);

            console = new Mock <ConsoleWrapper>();

            Container container = ContainerProvider.GetContainer();

            container.Register <FileWrapper>(() => file.Object);
            container.Register <ConsoleWrapper>(() => console.Object);

            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());
            var primeMapper     = new Rfc3526PrimeMapper();
            var curveNameMapper = new FieldToCurveNameMapper();

            rsaKeyProvider     = new RsaKeyProvider(asymmetricKeyPairGenerator);
            dsaKeyProvider     = new DsaKeyProvider(asymmetricKeyPairGenerator);
            ecKeyProvider      = new EcKeyProvider(asymmetricKeyPairGenerator, curveNameMapper);
            elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper);

            signatureProvider = new SignatureProvider(new SignatureAlgorithmIdentifierMapper(), new SecureRandomGenerator(), new SignerUtilitiesWrapper());
            pkcs8PemFormatter = new Pkcs8PemFormattingProvider(new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, elGamalKeyProvider));

            base64   = new Base64Wrapper();
            encoding = new EncodingWrapper();
            random   = new SecureRandomGenerator();
        }
Beispiel #2
0
        public void SetupAsymmetricKeyProviderTest()
        {
            var configuration = Mock.Of <IConfiguration>(c => c.Get <int>("SaltLengthInBytes") == 100 &&
                                                         c.Get <int>("KeyDerivationIterationCount") == 10);
            var secureRandom = new SecureRandomGenerator();
            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(secureRandom);
            var primeMapper = new Rfc3526PrimeMapper();
            var fieldMapper = new FieldToCurveNameMapper();

            rsaKeyProvider     = new RsaKeyProvider(asymmetricKeyPairGenerator);
            dsaKeyProvider     = new DsaKeyProvider(asymmetricKeyPairGenerator);
            ecKeyProvider      = new EcKeyProvider(asymmetricKeyPairGenerator, fieldMapper);
            elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper);

            cipherTypeMapper = new OidToCipherTypeMapper();
            keyInfoWrapper   = new Mock <KeyInfoWrapper>();

            SetupValidKeyInfo();
            SetupValidKeyProvider();

            pkcsEncryptionProvider = new KeyEncryptionProvider(configuration, secureRandom, keyProvider, new Pkcs12KeyEncryptionGenerator(), new AesKeyEncryptionGenerator());

            rsaKeyPair = rsaKeyProvider.CreateKeyPair(2048);
            dsaKeyPair = dsaKeyProvider.CreateKeyPair(2048);
            ecKeyPair  = ecKeyProvider.CreateKeyPair("secp384r1");

            elGamalKeyPair = elGamalKeyProvider.CreateKeyPair(2048, true);
        }
        public void SetupVerifyKeyPairTest()
        {
            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());
            var primeMapper     = new Rfc3526PrimeMapper();
            var curveNameMapper = new FieldToCurveNameMapper();

            rsaKeyProvider     = new RsaKeyProvider(asymmetricKeyPairGenerator);
            dsaKeyProvider     = new DsaKeyProvider(asymmetricKeyPairGenerator);
            ecKeyProvider      = new EcKeyProvider(asymmetricKeyPairGenerator, curveNameMapper);
            elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper);

            encoding          = new EncodingWrapper();
            pkcs8PemFormatter = new Pkcs8PemFormattingProvider(new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, elGamalKeyProvider));

            files = new Dictionary <string, byte[]>();
            file  = new Mock <FileWrapper>();
            file.Setup(f => f.ReadAllBytes(It.IsAny <string>()))
            .Returns <string>(givenFile => files[givenFile]);

            console = new Mock <ConsoleWrapper>();

            Container container = ContainerProvider.GetContainer();

            container.Register <FileWrapper>(() => file.Object);
            container.Register <ConsoleWrapper>(() => console.Object);
        }
Beispiel #4
0
        public void SetupDsaKeyProviderTest()
        {
            var secureRandomGenerator = new SecureRandomGenerator();
            var keyGenerator          = new AsymmetricKeyPairGenerator(secureRandomGenerator);

            keyProvider = new DsaKeyProvider(keyGenerator);
            keyPair     = keyProvider.CreateKeyPair(2048);
        }
            public void SetupGetKeyFromSsh()
            {
                var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());

                rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator);
                dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator);

                provider = new SshKeyProvider(new EncodingWrapper(), new Base64Wrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, null);
            }
            public void Setup()
            {
                var dsaKeyProvider         = new DsaKeyProvider(keyPairGenerator);
                IAsymmetricKeyPair keyPair = dsaKeyProvider.CreateKeyPair(2048);

                key = keyPair.PublicKey;

                string keyContent = provider.GetDsaPublicKeyContent(key);

                result = base64.FromBase64String(keyContent);

                using (var stream = new MemoryStream(result))
                {
                    rawHeader = ReadNextContent(stream);
                    rawP      = ReadNextContent(stream);
                    rawQ      = ReadNextContent(stream);
                    rawG      = ReadNextContent(stream);
                    rawY      = ReadNextContent(stream);
                }
            }
            public void SetupGetAsDer()
            {
                var secureRandom = new SecureRandomGenerator();
                var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(secureRandom);
                var rsaKeyProvider             = new RsaKeyProvider(asymmetricKeyPairGenerator);
                var dsaKeyProvider             = new DsaKeyProvider(asymmetricKeyPairGenerator);
                var ecKeyProvier = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper());
                var keyPair      = rsaKeyProvider.CreateKeyPair(1024);
                var key          = keyPair.PublicKey;

                var encoding       = new EncodingWrapper();
                var base64         = new Base64Wrapper();
                var sshKeyProvider = new SshKeyProvider(encoding, base64, rsaKeyProvider, dsaKeyProvider, ecKeyProvier, null);

                var formattingProvider = new SshFormattingProvider(sshKeyProvider, encoding, new Ssh2ContentFormatter(), null, base64);

                ssh2Key    = formattingProvider.GetAsSsh2PublicKey(key, "foo");
                keyContent = sshKeyProvider.GetRsaPublicKeyContent(key);
                openSshKey = formattingProvider.GetAsOpenSshPublicKey(key, "foo");
            }
Beispiel #8
0
        public void SetupCreateSignatureTest()
        {
            encoding = new EncodingWrapper();
            var random = new SecureRandomGenerator();

            fileContent = random.NextBytes(10000);

            file       = new Mock <FileWrapper>();
            fileOutput = new Dictionary <string, byte[]>();
            file.Setup(f => f.WriteAllBytes(It.IsAny <string>(), It.IsAny <byte[]>()))
            .Callback <string, byte[]>((path, content) =>
            {
                fileOutput.Add(path, content);
            });

            file.Setup(f => f.ReadAllBytes("foo.file"))
            .Returns(fileContent);

            console       = new Mock <ConsoleWrapper>();
            consoleOutput = new List <string>();

            console.Setup(c => c.WriteLine(It.IsAny <string>()))
            .Callback <string>(input => consoleOutput.Add(input));

            Container container = ContainerProvider.GetContainer();

            container.Register <FileWrapper>(() => file.Object);
            container.Register <ConsoleWrapper>(() => console.Object);

            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());

            rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator);
            dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator);
            ecKeyProvider  = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper());

            var asymmetricKeyProvider = new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, null, null);

            pkcs8PemFormatter = new Pkcs8PemFormattingProvider(asymmetricKeyProvider);
        }