New script used to automatically generate SSL certificate files

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-11-11 17:10:22 +08:00
parent ce2ac61e1f
commit 5757cbeb78
6 changed files with 20 additions and 1 deletions

5
.gitignore vendored
View File

@ -50,3 +50,8 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
server-cert.pem
server-key.pem
build/

View File

@ -49,7 +49,7 @@ int main(int argc, char **argv)
goto err;
}
if (uh_ssl_init(srv, "server.pem", "server.key") < 0)
if (uh_ssl_init(srv, "server-cert.pem", "server-key.pem") < 0)
goto err;
uh_register_route(srv, "/test", route_test);

3
gen_cert.sh 100755
View File

@ -0,0 +1,3 @@
#!/bin/sh
openssl req -x509 -newkey rsa:2048 -nodes -keyout server-key.pem -out server-cert.pem -config openssl.cnf

5
openssl.cnf 100644
View File

@ -0,0 +1,5 @@
[ req ]
distinguished_name = req_distinguished_name
prompt = no
[ req_distinguished_name ]
CN = DONT USE - test cert for libuhttp

View File

@ -86,6 +86,7 @@ int uh_register_route(struct uh_server *srv, const char *path, uh_route_handler_
struct uh_value *uh_get_url(struct uh_connection *con);
struct uh_value *uh_get_header(struct uh_connection *con, const char *name);
/* Init ssl for the server */
int uh_ssl_init(struct uh_server *srv, const char *cert, const char *key);
#endif

View File

@ -18,8 +18,13 @@ void __uh_log(const char *filename, int line, int priority, const char *format,
syslog(priority, "%s", buf);
#ifdef UH_DEBUG
fprintf(stderr, "%s\n", buf);
#else
if (priority == LOG_ERR)
fprintf(stderr, "%s\n", buf);
#endif
}