public void Derive_Hash512() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, _Salt, AlgorithmValues.AES_CCM_64_64_128, AlgorithmValues.ECDH_SS_HKDF_512); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x5E, 0x99, 0xCA, 0x7A, 0xA3, 0xB1, 0x50 }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0xF4, 0x5D, 0xB2, 0x0E, 0xEC, 0x35, 0x95, 0x7E, 0xC6, 0x40, 0x30, 0xF0, 0x0C, 0xE2, 0x7B, 0x7D }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x69, 0xA1, 0x79, 0xC5, 0xCD, 0x74, 0x43 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0x79, 0x2C, 0x4F, 0xD9, 0xDE, 0x44, 0xE1, 0x9B, 0xBF, 0xD6, 0xD4, 0x01, 0x1B, 0xB1, 0xB9, 0xCC }); }
public void Derive_GCM() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, null, AlgorithmValues.AES_GCM_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x6B, 0xE5, 0x0D, 0x26, 0x2D, 0xF4, 0x63 }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0xAA, 0x43, 0x2E, 0xA7, 0xF4, 0xC0, 0xAF, 0x8E, 0x1B, 0x0D, 0x82, 0xD0, 0x13, 0x50, 0xC1, 0xCB }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0xB3, 0x02, 0xED, 0xB7, 0xFB, 0xF7, 0x9E }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0x04, 0xCF, 0xD6, 0xF1, 0xE2, 0x64, 0xF4, 0x95, 0x7D, 0xC3, 0xE1, 0x6F, 0x32, 0x09, 0x11, 0x4E }); }
public void Derive_Hash512() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, _Salt, AlgorithmValues.AES_CCM_16_64_128, AlgorithmValues.ECDH_SS_HKDF_512); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0xAB, 0xCE, 0x1E, 0x0A, 0x26, 0x80, 0x66, 0x76, 0xC4, 0x3A, 0x38, 0x94, 0x55 }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0xB6, 0xC4, 0x06, 0xD0, 0x2C, 0x3B, 0xDC, 0x8D, 0xFE, 0x21, 0x03, 0x93, 0xC8, 0x3F, 0xFC, 0xFA }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0xAB, 0xCE, 0x0E, 0x03, 0x3D, 0x93, 0x6D, 0x70, 0xC4, 0x3A, 0x38, 0x94, 0x55 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0xA6, 0x60, 0x66, 0xBB, 0x88, 0xCE, 0x9B, 0x24, 0xCC, 0xE3, 0x00, 0xE7, 0x23, 0xB1, 0x5C, 0x7F }); }
public void Derive_Salt() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, _Salt, AlgorithmValues.AES_CCM_64_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x35, 0x12, 0x7A, 0x79, 0x77, 0xAD, 0x8C }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0xF4, 0x70, 0x23, 0x71, 0x3B, 0x40, 0xA2, 0x61, 0x17, 0xD4, 0xA8, 0x33, 0xF7, 0x70, 0xC3, 0xB0 }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x33, 0x86, 0xBA, 0x6E, 0x7E, 0x0C, 0x13 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0x09, 0xF6, 0x3F, 0xFB, 0x75, 0xAB, 0x1F, 0x10, 0x1B, 0x2D, 0x41, 0xA6, 0xB2, 0x2D, 0x42, 0x0E }); }
public void Derive_Salt() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, _Salt, AlgorithmValues.AES_CCM_16_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x84, 0x2C, 0xB2, 0x77, 0xDC, 0xA6, 0x1A, 0xE3, 0x8C, 0x2F, 0x3E, 0x25, 0x18 }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0x9E, 0x54, 0x18, 0x11, 0xD2, 0xFA, 0x52, 0xEB, 0x05, 0x86, 0xD3, 0x88, 0xA0, 0x92, 0xAC, 0x93 }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x84, 0x2C, 0xA2, 0x7E, 0xC7, 0xB5, 0x11, 0xE5, 0x8C, 0x2F, 0x3E, 0x25, 0x18 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0xAD, 0x35, 0xAF, 0xD2, 0xA8, 0x86, 0x08, 0x8A, 0x13, 0xD6, 0x94, 0x04, 0x34, 0x0A, 0xC0, 0x1E }); }
public void Ocoap_Get() { CoapClient client = new CoapClient($"coap://localhost:{_serverPort}/abc") { OscoreContext = SecurityContext.DeriveContext(_Secret, null, _ClientId, _ServerId) }; Response r = client.Get(); Assert.AreEqual("/abc", r.PayloadString); }
public void Derive_C_1_1() { SecurityContext ctx = SecurityContext.DeriveContext(_Doc_Secret, _Doc_SenderId, _Doc_RecipientId, _Doc_Salt); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x46, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x68, 0xee, 0xfb, 0x54, 0x98, 0x7c }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0xf0, 0x91, 0x0e, 0xd7, 0x29, 0x5e, 0x6a, 0xd4, 0xb5, 0x4f, 0xc7, 0x93, 0x15, 0x43, 0x02, 0xff }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0xff, 0xb1, 0x4e, 0x09, 0x3c, 0x94, 0xc9, 0xca, 0xc9, 0x47, 0x16, 0x48, 0xb4, 0xf9, 0x87, 0x10 }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x47, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x69, 0xee, 0xfb, 0x54, 0x98, 0x7c }); }
public void Derive_C_2_1() { byte[] senderId = new byte[] { 0 }; SecurityContext ctx = SecurityContext.DeriveContext(_Doc_Secret, senderId, _Doc_RecipientId); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0x32, 0x1b, 0x26, 0x94, 0x32, 0x53, 0xc7, 0xff, 0xb6, 0x00, 0x3b, 0x0b, 0x64, 0xd7, 0x40, 0x41 }); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe9, 0x10, 0xc5, 0x2e, 0x99, 0xf9 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0xe5, 0x7b, 0x56, 0x35, 0x81, 0x51, 0x77, 0xcd, 0x67, 0x9a, 0xb4, 0xbc, 0xec, 0x9d, 0x7d, 0xda }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe8, 0x10, 0xc5, 0x2e, 0x99, 0xf9 }); }
public void Derive_CCM() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, null, AlgorithmValues.AES_CCM_64_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x01, 0x53, 0xDD, 0xFE, 0xDE, 0x44, 0x19 }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0x21, 0x64, 0x42, 0xDA, 0x60, 0x3C, 0x51, 0x59, 0x2D, 0xF4, 0xC3, 0xD0, 0xCD, 0x1D, 0x0D, 0x48 }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x20, 0x75, 0x0B, 0x95, 0xF9, 0x78, 0xC8 }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0xD5, 0xCB, 0x37, 0x10, 0x37, 0x15, 0x34, 0xA1, 0xCA, 0x22, 0x4E, 0x19, 0xEB, 0x96, 0xE9, 0x6D }); SecurityContext ctx2 = SecurityContext.DeriveContext(_Secret, _RecipientId, _SenderId, null, AlgorithmValues.AES_CCM_64_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, ctx2.Recipient.BaseIV); Assert.AreEqual(ctx.Sender.Key, ctx2.Recipient.Key); }
public void Derive_CCM() { SecurityContext ctx = SecurityContext.DeriveContext(_Secret, _SenderId, _RecipientId, null, AlgorithmValues.AES_CCM_16_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, new byte[] { 0x6D, 0xD5, 0x8C, 0x18, 0xFD, 0x22, 0xFB, 0xA8, 0xB4, 0xA7, 0xA2, 0xD0, 0x6B }); Assert.AreEqual(ctx.Sender.Key, new byte[] { 0x8D, 0x41, 0x3A, 0xD6, 0x59, 0xFA, 0x1C, 0xF0, 0xB0, 0x7C, 0x2F, 0xD9, 0x6A, 0x53, 0x75, 0xC3 }); Assert.AreEqual(ctx.Recipient.BaseIV, new byte[] { 0x6D, 0xD5, 0x9C, 0x11, 0xE6, 0x31, 0xF0, 0xAE, 0xB4, 0xA7, 0xA2, 0xD0, 0x6B }); Assert.AreEqual(ctx.Recipient.Key, new byte[] { 0x4E, 0x48, 0xF7, 0xCB, 0xDC, 0x2E, 0x71, 0x89, 0x9A, 0x6B, 0x3C, 0x82, 0x13, 0x4F, 0xE5, 0x09 }); SecurityContext ctx2 = SecurityContext.DeriveContext(_Secret, _RecipientId, _SenderId, null, AlgorithmValues.AES_CCM_16_64_128, _KeyAgreeAlg); Assert.AreEqual(ctx.Sender.BaseIV, ctx2.Recipient.BaseIV); Assert.AreEqual(ctx.Sender.Key, ctx2.Recipient.Key); }
private void CreateServer() { CoAPEndPoint endpoint = new CoAPEndPoint(0); _server = new CoapServer(); // _resource = new StorageResource(TARGET, CONTENT_1); // _server.Add(_resource); Resource r2 = new EchoLocation("abc"); _server.Add(r2); r2.Add(new EchoLocation("def")); _server.AddEndPoint(endpoint); _server.Start(); _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port; SecurityContextSet oscoapContexts = new SecurityContextSet(); SecurityContextSet.AllContexts.Add(SecurityContext.DeriveContext(_Secret, null, _ServerId, _ClientId)); }