Skip to content

Commit

Permalink
enh: Add server authentication API functions (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzyStatic authored and bmah888 committed Oct 1, 2019
1 parent 60e9b84 commit 22da02d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,18 @@ iperf_set_test_client_rsa_pubkey(struct iperf_test *ipt, char *client_rsa_pubkey
{
ipt->settings->client_rsa_pubkey = load_pubkey_from_base64(client_rsa_pubkey_base64);
}

void
iperf_set_test_server_authorized_users(struct iperf_test *ipt, char *server_authorized_users)
{
ipt->server_authorized_users = server_authorized_users;
}

void
iperf_set_test_server_rsa_privkey(struct iperf_test *ipt, char *server_rsa_privkey_base64)
{
ipt->server_rsa_private_key = load_privkey_from_base64(server_rsa_privkey_base64);
}
#endif // HAVE_SSL

void
Expand Down
2 changes: 2 additions & 0 deletions src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ void iperf_set_test_no_delay( struct iperf_test* ipt, int no_delay);
void iperf_set_test_client_username(struct iperf_test *ipt, char *client_username);
void iperf_set_test_client_password(struct iperf_test *ipt, char *client_password);
void iperf_set_test_client_rsa_pubkey(struct iperf_test *ipt, char *client_rsa_pubkey_base64);
void iperf_set_test_server_authorized_users(struct iperf_test *ipt, char *server_authorized_users);
void iperf_set_test_server_rsa_privkey(struct iperf_test *ipt, char *server_rsa_privkey_base64);
#endif // HAVE_SSL

/**
Expand Down
13 changes: 11 additions & 2 deletions src/iperf_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,14 @@ int Base64Decode(const char* b64message, unsigned char** buffer, size_t* length)
return (0); //success
}


EVP_PKEY *load_pubkey_from_file(const char *file) {
BIO *key = NULL;
EVP_PKEY *pkey = NULL;

if (file) {
key = BIO_new_file(file, "r");
pkey = PEM_read_bio_PUBKEY(key, NULL, NULL, NULL);

BIO_free(key);
}
return (pkey);
Expand Down Expand Up @@ -189,6 +188,16 @@ EVP_PKEY *load_privkey_from_file(const char *file) {
return (pkey);
}

EVP_PKEY *load_privkey_from_base64(const char *buffer) {
unsigned char *key = NULL;
size_t key_len;
Base64Decode(buffer, &key, &key_len);

BIO* bio = BIO_new(BIO_s_mem());
BIO_write(bio, key, key_len);
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
return (pkey);
}

int test_load_pubkey_from_file(const char *file){
EVP_PKEY *key = load_pubkey_from_file(file);
Expand Down
1 change: 1 addition & 0 deletions src/iperf_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ int test_load_private_key_from_file(const char *private_keyfile);
EVP_PKEY *load_pubkey_from_file(const char *file);
EVP_PKEY *load_pubkey_from_base64(const char *buffer);
EVP_PKEY *load_privkey_from_file(const char *file);
EVP_PKEY *load_privkey_from_base64(const char *buffer);
int encode_auth_setting(const char *username, const char *password, EVP_PKEY *public_key, char **authtoken);
int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *private_key, char **username, char **password, time_t *ts);
int check_authentication(const char *username, const char *password, const time_t ts, const char *filename);
Expand Down

0 comments on commit 22da02d

Please sign in to comment.