Implements key support for host algorithm.
상속: HostAlgorithm
 /// <summary>
 /// Called when type specific data need to be loaded.
 /// </summary>
 protected override void LoadData()
 {
     base.LoadData();
     var ignored = this.ReadUInt32();
     this.Key = new KeyHostAlgorithm("ssh1", this.ReadRsaKey());
     this.Comment = this.ReadString();
 }
예제 #2
0
 [Ignore] // placeholder for actual test
 public void KeyHostAlgorithmConstructorTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     Key key = null; // TODO: Initialize to an appropriate value
     KeyHostAlgorithm target = new KeyHostAlgorithm(name, key);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
예제 #3
0
        public PrivateKeyAgentKey AddSsh1(KeyHostAlgorithm key, string comment)
        {
            if (!(key.Key is RsaKey))
            {
                throw new SshException("SSH1 keys can only be RSA keys.");
            }

            return Add(this.keysSsh1, key, comment);
        }
예제 #4
0
 public void DataTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     Key key = null; // TODO: Initialize to an appropriate value
     KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value
     byte[] actual;
     actual = target.Data;
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
예제 #5
0
        /// <summary>
        /// Determines whether the specified host key can be trusted.
        /// </summary>
        /// <param name="host">The host algorithm.</param>
        /// <returns>
        ///   <c>true</c> if the specified host can be trusted; otherwise, <c>false</c>.
        /// </returns>
        protected bool CanTrustHostKey(KeyHostAlgorithm host)
        {
            var args = new HostKeyEventArgs(host);

            if (this.HostKeyReceived != null)
            {
                this.HostKeyReceived(this, args);
            }

            return(args.CanTrust);
        }
 /// <summary>
 /// Called when type specific data need to be loaded.
 /// </summary>
 protected override void LoadData()
 {
     int count = (int)this.ReadUInt32();
     this.Keys = new List<PrivateKeyAgentKey>(count);
     for (int i = 0; i < count; i++)
     {
         var key = new KeyHostAlgorithm("", new RsaKey(), this.ReadBytes());
         string comment = this.ReadString();
         this.Keys.Add(new PrivateKeyAgentKey(key, comment));
     }
 }
예제 #7
0
 [Ignore] // placeholder for actual test
 public void SignTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     Key key = null; // TODO: Initialize to an appropriate value
     KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value
     byte[] data = null; // TODO: Initialize to an appropriate value
     byte[] expected = null; // TODO: Initialize to an appropriate value
     byte[] actual;
     actual = target.Sign(data);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostKeyEventArgs"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        public HostKeyEventArgs(KeyHostAlgorithm host)
        {
            this.CanTrust = true;   //  Set default value

            this.HostKey = host.Data;

            this.KeyLength = host.Key.KeyLength;

            var md5 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
            byte[] buffer;
            CryptographicBuffer.CopyToByteArray(md5.HashData(CryptographicBuffer.CreateFromByteArray(host.Data)), out buffer);
            this.FingerPrint = buffer;
        }
예제 #9
0
        /// <summary>
        /// Determines whether the specified host key can be trusted.
        /// </summary>
        /// <param name="host">The host algorithm.</param>
        /// <returns>
        /// <c>true</c> if the specified host can be trusted; otherwise, <c>false</c>.
        /// </returns>
        protected bool CanTrustHostKey(KeyHostAlgorithm host)
        {
            var handlers = HostKeyReceived;

            if (handlers != null)
            {
                var args = new HostKeyEventArgs(host);
                handlers(this, args);
                return(args.CanTrust);
            }

            return(true);
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostKeyEventArgs"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        public HostKeyEventArgs(KeyHostAlgorithm host)
        {
            this.CanTrust = true;   //  Set default value

            this.HostKey = host.Data;

            this.KeyLength = host.Key.KeyLength;

            using (var md5 = new MD5Hash())
            {
                this.FingerPrint = md5.ComputeHash(host.Data);
            }
        }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostKeyEventArgs"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        public HostKeyEventArgs(KeyHostAlgorithm host)
        {
            CanTrust = true;   //  Set default value

            HostKey = host.Data;

            HostKeyName = host.Name;

            KeyLength = host.Key.KeyLength;

            using (var md5 = CryptoAbstraction.CreateMD5())
            {
                FingerPrint = md5.ComputeHash(host.Data);
            }
        }
예제 #12
0
        /// <summary>
        /// Called when type specific data need to be loaded.
        /// </summary>
        protected override void LoadData()
        {
            base.LoadData();
            var keyType = this.ReadString();
            switch (keyType)
            {
                case "ssh-rsa":
                    this.Key = new KeyHostAlgorithm(keyType, this.ReadRsaKey());
                    break;
                case "ssh-dss":
                    this.Key = new KeyHostAlgorithm(keyType, this.ReadDsaKey());
                    break;
                default:
                    throw new SshException("Private key type '" + keyType + "' is not supported.");
            }

            this.Comment = this.ReadString();
        }
예제 #13
0
 public PrivateKeyAgentKey(KeyHostAlgorithm key, string comment)
 {
     this.Key = key;
     this.Comment = comment;
 }
예제 #14
0
        /// <summary>
        /// Determines whether the specified host key can be trusted.
        /// </summary>
        /// <param name="host">The host algorithm.</param>
        /// <returns>
        ///   <c>true</c> if the specified host can be trusted; otherwise, <c>false</c>.
        /// </returns>
        protected bool CanTrustHostKey(KeyHostAlgorithm host)
        {
            var args = new HostKeyEventArgs(host);

            if (this.HostKeyReceived != null)
            {
                this.HostKeyReceived(this, args);
            }

            return args.CanTrust;
        }
예제 #15
0
        /// <summary>
        /// Determines whether the specified host key can be trusted.
        /// </summary>
        /// <param name="host">The host algorithm.</param>
        /// <returns>
        /// <c>true</c> if the specified host can be trusted; otherwise, <c>false</c>.
        /// </returns>
        protected bool CanTrustHostKey(KeyHostAlgorithm host)
        {
            var handlers = HostKeyReceived;
            if (handlers != null)
            {
                var args = new HostKeyEventArgs(host);
                handlers(this, args);
                return args.CanTrust;
            }

            return true;
        }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoveIdentityMessage"/> class.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 /// <param name="username">Authentication username.</param>
 /// <param name="keyAlgorithmName">Name of private key algorithm.</param>
 /// <param name="keyData">Private key data.</param>
 public AddIdentityMessage(KeyHostAlgorithm key, string comment)
 {
     this.Key = key;
     this.Comment = comment;
 }
예제 #17
0
        private static PrivateKeyAgentKey Add(List<PrivateKeyAgentKey> keys, KeyHostAlgorithm key, string comment)
        {
            var existingKey = GetKey(keys, key.Data);
            if (existingKey != null)
            {
                return null;
            }

            var agentKey = new PrivateKeyAgentKey(key, comment);
            keys.Add(agentKey);
            return agentKey;
        }
예제 #18
0
 public PrivateKeyAgentKey AddSsh2(KeyHostAlgorithm key, string comment)
 {
     return Add(this.keysSsh2, key, comment);
 }