private ErrorCode?ValidateRequest(TurnMessage request) { if (request.MessageIntegrity == null) { return(ErrorCode.Unauthorized); } if (request.MessageType == MessageType.AllocateRequest) { if (request.Realm == null) { return(ErrorCode.MissingRealm); } if (request.Nonce == null) { return(ErrorCode.MissingNonce); } if (IsValidNonce(request.Nonce.Value) == false) { return(ErrorCode.StaleNonce); } } if (request.MsUsername == null) { return(ErrorCode.MissingUsername); } if (request.IsValidMsUsername(Key1) == false) { return(ErrorCode.UnknownUsername); } if (request.Realm != null) { if (request.Realm.Value != Realm) { return(ErrorCode.MissingRealm); } } else { request.Realm = realm; } if (request.IsValidMessageIntegrity(Key2) == false) { return(ErrorCode.IntegrityCheckFailure); } return(null); }
public void MsTurnMessageTest4() { byte[] bytes = new byte[] { 0x00, 0x04, 0x01, 0x04, 0x05, 0x05, 0x1D, 0x39, 0xAA, 0x39, 0x58, 0x49, 0x79, 0x0D, 0x59, 0x0B, 0x24, 0x79, 0x0B, 0x4D, 0x00, 0x0F, 0x00, 0x04, 0x72, 0xC6, 0x4B, 0xC6, 0x80, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x80, 0x50, 0x00, 0x18, 0x06, 0x1C, 0xF9, 0x10, 0xC4, 0x3A, 0x3B, 0x08, 0x60, 0xD5, 0xA7, 0x00, 0x04, 0x4B, 0x05, 0xA5, 0x40, 0xF7, 0x73, 0x9E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x34, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5E, 0xE3, 0x27, 0xE3, 0xF4, 0xB5, 0xF8, 0xDE, 0x63, 0x8D, 0x3D, 0x73, 0x43, 0xF6, 0xD8, 0x2C, 0x64, 0x56, 0xE2, 0x03, 0xCD, 0xBC, 0xCA, 0x33, 0xAB, 0x03, 0xEF, 0x2D, 0xAB, 0x01, 0xD6, 0xC8, 0x99, 0x9D, 0xE2, 0x4E, 0x6C, 0x8E, 0xB6, 0xED, 0x00, 0x11, 0x00, 0x08, 0x00, 0x01, 0xE1, 0x9D, 0xC0, 0xA8, 0x01, 0x0F, 0x00, 0x13, 0x00, 0x78, 0x00, 0x01, 0x00, 0x64, 0x7F, 0x52, 0x04, 0x22, 0x1C, 0x5E, 0x73, 0x53, 0x4A, 0xD7, 0x49, 0x58, 0xEA, 0x22, 0x1F, 0xF0, 0x00, 0x06, 0x00, 0x48, 0xAD, 0x2B, 0x14, 0x6A, 0x3F, 0xF0, 0xCF, 0x0F, 0x91, 0x6E, 0xDE, 0x73, 0xD7, 0xBA, 0xAA, 0xEA, 0xBF, 0x6D, 0x9B, 0xEB, 0x9A, 0x6D, 0x26, 0x21, 0xED, 0x3E, 0x97, 0x4B, 0xDB, 0x95, 0x61, 0xCA, 0x3A, 0x32, 0x3A, 0xBA, 0x8F, 0x1C, 0x51, 0xAC, 0x35, 0xCF, 0x21, 0x53, 0xED, 0x42, 0x91, 0xC9, 0x63, 0x4D, 0x76, 0x1C, 0x61, 0x6E, 0x95, 0x3F, 0x45, 0xC1, 0x11, 0x50, 0x8A, 0xAD, 0x92, 0x8E, 0x34, 0xF9, 0xA2, 0x3A, 0x32, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x14, 0xFD, 0xA2, 0x22, 0x0F, 0x10, 0x6B, 0x95, 0xFF, 0xF1, 0x51, 0x4D, 0x7B, 0x63, 0xF9, 0x17, 0x0D, 0x91, 0x99, 0x04, 0x25, 0x00, 0x08, 0x00, 0x14, 0xEB, 0xB5, 0x0C, 0x16, 0xFF, 0x81, 0x6F, 0xEC, 0x8F, 0x1A, 0xFF, 0x41, 0xC9, 0x80, 0x37, 0x51, 0x36, 0xDE, 0xBF, 0x3B, // 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, }; byte[] key1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; byte[] key2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; TurnMessage message = TurnMessage.Parse(bytes, TurnMessageRfc.MsTurn); message.Realm = new Realm(TurnMessageRfc.MsTurn) { Value = "officesip.local", }; Assert.AreEqual(MessageType.SendRequest, message.MessageType); Assert.IsTrue(message.IsValidMsUsername(key1)); Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed."); }
public void MsTurnMessageTest2() { byte[] bytes = new byte[] { 0x00, 0x03, 0x00, 0x9B, 0x4A, 0x07, 0x32, 0x01, 0x52, 0x11, 0xE9, 0x94, 0xAE, 0x02, 0x4A, 0x13, 0x8A, 0xA2, 0x0D, 0x26, 0x00, 0x0F, 0x00, 0x04, 0x72, 0xC6, 0x4B, 0xC6, 0x80, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x34, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x6F, 0x67, 0x2E, 0x88, 0xC2, 0xF8, 0xDE, 0xB8, 0x4E, 0x72, 0x65, 0x5C, 0x43, 0x31, 0x49, 0x07, 0x94, 0x46, 0xC2, 0x19, 0x77, 0x73, 0x92, 0xE0, 0x24, 0x03, 0x08, 0x1D, 0x86, 0x27, 0xA8, 0x50, 0x45, 0x1D, 0xB5, 0x41, 0x8E, 0xC6, 0xCA, 0x00, 0x14, 0x00, 0x24, 0x61, 0x34, 0x31, 0x66, 0x37, 0x61, 0x63, 0x35, 0x2D, 0x38, 0x32, 0x37, 0x64, 0x2D, 0x34, 0x30, 0x65, 0x37, 0x2D, 0x38, 0x35, 0x31, 0x33, 0x2D, 0x63, 0x35, 0x66, 0x36, 0x39, 0x31, 0x65, 0x35, 0x66, 0x61, 0x64, 0x34, 0x00, 0x15, 0x00, 0x0F, 0x6F, 0x66, 0x66, 0x69, 0x63, 0x65, 0x73, 0x69, 0x70, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x08, 0x00, 0x14, 0xE3, 0xB3, 0x88, 0x94, 0x79, 0x3B, 0x28, 0x3A, 0x34, 0x67, 0xA4, 0x46, 0xAD, 0xD5, 0x6C, 0xD0, 0xE6, 0xA7, 0x50, 0x90, }; byte[] key1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; byte[] key2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; string nonce = "a41f7ac5-827d-40e7-8513-c5f691e5fad4"; string realm = "officesip.local"; TurnMessage message = TurnMessage.Parse(bytes, TurnMessageRfc.MsTurn); Assert.AreEqual(MessageType.AllocateRequest, message.MessageType); Assert.AreEqual(nonce, message.Nonce.Value); Assert.AreEqual(realm, message.Realm.Value); Assert.IsTrue(message.IsValidMsUsername(key1)); Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed."); message.MessageIntegrity = new MessageIntegrity(); Helpers.AreArrayEqual(bytes, message.GetBytes(key2)); }
public void MsTurnMessageTest3() { byte[] bytes = new byte[] { 0x00, 0x04, 0x01, 0x13, 0xe0, 0x8d, 0x79, 0x8f, 0xae, 0x56, 0xbf, 0x16, 0x4f, 0x15, 0xdd, 0xe9, 0x8c, 0x7e, 0x87, 0x7e, 0x00, 0x0f, 0x00, 0x04, 0x72, 0xc6, 0x4b, 0xc6, 0x80, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x80, 0x50, 0x00, 0x18, 0xf0, 0x99, 0x55, 0xbd, 0x46, 0x61, 0x2f, 0xd5, 0xd7, 0xa8, 0xee, 0x2d, 0xae, 0x3b, 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 0x23, 0xea, 0x75, 0x42, 0x1f, 0x14, 0xa9, 0xe3, 0x56, 0xc3, 0xd8, 0xc1, 0x18, 0x2d, 0x4a, 0x80, 0x00, 0x00, 0x3c, 0x01, 0xb1, 0xb2, 0xae, 0x98, 0xd1, 0x5d, 0x9b, 0x3f, 0xa9, 0xc4, 0x00, 0x08, 0x00, 0x14, 0xdd, 0x16, 0x9f, 0xb2, 0x75, 0x39, 0x69, 0x92, 0xf2, 0x2e, 0x8c, 0x6b, 0xaa, 0x67, 0xcf, 0x16, 0x33, 0xc8, 0xbe, 0x07, }; byte[] key1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; byte[] key2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; TurnMessage message = TurnMessage.Parse(bytes, TurnMessageRfc.MsTurn); message.Realm = new Realm(TurnMessageRfc.MsTurn) { Value = "officesip.local", }; Assert.AreEqual(MessageType.SendRequest, message.MessageType); Assert.IsTrue(message.IsValidMsUsername(key1)); Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed."); }
public void MsTurnMessageTest() { byte[] bytes = new byte[] { //0x00, 0x04, 0x23, 0x1E, //0xE6, 0x2D, 0x50, 0x18, //0x3F, 0x87, 0xF0, 0x9A, //0x00, 0x00, 0x02, 0x00, //0x00, 0xB1, 0x00, 0x03, 0x00, 0x9D, 0x30, 0xB8, 0xC9, 0xC7, 0xAF, 0xFC, 0xF4, 0xA2, 0x4D, 0xDB, 0x6E, 0x2A, 0x0A, 0xE0, 0xEA, 0x5D, 0x00, 0x0F, 0x00, 0x04, 0x72, 0xC6, 0x4B, 0xC6, 0x80, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x34, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x6F, 0x67, 0x2E, 0x88, 0xC2, 0xF8, 0xDE, 0xB8, 0x4E, 0x72, 0x65, 0x5C, 0x43, 0x31, 0x49, 0x07, 0x94, 0x46, 0xC2, 0x19, 0x77, 0x73, 0x92, 0xE0, 0x24, 0x03, 0x08, 0x1D, 0x86, 0x27, 0xA8, 0x50, 0x45, 0x1D, 0xB5, 0x41, 0x8E, 0xC6, 0xCA, 0x00, 0x14, 0x00, 0x26, 0x62, 0x62, 0x30, 0x30, 0x65, 0x65, 0x30, 0x32, 0x2D, 0x31, 0x62, 0x38, 0x38, 0x2D, 0x34, 0x31, 0x39, 0x35, 0x2D, 0x39, 0x38, 0x34, 0x34, 0x2D, 0x39, 0x38, 0x36, 0x39, 0x64, 0x37, 0x38, 0x39, 0x30, 0x33, 0x62, 0x61, 0x78, 0x78, 0x00, 0x15, 0x00, 0x0F, 0x6F, 0x66, 0x66, 0x69, 0x63, 0x65, 0x73, 0x69, 0x70, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x08, 0x00, 0x14, // MESSAGE-INTEGRITY attribute header 0x29, // } 0x48, 0x38, 0xD7, 0x37, // } 0x62, 0xB1, 0x26, 0x70, // } HMAC-SHA1 0x95, 0xA3, 0x13, 0xAF, // } 0xA3, 0xBE, 0x78, 0x86, // } 0xFE, 0x53, 0x08, // } }; byte[] key1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; byte[] key2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; string nonce = "bb00ee02-1b88-4195-9844-9869d78903baxx"; string realm = "officesip.local"; string usernameBase64 = @"AQAAIAAAAAAAAAAATG9nLojC+N64TnJlXEMxSQeURsIZd3OS4CQDCB2GJ6hQRR21QY7Gyg=="; string passwordBase64 = @"oUU0sl7OCLQNpLUYuI1cX7OAwXE="; TurnMessage message = TurnMessage.Parse(bytes, TurnMessageRfc.MsTurn); Assert.AreEqual(MessageType.AllocateRequest, message.MessageType); Assert.AreEqual(nonce, message.Nonce.Value); Assert.AreEqual(realm, message.Realm.Value); Assert.AreEqual(usernameBase64, Convert.ToBase64String(message.MsUsername.Value)); Assert.IsTrue(message.IsValidMsUsername(key1)); Assert.AreEqual(passwordBase64, Convert.ToBase64String(message.ComputeMsPasswordBytes(key2))); Assert.IsTrue(message.IsValidMessageIntegrity(key2), @"IsValidMessageIntegrity failed."); message.MessageIntegrity = new MessageIntegrity(); Helpers.AreArrayEqual(bytes, message.GetBytes(key2)); }