1
0

jose_jwe.3 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. .TH "jose_jwe" 3 "Tue May 30 2017" "José" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. jose_jwe \- JSON Web Encryption (RFC 7516)
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .SS "Functions"
  10. .in +1c
  11. .ti -1c
  12. .RI "json_t * \fBjose_jwe_hdr\fP (const json_t *jwe, const json_t *rcp)"
  13. .br
  14. .RI "Merges the JOSE headers of a JWE object and a JWE recpient object\&. "
  15. .ti -1c
  16. .RI "bool \fBjose_jwe_enc\fP (jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, const void *pt, size_t ptl)"
  17. .br
  18. .RI "Wraps and encrypts plaintext\&. "
  19. .ti -1c
  20. .RI "\fBjose_io_t\fP * \fBjose_jwe_enc_io\fP (jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, \fBjose_io_t\fP *next)"
  21. .br
  22. .RI "Wraps and encrypts plaintext using streaming\&. "
  23. .ti -1c
  24. .RI "bool \fBjose_jwe_enc_jwk\fP (jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, json_t *cek)"
  25. .br
  26. .RI "Wraps a CEK with a JWK\&. "
  27. .ti -1c
  28. .RI "bool \fBjose_jwe_enc_cek\fP (jose_cfg_t *cfg, json_t *jwe, const json_t *cek, const void *pt, size_t ptl)"
  29. .br
  30. .RI "Encrypts plaintext with the CEK\&. "
  31. .ti -1c
  32. .RI "\fBjose_io_t\fP * \fBjose_jwe_enc_cek_io\fP (jose_cfg_t *cfg, json_t *jwe, const json_t *cek, \fBjose_io_t\fP *next)"
  33. .br
  34. .RI "Encrypts plaintext with the CEK using streaming\&. "
  35. .ti -1c
  36. .RI "void * \fBjose_jwe_dec\fP (jose_cfg_t *cfg, const json_t *jwe, const json_t *rcp, const json_t *jwk, size_t *ptl)"
  37. .br
  38. .RI "Unwraps and decrypts ciphertext\&. "
  39. .ti -1c
  40. .RI "\fBjose_io_t\fP * \fBjose_jwe_dec_io\fP (jose_cfg_t *cfg, const json_t *jwe, const json_t *rcp, const json_t *jwk, \fBjose_io_t\fP *next)"
  41. .br
  42. .RI "Unwraps and decrypts ciphertext using streaming\&. "
  43. .ti -1c
  44. .RI "json_t * \fBjose_jwe_dec_jwk\fP (jose_cfg_t *cfg, const json_t *jwe, const json_t *rcp, const json_t *jwk)"
  45. .br
  46. .RI "Unwraps a CEK with a JWK\&. "
  47. .ti -1c
  48. .RI "void * \fBjose_jwe_dec_cek\fP (jose_cfg_t *cfg, const json_t *jwe, const json_t *cek, size_t *ptl)"
  49. .br
  50. .RI "Decrypts ciphertext with the CEK\&. "
  51. .ti -1c
  52. .RI "\fBjose_io_t\fP * \fBjose_jwe_dec_cek_io\fP (jose_cfg_t *cfg, const json_t *jwe, const json_t *cek, \fBjose_io_t\fP *next)"
  53. .br
  54. .RI "Decrypts ciphertext with the CEK using streaming\&. "
  55. .in -1c
  56. .SH "Detailed Description"
  57. .PP
  58. JSON Web Encryption (RFC 7516)
  59. A JSON Web Encryption (JWE) object contains (usually) two levels of encryption\&. First, the plaintext is encrypted with a random symmetric key\&. In José, we call this key the Content Encryption Key (CEK)\&. Next, the CEK is wrapped (encrypted) with one or more keys\&. These keys are standard JSON Web Keys (JWK) and may be symmetric or asymmetric\&.
  60. .PP
  61. Thus there is (usually) one CEK and one or more JWKs\&. However, there are some exceptions to this rule\&. Two such examples are the algorithms: 'dir' and 'ECDH-ES'\&. In the first case, the JWK is a symmetric key and is used directly as the CEK\&. In the second case, an ECDH key exchange is performed and the result is used directly as the CEK\&. But in general, the maxim holds\&.
  62. .PP
  63. This means that you can encrypt the data using one CEK and then encrypt the CEK to multiple recipients\&. With this schema, multiple recipients can each decrypt the data using their own key without having to send separate ciphertext to each recipient\&.
  64. .PP
  65. For maximum flexibility, José structures its API to take advantage of this schema\&. For example, when encrypting to two recipients, the code could look like this (error handling omitted):
  66. .PP
  67. .nf
  68. json_t *enc(void *plaintext, size_t len, json_t *jwk0, json_t *jwk1) {
  69. json_auto_t *jwe = json_object();
  70. json_auto_t *cek = json_object();
  71. // Wrap to the first recipient (CEK generated implicitly)
  72. jose_jwe_enc_jwk(NULL, jwe, NULL, jwk0, cek);
  73. // Wrap to the second recipient
  74. jose_jwe_enc_jwk(NULL, jwe, NULL, jwk1, cek);
  75. // Encrypt plaintext using the generated CEK
  76. jose_jwe_enc_cek(NULL, jwe, cek, plaintext, len);
  77. return json_incref(jwe);
  78. }
  79. .fi
  80. .PP
  81. .PP
  82. However, because José intends to be easy to use, we also provide shortcuts\&. For example, you could use a JWKSet which contains multiple JWKs:
  83. .PP
  84. .nf
  85. json_t *enc(void *plaintext, size_t len, json_t *jwkset) {
  86. json_auto_t *jwe = json_object();
  87. // Perform wrapping and encryption to all recipients
  88. jose_jwe_enc(NULL, jwe, NULL, jwkset, plaintext, len);
  89. return json_incref(jwe);
  90. }
  91. .fi
  92. .PP
  93. .PP
  94. Here are two tips to remember\&. First, let José generate your CEK implicitly\&. Second, always perform wrapping before encryption\&. Both of these tips are important because some wrapping algorithms may impose constraints on the generation of the CEK\&.
  95. .PP
  96. To decrypt a JWE, we just reverse the process\&. First, we use a JWK to unwrap the CEK\&. Then we use the CEK to decrypt the ciphertext\&. Here is how that might look in code (again, error handling omitted):
  97. .PP
  98. .nf
  99. void *dec(json_t *jwe, json_t *jwk, size_t *len) {
  100. json_auto_t *cek = NULL;
  101. // Unwrap the CEK using our JWK
  102. cek = jose_jwe_dec_jwk(NULL, jwe, NULL, jwk);
  103. // Decrypt ciphertext using the CEK
  104. return jose_jwe_dec_cek(NULL, jwe, cek, len);
  105. }
  106. .fi
  107. .PP
  108. .PP
  109. Or, again, in simplified form:
  110. .PP
  111. .nf
  112. void *dec(json_t *jwe, json_t *jwk, size_t *len) {
  113. return jose_jwe_dec(NULL, jwe, NULL, jwk, len);
  114. }
  115. .fi
  116. .PP
  117. .PP
  118. If you need to forward a JWE to a new recipient, you can do this without performing re-encryption\&. Just unwrap the CEK and then wrap the CEK again using a new JWK\&. For example:
  119. .PP
  120. .nf
  121. void fwd(json_t *jwe, json_t *oldjwk, json_t *newjwk) {
  122. json_auto_t *cek = NULL;
  123. // Unwrap the CEK using the old JWK
  124. cek = jose_jwe_dec_jwk(NULL, jwe, NULL, oldjwk);
  125. // Wrap the CEK to the new JWK
  126. jose_jwe_enc_jwk(NULL, jwe, NULL, newjwk, cek);
  127. }
  128. .fi
  129. .PP
  130. .PP
  131. In all the above examples, parameters like which encryption algorithms to use were inferred from our keys\&. Where such an inferrence cannot be made, sensible and secure defaults were chosen automatically\&. If you would like more control over the process, simply set parameters in the appropriate objects (more on this in the function documentation)\&. For example, to enable plaintext compression, you can specify the \fCzip\fP property in the JWE Protected Header:
  132. .PP
  133. .nf
  134. json_t *enc(void *plaintext, size_t len, json_t *jwkset) {
  135. json_auto_t *jwe = json_pack("{s:{s:s}}", "protected", "zip", "DEF");
  136. // Perform compressed wrapping and encryption to all recipients
  137. jose_jwe_enc(NULL, jwe, NULL, jwkset, plaintext, len);
  138. return json_incref(jwe);
  139. }
  140. .fi
  141. .PP
  142. .PP
  143. José currently supports the 'alg', 'enc' and 'zip' header parameters, as well as any algorithm-specific header parameters used by the specific algorithms we implement\&. Other header parameters may be specified, but do not effect the behavior of José's JWE implementation\&.
  144. .PP
  145. \fBSee also:\fP
  146. .RS 4
  147. https://tools.ietf.org/html/rfc7516
  148. .RE
  149. .PP
  150. .SH "Function Documentation"
  151. .PP
  152. .SS "json_t* jose_jwe_hdr (const json_t * jwe, const json_t * rcp)"
  153. .PP
  154. Merges the JOSE headers of a JWE object and a JWE recpient object\&.
  155. .PP
  156. \fBParameters:\fP
  157. .RS 4
  158. \fIjwe\fP A JWE object\&.
  159. .br
  160. \fIrcp\fP A JWE recipient object\&.
  161. .RE
  162. .PP
  163. \fBReturns:\fP
  164. .RS 4
  165. The newly allocated JOSE header\&.
  166. .RE
  167. .PP
  168. .SS "bool jose_jwe_enc (jose_cfg_t * cfg, json_t * jwe, json_t * rcp, const json_t * jwk, const void * pt, size_t ptl)"
  169. .PP
  170. Wraps and encrypts plaintext\&. This function is a thin wrapper around the \fBjose_jwe_enc_io()\fP function allowing the user to specify the plaintext in a single call\&. The ciphertext output will be appended to the JWE as the 'ciphertext' property\&.
  171. .PP
  172. \fBSee also:\fP
  173. .RS 4
  174. \fBjose_jwe_enc_cek_io()\fP
  175. .RE
  176. .PP
  177. \fBParameters:\fP
  178. .RS 4
  179. \fIcfg\fP The configuration context (optional)\&.
  180. .br
  181. \fIjwe\fP The JWE object\&.
  182. .br
  183. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  184. .br
  185. \fIjwk\fP The JWK(s) or JWKSet used for wrapping\&.
  186. .br
  187. \fIpt\fP The plaintext\&.
  188. .br
  189. \fIptl\fP The length of the plaintext\&.
  190. .RE
  191. .PP
  192. \fBReturns:\fP
  193. .RS 4
  194. On success, true\&. Otherwise, false\&.
  195. .RE
  196. .PP
  197. .SS "\fBjose_io_t\fP* jose_jwe_enc_io (jose_cfg_t * cfg, json_t * jwe, json_t * rcp, const json_t * jwk, \fBjose_io_t\fP * next)"
  198. .PP
  199. Wraps and encrypts plaintext using streaming\&. This function is a thin wrapper around the \fBjose_jwe_enc_jwk()\fP and \fBjose_jwe_enc_cek_io()\fP functions, removing the complexity of managing the CEK\&.
  200. .PP
  201. \fBSee also:\fP
  202. .RS 4
  203. \fBjose_jwe_enc_jwk()\fP
  204. .PP
  205. \fBjose_jwe_enc_cek_io()\fP
  206. .RE
  207. .PP
  208. \fBParameters:\fP
  209. .RS 4
  210. \fIcfg\fP The configuration context (optional)\&.
  211. .br
  212. \fIjwe\fP The JWE object\&.
  213. .br
  214. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  215. .br
  216. \fIjwk\fP The JWK(s) or JWKSet used for wrapping\&.
  217. .br
  218. \fInext\fP The next IO object in the chain\&.
  219. .RE
  220. .PP
  221. \fBReturns:\fP
  222. .RS 4
  223. The new IO object or NULL on error\&.
  224. .RE
  225. .PP
  226. .SS "bool jose_jwe_enc_jwk (jose_cfg_t * cfg, json_t * jwe, json_t * rcp, const json_t * jwk, json_t * cek)"
  227. .PP
  228. Wraps a CEK with a JWK\&. The purpose of this function is to wrap (encrypt) or, in some cases, produce the CEK (\fCcek\fP) from the provided JWK(s) (\fCjwk\fP)\&. This function can be used in two modes: single-JWK and multi-JWK\&.
  229. .PP
  230. In single-JWK mode, the \fCjwk\fP parameter contains a JWK object and the \fCrcp\fP parameter must contain either a JWE recipient object or NULL, in which case a default empty JWE recipient object is created internally\&.
  231. .PP
  232. Multi-JWK mode works exactly the same as single-JWK mode except that it performs multiple wrappings in a single call\&. This mode is enabled by passing either an array of JWK objects or a JWKSet as the \fCjwk\fP parameter\&. In this mode, the \fCrcp\fP parameter contains one of the following values:
  233. .PP
  234. .IP "1." 4
  235. A JWE recipient object that will be used for all wrappings\&. In this case, a copy will be made for each wrapping and \fCrcp\fP will not be modified in any way\&.
  236. .IP "2." 4
  237. An array of JWE recipient objects\&. Each object will be used with its corresponding JWK from \fCjwk\fP\&. If the arrays in \fCsig\fP and \fCjwk\fP are a different size, an error will occur\&.
  238. .IP "3." 4
  239. NULL\&. This has the same effect as passing NULL for each separate JWK\&.
  240. .PP
  241. .PP
  242. In either mode, if the resulting JWE (\fCjwe\fP) would contain only a single recipient, the JWE will be represented in Flattened JWE JSON Serialization Syntax\&. Otherwise, it will be represented in General JWE JSON Serialization Syntax\&.
  243. .PP
  244. If the 'alg' parameter is not specified in the JOSE Header, it will be inferred from the JWK and the chosen algorithm will be added to the JWE Per-Recipient Unprotected Header\&. Likewise, any missing, required, algorithm-specific parameters will be either inferred or sensible, secure defaults will be chosen and the results will be added to the JWE Per-Recipient Unprotected Header\&.
  245. .PP
  246. If the provided CEK (\fCcek\fP) does not contain key material, it will be implicitly generated during the first call to \fBjose_jwe_enc_jwk()\fP\&. This important feature enables the use of the 'dir' and 'ECDH-ES' algorithms\&. In the case of the 'dir' algorithm, the JWK is the CEK and thus the key material is copied from \fCjwk\fP to \fCcek\fP\&. A similar situation arises with the algorithm 'ECDH-ES' where the result of a key exchange is used as the CEK; thus, the CEK is produced during the wrapping process\&. This feature implies that if multiple wrappings are created, only one of them may have the algorithm 'ECDH-ES' and it must be the first wrapping\&. Attempting to use 'ECDH-ES' with an existing CEK will result in an error\&.
  247. .PP
  248. It is additionally possible to pass a password JSON string as key input to the PBES2 family of algorithms anywhere a JWK can be used\&. Likewise, if the 'alg' JOSE Header parameter is not specified and a JSON string is used in place of a JWK, the PBES2 family of algorithms will be inferred\&.
  249. .PP
  250. \fBParameters:\fP
  251. .RS 4
  252. \fIcfg\fP The configuration context (optional)\&.
  253. .br
  254. \fIjwe\fP The JWE object\&.
  255. .br
  256. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  257. .br
  258. \fIjwk\fP The JWK(s) or JWKSet used for wrapping\&.
  259. .br
  260. \fIcek\fP The CEK to wrap (if empty, generated)\&.
  261. .RE
  262. .PP
  263. \fBReturns:\fP
  264. .RS 4
  265. On success, true\&. Otherwise, false\&.
  266. .RE
  267. .PP
  268. .SS "bool jose_jwe_enc_cek (jose_cfg_t * cfg, json_t * jwe, const json_t * cek, const void * pt, size_t ptl)"
  269. .PP
  270. Encrypts plaintext with the CEK\&. This function is a thin wrapper around the \fBjose_jwe_enc_cek_io()\fP function allowing the user to specify the plaintext in a single call\&. The ciphertext output will be appended to the JWE as the 'ciphertext' property\&.
  271. .PP
  272. \fBSee also:\fP
  273. .RS 4
  274. \fBjose_jwe_enc_cek_io()\fP
  275. .RE
  276. .PP
  277. \fBParameters:\fP
  278. .RS 4
  279. \fIcfg\fP The configuration context (optional)\&.
  280. .br
  281. \fIjwe\fP The JWE object\&.
  282. .br
  283. \fIcek\fP The CEK object\&.
  284. .br
  285. \fIpt\fP The plaintext\&.
  286. .br
  287. \fIptl\fP The length of the plaintext\&.
  288. .RE
  289. .PP
  290. \fBReturns:\fP
  291. .RS 4
  292. On success, true\&. Otherwise, false\&.
  293. .RE
  294. .PP
  295. .SS "\fBjose_io_t\fP* jose_jwe_enc_cek_io (jose_cfg_t * cfg, json_t * jwe, const json_t * cek, \fBjose_io_t\fP * next)"
  296. .PP
  297. Encrypts plaintext with the CEK using streaming\&. The plaintext is provided through the returned IO object\&. The plaintext will be encrypted and written to the \fCnext\fP IO object\&. This IO object works on binary data, so you may need to use a URL-safe Base64 decoder on input and a URL-safe Base64 encoder on output, depending on your situation\&.
  298. .PP
  299. Compressed plaintext can be implicitly enabled by specifying the 'zip' parameter the JWE Protected Header\&.
  300. .PP
  301. If the JWE Protected Header is a JSON object rather than an encoded string, this function will encode the JWE Protected Header to its URL-safe Base64 encoding as defined in RFC 7516\&. However, this function will never modify a JWE Protected Header that is already encoded\&.
  302. .PP
  303. If the 'enc' parameter is not specified in the JWE Protected Header or the JWE Shared Unprotected Header, it will be inferred from the CEK and stored in either the JWE Protected Header or the JWE Shared Unprotected Header (preferring the JWE Protected header if it can be modified)\&.
  304. .PP
  305. Please note that the 'tag' property will only be added to the JWE when \fBjose_io_t::done()\fP returns\&.
  306. .PP
  307. \fBParameters:\fP
  308. .RS 4
  309. \fIcfg\fP The configuration context (optional)\&.
  310. .br
  311. \fIjwe\fP The JWE object\&.
  312. .br
  313. \fIcek\fP The CEK object\&.
  314. .br
  315. \fInext\fP The next IO object in the chain\&.
  316. .RE
  317. .PP
  318. \fBReturns:\fP
  319. .RS 4
  320. The new IO object or NULL on error\&.
  321. .RE
  322. .PP
  323. .SS "void* jose_jwe_dec (jose_cfg_t * cfg, const json_t * jwe, const json_t * rcp, const json_t * jwk, size_t * ptl)"
  324. .PP
  325. Unwraps and decrypts ciphertext\&. This function is a thin wrapper around the \fBjose_jwe_dec_io()\fP function allowing the user to obtain the plaintext in a single call\&. The ciphertext input will be obtained from the JWE 'ciphertext' property\&.
  326. .PP
  327. \fBSee also:\fP
  328. .RS 4
  329. \fBjose_jwe_dec_io()\fP
  330. .RE
  331. .PP
  332. \fBParameters:\fP
  333. .RS 4
  334. \fIcfg\fP The configuration context (optional)\&.
  335. .br
  336. \fIjwe\fP The JWE object\&.
  337. .br
  338. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  339. .br
  340. \fIjwk\fP The JWK(s) or JWKSet used for wrapping\&.
  341. .br
  342. \fIptl\fP The length of the plaintext (output)\&.
  343. .RE
  344. .PP
  345. \fBReturns:\fP
  346. .RS 4
  347. The newly-allocated plaintext\&.
  348. .RE
  349. .PP
  350. .SS "\fBjose_io_t\fP* jose_jwe_dec_io (jose_cfg_t * cfg, const json_t * jwe, const json_t * rcp, const json_t * jwk, \fBjose_io_t\fP * next)"
  351. .PP
  352. Unwraps and decrypts ciphertext using streaming\&. This function is a thin wrapper around the \fBjose_jwe_dec_jwk()\fP and \fBjose_jwe_dec_cek_io()\fP functions, removing the complexity of managing the CEK\&.
  353. .PP
  354. \fBSee also:\fP
  355. .RS 4
  356. \fBjose_jwe_dec_jwk()\fP
  357. .PP
  358. \fBjose_jwe_dec_cek_io()\fP
  359. .RE
  360. .PP
  361. \fBParameters:\fP
  362. .RS 4
  363. \fIcfg\fP The configuration context (optional)\&.
  364. .br
  365. \fIjwe\fP The JWE object\&.
  366. .br
  367. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  368. .br
  369. \fIjwk\fP The JWK(s) or JWKSet used for unwrapping\&.
  370. .br
  371. \fInext\fP The next IO object in the chain\&.
  372. .RE
  373. .PP
  374. \fBReturns:\fP
  375. .RS 4
  376. The new IO object or NULL on error\&.
  377. .RE
  378. .PP
  379. .SS "json_t* jose_jwe_dec_jwk (jose_cfg_t * cfg, const json_t * jwe, const json_t * rcp, const json_t * jwk)"
  380. .PP
  381. Unwraps a CEK with a JWK\&. The purpose of this function is to unwrap (decrypt) or, in some cases, produce the CEK (\fCcek\fP) from the provided JWK(s) (\fCjwk\fP)\&. This function can be used in two modes: single-JWK and multi-JWK\&.
  382. .PP
  383. In single-JWK mode, the \fCjwk\fP parameter contains a JWK object and the \fCrcp\fP parameter must contain either a JWE recipient object you wish to unwrap or NULL, in which case all JWE recipients will be tried\&.
  384. .PP
  385. Multi-JWK mode works exactly the same as single-JWK mode except that it attempts to unwrap with multiple JWKs in a single call\&. This mode is enabled by passing either an array of JWK objects or a JWKSet as the \fCjwk\fP parameter\&. In this mode, the \fCrcp\fP parameter contains one of the following values:
  386. .PP
  387. .IP "1." 4
  388. A JWE recipient object that will be used for all attempted unwrappings\&.
  389. .IP "2." 4
  390. An array of JWE recipient objects\&. Each object will be used with its corresponding JWK from \fCjwk\fP\&. If the arrays in \fCsig\fP and \fCjwk\fP are a different size, an error will occur\&.
  391. .IP "3." 4
  392. NULL\&. This has the same effect as passing NULL for each separate JWK\&.
  393. .PP
  394. .PP
  395. In either mode, a CEK is returned for the first JWK that successfully unwraps a CEK\&. Two exceptions to this rule are if the 'dir' or 'ECDH-ES' algorithms are used\&. In this case, a CEK may be returned which will fail during decryption since there is no way to completely validate the JWK with these algorithms\&. Thus, we suggest placing the keys for these algorithms last when unwrapping with multiple JWKs\&.
  396. .PP
  397. If the 'alg' parameter is not specified in the JOSE Header, it will be inferred from the JWK\&. This includes using a JSON string in place of a JWK for the PBES2 family of algorithms\&.
  398. .PP
  399. \fBParameters:\fP
  400. .RS 4
  401. \fIcfg\fP The configuration context (optional)\&.
  402. .br
  403. \fIjwe\fP The JWE object\&.
  404. .br
  405. \fIrcp\fP The JWE recipient object(s) or NULL\&.
  406. .br
  407. \fIjwk\fP The JWK(s) or JWKSet used for wrapping\&.
  408. .RE
  409. .PP
  410. \fBReturns:\fP
  411. .RS 4
  412. On success, a newly-allocated CEK object\&. Otherwise, NULL\&.
  413. .RE
  414. .PP
  415. .SS "void* jose_jwe_dec_cek (jose_cfg_t * cfg, const json_t * jwe, const json_t * cek, size_t * ptl)"
  416. .PP
  417. Decrypts ciphertext with the CEK\&. This function is a thin wrapper around the \fBjose_jwe_dec_cek_io()\fP function allowing the user to obtain the plaintext in a single call\&. The ciphertext input will be obtained from the JWE 'ciphertext' property\&.
  418. .PP
  419. \fBSee also:\fP
  420. .RS 4
  421. \fBjose_jwe_dec_cek_io()\fP
  422. .RE
  423. .PP
  424. \fBParameters:\fP
  425. .RS 4
  426. \fIcfg\fP The configuration context (optional)\&.
  427. .br
  428. \fIjwe\fP The JWE object\&.
  429. .br
  430. \fIcek\fP The CEK object\&.
  431. .br
  432. \fIptl\fP The length of the plaintext (output)\&.
  433. .RE
  434. .PP
  435. \fBReturns:\fP
  436. .RS 4
  437. The newly-allocated plaintext\&.
  438. .RE
  439. .PP
  440. .SS "\fBjose_io_t\fP* jose_jwe_dec_cek_io (jose_cfg_t * cfg, const json_t * jwe, const json_t * cek, \fBjose_io_t\fP * next)"
  441. .PP
  442. Decrypts ciphertext with the CEK using streaming\&. The ciphertext is provided through the returned IO object\&. The ciphertext will be decrypted and written to the \fCnext\fP IO object\&. This IO object works on binary data, so you may need to use a URL-safe Base64 decoder on input and a URL-safe Base64 encoder on output, depending on your situation\&.
  443. .PP
  444. Please note that validation of the ciphertext integrity protection is delayed until \fBjose_io_t::done()\fP returns\&. This means it is incredibly important to check this return value and it is also important to be careful with the plaintext emitted until this check is performed\&.
  445. .PP
  446. Compressed plaintext will be internally decompressed if the 'zip' property is appropriately defined\&.
  447. .PP
  448. If the 'enc' parameter is not specified in the JWE Protected Header or the JWE Shared Unprotected Header, it will be inferred from the CEK\&.
  449. .PP
  450. Please note that the 'tag' property on the JWE will only be accessed when \fBjose_io_t::done()\fP is called\&. So you may define it at any time on the JWE object before calling \fBjose_io_t::done()\fP\&.
  451. .PP
  452. \fBParameters:\fP
  453. .RS 4
  454. \fIcfg\fP The configuration context (optional)\&.
  455. .br
  456. \fIjwe\fP The JWE object\&.
  457. .br
  458. \fIcek\fP The CEK object\&.
  459. .br
  460. \fInext\fP The next IO object in the chain\&.
  461. .RE
  462. .PP
  463. \fBReturns:\fP
  464. .RS 4
  465. The new IO object or NULL on error\&.
  466. .RE
  467. .PP
  468. .SH "Author"
  469. .PP
  470. Generated automatically by Doxygen for José from the source code\&.