{"action":"created","issue":{"url":"https://api.github.com/repos/Demonware/jose/issues/3","labels_url":"https://api.github.com/repos/Demonware/jose/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/Demonware/jose/issues/3/comments","events_url":"https://api.github.com/repos/Demonware/jose/issues/3/events","html_url":"https://github.com/Demonware/jose/pull/3","id":52791019,"number":3,"title":"Fix several issues with JWE encryption.","user":{"login":"jaimeperez","id":1942728,"avatar_url":"https://avatars.githubusercontent.com/u/1942728?v=3","gravatar_id":"","url":"https://api.github.com/users/jaimeperez","html_url":"https://github.com/jaimeperez","followers_url":"https://api.github.com/users/jaimeperez/followers","following_url":"https://api.github.com/users/jaimeperez/following{/other_user}","gists_url":"https://api.github.com/users/jaimeperez/gists{/gist_id}","starred_url":"https://api.github.com/users/jaimeperez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaimeperez/subscriptions","organizations_url":"https://api.github.com/users/jaimeperez/orgs","repos_url":"https://api.github.com/users/jaimeperez/repos","events_url":"https://api.github.com/users/jaimeperez/events{/privacy}","received_events_url":"https://api.github.com/users/jaimeperez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Demonware/jose/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-12-24T02:24:11Z","updated_at":"2015-01-15T02:14:33Z","closed_at":"2015-01-15T02:14:33Z","pull_request":{"url":"https://api.github.com/repos/Demonware/jose/pulls/3","html_url":"https://github.com/Demonware/jose/pull/3","diff_url":"https://github.com/Demonware/jose/pull/3.diff","patch_url":"https://github.com/Demonware/jose/pull/3.patch"},"body":"The issues, according to the [JWA spec](https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-38#section-5.2.2.1) are:\r\n* the **AL** field is not correctly calculated. It must represent the **length in bits** of the *additional authenticated data*, not in bytes. Additionally, it must be represented as an unsigned 64-bit octet string in big-endian, not as a simple string.\r\n\r\n> 5.2.2.1.4.  The octet string AL is equal to the number of bits in the additional authenticated data A expressed as a 64-bit unsigned big endian integer.\r\n\r\n* in order to compute the *authentication tag*, the **ciphertext** must be used, not the plaintext.\r\n\r\n> 5.2.2.1.5.  A message authentication tag T is computed by applying HMAC [RFC2104] to the following data, in order:\r\n> *         the additional authenticated data A,\r\n> *         the initialization vector IV,\r\n> *         the ciphertext E computed in the previous step, and\r\n> *         the octet string AL defined above.\r\n\r\n* in <tt>AES_CBC_HMAC_SHA2</tt>, the length of the input key equals to the digest size, that being 32, 48 and 64 octets for each of the three variants.\r\n\r\n>The AES_CBC_HMAC_SHA2 parameters specific to AES_128_CBC_HMAC_SHA_256 are:\r\n> *      The input key K is 32 octets long.\r\n> *     ENC_KEY_LEN is 16 octets.\r\n> *      MAC_KEY_LEN is 16 octets.\r\n\r\n* the **integrity key** and **encryption key** are derived as the first and second half of the input key, respectively.\r\n\r\n>The secondary keys MAC_KEY and ENC_KEY are generated from the input key K as follows.  Each of these two keys is an octet string.\r\n*         MAC_KEY consists of the initial MAC_KEY_LEN octets of K, in order.\r\n*         ENC_KEY consists of the final ENC_KEY_LEN octets of K, in order.\r\n\r\n>The number of octets in the input key K MUST be the sum of MAC_KEY_LEN and ENC_KEY_LEN.  The values of these parameters are specified by the Authenticated Encryption algorithms in Sections 5.2.3 through 5.2.5.  Note that the MAC key comes before the encryption key in the input key K; this is in the opposite order of the algorithm names in the identifier \"AES_CBC_HMAC_SHA2\"."},"comment":{"url":"https://api.github.com/repos/Demonware/jose/issues/comments/70029699","html_url":"https://github.com/Demonware/jose/pull/3#issuecomment-70029699","issue_url":"https://api.github.com/repos/Demonware/jose/issues/3","id":70029699,"user":{"login":"demianbrecht","id":1422155,"avatar_url":"https://avatars.githubusercontent.com/u/1422155?v=3","gravatar_id":"","url":"https://api.github.com/users/demianbrecht","html_url":"https://github.com/demianbrecht","followers_url":"https://api.github.com/users/demianbrecht/followers","following_url":"https://api.github.com/users/demianbrecht/following{/other_user}","gists_url":"https://api.github.com/users/demianbrecht/gists{/gist_id}","starred_url":"https://api.github.com/users/demianbrecht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demianbrecht/subscriptions","organizations_url":"https://api.github.com/users/demianbrecht/orgs","repos_url":"https://api.github.com/users/demianbrecht/repos","events_url":"https://api.github.com/users/demianbrecht/events{/privacy}","received_events_url":"https://api.github.com/users/demianbrecht/received_events","type":"User","site_admin":false},"created_at":"2015-01-15T02:14:33Z","updated_at":"2015-01-15T02:14:33Z","body":"This has been merged as part of the 0.2.2 release (and I've added you to CONTRIB). Thanks for the contribution!"}}