public void testAddRecipient() { Recipient recipient = null; MACMessage instance = new MACMessage(); CoseException e = Assert.ThrowsException <CoseException>(() => instance.AddRecipient(recipient)); Assert.AreEqual(e.Message, ("Recipient is null")); }
public void macNoContent() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("No Content Specified")); }
public void macNoAlgorithm() { MAC0Message msg = new MAC0Message(); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("No Algorithm Specified")); }
public void EncryptNoContent() { Encrypt0Message msg = new Encrypt0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey128)); Assert.AreEqual(e.Message, ("No Content Specified")); }
public void noAlgorithm() { Sign1Message msg = new Sign1Message(); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Sign(cnKeyPrivate)); Assert.AreEqual(e.Message, ("No Algorithm Specified")); }
public void noContent() { Sign1Message msg = new Sign1Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.ECDSA_256, Attributes.PROTECTED); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Sign(cnKeyPrivate)); Assert.AreEqual(e.Message, ("No Content Specified")); }
public void macDecodeWrongBasis() { CBORObject obj = CBORObject.NewMap(); byte[] rgb = obj.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => Message.DecodeFromBytes(rgb, Tags.MAC)); Assert.AreEqual(e.Message, ("Message is not a COSE security message.")); }
public void EncryptUnsupportedAlgorithm() { Encrypt0Message msg = new Encrypt0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey128)); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void EncryptUnknownAlgorithm() { Encrypt0Message msg = new Encrypt0Message(); msg.AddAttribute(HeaderKeys.Algorithm, CBORObject.FromObject("Unknown"), Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey128)); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void macUnsupportedAlgorithm() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_CCM_16_64_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("MAC algorithm not recognized 11")); }
public void EncryptNoRecipients() { EncryptMessage msg = new EncryptMessage(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt()); Assert.AreEqual(e.Message, ("No recipients supplied")); }
public void EncryptIncorrectKeySize() { Encrypt0Message msg = new Encrypt0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey256)); Assert.AreEqual(e.Message, ("Incorrect Key Size")); }
public void signerDecodeWrongBasis() { CBORObject obj = CBORObject.NewMap(); Signer sig = new Signer(); CoseException e = Assert.ThrowsException <CoseException>(() => sig.DecodeFromCBORObject(obj)); Assert.AreEqual(e.Message, ("Invalid Signer structure")); }
public void unsupportedAlgorithm() { Sign1Message msg = new Sign1Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Sign(cnKeyPrivate)); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void macNoRecipients() { MACMessage msg = new MACMessage(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute()); Assert.AreEqual(e.Message, ("No recipients supplied")); }
public void publicKey() { Sign1Message msg = new Sign1Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.ECDSA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Sign(cnKeyPublic)); Assert.AreEqual(e.Message, ("Private key required to sign")); }
public void EncryptNoAlgorithm() { Encrypt0Message msg = new Encrypt0Message(); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey128)); Assert.AreEqual(e.Message, ("No Algorithm Specified")); }
public void unknownAlgorithm() { Sign1Message msg = new Sign1Message(); msg.AddAttribute(HeaderKeys.Algorithm, CBORObject.FromObject("Unknown"), Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Sign(cnKeyPrivate)); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void EncryptIncorrectIV() { Encrypt0Message msg = new Encrypt0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV128), Attributes.UNPROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt(rgbKey128)); Assert.AreEqual(e.Message, ("IV size is incorrect.")); }
public void macDecodeWrongCount() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.False); byte[] rgb = obj.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => Message.DecodeFromBytes(rgb, Tags.MAC)); Assert.AreEqual(e.Message, ("Invalid MAC structure")); }
public void macUnknownAlgorithm() { MACMessage msg = new MACMessage(); msg.AddRecipient(recipient256); msg.AddAttribute(HeaderKeys.Algorithm, CBORObject.FromObject("Unknown"), Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute()); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void EncryptUnsupportedAlgorithm() { EncryptMessage msg = new EncryptMessage(); msg.AddRecipient(recipient128); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt()); Assert.AreEqual(e.Message, ("Incorrect key size" /*"Unsupported Algorithm Specified"*/)); }
public void signerDecodeWrongCount() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.False); Signer sig = new Signer(); CoseException e = Assert.ThrowsException <CoseException>(() => sig.DecodeFromCBORObject(obj)); Assert.AreEqual(e.Message, ("Invalid Signer structure")); }
public void EncryptBadIV() { EncryptMessage msg = new EncryptMessage(); msg.AddRecipient(recipient128); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject("IV"), Attributes.UNPROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Encrypt()); Assert.AreEqual(e.Message, ("IV is incorrectly formed.")); }
public void EncryptDecodeBadTag() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.FromObject(CBORObject.NewArray()).EncodeToBytes()); obj.Add(CBORObject.NewMap()); obj.Add(new byte[0]); byte[] rgb = obj.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => Message.DecodeFromBytes(rgb, Tags.Encrypt0)); Assert.AreEqual(e.Message, ("Invalid Encrypt0 structure")); }
public void signerDecodeBadUnprotected() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.FromObject(CBORObject.NewArray()).EncodeToBytes()); obj.Add(CBORObject.False); obj.Add(CBORObject.False); Signer sig = new Signer(); CoseException e = Assert.ThrowsException <CoseException>(() => sig.DecodeFromCBORObject(obj)); Assert.AreEqual(e.Message, ("Invalid Signer structure")); }
public void testDecodeUnknown() { Encrypt0Message msg = new Encrypt0Message(false, true); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.PROTECTED); msg.SetContent(rgbContent); msg.Encrypt(rgbKey128); byte[] rgbMsg = msg.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => msg = (Encrypt0Message)Message.DecodeFromBytes(rgbMsg, Tags.Unknown)); Assert.AreEqual(e.Message, ("Message was not tagged and no default tagging option given")); }
public void decodeBadUnprotected() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.FromObject(CBORObject.NewArray()).EncodeToBytes()); obj.Add(CBORObject.False); obj.Add(CBORObject.False); obj.Add(CBORObject.False); byte[] rgb = obj.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => Message.DecodeFromBytes(rgb, Tags.Sign1)); Assert.AreEqual(e.Message, ("Invalid Sign1 structure")); }
public void signDecodeBadRecipients() { CBORObject obj = CBORObject.NewArray(); obj.Add(CBORObject.FromObject(CBORObject.NewArray()).EncodeToBytes()); obj.Add(CBORObject.NewMap()); obj.Add(new byte[0]); obj.Add(CBORObject.False); byte[] rgb = obj.EncodeToBytes(); CoseException e = Assert.ThrowsException <CoseException>(() => Message.DecodeFromBytes(rgb, Tags.Sign)); Assert.AreEqual(e.Message, ("Invalid SignMessage structure")); }
public void NoContentForDecrypt() { Encrypt0Message msg = new Encrypt0Message(true, false); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.UNPROTECTED); msg.SetContent(rgbContent); msg.Encrypt(rgbKey128); byte[] rgb = msg.EncodeToBytes(); msg = (Encrypt0Message)Message.DecodeFromBytes(rgb); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Decrypt(rgbKey128)); Assert.AreEqual(e.Message, ("No Encrypted Content Specified.")); }