Exemplo n.º 1
0
 public void SetupEcKeyProviderTest()
 {
     asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());
     keyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper());
     
     keyPair = keyProvider.CreateKeyPair("brainpoolP384t1");
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        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);
        }
        public void SetupEcPemFormattingProviderTest()
        {
            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());

            ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper());
            provider      = new EcPemFormattingProvider(ecKeyProvider);
            keyPair       = ecKeyProvider.CreateKeyPair("P-256");
        }
        public void Setup()
        {
            var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());

            keyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper());

            mapper = new FieldToCurveNameMapper();
        }
Exemplo n.º 7
0
        public void SetupSshKeyProviderTest()
        {
            encoding         = new EncodingWrapper();
            keyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator());
            ecKeyProvider    = new EcKeyProvider(keyPairGenerator, new FieldToCurveNameMapper());
            provider         = new SshKeyProvider(encoding, new Base64Wrapper(), Mock.Of <IRsaKeyProvider>(), Mock.Of <IDsaKeyProvider>(), ecKeyProvider, new SecureRandomGenerator());

            base64 = new Base64Wrapper();
        }
            public void Setup()
            {
                var randomGenerator = new Mock <SecureRandomGenerator>();

                randomGenerator.Setup(r => r.NextBytes(4))
                .Returns(new byte[] { 1, 1, 1, 1 });

                ecKeyProvider  = new EcKeyProvider(new AsymmetricKeyPairGenerator(new SecureRandomGenerator()), new FieldToCurveNameMapper());
                sshKeyProvider = new SshKeyProvider(new EncodingWrapper(), new Base64Wrapper(), null, null, ecKeyProvider, randomGenerator.Object);

                keyPair  = ecKeyProvider.CreateKeyPair("curve25519");
                provider = new SshFormattingProvider(sshKeyProvider, new EncodingWrapper(), new Ssh2ContentFormatter(), new OpenSshContentFormatter(), new Base64Wrapper());

                string result = provider.GetAsOpenSshPrivateKey(keyPair, "key comment");

                resultLines = result.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            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");
            }
Exemplo n.º 10
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);
        }