aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-16 00:46:34 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-16 00:47:43 +0200
commit19a3f5a61d96f4dbbb60b3a3fc19e50dde6870c0 (patch)
tree1b941bc34de222905e9c42fe664b1c88de672158
parent9dfef44fd88292ab19f46bdfa428e5378f5ae41f (diff)
downloadlibssh-19a3f5a61d96f4dbbb60b3a3fc19e50dde6870c0.tar.gz
libssh-19a3f5a61d96f4dbbb60b3a3fc19e50dde6870c0.tar.xz
libssh-19a3f5a61d96f4dbbb60b3a3fc19e50dde6870c0.zip
pki: Make publickey_from_file() a legacy function.
-rw-r--r--src/legacy.c24
-rw-r--r--src/pki_gcrypt.c85
2 files changed, 22 insertions, 87 deletions
diff --git a/src/legacy.c b/src/legacy.c
index a17cb825..ed754904 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -194,8 +194,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
void publickey_free(ssh_public_key key);
int ssh_publickey_to_file(ssh_session session, const char *file,
ssh_string pubkey, int type);
-ssh_string publickey_from_file(ssh_session session, const char *filename,
- int *type);
ssh_public_key publickey_from_privatekey(ssh_private_key prv);
ssh_string publickey_to_string(ssh_public_key key);
*
@@ -319,6 +317,28 @@ void privatekey_free(ssh_private_key prv) {
SAFE_FREE(prv);
}
+ssh_string publickey_from_file(ssh_session session, const char *filename,
+ int *type) {
+ ssh_key key;
+ ssh_string key_str;
+ int rc;
+
+ rc = ssh_pki_import_pubkey_file(session, filename, &key);
+ if (rc < 0) {
+ return NULL;
+ }
+
+ key_str = ssh_pki_publickey_to_blob(key);
+ if (key_str == NULL) {
+ return NULL;
+ }
+
+ *type = key->type;
+ ssh_key_free(key);
+
+ return key_str;
+}
+
/****************************************************************************
* SERVER SUPPORT
****************************************************************************/
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.