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 
37 
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  unsigned short possible;
68 };
69 
93 LWS_VISIBLE LWS_EXTERN int
94 lws_jwk_import(struct lws_jwk *jwk, lws_jwk_key_import_callback cb, void *user,
95  const char *in, size_t len);
96 
103 LWS_VISIBLE LWS_EXTERN void
104 lws_jwk_destroy(struct lws_jwk *jwk);
105 
115 LWS_VISIBLE LWS_EXTERN int
116 lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len);
117 
129 LWS_VISIBLE LWS_EXTERN int
130 lws_jwk_export(struct lws_jwk *jwk, int _private, char *p, int *len);
131 
150 LWS_VISIBLE LWS_EXTERN int
151 lws_jwk_load(struct lws_jwk *jwk, const char *filename,
152  lws_jwk_key_import_callback cb, void *user);
153 
161 LWS_VISIBLE LWS_EXTERN int
162 lws_jwk_save(struct lws_jwk *jwk, const char *filename);
163 
171 LWS_VISIBLE LWS_EXTERN int
172 lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32);
173 
183 LWS_VISIBLE LWS_EXTERN int
184 lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx,
185  const char *in, int len);
186 
187 
188 LWS_VISIBLE LWS_EXTERN int
189 lws_jwk_dump(struct lws_jwk *jwk);
190 
201 LWS_VISIBLE int
202 lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk,
203  enum lws_gencrypto_kty kty, int bits, const char *curve);
204 
LWS_VISIBLE LWS_EXTERN int lws_jwk_export(struct lws_jwk *jwk, int _private, char *p, int *len)
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_dup_oct(struct lws_jwk *jwk, const void *key, int len)
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_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32)
LWS_VISIBLE LWS_EXTERN int lws_jwk_load(struct lws_jwk *jwk, const char *filename, lws_jwk_key_import_callback cb, void *user)
Definition: lws-jwk.h:61
int kty
Definition: lws-jwk.h:55
Definition: lws-jwk.h:50
LWS_VISIBLE LWS_EXTERN int lws_jwk_save(struct lws_jwk *jwk, const char *filename)
LWS_VISIBLE LWS_EXTERN void lws_jwk_destroy(struct lws_jwk *jwk)
LWS_VISIBLE LWS_EXTERN int lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx, const char *in, int len)