public void Setup()
            {
                keyPair = keyProvider.CreateKeyPair("curve25519");
                publicKeyParameters = (ECPublicKeyParameters) PublicKeyFactory.CreateKey(keyPair.PublicKey.Content);

                q = publicKeyParameters.Q.GetEncoded();
                result = keyProvider.GetPublicKey(q, "curve25519");
            }
Example #2
0
        public void Setup()
        {
            formattedKey = Mock.Of <IEcKey>();
            keyProvider  = new Mock <IEcKeyProvider>();
            keyProvider.Setup(kp => kp.GetPkcs8PrivateKeyAsSec1(It.IsAny <IEcKey>()))
            .Returns(formattedKey);

            decoratedCommandHandler = new Mock <ICommandHandler <WriteFileCommand <IAsymmetricKey> > >();
            decorator = new EcSec1WriteFormattingDecorator <WriteFileCommand <IAsymmetricKey> >(decoratedCommandHandler.Object, keyProvider.Object);
        }
Example #3
0
        public IEcKey GetPkcs8PrivateKeyAsSec1(IEcKey key)
        {
            AsymmetricKeyParameter keyContent = PrivateKeyFactory.CreateKey(key.Content);

            byte[] privateKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyContent)
                                .ParsePrivateKey()
                                .GetDerEncoded();

            return(new EcKey(privateKey, AsymmetricKeyType.Private, key.KeySize, key.Curve));
        }
        public void Setup()
        {
            convertedKey     = Mock.Of <IEcKey>();
            sec1PemFormatter = new Mock <IPemFormattingProvider <IEcKey> >();
            sec1PemFormatter.Setup(s => s.GetAsDer("-----BEGIN EC PRIVATE KEY given content"))
            .Returns(convertedKey);

            encoding = new EncodingWrapper();
            decoratedCommandHandler = new Mock <ICommandHandler <ReadKeyFromFileCommand> >();
            decorator = new EcSec1PemReadFormattingDecorator <ReadKeyFromFileCommand>(decoratedCommandHandler.Object, sec1PemFormatter.Object, encoding);
        }
        public void ShouldThrowWhenSec1IsAppliedForNonEcKey()
        {
            key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Rsa);
            var command = new WriteFileCommand <IAsymmetricKey>
            {
                Out         = key,
                ContentType = ContentType.Sec1
            };

            Assert.Throws <InvalidOperationException>(() => decorator.Execute(command));
        }
        public void ShouldNotSetFileContentWhenCipherTypeIsNotEc()
        {
            key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Rsa);
            var command = new WriteFileCommand <IAsymmetricKey>
            {
                Out         = key,
                ContentType = ContentType.Sec1
            };

            decorator.Execute(command);
            decoratedCommandHandler.Verify(d => d.Execute(It.Is <WriteFileCommand <IAsymmetricKey> >(k => k.FileContent == null)));
        }
        public void Setup()
        {
            formattingProvider = new Mock <IPemFormattingProvider <IEcKey> >();
            encoding           = new EncodingWrapper();

            decoratedCommandHandler = new Mock <ICommandHandler <WriteFileCommand <IAsymmetricKey> > >();
            decorator = new EcSec1PemWriteFormattingDecorator <WriteFileCommand <IAsymmetricKey> >(decoratedCommandHandler.Object, formattingProvider.Object, encoding);

            key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Ec);
            formattingProvider.Setup(fp => fp.GetAsPem(key))
            .Returns("EcPem");
        }
                public void Setup()
                {
                    key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Ec && k.Curve == "foo");

                    keyProvider.Setup(kp => kp.GetEcPublicKeyContent(key))
                    .Returns("ECKeyContent");
                    keyProvider.Setup(kp => kp.IsSupportedCurve("foo"))
                    .Returns(true);

                    rawContent = provider.GetAsSsh2PublicKey(key, "eccomment");
                    result     = rawContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                }
        public void ShouldExecuteDecoratedCommandHandler()
        {
            key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Ec);
            var command = new WriteFileCommand <IAsymmetricKey>
            {
                Out         = key,
                ContentType = ContentType.Sec1
            };

            decorator.Execute(command);
            decoratedCommandHandler.Verify(ch => ch.Execute(command));
        }
            private void SetupForCurve(string curveName)
            {
                IAsymmetricKeyPair keyPair = ecKeyProvider.CreateKeyPair(curveName);

                publicKey = (IEcKey)keyPair.PublicKey;

                string keyContent = provider.GetEcPublicKeyContent(publicKey);

                result = base64.FromBase64String(keyContent);

                using (var stream = new MemoryStream(result))
                {
                    rawIdentifier = ReadNextContent(stream);
                    rawHeader     = ReadNextContent(stream);
                    rawQ          = ReadNextContent(stream);
                }
            }
                public void Setup()
                {
                    key   = Mock.Of <IEcKey>(k => k.Curve == "foo" && k.CipherType == CipherType.Ec);
                    edKey = Mock.Of <IEcKey>(k => k.Curve == "foo" && k.CipherType == CipherType.Ec && k.IsCurve25519);

                    keyProvider.Setup(kp => kp.IsSupportedCurve("foo"))
                    .Returns(true);
                    keyProvider.Setup(kp => kp.GetCurveSshHeader("foo"))
                    .Returns("fooHeader");
                    keyProvider.Setup(kp => kp.GetEcPublicKeyContent(key))
                    .Returns("EcKeyContent");
                    keyProvider.Setup(kp => kp.GetEd25519PublicKeyContent(edKey))
                    .Returns("25519KeyContent");

                    rawResult = provider.GetAsOpenSshPublicKey(key, "eccomment");
                    result    = rawResult.Split(' ');
                }
 public void Setup()
 {
     sec1PrivateKey = ecKeyProvider.GetPkcs8PrivateKeyAsSec1((IEcKey)keyPair.PrivateKey);
     privateKey     = provider.GetAsPem(sec1PrivateKey);
     publicKey      = provider.GetAsPem((IEcKey)keyPair.PublicKey);
 }
            public void ShouldReturnValidPkcs8Key()
            {
                IEcKey result = provider.GetAsDer(privateKey);

                Assert.IsTrue(ecKeyProvider.VerifyKeyPair(new AsymmetricKeyPair(result, keyPair.PublicKey)));
            }
 public void Setup()
 {
     var sec1Key = keyProvider.GetPkcs8PrivateKeyAsSec1((IEcKey)keyPair.PrivateKey);
     convertedKey = keyProvider.GetSec1PrivateKeyAsPkcs8(sec1Key.Content);
     keySequence = (DerSequence)Asn1Object.FromByteArray(convertedKey.Content);
 }
 public void ShouldThrowExceptionWhenCurveIsNotSupported()
 {
     key = Mock.Of <IEcKey>(k => k.Curve == "bar" && k.CipherType == CipherType.Ec);
     Assert.Throws <ArgumentException>(() => provider.GetAsOpenSshPublicKey(key, "comment"));
 }
 public void ShouldThrowWhenCurveIsNotSupported()
 {
     key = Mock.Of <IEcKey>(k => k.CipherType == CipherType.Ec && k.Curve == "bar");
     Assert.Throws <ArgumentException>(() => provider.GetAsSsh2PublicKey(key, "foobar"));
 }