jose_jwk.3 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. .TH "jose_jwk" 3 "Tue May 30 2017" "José" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. jose_jwk \- JSON Web Keys (RFC 7517)
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .SS "Functions"
  10. .in +1c
  11. .ti -1c
  12. .RI "bool \fBjose_jwk_gen\fP (jose_cfg_t *cfg, json_t *jwk)"
  13. .br
  14. .RI "Generates a new JWK\&. "
  15. .ti -1c
  16. .RI "bool \fBjose_jwk_pub\fP (jose_cfg_t *cfg, json_t *jwk)"
  17. .br
  18. .RI "Removes all private key material from a JWK\&. "
  19. .ti -1c
  20. .RI "bool \fBjose_jwk_prm\fP (jose_cfg_t *cfg, const json_t *jwk, bool req, const char *op)"
  21. .br
  22. .RI "Determines if an operation is permitted for a JWK\&. "
  23. .ti -1c
  24. .RI "json_t * \fBjose_jwk_thp\fP (jose_cfg_t *cfg, const json_t *jwk, const char *alg)"
  25. .br
  26. .RI "Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string\&. "
  27. .ti -1c
  28. .RI "size_t \fBjose_jwk_thp_buf\fP (jose_cfg_t *cfg, const json_t *jwk, const char *alg, uint8_t *thp, size_t len)"
  29. .br
  30. .RI "Calculates the thumbprint of a JWK\&. "
  31. .ti -1c
  32. .RI "json_t * \fBjose_jwk_exc\fP (jose_cfg_t *cfg, const json_t *prv, const json_t *pub)"
  33. .br
  34. .RI "Perform a key exchange\&. "
  35. .in -1c
  36. .SH "Detailed Description"
  37. .PP
  38. JSON Web Keys (RFC 7517)
  39. A JSON Web Key (JWS) is a standard data format for expresing cryptographic keys in JSON\&.
  40. .PP
  41. \fBSee also:\fP
  42. .RS 4
  43. https://tools.ietf.org/html/rfc7517
  44. .PP
  45. https://tools.ietf.org/html/rfc7638
  46. .RE
  47. .PP
  48. .SH "Function Documentation"
  49. .PP
  50. .SS "bool jose_jwk_gen (jose_cfg_t * cfg, json_t * jwk)"
  51. .PP
  52. Generates a new JWK\&. The JWK is generated using hints from the input in exactly the same format as you would find in the output\&. For example, the most common way to generate a key is to specify the algorithm you'd like to use the key with\&. For example (error handling omitted):
  53. .PP
  54. .nf
  55. json_t *gen(void) {
  56. json_auto_t *jwk = json_pack("{s:s}", "alg", "ES256");
  57. jose_jwk_gen(NULL, jwk);
  58. return json_incref(jwk);
  59. }
  60. .fi
  61. .PP
  62. .PP
  63. This method is preferred because other metadata can be inferred from the algorithm name, such as the key usage\&. Additionally, the algorithm metadata can be used to automatically generate correct headers when creating signatures (JWS) or encryptions (JWE)\&. Thus, you should always default to creating keys by their algorithm usage\&.
  64. .PP
  65. However, should your requirements differ, you can also generate a key using raw parameters (again, error handling omitted):
  66. .PP
  67. .nf
  68. json_t *gen(void) {
  69. json_auto_t *jwk = json_pack("{s:s,s:s}", "kty", "EC", "crv", "P-256");
  70. jose_jwk_gen(NULL, jwk);
  71. return json_incref(jwk);
  72. }
  73. json_t *gen(void) {
  74. json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "RSA", "bits", 2048);
  75. jose_jwk_gen(NULL, jwk);
  76. return json_incref(jwk);
  77. }
  78. json_t *gen(void) {
  79. json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "oct", "bytes", 32);
  80. jose_jwk_gen(NULL, jwk);
  81. return json_incref(jwk);
  82. }
  83. .fi
  84. .PP
  85. .PP
  86. In this case, 'bits' and 'bytes' will be removed from the final output\&.
  87. .PP
  88. \fBSee also:\fP
  89. .RS 4
  90. https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms
  91. .RE
  92. .PP
  93. \fBParameters:\fP
  94. .RS 4
  95. \fIcfg\fP The configuration context (optional)\&.
  96. .br
  97. \fIjwk\fP The JWK to generate\&.
  98. .RE
  99. .PP
  100. \fBReturns:\fP
  101. .RS 4
  102. On success, true\&. Otherwise, false\&.
  103. .RE
  104. .PP
  105. .SS "bool jose_jwk_pub (jose_cfg_t * cfg, json_t * jwk)"
  106. .PP
  107. Removes all private key material from a JWK\&. In addition, this function will remove any key operations from the \fCkey_ops\fP JWK property (if present) that apply only to the private key\&.
  108. .PP
  109. This function should be used before exporting keys to third parties\&.
  110. .PP
  111. \fBParameters:\fP
  112. .RS 4
  113. \fIcfg\fP The configuration context (optional)\&.
  114. .br
  115. \fIjwk\fP The JWK to remove private keys from\&.
  116. .RE
  117. .PP
  118. \fBReturns:\fP
  119. .RS 4
  120. On success, true\&. Otherwise, false\&.
  121. .RE
  122. .PP
  123. .SS "bool jose_jwk_prm (jose_cfg_t * cfg, const json_t * jwk, bool req, const char * op)"
  124. .PP
  125. Determines if an operation is permitted for a JWK\&. The operation to be confirmed (\fCop\fP) is always specified according to the syntax of the 'key_ops' JWK property, even when the 'use' property is defined on the JWK\&.
  126. .PP
  127. This function has two modes of operation\&. If \fCreq\fP is false, then JWKs which do not have any key use metadata will be approved for this operation\&. However, if \fCreq\fP is true then this metadata will be required for approval\&.
  128. .PP
  129. \fBParameters:\fP
  130. .RS 4
  131. \fIcfg\fP The configuration context (optional)\&.
  132. .br
  133. \fIjwk\fP The JWK from which to remove private keys\&.
  134. .br
  135. \fIreq\fP Whether JWK key use metadata is required or not\&.
  136. .br
  137. \fIop\fP The opperation to seek approval for\&.
  138. .RE
  139. .PP
  140. \fBReturns:\fP
  141. .RS 4
  142. When the JWK is approved, true\&. Otherwise, false\&.
  143. .RE
  144. .PP
  145. .SS "json_t* jose_jwk_thp (jose_cfg_t * cfg, const json_t * jwk, const char * alg)"
  146. .PP
  147. Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string\&. This function is a thin wrapper around \fBjose_jwk_thp_buf()\fP\&.
  148. .PP
  149. \fBSee also:\fP
  150. .RS 4
  151. \fBjose_jwk_thp_buf()\fP
  152. .RE
  153. .PP
  154. \fBParameters:\fP
  155. .RS 4
  156. \fIcfg\fP The configuration context (optional)\&.
  157. .br
  158. \fIjwk\fP The JWK to calculate the thumbprint for\&.
  159. .br
  160. \fIalg\fP The hash algorithm to use\&.
  161. .RE
  162. .PP
  163. \fBReturns:\fP
  164. .RS 4
  165. On success, a newly-allocated JSON string\&. Otherwise, NULL\&.
  166. .RE
  167. .PP
  168. .SS "size_t jose_jwk_thp_buf (jose_cfg_t * cfg, const json_t * jwk, const char * alg, uint8_t * thp, size_t len)"
  169. .PP
  170. Calculates the thumbprint of a JWK\&. This function calculates the thumbprint of a JWK according to the method defined by RFC 7638\&.
  171. .PP
  172. If \fCthp\fP is NULL, this function returns the size of the buffer required for the thumbprint output\&.
  173. .PP
  174. \fBSee also:\fP
  175. .RS 4
  176. https://tools.ietf.org/html/rfc7638
  177. .RE
  178. .PP
  179. \fBParameters:\fP
  180. .RS 4
  181. \fIcfg\fP The configuration context (optional)\&.
  182. .br
  183. \fIjwk\fP The JWK to calculate the thumbprint for\&.
  184. .br
  185. \fIalg\fP The hash algorithm to use\&.
  186. .br
  187. \fIthp\fP The output hash buffer\&.
  188. .br
  189. \fIlen\fP The size of the output hash buffer\&.
  190. .RE
  191. .PP
  192. \fBReturns:\fP
  193. .RS 4
  194. On success, the number of bytes written\&. Otherwise, SIZE_MAX\&.
  195. .RE
  196. .PP
  197. .SS "json_t* jose_jwk_exc (jose_cfg_t * cfg, const json_t * prv, const json_t * pub)"
  198. .PP
  199. Perform a key exchange\&. The only currently implemented algorithm is ECDH\&.
  200. .PP
  201. \fBParameters:\fP
  202. .RS 4
  203. \fIcfg\fP The configuration context (optional)\&.
  204. .br
  205. \fIprv\fP The private JWK\&.
  206. .br
  207. \fIpub\fP The public JWK\&.
  208. .RE
  209. .PP
  210. \fBReturns:\fP
  211. .RS 4
  212. On success, the JWK result of the key exchange\&. Otherwise, NULL\&.
  213. .RE
  214. .PP
  215. .SH "Author"
  216. .PP
  217. Generated automatically by Doxygen for José from the source code\&.