public void AlertTest() { Configuration configuration = new Configuration() { VerifyCertificate = false, StandardTLSFormat = true }; X509Certificate2 certificate = new X509Certificate2(NUnit.Framework.TestContext.CurrentContext.TestDirectory + "\\server.pfx", "1234"); byte [] sessionId = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")); SecureChannel serverSecureChannel = SecureChannel.CreateServerSecureChannel(configuration); serverSecureChannel.Certificate = certificate; SecureChannel clientSecureChannel = SecureChannel.CreateClientSecureChannel(sessionId, configuration); IList <NetMQMessage> clientOutgoingMessages = new List <NetMQMessage>(); IList <NetMQMessage> serverOutgoingMessages = new List <NetMQMessage>(); bool clientComplete = clientSecureChannel.ProcessMessage(null, clientOutgoingMessages); bool serverComplete = false; int offset; List <NetMQMessage> sslMessages; foreach (var message in clientOutgoingMessages) { serverSecureChannel.ResolveRecordLayer(message.Last.Buffer, out offset, out sslMessages); foreach (var sslMessage in sslMessages) { serverComplete = serverSecureChannel.ProcessMessage(sslMessage, serverOutgoingMessages); Assert.IsTrue(serverSecureChannel.SessionId.SequenceEqual(sessionId)); if (serverComplete) { break; } } if (serverComplete) { break; } } var alertMessage = serverSecureChannel.Alert(AlertLevel.Warning, AlertDescription.DecryptError); Assert.AreEqual(alertMessage.FrameCount, 5); Assert.AreEqual(alertMessage.First.BufferSize, 1); Assert.AreEqual((int)alertMessage.First.Buffer[0], 21); Assert.AreEqual(alertMessage[3].BufferSize, 1); Assert.AreEqual((AlertLevel)alertMessage[3].Buffer[0], AlertLevel.Warning); Assert.AreEqual(alertMessage[4].BufferSize, 1); Assert.AreEqual((AlertDescription)alertMessage[4].Buffer[0], AlertDescription.DecryptError); byte[] combineBytes = new byte[0]; int sum = 0; foreach (var frame in alertMessage) { combineBytes = combineBytes.Combine(frame.Buffer); sum += frame.BufferSize; } Assert.AreEqual(sum, combineBytes.Length); bool result = clientSecureChannel.ResolveRecordLayer(combineBytes, out offset, out sslMessages); Assert.AreEqual(offset, combineBytes.Length); Assert.IsTrue(result); Assert.AreEqual(sslMessages.Count, 1); for (int j = 0; j < sslMessages[0].FrameCount; j++) { Assert.AreEqual(sslMessages[0][j].Buffer, alertMessage[j].Buffer); } alertMessage = clientSecureChannel.Alert(AlertLevel.Warning, AlertDescription.DecryptError); Assert.AreEqual(alertMessage.FrameCount, 5); Assert.AreEqual(alertMessage.First.BufferSize, 1); Assert.AreEqual((int)alertMessage.First.Buffer[0], 21); Assert.AreEqual(alertMessage[3].BufferSize, 1); Assert.AreEqual((AlertLevel)alertMessage[3].Buffer[0], AlertLevel.Warning); Assert.AreEqual(alertMessage[4].BufferSize, 1); Assert.AreEqual((AlertDescription)alertMessage[4].Buffer[0], AlertDescription.DecryptError); clientSecureChannel.Dispose(); serverSecureChannel.Dispose(); }