public void ChangeEncryptedFrameLength() { NetMQMessage plainMessage = new NetMQMessage(); plainMessage.Append("Hello"); NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage); int offset; List <NetMQMessage> sslMessages; bool result = m_clientSecureChannel.ResolveRecordLayer(cipherMessage.First.Buffer, out offset, out sslMessages); Assert.AreEqual(sslMessages.Count, 1); cipherMessage = sslMessages[0]; cipherMessage.RemoveFrame(cipherMessage.Last); // appending new frame with length different then block size cipherMessage.Append("ChangeEncryptedFrame"); NetMQSecurityException exception = Assert.Throws <NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage)); Assert.AreEqual(NetMQSecurityErrorCode.EncryptedFrameInvalidLength, exception.ErrorCode); }
public void ReorderFrames() { NetMQMessage plainMessage = new NetMQMessage(); plainMessage.Append("Hello"); plainMessage.Append("World"); NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage); NetMQFrame lastFrame = cipherMessage.Last; cipherMessage.RemoveFrame(lastFrame); NetMQFrame oneBeforeLastFrame = cipherMessage.Last; cipherMessage.RemoveFrame(oneBeforeLastFrame); cipherMessage.Append(lastFrame); cipherMessage.Append(oneBeforeLastFrame); NetMQSecurityException exception = Assert.Throws <NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage)); Assert.AreEqual(NetMQSecurityErrorCode.MACNotMatched, exception.ErrorCode); }
public void WrongFramesCount() { NetMQMessage plainMessage = new NetMQMessage(); plainMessage.Append("Hello"); NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage); // remove the first frame cipherMessage.RemoveFrame(cipherMessage.Last); NetMQSecurityException exception = Assert.Throws <NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage)); Assert.AreEqual(NetMQSecurityErrorCode.EncryptedFramesMissing, exception.ErrorCode); }
public void WrongFramesCount() { NetMQMessage plainMessage = new NetMQMessage(); plainMessage.Append("Hello"); NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage); int offset; List <NetMQMessage> sslMessages; bool result = m_clientSecureChannel.ResolveRecordLayer(cipherMessage.First.Buffer, out offset, out sslMessages); Assert.AreEqual(sslMessages.Count, 1); cipherMessage = sslMessages[0]; // remove the first frame cipherMessage.RemoveFrame(cipherMessage.Last); cipherMessage.RemoveFrame(cipherMessage.Last); cipherMessage.RemoveFrame(cipherMessage.Last); NetMQSecurityException exception = Assert.Throws <NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage)); Assert.AreEqual(NetMQSecurityErrorCode.InvalidFramesCount, exception.ErrorCode); }
public void ChangeEncryptedFrameLength() { NetMQMessage plainMessage = new NetMQMessage(); plainMessage.Append("Hello"); NetMQMessage cipherMessage = m_serverSecureChannel.EncryptApplicationMessage(plainMessage); cipherMessage.RemoveFrame(cipherMessage.Last); // appending new frame with length different then block size cipherMessage.Append("Hello"); NetMQSecurityException exception = Assert.Throws <NetMQSecurityException>(() => m_clientSecureChannel.DecryptApplicationMessage(cipherMessage)); Assert.AreEqual(NetMQSecurityErrorCode.EncryptedFrameInvalidLength, exception.ErrorCode); }
/// <summary> /// verifies if the message replied obeys the MDP 0.2 protocol /// </summary> /// <remarks> /// socket strips [client adr][e] from message /// message -> /// [empty frame][protocol header][service name][requestId][reply] /// [empty frame][protocol header][service name][result code of service lookup] /// </remarks> private Guid ExtractRequest(NetMQMessage reply) { if (reply.FrameCount < 4) // TODO Check if I need to change to 5 because of reqId! { throw new ApplicationException("[CLIENT ERROR] received a malformed reply"); } var emptyFrame = reply.Pop(); if (emptyFrame != NetMQFrame.Empty) { throw new ApplicationException($"[CLIENT ERROR] received a malformed reply expected empty frame instead of: { emptyFrame } "); } var header = reply.Pop(); if (header.ConvertToString() != m_mdpClient) { throw new ApplicationException($"[CLIENT INFO] MDP Version mismatch: {header}"); } var service = reply.Pop(); if (service.ConvertToString() != m_serviceName) { throw new ApplicationException($"[CLIENT INFO] answered by wrong service: {service.ConvertToString()}"); } Guid requestId; // TODO: Not sure if requestId should be the last frame or the request itself... var reqIdFrame = reply.Last; reply.RemoveFrame(reqIdFrame); if (!Guid.TryParse(reqIdFrame.ConvertToString(), out requestId) || requestId == Guid.Empty) { throw new ApplicationException($"[CLIENT INFO] RequestID was not retrieved"); } return(requestId); }
/// <summary> /// verifies if the message replied obeys the MDP 0.2 protocol /// </summary> /// <remarks> /// socket strips [client adr][e] from message /// message -> /// [empty frame][protocol header][service name][requestId][reply] /// [empty frame][protocol header][service name][result code of service lookup] /// </remarks> private Guid ExtractRequest(NetMQMessage reply) { if (reply.FrameCount < 4) // TODO Check if I need to change to 5 because of reqId! throw new ApplicationException("[CLIENT ERROR] received a malformed reply"); var emptyFrame = reply.Pop(); if (emptyFrame != NetMQFrame.Empty) { throw new ApplicationException($"[CLIENT ERROR] received a malformed reply expected empty frame instead of: { emptyFrame } "); } var header = reply.Pop(); if (header.ConvertToString() != m_mdpClient) throw new ApplicationException($"[CLIENT INFO] MDP Version mismatch: {header}"); var service = reply.Pop(); if (service.ConvertToString() != m_serviceName) throw new ApplicationException($"[CLIENT INFO] answered by wrong service: {service.ConvertToString()}"); Guid requestId; // TODO: Not sure if requestId should be the last frame or the request itself... var reqIdFrame = reply.Last; reply.RemoveFrame(reqIdFrame); if (!Guid.TryParse(reqIdFrame.ConvertToString(), out requestId) || requestId == Guid.Empty) { throw new ApplicationException($"[CLIENT INFO] RequestID was not retrieved"); } return requestId; }