]> andersk Git - openssh.git/blobdiff - authfile.c
set SHELL in Makefile in case someone makes from a non bourne compatable shell
[openssh.git] / authfile.c
index cd600362a50da704f373fd1fca007e36b95cecc4..de8b1022ee4a4232ca9d75798b35526ddd88e1d2 100644 (file)
@@ -36,7 +36,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: authfile.c,v 1.43 2001/12/27 18:22:16 markus Exp $");
+RCSID("$OpenBSD: authfile.c,v 1.48 2002/02/28 15:46:33 markus Exp $");
 
 #include <openssl/err.h>
 #include <openssl/evp.h>
@@ -50,6 +50,7 @@ RCSID("$OpenBSD: authfile.c,v 1.43 2001/12/27 18:22:16 markus Exp $");
 #include "ssh.h"
 #include "log.h"
 #include "authfile.h"
+#include "rsa.h"
 
 /* Version identification string for SSH v1 identity files. */
 static const char authfile_id_string[] =
@@ -67,8 +68,8 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
     const char *comment)
 {
        Buffer buffer, encrypted;
-       char buf[100], *cp;
-       int fd, i;
+       u_char buf[100], *cp;
+       int fd, i, cipher_num;
        CipherContext ciphercontext;
        Cipher *cipher;
        u_int32_t rand;
@@ -77,11 +78,9 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
         * If the passphrase is empty, use SSH_CIPHER_NONE to ease converting
         * to another cipher; otherwise use SSH_AUTHFILE_CIPHER.
         */
-       if (strcmp(passphrase, "") == 0)
-               cipher = cipher_by_number(SSH_CIPHER_NONE);
-       else
-               cipher = cipher_by_number(SSH_AUTHFILE_CIPHER);
-       if (cipher == NULL)
+       cipher_num = (strcmp(passphrase, "") == 0) ?
+           SSH_CIPHER_NONE : SSH_AUTHFILE_CIPHER;
+       if ((cipher = cipher_by_number(cipher_num)) == NULL)
                fatal("save_private_key_rsa: bad cipher");
 
        /* This buffer is used to built the secret part of the private key. */
@@ -118,7 +117,7 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
        buffer_put_char(&encrypted, 0);
 
        /* Store cipher type. */
-       buffer_put_char(&encrypted, cipher->number);
+       buffer_put_char(&encrypted, cipher_num);
        buffer_put_int(&encrypted, 0);  /* For future extension */
 
        /* Store public key.  This will be in plain text. */
@@ -130,9 +129,11 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase,
        /* Allocate space for the private part of the key in the buffer. */
        cp = buffer_append_space(&encrypted, buffer_len(&buffer));
 
-       cipher_set_key_string(&ciphercontext, cipher, passphrase);
-       cipher_encrypt(&ciphercontext, (u_char *) cp,
-           (u_char *) buffer_ptr(&buffer), buffer_len(&buffer));
+       cipher_set_key_string(&ciphercontext, cipher, passphrase,
+           CIPHER_ENCRYPT);
+       cipher_crypt(&ciphercontext, cp,
+           buffer_ptr(&buffer), buffer_len(&buffer));
+       cipher_cleanup(&ciphercontext);
        memset(&ciphercontext, 0, sizeof(ciphercontext));
 
        /* Destroy temporary data. */
@@ -167,8 +168,8 @@ key_save_private_pem(Key *key, const char *filename, const char *_passphrase,
        int fd;
        int success = 0;
        int len = strlen(_passphrase);
-       char *passphrase = (len > 0) ? (char *)_passphrase : NULL;
-       EVP_CIPHER *cipher = (len > 0) ? EVP_des_ede3_cbc() : NULL;
+       u_char *passphrase = (len > 0) ? (u_char *)_passphrase : NULL;
+       const EVP_CIPHER *cipher = (len > 0) ? EVP_des_ede3_cbc() : NULL;
 
        if (len > 0 && len <= 4) {
                error("passphrase too short: have %d bytes, need > 4", len);
@@ -313,7 +314,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
        int i, check1, check2, cipher_type;
        off_t len;
        Buffer buffer, decrypted;
-       char *cp;
+       u_char *cp;
        CipherContext ciphercontext;
        Cipher *cipher;
        Key *prv = NULL;
@@ -379,9 +380,11 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
        cp = buffer_append_space(&decrypted, buffer_len(&buffer));
 
        /* Rest of the buffer is encrypted.  Decrypt it using the passphrase. */
-       cipher_set_key_string(&ciphercontext, cipher, passphrase);
-       cipher_decrypt(&ciphercontext, (u_char *) cp,
-           (u_char *) buffer_ptr(&buffer), buffer_len(&buffer));
+       cipher_set_key_string(&ciphercontext, cipher, passphrase,
+           CIPHER_DECRYPT);
+       cipher_crypt(&ciphercontext, cp,
+           buffer_ptr(&buffer), buffer_len(&buffer));
+       cipher_cleanup(&ciphercontext);
        memset(&ciphercontext, 0, sizeof(ciphercontext));
        buffer_free(&buffer);
 
This page took 0.05301 seconds and 4 git commands to generate.