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  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
105 
115 LWS_VISIBLE LWS_EXTERN int
116 lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len);
117 
118 #define LWSJWKF_EXPORT_PRIVATE (1 << 0)
119 #define LWSJWKF_EXPORT_NOCRLF (1 << 1)
120 
140 LWS_VISIBLE LWS_EXTERN int
141 lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len);
142 
163 LWS_VISIBLE LWS_EXTERN int
164 lws_jwk_load(struct lws_jwk *jwk, const char *filename,
165  lws_jwk_key_import_callback cb, void *user);
166 
174 LWS_VISIBLE LWS_EXTERN int
175 lws_jwk_save(struct lws_jwk *jwk, const char *filename);
176 
184 LWS_VISIBLE LWS_EXTERN int
185 lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32);
186 
196 LWS_VISIBLE LWS_EXTERN int
197 lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx,
198  const char *in, int len);
199 
200 
201 LWS_VISIBLE LWS_EXTERN int
202 lws_jwk_dump(struct lws_jwk *jwk);
203 
214 LWS_VISIBLE int
215 lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk,
216  enum lws_gencrypto_kty kty, int bits, const char *curve);
217 
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:92
Definition: lws-jwk.h:61
Definition: lws-jwk.h:50
int kty
Definition: lws-jwk.h:55