]> andersk Git - gssapi-openssh.git/blobdiff - openssh/authfile.c
Import of OpenSSH 3.7p1
[gssapi-openssh.git] / openssh / authfile.c
index 6d936de56e39e76f913bfa4b88887b3c24a1b266..1f46093e3ed7a0d95f0b19a8a853beefe7e5eb6b 100644 (file)
@@ -36,7 +36,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: authfile.c,v 1.49 2002/05/23 19:24:30 markus Exp $");
+RCSID("$OpenBSD: authfile.c,v 1.54 2003/05/24 09:30:39 djm Exp $");
 
 #include <openssl/err.h>
 #include <openssl/evp.h>
@@ -232,12 +232,17 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp)
 {
        Buffer buffer;
        Key *pub;
+       struct stat st;
        char *cp;
        int i;
        off_t len;
 
-       len = lseek(fd, (off_t) 0, SEEK_END);
-       lseek(fd, (off_t) 0, SEEK_SET);
+       if (fstat(fd, &st) < 0) {
+               error("fstat for key file %.200s failed: %.100s",
+                   filename, strerror(errno));
+               return NULL;
+       }
+       len = st.st_size;
 
        buffer_init(&buffer);
        cp = buffer_append_space(&buffer, len);
@@ -270,7 +275,7 @@ key_load_public_rsa1(int fd, const char *filename, char **commentp)
        (void) buffer_get_int(&buffer);         /* reserved */
 
        /* Read the public key from the buffer. */
-       buffer_get_int(&buffer);
+       (void) buffer_get_int(&buffer);
        pub = key_new(KEY_RSA1);
        buffer_get_bignum(&buffer, pub->rsa->n);
        buffer_get_bignum(&buffer, pub->rsa->e);
@@ -318,9 +323,15 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
        CipherContext ciphercontext;
        Cipher *cipher;
        Key *prv = NULL;
+       struct stat st;
 
-       len = lseek(fd, (off_t) 0, SEEK_END);
-       lseek(fd, (off_t) 0, SEEK_SET);
+       if (fstat(fd, &st) < 0) {
+               error("fstat for key file %.200s failed: %.100s",
+                   filename, strerror(errno));
+               close(fd);
+               return NULL;
+       }
+       len = st.st_size;
 
        buffer_init(&buffer);
        cp = buffer_append_space(&buffer, len);
@@ -357,7 +368,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
        (void) buffer_get_int(&buffer); /* Reserved data. */
 
        /* Read the public key from the buffer. */
-       buffer_get_int(&buffer);
+       (void) buffer_get_int(&buffer);
        prv = key_new_private(KEY_RSA1);
 
        buffer_get_bignum(&buffer, prv->rsa->n);
@@ -410,6 +421,12 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
        rsa_generate_additional_parameters(prv->rsa);
 
        buffer_free(&decrypted);
+
+       /* enable blinding */
+       if (RSA_blinding_on(prv->rsa, NULL) != 1) {
+               error("key_load_private_rsa1: RSA_blinding_on failed");
+               goto fail;
+       }
        close(fd);
        return prv;
 
@@ -449,6 +466,11 @@ key_load_private_pem(int fd, int type, const char *passphrase,
 #ifdef DEBUG_PK
                RSA_print_fp(stderr, prv->rsa, 8);
 #endif
+               if (RSA_blinding_on(prv->rsa, NULL) != 1) {
+                       error("key_load_private_pem: RSA_blinding_on failed");
+                       key_free(prv);
+                       prv = NULL;
+               }
        } else if (pk->type == EVP_PKEY_DSA &&
            (type == KEY_UNSPEC||type==KEY_DSA)) {
                prv = key_new(KEY_UNSPEC);
@@ -492,7 +514,7 @@ key_perm_ok(int fd, const char *filename)
                error("@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @");
                error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                error("Permissions 0%3.3o for '%s' are too open.",
-                   st.st_mode & 0777, filename);
+                   (u_int)st.st_mode & 0777, filename);
                error("It is recommended that your private key files are NOT accessible by others.");
                error("This private key will be ignored.");
                return 0;
@@ -607,9 +629,18 @@ key_load_public(const char *filename, char **commentp)
        Key *pub;
        char file[MAXPATHLEN];
 
+       /* try rsa1 private key */
        pub = key_load_public_type(KEY_RSA1, filename, commentp);
        if (pub != NULL)
                return pub;
+
+       /* try rsa1 public key */
+       pub = key_new(KEY_RSA1);
+       if (key_try_load_public(pub, filename, commentp) == 1)
+               return pub;
+       key_free(pub);
+
+       /* try ssh2 public key */
        pub = key_new(KEY_UNSPEC);
        if (key_try_load_public(pub, filename, commentp) == 1)
                return pub;
This page took 0.050918 seconds and 4 git commands to generate.