libwebsockets
Lightweight C library for HTML5 websockets
lws-x509.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 
25 enum lws_tls_cert_info {
26  LWS_TLS_CERT_INFO_VALIDITY_FROM,
28  LWS_TLS_CERT_INFO_VALIDITY_TO,
30  LWS_TLS_CERT_INFO_COMMON_NAME,
32  LWS_TLS_CERT_INFO_ISSUER_NAME,
34  LWS_TLS_CERT_INFO_USAGE,
36  LWS_TLS_CERT_INFO_VERIFIED,
39  LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY,
45  LWS_TLS_CERT_INFO_DER_RAW,
50 };
51 
53  unsigned int verified;
54  time_t time;
55  unsigned int usage;
56  struct {
57  int len;
58  /* KEEP LAST... notice the [64] is only there because
59  * name[] is not allowed in a union. The actual length of
60  * name[] is arbitrary and is passed into the api using the
61  * len parameter. Eg
62  *
63  * char big[1024];
64  * union lws_tls_cert_info_results *buf =
65  * (union lws_tls_cert_info_results *)big;
66  *
67  * lws_tls_peer_cert_info(wsi, type, buf, sizeof(big) -
68  * sizeof(*buf) + sizeof(buf->ns.name));
69  */
70  char name[64];
71  } ns;
72 };
73 
74 struct lws_x509_cert;
75 struct lws_jwk;
76 
84 LWS_VISIBLE LWS_EXTERN int
85 lws_x509_create(struct lws_x509_cert **x509);
86 
103 LWS_VISIBLE LWS_EXTERN int
104 lws_x509_parse_from_pem(struct lws_x509_cert *x509, const void *pem, size_t len);
105 
118 LWS_VISIBLE LWS_EXTERN int
119 lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted,
120  const char *common_name);
121 
135 LWS_VISIBLE LWS_EXTERN int
136 lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509,
137  const char *curves, int rsabits);
138 
157 LWS_VISIBLE LWS_EXTERN int
158 lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len,
159  const char *passphrase);
160 
168 LWS_VISIBLE LWS_EXTERN void
169 lws_x509_destroy(struct lws_x509_cert **x509);
170 
171 LWS_VISIBLE LWS_EXTERN int
172 lws_x509_info(struct lws_x509_cert *x509, enum lws_tls_cert_info type,
173  union lws_tls_cert_info_results *buf, size_t len);
174 
192 LWS_VISIBLE LWS_EXTERN int
193 lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type,
194  union lws_tls_cert_info_results *buf, size_t len);
195 
213 LWS_VISIBLE LWS_EXTERN int
214 lws_tls_vhost_cert_info(struct lws_vhost *vhost, enum lws_tls_cert_info type,
215  union lws_tls_cert_info_results *buf, size_t len);
216 
231 LWS_VISIBLE LWS_EXTERN int
232 lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a,
233  const char *san_b);
234 
257 LWS_VISIBLE LWS_EXTERN int
258 lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[],
259  uint8_t *csr, size_t csr_len, char **privkey_pem,
260  size_t *privkey_len);
261 
279 LWS_VISIBLE LWS_EXTERN int
280 lws_tls_cert_updated(struct lws_context *context, const char *certpath,
281  const char *keypath,
282  const char *mem_cert, size_t len_mem_cert,
283  const char *mem_privkey, size_t len_mem_privkey);
284 
Definition: lws-jwk.h:50
Definition: lws-x509.h:52