private void PopulateVersionInfo() { ProtocolVersion biz = new ProtocolVersion(); // populate existing if (numVersionId != -1) { biz.Get(numVersionId); base.PopulateForm(biz); // specially format date ApprovalDate.Text = string.Format("{0:d}", biz[ProtocolVersion.ApprovalDate]); } // if copying exising defult from exisintg else if (!string.IsNullOrEmpty(CopyVersionId)) { biz.Get(int.Parse(CopyVersionId)); // set field values base.PopulateForm(biz); // specially format date ApprovalDate.Text = string.Format("{0:d}", biz[ProtocolVersion.ApprovalDate]); // update verion number string baseVersionNumber = biz[ProtocolVersion.VersionNumber].ToString(); VersionNumber.Text = string.Format("Copy of {0}", baseVersionNumber); } }
private void ProcessHelloVerifyRequest(IByteBuffer body) { ProtocolVersion recordLayerVersion = recordLayer.GetReadVersion(); ProtocolVersion client_version = clientState.ClientContext.ClientVersion; if (!recordLayerVersion.IsEqualOrEarlierVersionOf(client_version)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } recordLayer.SetReadVersion(null); ProtocolVersion server_version = ProtocolVersion.Get(body.ReadByte() & 0xFF, body.ReadByte() & 0xFF); byte[] cookie = new byte[body.ReadByte()]; body.ReadBytes(cookie); if (!server_version.IsEqualOrEarlierVersionOf(clientState.ClientContext.ClientVersion)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } if (!ProtocolVersion.DTLSv12.IsEqualOrEarlierVersionOf(server_version) && cookie.Length > 32) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } ((AsyncDtlsSecurityParameters)clientState.ClientContext.SecurityParameters).SetCookie(cookie); }
/// <summary> /// Deletes the association of metadatasurvey a protocol version /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteAssociationClick(object sender, EventArgs e) { // get versionid for this row and remove association int rowIndex = ((sender as ImageButton).NamingContainer as GridViewRow).RowIndex; int versionId = (int)ProtocolVersionsGrid.DataKeys[rowIndex][ProtocolVersion.ProtocolVersionId]; ProtocolVersion version = new ProtocolVersion(); version.Get(versionId); version[ProtocolVersion.MetadataSurveyId] = string.Empty; version.Save(); // rebind list to show changes BindProtocolVersions(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateAssociationClick(object sender, EventArgs e) { // locate selected survey GridViewRow row = (sender as ImageButton).NamingContainer as GridViewRow; string metaSurveyId = (row.FindControl("AssociatedSurveyList") as DropDownList).SelectedValue; if (!string.IsNullOrEmpty(metaSurveyId)) { // get pri key int versionId = int.Parse(ProtocolVersionsGrid.DataKeys[row.RowIndex][ProtocolVersion.ProtocolVersionId].ToString()); ProtocolVersion biz = new ProtocolVersion(); biz.Get(versionId); biz[ProtocolVersion.MetadataSurveyId] = metaSurveyId; biz.Save(); // rebind list of versions BindProtocolVersions(); // load survey BuildEligibilityQuestionnaire(int.Parse(metaSurveyId)); } }
protected void SaveButton_Click(object sender, EventArgs e) { // validate approval date DateTime testDate = DateTime.Now; if (string.IsNullOrEmpty(ApprovalDate.Text) || !DateTime.TryParse(ApprovalDate.Text, out testDate)) { ApprovalDateValidator.IsValid = false; } else { ProtocolVersion biz = new ProtocolVersion(); int protocolId = int.Parse(BaseProtocolId); // copying if (!string.IsNullOrEmpty(CopyVersionId)) { biz = ProtocolMgmtController.CopyProtocolVersion(int.Parse(CopyVersionId)); } else { // updating if (numVersionId != -1) { biz.Get(numVersionId); } // new record else { biz[ProtocolVersion.ProtocolId] = protocolId; } } CICHelper.SetBOValues(Form.Controls, biz, protocolId); biz.Save(); RefreshMainScreen((int)biz[biz.PrimaryKeyName]); } }
private void ProcessServerHello(IByteBuffer body) { ProtocolVersion recordLayerVersion = recordLayer.GetReadVersion(); ReportServerVersion(recordLayerVersion); recordLayer.SetWriteVersion(recordLayerVersion); AsyncDtlsSecurityParameters securityParameters = (AsyncDtlsSecurityParameters)clientState.ClientContext.SecurityParameters; ProtocolVersion server_version = ProtocolVersion.Get(body.ReadByte() & 0xFF, body.ReadByte() & 0xFF); ReportServerVersion(server_version); byte[] serverRandom = new byte[32]; body.ReadBytes(serverRandom); securityParameters.SetServerRandom(serverRandom); byte[] selectedSessionID = new byte[body.ReadByte() & 0x0FF]; if (selectedSessionID.Length > 0) { body.ReadBytes(selectedSessionID); } clientState.SelectedSessionID = selectedSessionID; if (selectedSessionID.Length > 32) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } clientState.Client.NotifySessionID(selectedSessionID); clientState.ResumedSession = selectedSessionID.Length > 0 && clientState.TlsSession != null && ArrayUtils.Equals(clientState.SelectedSessionID, clientState.TlsSession.SessionID); int selectedCipherSuite = body.ReadUnsignedShort(); Boolean inOfferedCipherSuites = false; for (int i = 0; i < clientState.OfferedCipherSuites.Length; i++) { if (selectedCipherSuite == clientState.OfferedCipherSuites[i]) { inOfferedCipherSuites = true; break; } } if (!inOfferedCipherSuites || selectedCipherSuite == CipherSuite.TLS_NULL_WITH_NULL_NULL || CipherSuite.IsScsv(selectedCipherSuite) || !DtlsHelper.GetMinimumVersion(selectedCipherSuite).IsEqualOrEarlierVersionOf(clientState.ClientContext.ServerVersion.GetEquivalentTLSVersion())) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } switch (DtlsHelper.GetEncryptionAlgorithm(selectedCipherSuite)) { case EncryptionAlgorithm.RC4_40: case EncryptionAlgorithm.RC4_128: throw new TlsFatalAlert(AlertDescription.internal_error); } clientState.Client.NotifySelectedCipherSuite(selectedCipherSuite); byte selectedCompressionMethod = body.ReadByte(); Boolean inOfferedCompressionMethods = false; for (int i = 0; i < clientState.OfferedCompressionMethods.Length; i++) { if (selectedCompressionMethod == clientState.OfferedCompressionMethods[i]) { inOfferedCompressionMethods = true; break; } } if (!inOfferedCompressionMethods) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } clientState.Client.NotifySelectedCompressionMethod(selectedCompressionMethod); clientState.ServerExtensions = DtlsHelper.ReadSelectedExtensions(body); if (clientState.ServerExtensions != null) { foreach (Int32 extType in clientState.ServerExtensions.Keys) { if (extType.Equals(DtlsHelper.EXT_RenegotiationInfo)) { continue; } if (!clientState.ClientExtensions.Contains(extType)) { throw new TlsFatalAlert(AlertDescription.unsupported_extension); } } } byte[] renegExtData = null; if (clientState.ServerExtensions.Contains(DtlsHelper.EXT_RenegotiationInfo)) { renegExtData = (byte[])clientState.ServerExtensions[DtlsHelper.EXT_RenegotiationInfo]; } if (renegExtData != null) { clientState.SecureRenegotiation = true; if (!ArrayUtils.Equals(renegExtData, DtlsHelper.EMPTY_BYTES_WITH_LENGTH)) { throw new TlsFatalAlert(AlertDescription.handshake_failure); } } if (clientState.SecureRenegotiation) { clientState.Client.NotifySecureRenegotiation(clientState.SecureRenegotiation); } IDictionary sessionClientExtensions = clientState.ClientExtensions; IDictionary sessionServerExtensions = clientState.ServerExtensions; if (clientState.ResumedSession) { if (selectedCipherSuite != clientState.SessionParameters.CipherSuite || selectedCompressionMethod != clientState.SessionParameters.CompressionAlgorithm) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } sessionClientExtensions = null; sessionServerExtensions = (Dictionary <Int32, byte[]>)clientState.SessionParameters.ReadServerExtensions(); } securityParameters.SetCipherSuite(selectedCipherSuite); securityParameters.SetCompressionAlgorithm(selectedCompressionMethod); if (sessionServerExtensions != null) { byte[] encryptThenMac = null; if (sessionServerExtensions.Contains(DtlsHelper.EXT_encrypt_then_mac)) { encryptThenMac = (byte[])sessionServerExtensions[DtlsHelper.EXT_encrypt_then_mac]; } if (encryptThenMac != null && encryptThenMac.Length > 0) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } Boolean serverSentEncryptThenMAC = encryptThenMac != null; if (serverSentEncryptThenMAC && DtlsHelper.GetCipherType(securityParameters.CipherSuite) != CipherType.block) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } securityParameters.SetEncryptThenMAC(serverSentEncryptThenMAC); byte[] extendedMacSecret = null; if (sessionServerExtensions.Contains(DtlsHelper.EXT_extended_master_secret)) { extendedMacSecret = (byte[])sessionServerExtensions[DtlsHelper.EXT_extended_master_secret]; } if (extendedMacSecret != null && extendedMacSecret.Length > 0) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } securityParameters.SetExtendedMasterSecret(extendedMacSecret != null); securityParameters.SetMaxFragmentLength(DtlsHelper.EvaluateMaxFragmentLengthExtension(clientState.ResumedSession, sessionClientExtensions, sessionServerExtensions, AlertDescription.illegal_parameter)); byte[] truncatedHMAC = null; if (sessionServerExtensions.Contains(DtlsHelper.EXT_truncated_hmac)) { truncatedHMAC = (byte[])sessionServerExtensions[DtlsHelper.EXT_truncated_hmac]; } if (truncatedHMAC != null && truncatedHMAC.Length > 0) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } securityParameters.SetTruncatedHMac(truncatedHMAC != null); byte[] statusRequest = null; if (sessionServerExtensions.Contains(DtlsHelper.EXT_status_request)) { statusRequest = (byte[])sessionServerExtensions[DtlsHelper.EXT_status_request]; } if (statusRequest != null && statusRequest.Length > 0) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } clientState.AllowCertificateStatus = (!clientState.ResumedSession && statusRequest != null); byte[] sessionTicket = null; if (sessionServerExtensions.Contains(DtlsHelper.EXT_SessionTicket)) { sessionTicket = (byte[])sessionServerExtensions[DtlsHelper.EXT_SessionTicket]; } if (sessionTicket != null && sessionTicket.Length > 0) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } clientState.ExpectSessionTicket = (!clientState.ResumedSession && sessionTicket != null); } if (sessionClientExtensions != null) { clientState.Client.ProcessServerExtensions(sessionServerExtensions); } securityParameters.SetPrfAlgorithm(DtlsHelper.GetPRFAlgorithm(clientState.ClientContext.ServerVersion, securityParameters.CipherSuite)); securityParameters.SetVerifyDataLength(12); }
public List <IByteBuffer> Receive(IByteBuffer record) { List <IByteBuffer> outputList = new List <IByteBuffer>(); while (record.ReadableBytes > RECORD_HEADER_LENGTH) { byte type = (byte)(record.ReadByte() & 0x00FF); ProtocolVersion version = ProtocolVersion.Get(record.ReadByte() & 0xFF, record.ReadByte() & 0xFF); int epoch = record.ReadUnsignedShort(); long seq = DtlsHelper.ReadUint48(record); //just reading length,not using it short packetLength = record.ReadShort(); byte[] realData = new byte[packetLength]; record.ReadBytes(realData); AsyncDtlsEpoch recordEpoch = null; if (epoch == readEpoch.Epoch) { recordEpoch = readEpoch; } if (recordEpoch == null) { continue; } if (recordEpoch.ReplayWindow.ShouldDiscard(seq)) { continue; } if (!version.IsDtls) { continue; } if (readVersion != null && !readVersion.Equals(version)) { continue; } byte[] plaintext = recordEpoch.getCipher().DecodeCiphertext(GetMacSequenceNumber(recordEpoch.Epoch, seq), type, realData, 0, realData.Length); IByteBuffer output = Unpooled.WrappedBuffer(plaintext); recordEpoch.ReplayWindow.ReportAuthenticated(seq); if (plaintext.Length > this.plaintextLimit) { continue; } if (readVersion == null) { readVersion = version; } switch (type) { case ContentType.alert: if (output.ReadableBytes == 2) { byte alertLevel = (byte)(output.ReadByte() & 0x0FF); byte alertDescription = (byte)(output.ReadByte() & 0x0FF); peer.NotifyAlertReceived(alertLevel, alertDescription); if (alertLevel == AlertLevel.fatal) { Failed(); throw new TlsFatalAlert(alertDescription); } if (alertDescription == AlertDescription.close_notify) { CloseTransport(); } } continue; case ContentType.application_data: if (inHandshake) { continue; } break; case ContentType.change_cipher_spec: while (output.ReadableBytes > 0) { short message = (short)(output.ReadByte() & 0x0FF); if (message != ChangeCipherSpec.change_cipher_spec) { continue; } if (pendingEpoch != null) { readEpoch = pendingEpoch; } } continue; case ContentType.handshake: if (!inHandshake) { continue; } HandshakeHeader handshakeHeader = DtlsHelper.ReadHandshakeHeader(output); if (handshakeHeader != null) { if (!handshakeHeader.FragmentLength.Equals(handshakeHeader.TotalLength)) { PendingMessageData data = null; if (pendingBuffers.ContainsKey(handshakeHeader.MessageSequence)) { data = pendingBuffers[handshakeHeader.MessageSequence]; } if (data == null) { data = new PendingMessageData(Unpooled.Buffer(handshakeHeader.TotalLength)); pendingBuffers[handshakeHeader.MessageSequence] = data; } data.WriteBytes(output, handshakeHeader.FragmentOffset); if (data.WrottenBytes.Equals(handshakeHeader.TotalLength)) { data.Buffer.SetWriterIndex(handshakeHeader.TotalLength); byte[] packetData = null; IByteBuffer copy = data.Buffer.Copy(); packetData = new byte[copy.ReadableBytes]; copy.ReadBytes(packetData); if (handshakeHeader.MessageType.HasValue && handshakeHandler != null) { handshakeHandler.HandleHandshake(handshakeHeader.MessageType.Value, data.Buffer); } byte[] pseudoHeader = new byte[DtlsHelper.HANDSHAKE_MESSAGE_HEADER_LENGTH]; IByteBuffer headerBuffer = Unpooled.WrappedBuffer(pseudoHeader); headerBuffer.SetWriterIndex(0); DtlsHelper.WriteHandshakeHeader(handshakeHeader.MessageSequence, handshakeHeader.MessageType.Value, headerBuffer, handshakeHeader.TotalLength); headerBuffer.SetReaderIndex(0); handshakeHash.BlockUpdate(pseudoHeader, 0, pseudoHeader.Length); handshakeHash.BlockUpdate(packetData, 0, packetData.Length); if (handshakeHeader.MessageType.HasValue && handshakeHandler != null) { handshakeHandler.PostProcessHandshake(handshakeHeader.MessageType.Value, data.Buffer); } pendingBuffers.Remove(handshakeHeader.MessageSequence); } } else { byte[] packetData = null; IByteBuffer copy = output.Copy(); packetData = new byte[copy.ReadableBytes]; copy.ReadBytes(packetData); if (handshakeHeader.MessageType.HasValue && handshakeHandler != null) { handshakeHandler.HandleHandshake(handshakeHeader.MessageType.Value, output); } byte[] pseudoHeader = new byte[DtlsHelper.HANDSHAKE_MESSAGE_HEADER_LENGTH]; IByteBuffer headerBuffer = Unpooled.WrappedBuffer(pseudoHeader); headerBuffer.SetWriterIndex(0); DtlsHelper.WriteHandshakeHeader(handshakeHeader.MessageSequence, handshakeHeader.MessageType.Value, headerBuffer, handshakeHeader.TotalLength); headerBuffer.SetReaderIndex(0); handshakeHash.BlockUpdate(pseudoHeader, 0, pseudoHeader.Length); handshakeHash.BlockUpdate(packetData, 0, packetData.Length); if (handshakeHeader.MessageType.HasValue && handshakeHandler != null) { handshakeHandler.PostProcessHandshake(handshakeHeader.MessageType.Value, output); } } } continue; case ContentType.heartbeat: continue; } outputList.Add(output); } return(outputList); }