libwebsockets
Lightweight C library for HTML5 websockets
lws-jwk.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
38 
39 enum enum_jwk_meta_tok {
40  JWK_META_KTY,
41  JWK_META_KID,
42  JWK_META_USE,
43  JWK_META_KEY_OPS,
44  JWK_META_X5C,
45  JWK_META_ALG,
46 
47  LWS_COUNT_JWK_ELEMENTS
48 };
49 
50 struct lws_jwk {
51  /* key data elements */
52  struct lws_gencrypto_keyelem e[LWS_GENCRYPTO_MAX_KEYEL_COUNT];
53  /* generic meta key elements, like KID */
54  struct lws_gencrypto_keyelem meta[LWS_COUNT_JWK_ELEMENTS];
55  int kty;
56  char private_key; /* nonzero = has private key elements */
57 };
58 
59 typedef int (*lws_jwk_key_import_callback)(struct lws_jwk *s, void *user);
60 
62  struct lws_jwk *jwk;
63  char b64[(((8192 / 8) * 4) / 3) + 1]; /* enough for 8Kb key */
64  lws_jwk_key_import_callback per_key_cb;
65  void *user;
66  int pos;
67  int cose_state;
68  int seen;
69  unsigned short possible;
70 };
71 
95 LWS_VISIBLE LWS_EXTERN int
96 lws_jwk_import(struct lws_jwk *jwk, lws_jwk_key_import_callback cb, void *user,
97  const char *in, size_t len);
98 
105 LWS_VISIBLE LWS_EXTERN void
107 
117 LWS_VISIBLE LWS_EXTERN int
118 lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len);
119 
120 #define LWSJWKF_EXPORT_PRIVATE (1 << 0)
121 #define LWSJWKF_EXPORT_NOCRLF (1 << 1)
122 
142 LWS_VISIBLE LWS_EXTERN int
143 lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len);
144 
165 LWS_VISIBLE LWS_EXTERN int
166 lws_jwk_load(struct lws_jwk *jwk, const char *filename,
167  lws_jwk_key_import_callback cb, void *user);
168 
176 LWS_VISIBLE LWS_EXTERN int
177 lws_jwk_save(struct lws_jwk *jwk, const char *filename);
178 
186 LWS_VISIBLE LWS_EXTERN int
187 lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32);
188 
198 LWS_VISIBLE LWS_EXTERN int
199 lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx,
200  const char *in, int len);
201 
202 
203 LWS_VISIBLE LWS_EXTERN int
204 lws_jwk_dump(struct lws_jwk *jwk);
205 
216 LWS_VISIBLE int
217 lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk,
218  enum lws_gencrypto_kty kty, int bits, const char *curve);
219 
LWS_VISIBLE LWS_EXTERN int lws_jwk_import(struct lws_jwk *jwk, lws_jwk_key_import_callback cb, void *user, const char *in, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_jwk_load(struct lws_jwk *jwk, const char *filename, lws_jwk_key_import_callback cb, void *user)
LWS_VISIBLE LWS_EXTERN int lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx, const char *in, int len)
LWS_VISIBLE LWS_EXTERN int lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len)
LWS_VISIBLE LWS_EXTERN void lws_jwk_destroy(struct lws_jwk *jwk)
LWS_VISIBLE int lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk, enum lws_gencrypto_kty kty, int bits, const char *curve)
LWS_VISIBLE LWS_EXTERN int lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32)
LWS_VISIBLE LWS_EXTERN int lws_jwk_save(struct lws_jwk *jwk, const char *filename)
LWS_VISIBLE LWS_EXTERN int lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len)
Definition: lws-gencrypto.h:99
Definition: lws-jwk.h:61
Definition: lws-jwk.h:50
int kty
Definition: lws-jwk.h:55