-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_httpsrv_tls_cert_auth_8c-example.html
333 lines (331 loc) · 27.5 KB
/
example_httpsrv_tls_cert_auth_8c-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Sagui library: example_httpsrv_tls_cert_auth.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="sagui.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Sagui library<span id="projectnumber"> v3.5.1</span>
</div>
<div id="projectbrief">Cross-platform library which helps to develop web servers or frameworks.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
<input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">example_httpsrv_tls_cert_auth.c</div></div>
</div><!--header-->
<div class="contents">
<p>Simple client-side certificate authentication using GnuTLS.</p>
<div class="fragment"><div class="line"><span class="comment">/* _</span></div>
<div class="line"><span class="comment"> * ___ __ _ __ _ _ _(_)</span></div>
<div class="line"><span class="comment"> * / __|/ _` |/ _` | | | | |</span></div>
<div class="line"><span class="comment"> * \__ \ (_| | (_| | |_| | |</span></div>
<div class="line"><span class="comment"> * |___/\__,_|\__, |\__,_|_|</span></div>
<div class="line"><span class="comment"> * |___/</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Cross-platform library which helps to develop web servers or frameworks.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Copyright (C) 2016-2019 Silvio Clecio <[email protected]></span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Sagui library is free software; you can redistribute it and/or</span></div>
<div class="line"><span class="comment"> * modify it under the terms of the GNU Lesser General Public</span></div>
<div class="line"><span class="comment"> * License as published by the Free Software Foundation; either</span></div>
<div class="line"><span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Sagui library is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span></div>
<div class="line"><span class="comment"> * Lesser General Public License for more details.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * You should have received a copy of the GNU Lesser General Public</span></div>
<div class="line"><span class="comment"> * License along with Sagui library; if not, write to the Free Software</span></div>
<div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <stdlib.h></span></div>
<div class="line"><span class="preprocessor">#include <stdio.h></span></div>
<div class="line"><span class="preprocessor">#include <stdint.h></span></div>
<div class="line"><span class="preprocessor">#include <errno.h></span></div>
<div class="line"><span class="preprocessor">#include <gnutls/gnutls.h></span></div>
<div class="line"><span class="preprocessor">#include <gnutls/x509.h></span></div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="sagui_8h.html">sagui.h</a>></span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* NOTE: Error checking has been omitted to make it clear. */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Simple example using TLS client authentication.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Client example using cURL:</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * curl -k --cert certs/client.p12 --pass abc123 --cert-type p12 https://localhost:<PORT></span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Certificate generation:</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * ## CA</span></div>
<div class="line"><span class="comment"> * certtool --generate-privkey --outfile ca.key</span></div>
<div class="line"><span class="comment"> * echo 'cn = GnuTLS test CA' > ca.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'ca' >> ca.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'cert_signing_key' >> ca.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'expiration_days = 3650' >> ca.tmpl</span></div>
<div class="line"><span class="comment"> * certtool --generate-self-signed --load-privkey ca.key --template ca.tmpl --outfile ca.pem</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * ## Server</span></div>
<div class="line"><span class="comment"> * certtool --generate-privkey --outfile server.key</span></div>
<div class="line"><span class="comment"> * echo 'organization = GnuTLS test server' > server.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'cn = test.gnutls.org' >> server.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'tls_www_server' >> server.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'expiration_days = 3650' >> server.tmpl</span></div>
<div class="line"><span class="comment"> * certtool --generate-certificate --load-ca-privkey ca.key --load-ca-certificate ca.pem --load-privkey server.key --template server.tmpl --outfile server.pem</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * ## Client</span></div>
<div class="line"><span class="comment"> * certtool --generate-privkey --outfile client.key</span></div>
<div class="line"><span class="comment"> * echo 'cn = GnuTLS test client' > client.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'tls_www_client' >> client.tmpl</span></div>
<div class="line"><span class="comment"> * echo 'expiration_days = 3650' >> client.tmpl</span></div>
<div class="line"><span class="comment"> * certtool --generate-certificate --load-ca-certificate ca.pem --load-ca-privkey ca.key --load-privkey client.key --template client.tmpl --outfile client.pem</span></div>
<div class="line"><span class="comment"> * certtool --to-p12 --p12-name=MyKey --password=abc123 --load-ca-certificate ca.pem --load-privkey client.key --load-certificate client.pem --outder --outfile client.p12</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define KEY_FILE SG_EXAMPLES_CERTS_DIR "/server.key"</span></div>
<div class="line"><span class="preprocessor">#define CERT_FILE SG_EXAMPLES_CERTS_DIR "/server.pem"</span></div>
<div class="line"><span class="preprocessor">#define CA_FILE SG_EXAMPLES_CERTS_DIR "/ca.pem"</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define ERR_SIZE 256</span></div>
<div class="line"><span class="preprocessor">#define PAGE_FMT \</span></div>
<div class="line"><span class="preprocessor"> "<html><head><title>Hello world</title></head><body><font "</span> \</div>
<div class="line"> "color=\"%s\">%s</font></font></body></html>"</div>
<div class="line"><span class="preprocessor">#define SECRET_MSG "Secret"</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> concat(<span class="keywordtype">char</span> *s1, ...) {</div>
<div class="line"> va_list ap;</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *s;</div>
<div class="line"> va_start(ap, s1);</div>
<div class="line"> <span class="keywordflow">while</span> ((s = va_arg(ap, <span class="keyword">const</span> <span class="keywordtype">char</span> *)))</div>
<div class="line"> strcat(s1, s);</div>
<div class="line"> va_end(ap);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">bool</span> sess_verify_cert(gnutls_session_t tls_session,</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *line_break, <span class="keywordtype">char</span> *err) {</div>
<div class="line"> gnutls_x509_crt_t cert = NULL;</div>
<div class="line"> <span class="keyword">const</span> gnutls_datum_t *certs;</div>
<div class="line"> <span class="keywordtype">size_t</span> len;</div>
<div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> status, certs_size;</div>
<div class="line"> <span class="keywordtype">int</span> ret;</div>
<div class="line"> <span class="keywordflow">if</span> (!tls_session || !line_break || !err) {</div>
<div class="line"> <a id="a0" name="a0"></a><a class="code hl_function" href="group__sg__utils.html#ga8f77f6063b04e3a24b3efc3703be72a1">sg_strerror</a>(EINVAL, err, ERR_SIZE);</div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_certificate_verify_peers2(tls_session, &status)) !=</div>
<div class="line"> GNUTLS_E_SUCCESS) {</div>
<div class="line"> concat(err, <span class="stringliteral">"Error verifying peers: "</span>, gnutls_strerror(ret), line_break,</div>
<div class="line"> NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (status & GNUTLS_CERT_INVALID)</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate is not trusted"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">if</span> (status & GNUTLS_CERT_SIGNER_NOT_FOUND)</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate has not got a known issuer"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">if</span> (status & GNUTLS_CERT_REVOKED)</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate has been revoked"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">if</span> (gnutls_certificate_type_get(tls_session) != GNUTLS_CRT_X509) {</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate type is not X.509"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_x509_crt_init(&cert)) != GNUTLS_E_SUCCESS) {</div>
<div class="line"> concat(err,</div>
<div class="line"> <span class="stringliteral">"Error in the certificate initialization: "</span>, gnutls_strerror(ret),</div>
<div class="line"> line_break, NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (!(certs = gnutls_certificate_get_peers(tls_session, &certs_size))) {</div>
<div class="line"> concat(err, <span class="stringliteral">"No certificate was found"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_x509_crt_import(cert, &certs[0], GNUTLS_X509_FMT_DER)) !=</div>
<div class="line"> GNUTLS_E_SUCCESS) {</div>
<div class="line"> concat(err, <span class="stringliteral">"Error parsing certificate: "</span>, gnutls_strerror(ret), line_break,</div>
<div class="line"> NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (gnutls_x509_crt_get_expiration_time(cert) < time(NULL)) {</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate has expired"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (gnutls_x509_crt_get_activation_time(cert) > time(NULL)) {</div>
<div class="line"> concat(err, <span class="stringliteral">"The certificate has not been activated yet"</span>, line_break, NULL);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line">error:</div>
<div class="line"> len = strlen(err);</div>
<div class="line"> err[len - strlen(<span class="stringliteral">"<br>"</span>)] = <span class="charliteral">'\0'</span>;</div>
<div class="line"> gnutls_x509_crt_deinit(cert);</div>
<div class="line"> <span class="keywordflow">return</span> len == 0;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> req_cb(__SG_UNUSED <span class="keywordtype">void</span> *cls, <span class="keyword">struct</span> <a id="_a1" name="_a1"></a><a class="code hl_struct" href="structsg__httpreq.html">sg_httpreq</a> *req,</div>
<div class="line"> <span class="keyword">struct</span> <a id="_a2" name="_a2"></a><a class="code hl_struct" href="structsg__httpres.html">sg_httpres</a> *res) {</div>
<div class="line"> <span class="keywordtype">char</span> msg[ERR_SIZE];</div>
<div class="line"> <span class="keywordtype">char</span> *color, *page;</div>
<div class="line"> <span class="keywordtype">size_t</span> page_size;</div>
<div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> status;</div>
<div class="line"> <span class="keywordflow">if</span> (sess_verify_cert(<a id="a3" name="a3"></a><a class="code hl_function" href="group__sg__httpsrv.html#ga66ab1966a5c0628be0523e13c5a97878">sg_httpreq_tls_session</a>(req), <span class="stringliteral">"<br>"</span>, msg)) {</div>
<div class="line"> strcpy(msg, SECRET_MSG);</div>
<div class="line"> color = <span class="stringliteral">"green"</span>;</div>
<div class="line"> status = 200;</div>
<div class="line"> } <span class="keywordflow">else</span> {</div>
<div class="line"> color = <span class="stringliteral">"red"</span>;</div>
<div class="line"> status = 500;</div>
<div class="line"> }</div>
<div class="line"> page_size = (size_t) snprintf(NULL, 0, PAGE_FMT, color, msg);</div>
<div class="line"> page = <a id="a4" name="a4"></a><a class="code hl_function" href="group__sg__utils.html#ga7354f1a6cfaea0a128810cac509a3d80">sg_alloc</a>(page_size);</div>
<div class="line"> snprintf(page, page_size, PAGE_FMT, color, msg);</div>
<div class="line"> <a id="a5" name="a5"></a><a class="code hl_define" href="group__sg__httpsrv.html#gae64c67ed9caee0189cf4fd669a869255">sg_httpres_send</a>(res, page, <span class="stringliteral">"text/html; charset=utf-8"</span>, status);</div>
<div class="line"> <a id="a6" name="a6"></a><a class="code hl_function" href="group__sg__utils.html#gae01910b94d1aa7d1a6fe44feaa3f111a">sg_free</a>(page);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span> *argv[]) {</div>
<div class="line"> <span class="keyword">struct </span><a id="_a7" name="_a7"></a><a class="code hl_struct" href="structsg__httpsrv.html">sg_httpsrv</a> *srv;</div>
<div class="line"> gnutls_datum_t key_file, cert_file, ca_file;</div>
<div class="line"> <span class="keywordtype">int</span> ret, status;</div>
<div class="line"> uint16_t port;</div>
<div class="line"> <span class="keywordflow">if</span> (argc != 2) {</div>
<div class="line"> printf(<span class="stringliteral">"%s <PORT>\n"</span>, argv[0]);</div>
<div class="line"> <span class="keywordflow">return</span> EXIT_FAILURE;</div>
<div class="line"> }</div>
<div class="line"> port = strtol(argv[1], NULL, 10);</div>
<div class="line"> status = EXIT_FAILURE;</div>
<div class="line"> srv = <a id="a8" name="a8"></a><a class="code hl_function" href="group__sg__httpsrv.html#ga56b59921f35e8fac91c48ddb0669b5d1">sg_httpsrv_new</a>(req_cb, NULL);</div>
<div class="line"> memset(&key_file, 0, <span class="keyword">sizeof</span>(gnutls_datum_t));</div>
<div class="line"> memset(&cert_file, 0, <span class="keyword">sizeof</span>(gnutls_datum_t));</div>
<div class="line"> memset(&ca_file, 0, <span class="keyword">sizeof</span>(gnutls_datum_t));</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_load_file(KEY_FILE, &key_file)) != GNUTLS_E_SUCCESS) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error loading the private key \"%s\": %s\n"</span>, KEY_FILE,</div>
<div class="line"> gnutls_strerror(ret));</div>
<div class="line"> fflush(stdout);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_load_file(CERT_FILE, &cert_file)) != GNUTLS_E_SUCCESS) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error loading the certificate \"%s\": %s\n"</span>, CERT_FILE,</div>
<div class="line"> gnutls_strerror(ret));</div>
<div class="line"> fflush(stdout);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> ((ret = gnutls_load_file(CA_FILE, &ca_file)) != GNUTLS_E_SUCCESS) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"Error loading the CA \"%s\": %s\n"</span>, CA_FILE,</div>
<div class="line"> gnutls_strerror(ret));</div>
<div class="line"> fflush(stdout);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span> (<a id="a9" name="a9"></a><a class="code hl_function" href="group__sg__httpsrv.html#ga1edeaed3fccc4edf0fee5a0b71aa6e45">sg_httpsrv_tls_listen2</a>(srv, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) key_file.data, NULL,</div>
<div class="line"> (<span class="keyword">const</span> <span class="keywordtype">char</span> *) cert_file.data,</div>
<div class="line"> (<span class="keyword">const</span> <span class="keywordtype">char</span> *) ca_file.data, NULL, port, <span class="keyword">false</span>)) {</div>
<div class="line"> status = EXIT_SUCCESS;</div>
<div class="line"> fprintf(stdout, <span class="stringliteral">"Server running at https://localhost:%d\n"</span>,</div>
<div class="line"> <a id="a10" name="a10"></a><a class="code hl_function" href="group__sg__httpsrv.html#gafdc2bab56e952bd8395f2ebfd91469f5">sg_httpsrv_port</a>(srv));</div>
<div class="line"> fflush(stdout);</div>
<div class="line"> getchar();</div>
<div class="line"> }</div>
<div class="line">error:</div>
<div class="line"> <a id="a11" name="a11"></a><a class="code hl_function" href="group__sg__httpsrv.html#gac377679c831c0b428ee80b2f63174bf8">sg_httpsrv_free</a>(srv);</div>
<div class="line"> <span class="keywordflow">if</span> (key_file.size > 0)</div>
<div class="line"> gnutls_free(key_file.data);</div>
<div class="line"> <span class="keywordflow">if</span> (cert_file.size > 0)</div>
<div class="line"> gnutls_free(cert_file.data);</div>
<div class="line"> <span class="keywordflow">if</span> (ca_file.size > 0)</div>
<div class="line"> gnutls_free(ca_file.data);</div>
<div class="line"> <span class="keywordflow">return</span> status;</div>
<div class="line">}</div>
<div class="ttc" id="agroup__sg__httpsrv_html_ga1edeaed3fccc4edf0fee5a0b71aa6e45"><div class="ttname"><a href="group__sg__httpsrv.html#ga1edeaed3fccc4edf0fee5a0b71aa6e45">sg_httpsrv_tls_listen2</a></div><div class="ttdeci">bool sg_httpsrv_tls_listen2(struct sg_httpsrv *srv, const char *key, const char *pwd, const char *cert, const char *trust, const char *dhparams, uint16_t port, bool threaded)</div></div>
<div class="ttc" id="agroup__sg__httpsrv_html_ga56b59921f35e8fac91c48ddb0669b5d1"><div class="ttname"><a href="group__sg__httpsrv.html#ga56b59921f35e8fac91c48ddb0669b5d1">sg_httpsrv_new</a></div><div class="ttdeci">struct sg_httpsrv * sg_httpsrv_new(sg_httpreq_cb cb, void *cls) __attribute__((malloc))</div></div>
<div class="ttc" id="agroup__sg__httpsrv_html_ga66ab1966a5c0628be0523e13c5a97878"><div class="ttname"><a href="group__sg__httpsrv.html#ga66ab1966a5c0628be0523e13c5a97878">sg_httpreq_tls_session</a></div><div class="ttdeci">void * sg_httpreq_tls_session(struct sg_httpreq *req)</div></div>
<div class="ttc" id="agroup__sg__httpsrv_html_gac377679c831c0b428ee80b2f63174bf8"><div class="ttname"><a href="group__sg__httpsrv.html#gac377679c831c0b428ee80b2f63174bf8">sg_httpsrv_free</a></div><div class="ttdeci">void sg_httpsrv_free(struct sg_httpsrv *srv)</div></div>
<div class="ttc" id="agroup__sg__httpsrv_html_gae64c67ed9caee0189cf4fd669a869255"><div class="ttname"><a href="group__sg__httpsrv.html#gae64c67ed9caee0189cf4fd669a869255">sg_httpres_send</a></div><div class="ttdeci">#define sg_httpres_send(res, val, content_type, status)</div><div class="ttdef"><b>Definition</b> sagui.h:1032</div></div>
<div class="ttc" id="agroup__sg__httpsrv_html_gafdc2bab56e952bd8395f2ebfd91469f5"><div class="ttname"><a href="group__sg__httpsrv.html#gafdc2bab56e952bd8395f2ebfd91469f5">sg_httpsrv_port</a></div><div class="ttdeci">uint16_t sg_httpsrv_port(struct sg_httpsrv *srv)</div></div>
<div class="ttc" id="agroup__sg__utils_html_ga7354f1a6cfaea0a128810cac509a3d80"><div class="ttname"><a href="group__sg__utils.html#ga7354f1a6cfaea0a128810cac509a3d80">sg_alloc</a></div><div class="ttdeci">void * sg_alloc(size_t size) __attribute__((malloc))</div></div>
<div class="ttc" id="agroup__sg__utils_html_ga8f77f6063b04e3a24b3efc3703be72a1"><div class="ttname"><a href="group__sg__utils.html#ga8f77f6063b04e3a24b3efc3703be72a1">sg_strerror</a></div><div class="ttdeci">char * sg_strerror(int errnum, char *errmsg, size_t errlen)</div></div>
<div class="ttc" id="agroup__sg__utils_html_gae01910b94d1aa7d1a6fe44feaa3f111a"><div class="ttname"><a href="group__sg__utils.html#gae01910b94d1aa7d1a6fe44feaa3f111a">sg_free</a></div><div class="ttdeci">void sg_free(void *ptr)</div></div>
<div class="ttc" id="asagui_8h_html"><div class="ttname"><a href="sagui_8h.html">sagui.h</a></div></div>
<div class="ttc" id="astructsg__httpreq_html"><div class="ttname"><a href="structsg__httpreq.html">sg_httpreq</a></div></div>
<div class="ttc" id="astructsg__httpres_html"><div class="ttname"><a href="structsg__httpres.html">sg_httpres</a></div></div>
<div class="ttc" id="astructsg__httpsrv_html"><div class="ttname"><a href="structsg__httpsrv.html">sg_httpsrv</a></div></div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Tue Jan 21 2025 18:32:17 for Sagui library by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7
</small></address>
</body>
</html>