diff options
-rw-r--r-- | include/libssh/libssh.h | 10 | ||||
-rw-r--r-- | include/libssh/pki.h | 6 | ||||
-rw-r--r-- | src/agent.c | 2 | ||||
-rw-r--r-- | src/legacy.c | 8 | ||||
-rw-r--r-- | src/pki.c | 60 | ||||
-rw-r--r-- | tests/unittests/torture_pki.c | 4 |
6 files changed, 38 insertions, 52 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 3acb5aef..80121b7f 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -452,17 +452,11 @@ LIBSSH_API int ssh_pki_import_privkey_file(const char *filename, void *auth_data, ssh_key *pkey); -LIBSSH_API int ssh_pki_import_pubkey_base64(ssh_session session, - const char *b64_key, +LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key, enum ssh_keytypes_e type, ssh_key *pkey); -LIBSSH_API int ssh_pki_import_pubkey_blob(ssh_session session, - const ssh_string key_blob, +LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey); -LIBSSH_API int ssh_pki_import_pubkey_file(ssh_session session, - const char *filename, - ssh_key *pkey); -LIBSSH_API ssh_string ssh_pki_publickey_to_blob(const ssh_key key); LIBSSH_API int ssh_pki_publickey_to_base64(const ssh_key key, unsigned char **b64_key, enum ssh_keytypes_e *ptype); diff --git a/include/libssh/pki.h b/include/libssh/pki.h index 60bac978..429dd168 100644 --- a/include/libssh/pki.h +++ b/include/libssh/pki.h @@ -68,6 +68,12 @@ ssh_key ssh_key_dup(const ssh_key key); void ssh_key_clean (ssh_key key); ssh_key ssh_pki_publickey_from_privatekey(const ssh_key privkey); + +int ssh_pki_import_pubkey_blob(const ssh_string key_blob, + ssh_key *pkey); + +ssh_string ssh_pki_publickey_to_blob(const ssh_key key); + ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf, ssh_key privatekey); diff --git a/src/agent.c b/src/agent.c index 8eda8f19..9ab5175c 100644 --- a/src/agent.c +++ b/src/agent.c @@ -387,7 +387,7 @@ struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *se ssh_string_free(tmp); /* get key from blob */ - rc = ssh_pki_import_pubkey_blob(session, blob, &key); + rc = ssh_pki_import_pubkey_blob(blob, &key); ssh_string_free(blob); if (rc == SSH_ERROR) { return NULL; diff --git a/src/legacy.c b/src/legacy.c index 32855577..ec81c220 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -348,7 +348,9 @@ ssh_string publickey_from_file(ssh_session session, const char *filename, ssh_string key_str; int rc; - rc = ssh_pki_import_pubkey_file(session, filename, &key); + (void) session; /* unused */ + + rc = ssh_pki_import_pubkey_file(filename, &key); if (rc < 0) { return NULL; } @@ -377,7 +379,9 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) { ssh_key key; int rc; - rc = ssh_pki_import_pubkey_blob(session, pubkey_s, &key); + (void) session; /* unused */ + + rc = ssh_pki_import_pubkey_blob(pubkey_s, &key); if (rc < 0) { return NULL; } @@ -389,8 +389,7 @@ ssh_private_key ssh_pki_convert_key_to_privatekey(const ssh_key key) { return privkey; } -static int pki_import_pubkey_buffer(ssh_session session, - ssh_buffer buffer, +static int pki_import_pubkey_buffer(ssh_buffer buffer, enum ssh_keytypes_e type, ssh_key *pkey) { ssh_key key; @@ -498,9 +497,7 @@ static int pki_import_pubkey_buffer(ssh_session session, break; case SSH_KEYTYPE_ECDSA: case SSH_KEYTYPE_UNKNOWN: - ssh_set_error(session, SSH_FATAL, - "Unknown public key protocol %d", - type); + ssh_pki_log("Unknown public key protocol %d", type); goto fail; } @@ -515,8 +512,6 @@ fail: /** * @brief Import a base64 formated public key from a memory c-string. * - * @param[in] session The ssh session to use. - * * @param[in] b64_key The base64 key to format. * * @param[in] type The type of the key to format. @@ -528,15 +523,14 @@ fail: * * @see ssh_key_free() */ -int ssh_pki_import_pubkey_base64(ssh_session session, - const char *b64_key, +int ssh_pki_import_pubkey_base64(const char *b64_key, enum ssh_keytypes_e type, ssh_key *pkey) { ssh_buffer buffer; ssh_string type_s; int rc; - if (session == NULL || b64_key == NULL || pkey == NULL) { + if (b64_key == NULL || pkey == NULL) { return SSH_ERROR; } @@ -552,7 +546,7 @@ int ssh_pki_import_pubkey_base64(ssh_session session, } ssh_string_free(type_s); - rc = pki_import_pubkey_buffer(session, buffer, type, pkey); + rc = pki_import_pubkey_buffer(buffer, type, pkey); ssh_buffer_free(buffer); return rc; @@ -563,8 +557,6 @@ int ssh_pki_import_pubkey_base64(ssh_session session, * * @brief Import a public key from a ssh string. * - * @param[in] session The ssh session to use. - * * @param[in] key_blob The key blob to import as specified in RFC 4253 section * 6.6 "Public Key Algorithms". * @@ -575,8 +567,7 @@ int ssh_pki_import_pubkey_base64(ssh_session session, * * @see ssh_key_free() */ -int ssh_pki_import_pubkey_blob(ssh_session session, - const ssh_string key_blob, +int ssh_pki_import_pubkey_blob(const ssh_string key_blob, ssh_key *pkey) { ssh_buffer buffer; ssh_string type_s = NULL; @@ -589,32 +580,31 @@ int ssh_pki_import_pubkey_blob(ssh_session session, buffer = ssh_buffer_new(); if (buffer == NULL) { - ssh_set_error_oom(session); + ssh_pki_log("Out of memory!"); return SSH_ERROR; } rc = buffer_add_data(buffer, ssh_string_data(key_blob), ssh_string_len(key_blob)); if (rc < 0) { - ssh_set_error_oom(session); + ssh_pki_log("Out of memory!"); goto fail; } type_s = buffer_get_ssh_string(buffer); if (type_s == NULL) { - ssh_set_error(session, SSH_FATAL, "Invalid public key format"); + ssh_pki_log("Out of memory!"); goto fail; } type_c = ssh_string_to_char(type_s); if (type_c == NULL) { - ssh_set_error_oom(session); + ssh_pki_log("Out of memory!"); goto fail; } ssh_string_free(type_s); - rc = pki_import_pubkey_buffer(session, buffer, - ssh_key_type_from_name(type_c), pkey); + rc = pki_import_pubkey_buffer(buffer, ssh_key_type_from_name(type_c), pkey); ssh_buffer_free(buffer); free(type_c); @@ -628,8 +618,7 @@ fail: return SSH_ERROR; } -int ssh_pki_import_pubkey_file(ssh_session session, const char *filename, - ssh_key *pkey) +int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey) { enum ssh_keytypes_e type; struct stat sb; @@ -639,34 +628,28 @@ int ssh_pki_import_pubkey_file(ssh_session session, const char *filename, off_t size; int rc; - if (session == NULL || pkey == NULL) { - return SSH_ERROR; - } - - if (filename == NULL || *filename == '\0') { + if (pkey == NULL || filename == NULL || *filename == '\0') { return SSH_ERROR; } rc = stat(filename, &sb); if (rc < 0) { - ssh_set_error(session, SSH_REQUEST_DENIED, - "Error gettint stat of %s: %s", - filename, strerror(errno)); + ssh_pki_log("Error gettint stat of %s: %s", + filename, strerror(errno)); return SSH_ERROR; } file = fopen(filename, "r"); if (file == NULL) { - ssh_set_error(session, SSH_REQUEST_DENIED, - "Error opening %s: %s", - filename, strerror(errno)); + ssh_pki_log("Error opening %s: %s", + filename, strerror(errno)); return SSH_ERROR; } key_buf = malloc(sb.st_size + 1); if (key_buf == NULL) { fclose(file); - ssh_set_error_oom(session); + ssh_pki_log("Out of memory!"); return SSH_ERROR; } @@ -675,9 +658,8 @@ int ssh_pki_import_pubkey_file(ssh_session session, const char *filename, if (size != sb.st_size) { SAFE_FREE(key_buf); - ssh_set_error(session, SSH_FATAL, - "Error reading %s: %s", - filename, strerror(errno)); + ssh_pki_log("Error reading %s: %s", + filename, strerror(errno)); return SSH_ERROR; } @@ -694,7 +676,7 @@ int ssh_pki_import_pubkey_file(ssh_session session, const char *filename, while (!isspace((int)*p)) p++; *p = '\0'; - rc = ssh_pki_import_pubkey_base64(session, q, type, pkey); + rc = ssh_pki_import_pubkey_base64(q, type, pkey); SAFE_FREE(key_buf); return rc; diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c index 007b509c..8a709927 100644 --- a/tests/unittests/torture_pki.c +++ b/tests/unittests/torture_pki.c @@ -284,7 +284,7 @@ static void torture_pki_publickey_dsa_base64(void **state) while (*p != ' ') p++; *p = '\0'; - rc = ssh_pki_import_pubkey_base64(session, q, type, &key); + rc = ssh_pki_import_pubkey_base64(q, type, &key); assert_true(rc == 0); rc = ssh_pki_publickey_to_base64(key, &b64_key, &type); @@ -322,7 +322,7 @@ static void torture_pki_publickey_rsa_base64(void **state) while (*p != ' ') p++; *p = '\0'; - rc = ssh_pki_import_pubkey_base64(session, q, type, &key); + rc = ssh_pki_import_pubkey_base64(q, type, &key); assert_true(rc == 0); rc = ssh_pki_publickey_to_base64(key, &b64_key, &type); |