Skip to content

Commit b9d4326

Browse files
author
cameronrich
committed
* axhttpd can load a certificate and private key from the command line
* axssl now prints all output regardless of null bytes. It no longer writes a null byte. git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@242 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
1 parent b3fc326 commit b9d4326

File tree

4 files changed

+74
-22
lines changed

4 files changed

+74
-22
lines changed

crypto/crypto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ typedef struct
153153
uint8_t buffer[64]; /* input buffer */
154154
} MD5_CTX;
155155

156-
void MD5_Init(MD5_CTX *);
157-
void MD5_Update(MD5_CTX *, const uint8_t *msg, int len);
158-
void MD5_Final(uint8_t *digest, MD5_CTX *);
156+
EXP_FUNC void STDCALL MD5_Init(MD5_CTX *);
157+
EXP_FUNC void STDCALL MD5_Update(MD5_CTX *, const uint8_t *msg, int len);
158+
EXP_FUNC void STDCALL MD5_Final(uint8_t *digest, MD5_CTX *);
159159

160160
/**************************************************************************
161161
* HMAC declarations

httpd/axhttpd.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ int main(int argc, char *argv[])
128128
int httpPort = CONFIG_HTTP_PORT;
129129
char *httpsAddress = NULL;
130130
int httpsPort = CONFIG_HTTP_HTTPS_PORT;
131+
uint32_t options = CONFIG_HTTP_DEFAULT_SSL_OPTIONS;
131132
char *portStr;
133+
char *private_key = NULL;
134+
char *cert = NULL;
132135

133136
#ifdef WIN32
134137
WORD wVersionRequested = MAKEWORD(2, 2);
@@ -190,9 +193,24 @@ int main(int argc, char *argv[])
190193
continue;
191194
}
192195

196+
if (strcmp(argv[i], "-cert") == 0 && argv[i+1] != NULL)
197+
{
198+
cert = argv[i+1];
199+
i += 2;
200+
continue;
201+
}
202+
203+
if (strcmp(argv[i], "-key") == 0 && argv[i+1] != NULL)
204+
{
205+
private_key = argv[i+1];
206+
i += 2;
207+
continue;
208+
}
193209
printf("%s:\n"
194210
" [-p [address:]httpport]\n"
195211
" [-s [address:]httpsport]\n"
212+
" [-key private_key]\n"
213+
" [-cert cert]\n"
196214
" [-w webroot]\n", argv[0]);
197215
exit(1);
198216
}
@@ -223,10 +241,35 @@ int main(int argc, char *argv[])
223241
}
224242

225243
addtoservers(active);
226-
servers->ssl_ctx = ssl_ctx_new(CONFIG_HTTP_DEFAULT_SSL_OPTIONS,
227-
CONFIG_HTTP_SESSION_CACHE_SIZE);
244+
245+
if (cert != NULL && private_key != NULL)
246+
options |= SSL_NO_DEFAULT_KEY;
247+
248+
servers->ssl_ctx = ssl_ctx_new(options, CONFIG_HTTP_SESSION_CACHE_SIZE);
228249
servers->is_ssl = 1;
229250

251+
if (cert != NULL && private_key != NULL)
252+
{
253+
printf("YEAH\n");
254+
if (ssl_obj_load(servers->ssl_ctx, SSL_OBJ_RSA_KEY, private_key,
255+
NULL))
256+
{
257+
#ifdef CONFIG_HTTP_VERBOSE
258+
fprintf(stderr, "ERR: Couldn't load private key %s\n", private_key);
259+
#endif
260+
exit(1);
261+
}
262+
263+
if (ssl_obj_load(servers->ssl_ctx, SSL_OBJ_X509_CERT, cert,
264+
NULL))
265+
{
266+
#ifdef CONFIG_HTTP_VERBOSE
267+
fprintf(stderr, "ERR: Couldn't load cert %s\n", cert);
268+
#endif
269+
exit(1);
270+
}
271+
}
272+
230273
#if defined(CONFIG_HTTP_HAS_CGI)
231274
addcgiext(CONFIG_HTTP_CGI_EXTENSIONS);
232275
#endif
@@ -263,7 +306,6 @@ int main(int argc, char *argv[])
263306
}
264307
#endif
265308

266-
267309
#ifndef WIN32
268310
#ifdef CONFIG_HTTP_IS_DAEMON
269311
if (fork() > 0) /* parent will die */

samples/c/axssl.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,12 @@ static void do_server(int argc, char *argv[])
382382
383383
if (res > SSL_OK) /* display our interesting output */
384384
{
385-
printf("%s", read_buf);
385+
int written = 0;
386+
while (written < res)
387+
{
388+
written += write(STDOUT_FILENO, read_buf+written,
389+
res-written);
390+
}
386391
TTY_FLUSH();
387392
}
388393
else if (res == SSL_CLOSE_NOTIFY)
@@ -711,7 +716,7 @@ static void do_client(int argc, char *argv[])
711716
}
712717
else
713718
{
714-
res = ssl_write(ssl, buf, strlen((char *)buf)+1);
719+
res = ssl_write(ssl, buf, strlen((char *)buf));
715720
}
716721
}
717722
}
@@ -724,7 +729,12 @@ static void do_client(int argc, char *argv[])
724729
725730
if (res > 0) /* display our interesting output */
726731
{
727-
printf("%s", read_buf);
732+
int written = 0;
733+
while (written < res)
734+
{
735+
written += write(STDOUT_FILENO, read_buf+written,
736+
res-written);
737+
}
728738
TTY_FLUSH();
729739
}
730740
}

0 commit comments

Comments
 (0)