Ejemplo n.º 1
0
        public void To(AgentWriter writer)
        {
            using var signStream = new MemoryStream();
            using var signWriter = new AgentWriter(signStream);
            signWriter.EncodeString(_key.KeyData);
            signWriter.EncodeString(_data);
            signWriter.Write((uint)0);
            var signData = signStream.ToArray();

            writer.Write((uint)(1 + signData.Length));
            writer.Write((byte)AgentMessageType.SSH2_AGENTC_SIGN_REQUEST);
            writer.Write(signData);
        }
Ejemplo n.º 2
0
        public void To(AgentWriter writer)
        {
            using var keyStream = new MemoryStream();
            using var keyWriter = new AgentWriter(keyStream);

            var key = ((KeyHostAlgorithm)_keyFile.HostKey).Key;

            keyWriter.EncodeString(key.ToString());
            switch (key.ToString())
            {
            case "ssh-ed25519":
                var ed25519 = (ED25519Key)key;
                keyWriter.EncodeBignum2(ed25519.PublicKey);
                keyWriter.EncodeBignum2(ed25519.PrivateKey);
                break;

            case "ssh-rsa":
                var rsa = (RsaKey)key;
                keyWriter.EncodeBignum2(rsa.Modulus.ToByteArray().Reverse());
                keyWriter.EncodeBignum2(rsa.Exponent.ToByteArray().Reverse());
                keyWriter.EncodeBignum2(rsa.D.ToByteArray().Reverse());
                keyWriter.EncodeBignum2(rsa.InverseQ.ToByteArray().Reverse());
                keyWriter.EncodeBignum2(rsa.P.ToByteArray().Reverse());
                keyWriter.EncodeBignum2(rsa.Q.ToByteArray().Reverse());
                break;

            case "ecdsa-sha2-nistp256":
            // Fallthrough
            case "ecdsa-sha2-nistp384":
            // Fallthrough
            case "ecdsa-sha2-nistp521":
                var ecdsa     = (EcdsaKey)key;
                var publicKey = ecdsa.Public;
                keyWriter.EncodeString(publicKey[0].ToByteArray().Reverse());
                keyWriter.EncodeString(publicKey[1].ToByteArray().Reverse());
                keyWriter.EncodeBignum2(ecdsa.PrivateKey.ToBigInteger2().ToByteArray().Reverse());
                break;
            }
            // comment
            keyWriter.EncodeString(key.Comment ?? "");
            var keyData = keyStream.ToArray();

            writer.Write((uint)(1 + keyData.Length));
            writer.Write((byte)AgentMessageType.SSH2_AGENTC_ADD_IDENTITY);
            writer.Write(keyData);
        }
Ejemplo n.º 3
0
        public void To(AgentWriter writer)
        {
            if (_agentKey is null)
            {
                writer.Write((uint)1);
                writer.Write((byte)AgentMessageType.SSH2_AGENTC_REMOVE_ALL_IDENTITIES);
                return;
            }

            using var keyStream = new MemoryStream();
            using var keyWriter = new AgentWriter(keyStream);
            keyWriter.EncodeString(_agentKey.KeyData);
            var keyData = keyStream.ToArray();

            writer.Write((uint)(1 + keyData.Length));
            writer.Write((byte)AgentMessageType.SSH2_AGENTC_REMOVE_IDENTITY);
            writer.Write(keyData);
        }