public void TestDecodeUnknown() { EncryptMessage msg = new EncryptMessage(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); // msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.PROTECTED); msg.SetContent(rgbContent); CBORObject obj = CBORObject.NewMap(); obj.Add("kty", "oct"); obj.Add("k", Encoding.UTF8.GetString(Base64.Encode(rgbKey128))); JWK key = new JWK(obj); Recipient recipient = new Recipient(key, "dir"); msg.AddRecipient(recipient); string rgbMsg = msg.Encode(); JoseException e = Assert.ThrowsException <JoseException>(() => msg = (EncryptMessage)Message.DecodeFromString(rgbMsg)); Assert.AreEqual(e.Message, ("Message was not tagged and no default tagging option given")); }
static Message ProcessEnveloped(CBORObject control, ref bool fDirty) { CBORObject input = control["input"]; CBORObject encrypt = input["enveloped"]; EncryptMessage msg = new EncryptMessage(); if (!input.ContainsKey("plaintext")) { throw new Exception("missing plaintext field"); } msg.SetContent(input["plaintext"].AsString()); if (encrypt.ContainsKey("protected")) { AddAttributes(msg, encrypt["protected"], 0); } if (encrypt.ContainsKey("unprotected")) { AddAttributes(msg, encrypt["unprotected"], 1); } if (encrypt.ContainsKey("unsent")) { AddAttributes(msg, encrypt["unsent"], 2); } if (encrypt.ContainsKey("alg")) { encrypt.Remove(CBORObject.FromObject("alg")); } if ((!encrypt.ContainsKey("recipients")) || (encrypt["recipients"].Type != CBORType.Array)) { throw new Exception("Missing or malformed recipients"); } foreach (CBORObject recipient in encrypt["recipients"].Values) { msg.AddRecipient(GetRecipient(recipient)); } { msg.Encode(); CBORObject intermediates = Program.GetSection(control, "intermediates"); // SetField(intermediates, "AAD_hex", msg.getAADBytes(), ref fDirty); // SetField(intermediates, "CEK_hex", msg.getCEK(), ref fDirty); CBORObject rList = Program.GetSection(intermediates, "recipients"); // SaveRecipientDebug(msg.RecipientList, rList, ref fDirty); } #if false // If we want this to fail, look at the different failure methods. if (input.ContainsKey("failures")) { msgOut = ProcessFailures(msgOut, input["failures"], 2); } #endif return(msg); }