public SLPClientConnector( INameResolverFactory <IAsymetricCrypt> asymetricCryptFactory, ISymetricCrypt symetric, ISerializerFactory serializeT, ILogger logger, IHash hash, IPersistentPrivateKeyProvider persistentPrivateKeyProvider, ICompression compression, ISecureProtocolHandshake secureProtocolHandshake, IClientConnector clientConnector, IOptions <SLJPOption> sljpOptions = null ) { this.asymetricForDecrypt = asymetricCryptFactory.Resolve(); this.asymetricToEncrypt = asymetricCryptFactory.Resolve(); this.firstAsymetricHandshakeToDecrypt = asymetricCryptFactory.Resolve(); this.firstAsymetricHandshakeToEncrypt = asymetricCryptFactory.Resolve(); this.textPlainTCPChannel = clientConnector; this.symetric = symetric; this.serializeT = serializeT.Resolve(SerializerType.Json); this.logger = logger; this.hash = hash; this.IPersistentPrivateKeyProvider = persistentPrivateKeyProvider; this.compression = compression; this.secureProtocolHandshake = secureProtocolHandshake; var SecurityMaxSizeToReceive = sljpOptions.Value.SecurityMaxSizeToReceive; this.sljpOptions = sljpOptions.Value ?? new SLJPOption(); }
public void Connect(IPAddress ipAddress, int port) { this.textPlainTCPChannel.Connect(ipAddress, port); //Read a persistent private key or create a new //TODO: See for domain name server rather than ip. var ppk = this.IPersistentPrivateKeyProvider.Read(ipAddress.ToString(), port); PublicKey publicKeyToSend = null; if (ppk == null)//New key to generate in server. { this.asymetricForDecrypt.GenerateKeys(); this.thisPrivateKey = this.asymetricForDecrypt.GetPrivateKey();//To Decrypt Server Messages publicKeyToSend = asymetricForDecrypt.GetPublicKey(); } else //Using existing key. { publicKeyToSend = new PublicKey { yExponent = ppk.PrivateKey.yExponent, yModulus = ppk.PrivateKey.yModulus }; this.thisPrivateKey = ppk.PrivateKey; } bool IsKeyFound = ppk != null; SendPublicKey(publicKeyToSend, IsKeyFound, false); //Should receive the public key this.Receive(littleBuffer, 0, littleBuffer.Length); //if (ppk == null)//No save yet { PersistentPrivateKey ppkNew = new PersistentPrivateKey { Port = port, Server = ipAddress.ToString(), PrivateKey = this.thisPrivateKey, PublicKeyRemote = this.remotePublicKey, FromServer = false }; IPersistentPrivateKeyProvider.Save(ppkNew); } }