//Renci.SshNet.Security.Cryptography.Ciphers.AesCipher; public static void test1() { //var cinfo = new CipherInfo(256, (key, iv) => new Ciphers.AesCipher(key, new CtrCipherMode(iv), null)); var cinfo = new CipherInfo(256, delegate(byte[] key, byte[] iv){ return(new crypto::Ciphers.AesCipher(key, new crypto::Ciphers.Modes.CtrCipherMode(iv), null)); }); }
[Ignore] // placeholder public void CipherInfoConstructorTest() { int keySize = 0; // TODO: Initialize to an appropriate value Func<byte[], byte[], Cipher> cipher = null; // TODO: Initialize to an appropriate value CipherInfo target = new CipherInfo(keySize, cipher); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void CipherInfoConstructorTest() { int keySize = 0; // TODO: Initialize to an appropriate value Func <byte[], byte[], BlockCipher> cipher = null; // TODO: Initialize to an appropriate value CipherInfo target = new CipherInfo(keySize, cipher); Assert.Inconclusive("TODO: Implement code to verify target"); }
public StreamCrypto(string method, string password) : base(method, password) { CipherInfo = GetCiphers()[method.ToLower()]; cipherFamily = CipherInfo.Type; StreamCipherParameter parameter = (StreamCipherParameter)CipherInfo.CipherParameter; keyLen = parameter.KeySize; ivLen = parameter.IvSize; InitKey(password); logger.Dump($"key {instanceId}", key, keyLen); }
public StreamCrypto(string method, string password) : base(method, password) { CipherInfo = GetCiphers()[method.ToLower()]; cipherFamily = CipherInfo.Type; StreamCipherParameter parameter = (StreamCipherParameter)CipherInfo.CipherParameter; keyLen = parameter.KeySize; ivLen = parameter.IvSize; InitKey(password); this.Log().Debug($"key {instanceId} {key} {keyLen}"); }
public AEADCrypto(string method, string password) : base(method, password) { CipherInfo = GetCiphers()[method.ToLower()]; cipherFamily = CipherInfo.Type; AEADCipherParameter parameter = (AEADCipherParameter)CipherInfo.CipherParameter; keyLen = parameter.KeySize; saltLen = parameter.SaltSize; tagLen = parameter.TagSize; nonceLen = parameter.NonceSize; InitKey(password); salt = new byte[saltLen]; // Initialize all-zero nonce for each connection nonce = new byte[nonceLen]; this.Log().Debug($"masterkey {instanceId} {masterKey} {keyLen}"); this.Log().Debug($"nonce {instanceId} {nonce} {keyLen}"); }
/// <summary> /// Starts key exchange algorithm /// </summary> /// <param name="session">The session.</param> /// <param name="message">Key exchange init message.</param> public virtual void Start(Session session, KeyExchangeInitMessage message) { this.Session = session; this.SendMessage(session.ClientInitMessage); // Determine encryption algorithm var clientEncryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys from a in message.EncryptionAlgorithmsClientToServer where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(clientEncryptionAlgorithmName)) { throw new SshConnectionException("Client encryption algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientEncryption = clientEncryptionAlgorithmName; // Determine encryption algorithm var serverDecryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys from a in message.EncryptionAlgorithmsServerToClient where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(serverDecryptionAlgorithmName)) { throw new SshConnectionException("Server decryption algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerEncryption = serverDecryptionAlgorithmName; // Determine client hmac algorithm var clientHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys from a in message.MacAlgorithmsClientToServer where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(clientHmacAlgorithmName)) { throw new SshConnectionException("Client HMAC algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientHmacAlgorithm = clientHmacAlgorithmName; // Determine server hmac algorithm var serverHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys from a in message.MacAlgorithmsServerToClient where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(serverHmacAlgorithmName)) { throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerHmacAlgorithm = serverHmacAlgorithmName; // Determine compression algorithm var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys from a in message.CompressionAlgorithmsClientToServer where a == b select a).LastOrDefault(); if (string.IsNullOrEmpty(compressionAlgorithmName)) { throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientCompressionAlgorithm = compressionAlgorithmName; // Determine decompression algorithm var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys from a in message.CompressionAlgorithmsServerToClient where a == b select a).LastOrDefault(); if (string.IsNullOrEmpty(decompressionAlgorithmName)) { throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerCompressionAlgorithm = decompressionAlgorithmName; this._clientCipherInfo = session.ConnectionInfo.Encryptions[clientEncryptionAlgorithmName]; this._serverCipherInfo = session.ConnectionInfo.Encryptions[clientEncryptionAlgorithmName]; this._cientHmacAlgorithmType = session.ConnectionInfo.HmacAlgorithms[clientHmacAlgorithmName]; this._serverHmacAlgorithmType = session.ConnectionInfo.HmacAlgorithms[serverHmacAlgorithmName]; this._compressionType = session.ConnectionInfo.CompressionAlgorithms[compressionAlgorithmName]; this._decompressionType = session.ConnectionInfo.CompressionAlgorithms[decompressionAlgorithmName]; }
/// <summary> /// Starts key exchange algorithm /// </summary> /// <param name="session">The session.</param> /// <param name="message">Key exchange init message.</param> public virtual void Start(Session session, KeyExchangeInitMessage message) { this.Session = session; this.SendMessage(session.ClientInitMessage); // Determine encryption algorithm var clientEncryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys from a in message.EncryptionAlgorithmsClientToServer where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(clientEncryptionAlgorithmName)) { throw new SshConnectionException("Client encryption algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientEncryption = clientEncryptionAlgorithmName; // Determine encryption algorithm var serverDecryptionAlgorithmName = (from b in session.ConnectionInfo.Encryptions.Keys from a in message.EncryptionAlgorithmsServerToClient where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(serverDecryptionAlgorithmName)) { throw new SshConnectionException("Server decryption algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerEncryption = serverDecryptionAlgorithmName; // Determine client hmac algorithm var clientHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys from a in message.MacAlgorithmsClientToServer where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(clientHmacAlgorithmName)) { throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientHmacAlgorithm = clientHmacAlgorithmName; // Determine server hmac algorithm var serverHmacAlgorithmName = (from b in session.ConnectionInfo.HmacAlgorithms.Keys from a in message.MacAlgorithmsServerToClient where a == b select a).FirstOrDefault(); if (string.IsNullOrEmpty(serverHmacAlgorithmName)) { throw new SshConnectionException("Server HMAC algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerHmacAlgorithm = serverHmacAlgorithmName; // Determine compression algorithm var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys from a in message.CompressionAlgorithmsClientToServer where a == b select a).LastOrDefault(); if (string.IsNullOrEmpty(compressionAlgorithmName)) { throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentClientCompressionAlgorithm = compressionAlgorithmName; // Determine decompression algorithm var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys from a in message.CompressionAlgorithmsServerToClient where a == b select a).LastOrDefault(); if (string.IsNullOrEmpty(decompressionAlgorithmName)) { throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed); } session.ConnectionInfo.CurrentServerCompressionAlgorithm = decompressionAlgorithmName; this._clientCipherInfo = session.ConnectionInfo.Encryptions[clientEncryptionAlgorithmName]; this._serverCipherInfo = session.ConnectionInfo.Encryptions[serverDecryptionAlgorithmName]; this._clientHashInfo = session.ConnectionInfo.HmacAlgorithms[clientHmacAlgorithmName]; this._serverHashInfo = session.ConnectionInfo.HmacAlgorithms[serverHmacAlgorithmName]; this._compressionType = session.ConnectionInfo.CompressionAlgorithms[compressionAlgorithmName]; this._decompressionType = session.ConnectionInfo.CompressionAlgorithms[decompressionAlgorithmName]; }