public virtual void Connect(TlsClient tlsClient) { if (tlsClient == null) { throw new ArgumentNullException("tlsClient"); } if (this.mTlsClient != null) { throw new InvalidOperationException("'Connect' can only be called once"); } this.mTlsClient = tlsClient; base.mSecurityParameters = new SecurityParameters(); base.mSecurityParameters.entity = 1; this.mTlsClientContext = new TlsClientContextImpl(base.mSecureRandom, base.mSecurityParameters); base.mSecurityParameters.clientRandom = TlsProtocol.CreateRandomBlock(tlsClient.ShouldUseGmtUnixTime(), this.mTlsClientContext.NonceRandomGenerator); this.mTlsClient.Init(this.mTlsClientContext); base.mRecordStream.Init(this.mTlsClientContext); TlsSession sessionToResume = tlsClient.GetSessionToResume(); if ((sessionToResume != null) && sessionToResume.IsResumable) { SessionParameters parameters = sessionToResume.ExportSessionParameters(); if (parameters != null) { base.mTlsSession = sessionToResume; base.mSessionParameters = parameters; } } this.SendClientHelloMessage(); base.mConnectionState = 1; this.BlockForHandshake(); }
public virtual void Connect(TlsClient tlsClient) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (tlsClient == null) { throw new ArgumentNullException("tlsClient"); } if (mTlsClient != null) { throw new InvalidOperationException("'Connect' can only be called once"); } mTlsClient = tlsClient; mSecurityParameters = new SecurityParameters(); mSecurityParameters.entity = 1; mTlsClientContext = new TlsClientContextImpl(mSecureRandom, mSecurityParameters); mSecurityParameters.clientRandom = TlsProtocol.CreateRandomBlock(tlsClient.ShouldUseGmtUnixTime(), mTlsClientContext.NonceRandomGenerator); mTlsClient.Init(mTlsClientContext); mRecordStream.Init(mTlsClientContext); TlsSession sessionToResume = tlsClient.GetSessionToResume(); if (sessionToResume != null && sessionToResume.IsResumable) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null) { mTlsSession = sessionToResume; mSessionParameters = sessionParameters; } } SendClientHelloMessage(); mConnectionState = 1; BlockForHandshake(); }
protected virtual void CompleteHandshake() { try { while (this.mConnectionState != 16) { bool arg_0A_0 = this.mClosed; this.SafeReadRecord(); } this.mRecordStream.FinaliseHandshake(); this.mSplitApplicationDataRecords = !TlsUtilities.IsTlsV11(this.Context); if (!this.mAppDataReady) { this.mAppDataReady = true; this.mTlsStream = new TlsStream(this); } if (this.mTlsSession != null) { if (this.mSessionParameters == null) { this.mSessionParameters = new SessionParameters.Builder().SetCipherSuite(this.mSecurityParameters.CipherSuite).SetCompressionAlgorithm(this.mSecurityParameters.CompressionAlgorithm).SetMasterSecret(this.mSecurityParameters.MasterSecret).SetPeerCertificate(this.mPeerCertificate).SetPskIdentity(this.mSecurityParameters.PskIdentity).SetSrpIdentity(this.mSecurityParameters.SrpIdentity).SetServerExtensions(this.mServerExtensions).Build(); this.mTlsSession = new TlsSessionImpl(this.mTlsSession.SessionID, this.mSessionParameters); } this.ContextAdmin.SetResumableSession(this.mTlsSession); } this.Peer.NotifyHandshakeComplete(); } finally { this.CleanupHandshake(); } }
protected virtual void CompleteHandshake() { try { mRecordStream.FinaliseHandshake(); mSplitApplicationDataRecords = !TlsUtilities.IsTlsV11(Context); if (!mAppDataReady) { mAppDataReady = true; if (mBlocking) { mTlsStream = new TlsStream(this); } } if (mTlsSession != null) { if (mSessionParameters == null) { mSessionParameters = new SessionParameters.Builder().SetCipherSuite(mSecurityParameters.CipherSuite).SetCompressionAlgorithm(mSecurityParameters.CompressionAlgorithm).SetMasterSecret(mSecurityParameters.MasterSecret) .SetPeerCertificate(mPeerCertificate) .SetPskIdentity(mSecurityParameters.PskIdentity) .SetSrpIdentity(mSecurityParameters.SrpIdentity) .SetServerExtensions(mServerExtensions) .Build(); mTlsSession = new TlsSessionImpl(mTlsSession.SessionID, mSessionParameters); } ContextAdmin.SetResumableSession(mTlsSession); } Peer.NotifyHandshakeComplete(); } finally { CleanupHandshake(); } }
public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport) { if (client == null) { throw new ArgumentNullException("client"); } if (transport == null) { throw new ArgumentNullException("transport"); } SecurityParameters securityParameters = new SecurityParameters(); securityParameters.entity = ConnectionEnd.client; ClientHandshakeState state = new ClientHandshakeState(); state.client = client; state.clientContext = new TlsClientContextImpl(mSecureRandom, securityParameters); securityParameters.clientRandom = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(), state.clientContext.NonceRandomGenerator); client.Init(state.clientContext); DtlsRecordLayer recordLayer = new DtlsRecordLayer(transport, state.clientContext, client, ContentType.handshake); TlsSession sessionToResume = state.client.GetSessionToResume(); if (sessionToResume != null) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null) { state.tlsSession = sessionToResume; state.sessionParameters = sessionParameters; } } try { return(ClientHandshake(state, recordLayer)); } catch (TlsFatalAlert fatalAlert) { recordLayer.Fail(fatalAlert.AlertDescription); throw fatalAlert; } catch (IOException e) { recordLayer.Fail(AlertDescription.internal_error); throw e; } catch (Exception e) { recordLayer.Fail(AlertDescription.internal_error); throw new TlsFatalAlert(AlertDescription.internal_error, e); } }
protected virtual void CompleteHandshake() { try { /* * We will now read data, until we have completed the handshake. */ while (this.mConnectionState != CS_END) { if (this.mClosed) { // TODO What kind of exception/alert? } SafeReadRecord(); } this.mRecordStream.FinaliseHandshake(); this.mSplitApplicationDataRecords = !TlsUtilities.IsTlsV11(Context); /* * If this was an initial handshake, we are now ready to send and receive application data. */ if (!mAppDataReady) { this.mAppDataReady = true; this.mTlsStream = new TlsStream(this); } if (this.mTlsSession != null) { if (this.mSessionParameters == null) { this.mSessionParameters = new SessionParameters.Builder() .SetCipherSuite(this.mSecurityParameters.CipherSuite) .SetCompressionAlgorithm(this.mSecurityParameters.CompressionAlgorithm) .SetMasterSecret(this.mSecurityParameters.MasterSecret) .SetPeerCertificate(this.mPeerCertificate) .SetPskIdentity(this.mSecurityParameters.PskIdentity) .SetSrpIdentity(this.mSecurityParameters.SrpIdentity) // TODO Consider filtering extensions that aren't relevant to resumed sessions .SetServerExtensions(this.mServerExtensions) .Build(); this.mTlsSession = new TlsSessionImpl(this.mTlsSession.SessionID, this.mSessionParameters); } ContextAdmin.SetResumableSession(this.mTlsSession); } Peer.NotifyHandshakeComplete(); } finally { CleanupHandshake(); } }
public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown if (client == null) { throw new ArgumentNullException("client"); } if (transport == null) { throw new ArgumentNullException("transport"); } SecurityParameters securityParameters = new SecurityParameters(); securityParameters.entity = 1; ClientHandshakeState clientHandshakeState = new ClientHandshakeState(); clientHandshakeState.client = client; clientHandshakeState.clientContext = new TlsClientContextImpl(mSecureRandom, securityParameters); securityParameters.clientRandom = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(), clientHandshakeState.clientContext.NonceRandomGenerator); client.Init(clientHandshakeState.clientContext); DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, clientHandshakeState.clientContext, client, 22); TlsSession sessionToResume = clientHandshakeState.client.GetSessionToResume(); if (sessionToResume != null && sessionToResume.IsResumable) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null) { clientHandshakeState.tlsSession = sessionToResume; clientHandshakeState.sessionParameters = sessionParameters; } } try { return(ClientHandshake(clientHandshakeState, dtlsRecordLayer)); } catch (TlsFatalAlert tlsFatalAlert) { dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription); throw tlsFatalAlert; } catch (IOException val) { IOException val2 = val; dtlsRecordLayer.Fail(80); throw val2; } catch (global::System.Exception alertCause) { dtlsRecordLayer.Fail(80); throw new TlsFatalAlert(80, alertCause); } }
public virtual DtlsTransport Connect(TlsClient client, DatagramTransport transport) { if (client == null) { throw new ArgumentNullException("client"); } if (transport == null) { throw new ArgumentNullException("transport"); } SecurityParameters securityParameters = new SecurityParameters(); securityParameters.entity = 1; DtlsClientProtocol.ClientHandshakeState clientHandshakeState = new DtlsClientProtocol.ClientHandshakeState(); clientHandshakeState.client = client; clientHandshakeState.clientContext = new TlsClientContextImpl(this.mSecureRandom, securityParameters); securityParameters.clientRandom = TlsProtocol.CreateRandomBlock(client.ShouldUseGmtUnixTime(), clientHandshakeState.clientContext.NonceRandomGenerator); client.Init(clientHandshakeState.clientContext); DtlsRecordLayer dtlsRecordLayer = new DtlsRecordLayer(transport, clientHandshakeState.clientContext, client, 22); TlsSession sessionToResume = clientHandshakeState.client.GetSessionToResume(); if (sessionToResume != null && sessionToResume.IsResumable) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null) { clientHandshakeState.tlsSession = sessionToResume; clientHandshakeState.sessionParameters = sessionParameters; } } DtlsTransport result; try { result = this.ClientHandshake(clientHandshakeState, dtlsRecordLayer); } catch (TlsFatalAlert tlsFatalAlert) { dtlsRecordLayer.Fail(tlsFatalAlert.AlertDescription); throw tlsFatalAlert; } catch (IOException ex) { dtlsRecordLayer.Fail(80); throw ex; } catch (Exception alertCause) { dtlsRecordLayer.Fail(80); throw new TlsFatalAlert(80, alertCause); } return(result); }
protected virtual void InvalidateSession() { if (this.mSessionParameters != null) { this.mSessionParameters.Clear(); this.mSessionParameters = null; } if (this.mTlsSession != null) { this.mTlsSession.Invalidate(); this.mTlsSession = null; } }
/** * Initiates a TLS handshake in the role of client.<br/> * <br/> * In blocking mode, this will not return until the handshake is complete. * In non-blocking mode, use {@link TlsPeer#NotifyHandshakeComplete()} to * receive a callback when the handshake is complete. * * @param tlsClient The {@link TlsClient} to use for the handshake. * @throws IOException If in blocking mode and handshake was not successful. */ public virtual void Connect(TlsClient tlsClient) { if (tlsClient == null) { throw new ArgumentNullException("tlsClient"); } if (this.mTlsClient != null) { throw new InvalidOperationException("'Connect' can only be called once"); } this.mTlsClient = tlsClient; base.LoggingContext = this.mTlsClient.LoggingContext; if (HTTPManager.Logger.Level <= Loglevels.All) { HTTPManager.Logger.Verbose("TlsClientProtocol", "Connect", this.LoggingContext); } this.mSecurityParameters = new SecurityParameters(); this.mSecurityParameters.entity = ConnectionEnd.client; this.mTlsClientContext = new TlsClientContextImpl(mSecureRandom, mSecurityParameters); this.mTlsClientContext.UserObject = this.LoggingContext; this.mSecurityParameters.clientRandom = CreateRandomBlock(tlsClient.ShouldUseGmtUnixTime(), mTlsClientContext.NonceRandomGenerator); this.mTlsClient.Init(mTlsClientContext); this.mRecordStream.Init(mTlsClientContext); tlsClient.NotifyCloseHandle(this); TlsSession sessionToResume = tlsClient.GetSessionToResume(); if (sessionToResume != null && sessionToResume.IsResumable) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null && sessionParameters.IsExtendedMasterSecret) { this.mTlsSession = sessionToResume; this.mSessionParameters = sessionParameters; } } SendClientHelloMessage(); this.mConnectionState = CS_CLIENT_HELLO; BlockForHandshake(); }
public override void NotifyHandshakeComplete() { base.NotifyHandshakeComplete(); if (mContext.ResumableSession != null) { if (session != null && session.SessionID.SequenceEqual(mContext.ResumableSession.SessionID)) { // Resume. } else { // New session. session = mContext.ResumableSession; } } var srtpProfileInformation = SrtpUtil.GetSrtpProfileInformationFromSrtpProtectionProfile(ChosenSrtpProtectionProfile); SrtpKeyingMaterial = mContext.ExportKeyingMaterial(ExporterLabel.dtls_srtp, null, 2 * (srtpProfileInformation.CipherKeyLength + srtpProfileInformation.CipherSaltLength)); }
/** * Initiates a TLS handshake in the role of client * * @param tlsClient The {@link TlsClient} to use for the handshake. * @throws IOException If handshake was not successful. */ public virtual void Connect(TlsClient tlsClient) { if (tlsClient == null) { throw new ArgumentNullException("tlsClient"); } if (this.mTlsClient != null) { throw new InvalidOperationException("'Connect' can only be called once"); } this.mTlsClient = tlsClient; this.mSecurityParameters = new SecurityParameters(); this.mSecurityParameters.entity = ConnectionEnd.client; this.mTlsClientContext = new TlsClientContextImpl(mSecureRandom, mSecurityParameters); this.mSecurityParameters.clientRandom = CreateRandomBlock(tlsClient.ShouldUseGmtUnixTime(), mTlsClientContext.NonceRandomGenerator); this.mTlsClient.Init(mTlsClientContext); this.mRecordStream.Init(mTlsClientContext); TlsSession sessionToResume = tlsClient.GetSessionToResume(); if (sessionToResume != null && sessionToResume.IsResumable) { SessionParameters sessionParameters = sessionToResume.ExportSessionParameters(); if (sessionParameters != null) { this.mTlsSession = sessionToResume; this.mSessionParameters = sessionParameters; } } SendClientHelloMessage(); this.mConnectionState = CS_CLIENT_HELLO; CompleteHandshake(); }
public override void NotifyHandshakeComplete() { base.NotifyHandshakeComplete(); TlsSession newSession = mContext.ResumableSession; if (newSession != null) { byte[] newSessionID = newSession.SessionID; string hex = Hex.ToHexString(newSessionID); if (this.mSession != null && Arrays.AreEqual(this.mSession.SessionID, newSessionID)) { Console.WriteLine("Resumed session: " + hex); } else { Console.WriteLine("Established session: " + hex); } this.mSession = newSession; } }
public override void NotifyHandshakeComplete() { base.NotifyHandshakeComplete(); TlsSession newSession = mContext.ResumableSession; if (newSession != null) { // byte[] newSessionID = newSession.SessionID; // string hex = Hex.ToHexString(newSessionID); // if (this.mSession != null && Arrays.AreEqual(this.mSession.SessionID, newSessionID)) { // Debug.LogError("Resumed session: " + hex); // } else { // Debug.LogError("Established session: " + hex); // } this.mSession = newSession; } handshakeDone(); }
internal TLSClient(TlsSession session, TlsKeyPair userKey) : base(session, userKey) { }
public DtlsClient(TlsSession session, TlsPskIdentity pskIdentity) { _mSession = session; _mPskIdentity = pskIdentity; }
internal MockTlsClient(TlsSession session) { this.mSession = session; }
protected virtual void CompleteHandshake() { try { this.mRecordStream.FinaliseHandshake(); this.mAppDataSplitEnabled = !TlsUtilities.IsTlsV11(Context); /* * If this was an initial handshake, we are now ready to send and receive application data. */ if (!mAppDataReady) { this.mAppDataReady = true; if (mBlocking) { this.mTlsStream = new TlsStream(this); } } if (this.mTlsSession != null) { if (this.mSessionParameters == null) { this.mSessionParameters = new SessionParameters.Builder() .SetCipherSuite(this.mSecurityParameters.CipherSuite) .SetCompressionAlgorithm(this.mSecurityParameters.CompressionAlgorithm) .SetMasterSecret(this.mSecurityParameters.MasterSecret) .SetPeerCertificate(this.mPeerCertificate) .SetPskIdentity(this.mSecurityParameters.PskIdentity) .SetSrpIdentity(this.mSecurityParameters.SrpIdentity) // TODO Consider filtering extensions that aren't relevant to resumed sessions .SetServerExtensions(this.mServerExtensions) .Build(); this.mTlsSession = new TlsSessionImpl(this.mTlsSession.SessionID, this.mSessionParameters); } ContextAdmin.SetResumableSession(this.mTlsSession); } Peer.NotifyHandshakeComplete(); } finally { CleanupHandshake(); } }
internal virtual void SetResumableSession(TlsSession session) { this.mSession = session; }
internal MockPskTlsClient(TlsSession session) : this(session, new BasicTlsPskIdentity("client", Strings.ToUtf8ByteArray("TLS_TEST_PSK"))) { }
internal MockPskTlsClient(TlsSession session, TlsPskIdentity pskIdentity) : base(pskIdentity) { this.mSession = session; }
internal TLSClient(TlsSession session, TlsPskIdentity pskIdentity) : base(session, pskIdentity) { }
internal TLSClient(TlsSession session, TlsKeyPair tlsKey, KeySet cwtTrustKeys) : base(session, tlsKey, cwtTrustKeys) { }
public MockDtlsClient(TlsSession session) { this.mSession = session; }
internal DtlsClient(TlsSession session, OneKey userKey) { _mSession = session; _rawPublicKey = userKey; }
public DtlsClient(TlsSession session, TlsKeyPair tlsKey, KeySet cwtTrustKeys) { _mSession = session; _tlsKeyPair = tlsKey ?? throw new ArgumentNullException(nameof(tlsKey)); CwtTrustKeySet = cwtTrustKeys; }
internal MockPskTlsClient(TlsSession session) : this(session, new BasicTlsPskIdentity("client", new byte[16])) { }
public HueDtlsClient(TlsPskIdentity identity, TlsSession session) { _identity = identity; _session = session; }
public DtlsClient(TlsSession session, TlsKeyPair userKey) { _mSession = session; _tlsKeyPair = userKey ?? throw new ArgumentNullException(nameof(userKey)); }
public WebuSocketTlsClient(Action handshakeDone, Action <Exception, string> handleError) { this.handshakeDone = handshakeDone; this.handleError = handleError; this.mSession = null; }
internal MockSrpTlsClient(TlsSession session, byte[] identity, byte[] password) : base(identity, password) { this.mSession = session; }