Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: add tls_set_selfsigned_rsa #6

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ int tls_alloc(struct tls **tlsp, enum tls_method method, const char *keyfile,
const char *pwd);
int tls_add_ca(struct tls *tls, const char *cafile);
int tls_set_selfsigned(struct tls *tls, const char *cn);
int tls_set_selfsigned_rsa(struct tls *tls, const char *cn, size_t bits);
int tls_set_certificate_pem(struct tls *tls, const char *cert, size_t len_cert,
const char *key, size_t len_key);
int tls_set_certificate_der(struct tls *tls, enum tls_keytype keytype,
Expand Down
8 changes: 7 additions & 1 deletion src/tls/openssl/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ int tls_add_ca(struct tls *tls, const char *cafile)
* @return 0 if success, otherwise errorcode
*/
int tls_set_selfsigned(struct tls *tls, const char *cn)
{
return tls_set_selfsigned_rsa(tls, cn, 1024);
}


int tls_set_selfsigned_rsa(struct tls *tls, const char *cn, size_t bits)
{
X509_NAME *subj = NULL;
EVP_PKEY *key = NULL;
Expand All @@ -258,7 +264,7 @@ int tls_set_selfsigned(struct tls *tls, const char *cn)
goto out;

BN_set_word(bn, RSA_F4);
if (!RSA_generate_key_ex(rsa, 1024, bn, NULL))
if (!RSA_generate_key_ex(rsa, (int)bits, bn, NULL))
goto out;

key = EVP_PKEY_new();
Expand Down