protected void SendMsgUserAuthInfoRequest(string name, string instruction, IList <AuthenticationPrompt> prompts) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.InfoRequest); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(name)); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(instruction)); msgWriter.Write(""); // language tag (deprecated) msgWriter.Write(prompts.Count); // Write info for each prompt. foreach (var prompt in prompts) { msgWriter.WriteByteString(Encoding.UTF8.GetBytes(prompt.Prompt)); msgWriter.Write(prompt.Echo); } _client.SendPacket <SshAuthenticationMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelExtendedData(SshChannel channel, SshExtendedDataType dataType, byte[] data) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Check if data is too large to send. if (data.Length > Math.Min(channel.MaxPacketSize, channel.WindowSize)) { throw new InvalidOperationException("Data is too large to send in one packet."); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelExtendedData); msgWriter.Write(channel.ClientChannel); msgWriter.Write((uint)dataType); msgWriter.WriteByteString(data); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
protected bool VerifyPublicKeySignature(PublicKeyAlgorithm alg, byte[] payload, int payloadOffset, int payloadCount, byte[] signature) { using (var hashInputStream = new MemoryStream()) using (var hashInputWriter = new SshStreamWriter(hashInputStream)) { // Write input data. hashInputWriter.WriteByteString(_client.SessionId); hashInputWriter.Write(payload, payloadOffset, payloadCount); // Verify signature. return(alg.VerifyData(hashInputStream.ToArray(), signature)); } }
internal void SendMsgRequestFailure() { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.RequestFailure); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthSuccess() { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.Success); _client.SendPacket <SshAuthenticationMessage>(msgStream.ToArray()); } }
public byte[] CreateSignatureData(byte[] data) { using (var dataStream = new MemoryStream()) { using (var dataWriter = new SshStreamWriter(dataStream)) { // Create signature from hash data. var signature = SignData(data); // Write signature to stream. dataWriter.Write(this.Name); dataWriter.WriteByteString(signature); } return(dataStream.ToArray()); } }
internal void SendMsgChannelSuccess(SshChannel channel) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelSuccess); msgWriter.Write(channel.ClientChannel); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
public byte[] CreateSignatureData(byte[] data) { using (var dataStream = new MemoryStream()) { using (var dataWriter = new SshStreamWriter(dataStream)) { // Create signature from hash data. var signature = SignData(data); // Write signature to stream. dataWriter.Write(this.Name); dataWriter.WriteByteString(signature); } return dataStream.ToArray(); } }
protected void SendMsgUserAuthFailure(bool partialSuccess) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.Failure); msgWriter.WriteNameList(this.AllowedAuthMethods.GetSshNames()); msgWriter.Write(partialSuccess); _client.SendPacket <SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthPasswdChangeReq(string prompt, string language) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.PasswordChangeRequired); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(prompt)); msgWriter.Write(language); _client.SendPacket <SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthPkOk(string algName, byte[] keyBlob) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.PublicKeyOk); // Write public key information. msgWriter.Write(algName); msgWriter.WriteByteString(keyBlob); _client.SendPacket <SshAuthenticationMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelRequest(SshChannel channel, string requestType, bool wantReply, byte[] requestData) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelRequest); msgWriter.Write(channel.ClientChannel); msgWriter.Write(requestType); msgWriter.Write(wantReply); msgWriter.Write(requestData); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelOpenFailure(SshChannel channel, SshChannelOpenFailureReason reason, string description, string language) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelOpenFailure); msgWriter.Write(channel.ClientChannel); msgWriter.Write((uint)reason); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(description)); msgWriter.Write(language); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgGlobalRequest(string requestName, bool wantReply, byte[] data) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.GlobalRequest); msgWriter.Write(requestName); msgWriter.Write(wantReply); if (data != null) { msgWriter.Write(data); } _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelOpenConfirmation(SshChannel channel) { if (_isDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelOpenConfirmation); msgWriter.Write(channel.ClientChannel); msgWriter.Write(channel.ServerChannel); msgWriter.Write(channel.WindowSize); msgWriter.Write(channel.MaxPacketSize); // Write channel-specific data. channel.WriteChannelOpenConfirmationData(); _client.SendPacket <SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelExtendedData(SshChannel channel, SshExtendedDataType dataType, byte[] data) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Check if data is too large to send. if (data.Length > Math.Min(channel.MaxPacketSize, channel.WindowSize)) throw new InvalidOperationException("Data is too large to send in one packet."); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelExtendedData); msgWriter.Write(channel.ClientChannel); msgWriter.Write((uint)dataType); msgWriter.WriteByteString(data); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
protected bool VerifyPublicKeySignature(PublicKeyAlgorithm alg, byte[] payload, int payloadOffset, int payloadCount, byte[] signature) { using (var hashInputStream = new MemoryStream()) using (var hashInputWriter = new SshStreamWriter(hashInputStream)) { // Write input data. hashInputWriter.WriteByteString(_client.SessionId); hashInputWriter.Write(payload, payloadOffset, payloadCount); // Verify signature. return alg.VerifyData(hashInputStream.ToArray(), signature); } }
protected void SendMsgUserAuthSuccess() { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.Success); _client.SendPacket<SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthPkOk(string algName, byte[] keyBlob) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.PublicKeyOk); // Write public key information. msgWriter.Write(algName); msgWriter.WriteByteString(keyBlob); _client.SendPacket<SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthPasswdChangeReq(string prompt, string language) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.PasswordChangeRequired); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(prompt)); msgWriter.Write(language); _client.SendPacket<SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthInfoRequest(string name, string instruction, IList<AuthenticationPrompt> prompts) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.InfoRequest); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(name)); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(instruction)); msgWriter.Write(""); // language tag (deprecated) msgWriter.Write(prompts.Count); // Write info for each prompt. foreach (var prompt in prompts) { msgWriter.WriteByteString(Encoding.UTF8.GetBytes(prompt.Prompt)); msgWriter.Write(prompt.Echo); } _client.SendPacket<SshAuthenticationMessage>(msgStream.ToArray()); } }
protected void SendMsgUserAuthFailure(bool partialSuccess) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshAuthenticationMessage.Failure); msgWriter.WriteNameList(this.AllowedAuthMethods.GetSshNames()); msgWriter.Write(partialSuccess); _client.SendPacket<SshAuthenticationMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelOpenFailure(SshChannel channel, SshChannelOpenFailureReason reason, string description, string language) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelOpenFailure); msgWriter.Write(channel.ClientChannel); msgWriter.Write((uint)reason); msgWriter.WriteByteString(Encoding.UTF8.GetBytes(description)); msgWriter.Write(language); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelRequest(SshChannel channel, string requestType, bool wantReply, byte[] requestData) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelRequest); msgWriter.Write(channel.ClientChannel); msgWriter.Write(requestType); msgWriter.Write(wantReply); msgWriter.Write(requestData); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelWindowAdjust(SshChannel channel, uint bytesToAdd) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelWindowAdjust); msgWriter.Write(channel.ClientChannel); msgWriter.Write(bytesToAdd); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgChannelOpenConfirmation(SshChannel channel) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.ChannelOpenConfirmation); msgWriter.Write(channel.ClientChannel); msgWriter.Write(channel.ServerChannel); msgWriter.Write(channel.WindowSize); msgWriter.Write(channel.MaxPacketSize); // Write channel-specific data. channel.WriteChannelOpenConfirmationData(); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgGlobalRequest(string requestName, bool wantReply, byte[] data) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.GlobalRequest); msgWriter.Write(requestName); msgWriter.Write(wantReply); if (data != null) msgWriter.Write(data); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }
internal void SendMsgRequestSuccess(byte[] data) { if (_isDisposed) throw new ObjectDisposedException(this.GetType().FullName); // Create message to send. using (var msgStream = new MemoryStream()) using (var msgWriter = new SshStreamWriter(msgStream)) { msgWriter.Write((byte)SshConnectionMessage.RequestSuccess); if (data != null) msgWriter.Write(data); _client.SendPacket<SshConnectionMessage>(msgStream.ToArray()); } }