diff options
Diffstat (limited to 'src/pki_gcrypt.c')
-rw-r--r-- | src/pki_gcrypt.c | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c index ea1bc2ef..6cac8f68 100644 --- a/src/pki_gcrypt.c +++ b/src/pki_gcrypt.c @@ -1299,91 +1299,6 @@ int ssh_publickey_to_file(ssh_session session, const char *file, } /** - * @brief Retrieve a public key from a file. - * - * @param[in] session The SSH session to use. - * - * @param[in] filename The filename of the public key. - * - * @param[out] type The Pointer to a integer. If it is not NULL, it will - * contain the type of the key after execution. - * - * @return A SSH String containing the public key, or NULL if it - * failed. - * - * @see string_free() - * @see publickey_from_privatekey() - */ -ssh_string publickey_from_file(ssh_session session, const char *filename, - int *type) { - ssh_buffer buffer = NULL; - char buf[4096] = {0}; - ssh_string str = NULL; - char *ptr = NULL; - int key_type; - int fd = -1; - int r; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - ssh_set_error(session, SSH_REQUEST_DENIED, "Public key file doesn't exist"); - return NULL; - } - - if (read(fd, buf, 8) != 8) { - close(fd); - ssh_set_error(session, SSH_REQUEST_DENIED, "Invalid public key file"); - return NULL; - } - - buf[7] = '\0'; - - key_type = ssh_type_from_name(buf); - if (key_type == -1) { - close(fd); - ssh_set_error(session, SSH_REQUEST_DENIED, "Invalid public key file"); - return NULL; - } - - r = read(fd, buf, sizeof(buf) - 1); - close(fd); - if (r <= 0) { - ssh_set_error(session, SSH_REQUEST_DENIED, "Invalid public key file"); - return NULL; - } - - buf[r] = 0; - ptr = strchr(buf, ' '); - - /* eliminate the garbage at end of file */ - if (ptr) { - *ptr = '\0'; - } - - buffer = base64_to_bin(buf); - if (buffer == NULL) { - ssh_set_error(session, SSH_REQUEST_DENIED, "Invalid public key file"); - return NULL; - } - - str = ssh_string_new(buffer_get_rest_len(buffer)); - if (str == NULL) { - ssh_set_error(session, SSH_FATAL, "Not enough space"); - ssh_buffer_free(buffer); - return NULL; - } - - ssh_string_fill(str, buffer_get_rest(buffer), buffer_get_rest_len(buffer)); - ssh_buffer_free(buffer); - - if (type) { - *type = key_type; - } - - return str; -} - -/** * @brief Try to read the public key from a given file. * * @param[in] session The ssh session to use. |