示例#1
0
        public void TestDeserializeRsaPublicKeyCert()
        {
            var keyFile   = Resources.rsa_1_cert_pub;
            var formatter = new OpensshPublicKeyFormatter();
            var key       = formatter.Deserialize(keyFile);

            Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
            Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.SSH_RSA_CERT_V1));
            var publicKey = (RsaKeyParameters)key.GetPublicKeyParameters();
            var param_n   = new BigInteger(Resources.rsa_1_param_n.Trim(), 16);

            Assert.That(publicKey.Modulus, Is.EqualTo(param_n));
            var fp = FormatFingerprint(key.GetMD5Fingerprint());

            Assert.That(fp, Is.EqualTo(Resources.rsa_1_cert_fp.Trim()));

            var certSigningKey = (Ed25519PublicKeyParameter)key.Certificate.SignatureKey;
            var param_pub      = new BigInteger(Resources.ed25519_1_param_pub.Trim(), 16);
            var k = new BigInteger(1, certSigningKey.Key);

            Assert.That(k, Is.EqualTo(param_pub));
            Assert.That(key.Certificate.Type, Is.EqualTo(Ssh2CertType.Host));
            Assert.That(key.Certificate.KeyId, Is.EqualTo("julius"));
            Assert.That(key.Certificate.Principals, Is.EquivalentTo(new[] { "host1", "host2" }));
            Assert.That(key.Certificate.ValidAfter, Is.EqualTo(new DateTime(1999, 1, 1).AddHours(-10)));
            Assert.That(key.Certificate.ValidBefore, Is.EqualTo(new DateTime(2011, 1, 1).AddHours(-10)));
            Assert.That(key.Certificate.Serial, Is.EqualTo(5));
        }
示例#2
0
        public void TestDeserializeEcdsaPublicKeyCert()
        {
            var keyFile   = Resources.ecdsa_1_cert_pub;
            var formatter = new OpensshPublicKeyFormatter();
            var key       = formatter.Deserialize(keyFile);

            Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
            Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.ECDSA_SHA2_NISTP256_CERT_V1));
            var publicKey = (ECPublicKeyParameters)key.GetPublicKeyParameters();
            var param_pub = new BigInteger(Resources.ecdsa_1_param_pub.Trim(), 16);
            var q         = new BigInteger(publicKey.Q.GetEncoded());

            Assert.That(q, Is.EqualTo(param_pub));
            var fp = FormatFingerprint(key.GetMD5Fingerprint());

            Assert.That(fp, Is.EqualTo(Resources.ecdsa_1_fp.Trim()));

            var certSigningKey = (ECPublicKeyParameters)key.Certificate.SignatureKey;
            var q2             = new BigInteger(certSigningKey.Q.GetEncoded());

            Assert.That(q2, Is.EqualTo(param_pub));
            Assert.That(key.Certificate.Type, Is.EqualTo(Ssh2CertType.Host));
            Assert.That(key.Certificate.KeyId, Is.EqualTo("julius"));
            Assert.That(key.Certificate.Principals, Is.EquivalentTo(new[] { "host1", "host2" }));
            Assert.That(key.Certificate.ValidAfter, Is.EqualTo(new DateTime(1999, 1, 1).AddHours(-10)));
            Assert.That(key.Certificate.ValidBefore, Is.EqualTo(new DateTime(2011, 1, 1).AddHours(-10)));
            Assert.That(key.Certificate.Serial, Is.EqualTo(7));
        }
示例#3
0
        public void TestDeserializeDsaPublicKey()
        {
            var keyFile   = Resources.dsa_1_pub;
            var formatter = new OpensshPublicKeyFormatter();
            var key       = formatter.Deserialize(keyFile);

            Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
            Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.SSH_DSS));
            var publicKey = (DsaPublicKeyParameters)key.GetPublicKeyParameters();
            var param_pub = new BigInteger(Resources.dsa_1_param_pub.Trim(), 16);

            Assert.That(publicKey.Y, Is.EqualTo(param_pub));
            var fp = FormatFingerprint(key.GetMD5Fingerprint());

            Assert.That(fp, Is.EqualTo(Resources.dsa_1_fp.Trim()));
        }
示例#4
0
        public void TestDeserializeEd25519PublicKey2()
        {
            var keyFile   = Resources.ed25519_2_pub;
            var formatter = new OpensshPublicKeyFormatter();
            var key       = formatter.Deserialize(keyFile);

            Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
            Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.ED25519));
            var publicKey = (Ed25519PublicKeyParameter)key.GetPublicKeyParameters();
            var param_pub = new BigInteger(Resources.ed25519_2_param_pub.Trim(), 16);
            var k         = new BigInteger(1, publicKey.Key);

            Assert.That(k, Is.EqualTo(param_pub));
            var fp = FormatFingerprint(key.GetMD5Fingerprint());

            Assert.That(fp, Is.EqualTo(Resources.ed25519_2_fp.Trim()));
        }
示例#5
0
        public void TestDeserializeEcdsaPublicKey2()
        {
            var keyFile   = Resources.ecdsa_2_pub;
            var formatter = new OpensshPublicKeyFormatter();
            var key       = formatter.Deserialize(keyFile);

            Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
            Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.ECDSA_SHA2_NISTP521));
            var publicKey = (ECPublicKeyParameters)key.GetPublicKeyParameters();
            var param_pub = new BigInteger(Resources.ecdsa_2_param_pub.Trim(), 16);
            var q         = new BigInteger(publicKey.Q.GetEncoded());

            Assert.That(q, Is.EqualTo(param_pub));
            var fp = FormatFingerprint(key.GetMD5Fingerprint());

            Assert.That(fp, Is.EqualTo(Resources.ecdsa_2_fp.Trim()));
        }