private static void ExchangeKeys(object state) { byte num = 0; KeyExchangeParameter parameter = (KeyExchangeParameter)state; DiffieHellmanKeyExchange exchange = null; try { exchange = new DiffieHellmanKeyExchange(); num = 1; exchange.DeriveSharedKey(parameter.ClientPublicKey); parameter.PublicKey = exchange.PublicKey; parameter.SharedKey = exchange.SharedKey; } catch (ThreadAbortException) { if (log.IsWarnEnabled) { string message = string.Format("Key exchange was aborted\r\nstep={0}\r\nClientKey={1}", num, (parameter.ClientPublicKey == null) ? "{null}" : BitConverter.ToString(parameter.ClientPublicKey)); if (exchange != null) { message = message + string.Format("\r\nSecret={0}\r\nPrime={1}\r\nPublicKey={2}\r\nSharedKey={3}", new object[] { (exchange.Secret == null) ? "{null}" : exchange.Secret.ToString(), (exchange.Prime == null) ? "{null}" : exchange.Prime.ToString(), (exchange.PublicKey == null) ? "{null}" : BitConverter.ToString(exchange.PublicKey), (exchange.SharedKey == null) ? "{null}" : BitConverter.ToString(exchange.SharedKey) }); } log.Warn(message); } } }
/// <summary> /// Initializes the peer to receive and send encrypted operations. /// </summary> /// <returns> /// Returns <see cref="F:Photon.SocketServer.SendResult.Ok"/> if the event was successfully sent; /// otherwise an error value. See <see cref="T:Photon.SocketServer.SendResult"/> for more information. /// </returns> public SendResult InitializeEncryption() { this.keyExchange = new DiffieHellmanKeyExchange(); OperationRequest request2 = new OperationRequest { OperationCode = 0 }; Dictionary <byte, object> dictionary = new Dictionary <byte, object>(2); dictionary.Add(1, this.keyExchange.PublicKey); dictionary.Add(2, (byte)0); request2.Parameters = dictionary; OperationRequest request = request2; return(this.SendInternalOperationRequest(request)); }
protected virtual TlsServerKeyExchange GenerateServerKeyExchange() { if (PendingCrypto.Cipher.ExchangeAlgorithmType == ExchangeAlgorithmType.RsaSign) { HandshakeParameters.KeyExchange = new RSAKeyExchange(); return(null); } else if (PendingCrypto.Cipher.ExchangeAlgorithmType != ExchangeAlgorithmType.DiffieHellman) { throw new InvalidOperationException(); } var signatureType = SelectSignatureAlgorithm(); var dh = DiffieHellmanKeyExchange.Create(Context, signatureType); HandshakeParameters.KeyExchange = dh; return(new TlsServerKeyExchange(dh)); }
protected virtual TlsServerKeyExchange GenerateServerKeyExchange () { if (PendingCrypto.Cipher.ExchangeAlgorithmType == ExchangeAlgorithmType.RsaSign) { HandshakeParameters.KeyExchange = new RSAKeyExchange (); return null; } else if (PendingCrypto.Cipher.ExchangeAlgorithmType != ExchangeAlgorithmType.DiffieHellman) { throw new InvalidOperationException (); } var dh = new DiffieHellmanKeyExchange (Context); HandshakeParameters.KeyExchange = dh; return new TlsServerKeyExchange (dh); }