Ejemplo n.º 1
0
        private void Authenticate(string method)
        {
            IPacket request;

            identity = method == "publickey" && keyfiles != null && keyfiles.Length > 0 && currentkey < keyfiles.Length ?
                       IdentityFile.Create(keyfiles[currentkey++]) : null;

            if (identity != null && session.PassphraseFunction != null)
            {
                identity.PassphraseFunction = session.PassphraseFunction;
            }

            if (method == "publickey")
            {
                request = new SshUserAuthRequestPublicKey(session.Username, identity);
            }
            else if (method == "password")
            {
                request = new SshUserAuthRequestPassword(session.Username, session.Password);
            }
            else
            {
                request = new SshUserAuthRequest(session.Username);
            }

            session.Socket.WritePacket(request);
        }
 public SshUserAuthRequestPublicKey(string username, IIdentityFile identity)
     : this()
 {
     Username      = username;
     Method        = "publickey";
     AlgorithmName = identity.AlgorithmName;
     PublicKey     = identity.PublicKey;
 }
Ejemplo n.º 3
0
        public SshUserAuthRequestSignature(string username, IIdentityFile identity, byte[] sessionId)
            : base(username, identity)
        {
            var buffer = SshUserAuthRequestPublicKey.CreateForSignature(username, identity).ToSshMessage();

            using (var pw1 = new PacketWriter())
            {
                pw1.WriteString(sessionId);
                pw1.Write(buffer);
                using (var pw2 = new PacketWriter())
                {
                    pw2.WriteBytes(identity.AlgorithmName);
                    pw2.WriteString(identity.Sign(((MemoryStream)pw1.BaseStream).ToArray()));
                    Signature = ((MemoryStream)pw2.BaseStream).ToArray();
                }
            }
        }
        internal static SshUserAuthRequestPublicKey CreateForSignature(string username, IIdentityFile identity)
        {
            var p = new SshUserAuthRequestPublicKey(username, identity)
            {
                SignatureIncluded = true
            };

            return(p);
        }
Ejemplo n.º 5
0
 public static SecureString ConsolePassphraseFunction(IIdentityFile identity)
 {
     return(ConsolePrompt("Passphrase: ", true));
 }