[BACK]Return to authfile.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/authfile.c between version 1.91 and 1.92

version 1.91, 2011/05/23 07:24:57 version 1.92, 2011/06/14 22:49:18
Line 268 
Line 268 
 key_parse_public_rsa1(Buffer *blob, char **commentp)  key_parse_public_rsa1(Buffer *blob, char **commentp)
 {  {
         Key *pub;          Key *pub;
           Buffer copy;
   
         /* Check that it is at least big enough to contain the ID string. */          /* Check that it is at least big enough to contain the ID string. */
         if (buffer_len(blob) < sizeof(authfile_id_string)) {          if (buffer_len(blob) < sizeof(authfile_id_string)) {
Line 284 
Line 285 
                 debug3("Incorrect RSA1 identifier");                  debug3("Incorrect RSA1 identifier");
                 return NULL;                  return NULL;
         }          }
         buffer_consume(blob, sizeof(authfile_id_string));          buffer_init(&copy);
           buffer_append(&copy, buffer_ptr(blob), buffer_len(blob));
           buffer_consume(&copy, sizeof(authfile_id_string));
   
         /* Skip cipher type and reserved data. */          /* Skip cipher type and reserved data. */
         (void) buffer_get_char(blob);   /* cipher type */          (void) buffer_get_char(&copy);          /* cipher type */
         (void) buffer_get_int(blob);            /* reserved */          (void) buffer_get_int(&copy);           /* reserved */
   
         /* Read the public key from the buffer. */          /* Read the public key from the buffer. */
         (void) buffer_get_int(blob);          (void) buffer_get_int(&copy);
         pub = key_new(KEY_RSA1);          pub = key_new(KEY_RSA1);
         buffer_get_bignum(blob, pub->rsa->n);          buffer_get_bignum(&copy, pub->rsa->n);
         buffer_get_bignum(blob, pub->rsa->e);          buffer_get_bignum(&copy, pub->rsa->e);
         if (commentp)          if (commentp)
                 *commentp = buffer_get_string(blob, NULL);                  *commentp = buffer_get_string(&copy, NULL);
         /* The encrypted private part is not parsed by this function. */          /* The encrypted private part is not parsed by this function. */
         buffer_clear(blob);          buffer_free(&copy);
   
         return pub;          return pub;
 }  }
Line 409 
Line 412 
         CipherContext ciphercontext;          CipherContext ciphercontext;
         Cipher *cipher;          Cipher *cipher;
         Key *prv = NULL;          Key *prv = NULL;
           Buffer copy;
   
         /* Check that it is at least big enough to contain the ID string. */          /* Check that it is at least big enough to contain the ID string. */
         if (buffer_len(blob) < sizeof(authfile_id_string)) {          if (buffer_len(blob) < sizeof(authfile_id_string)) {
Line 425 
Line 429 
                 debug3("Incorrect RSA1 identifier");                  debug3("Incorrect RSA1 identifier");
                 return NULL;                  return NULL;
         }          }
         buffer_consume(blob, sizeof(authfile_id_string));          buffer_init(&copy);
           buffer_append(&copy, buffer_ptr(blob), buffer_len(blob));
           buffer_consume(&copy, sizeof(authfile_id_string));
   
         /* Read cipher type. */          /* Read cipher type. */
         cipher_type = buffer_get_char(blob);          cipher_type = buffer_get_char(&copy);
         (void) buffer_get_int(blob);    /* Reserved data. */          (void) buffer_get_int(&copy);   /* Reserved data. */
   
         /* Read the public key from the buffer. */          /* Read the public key from the buffer. */
         (void) buffer_get_int(blob);          (void) buffer_get_int(&copy);
         prv = key_new_private(KEY_RSA1);          prv = key_new_private(KEY_RSA1);
   
         buffer_get_bignum(blob, prv->rsa->n);          buffer_get_bignum(&copy, prv->rsa->n);
         buffer_get_bignum(blob, prv->rsa->e);          buffer_get_bignum(&copy, prv->rsa->e);
         if (commentp)          if (commentp)
                 *commentp = buffer_get_string(blob, NULL);                  *commentp = buffer_get_string(&copy, NULL);
         else          else
                 (void)buffer_get_string_ptr(blob, NULL);                  (void)buffer_get_string_ptr(&copy, NULL);
   
         /* Check that it is a supported cipher. */          /* Check that it is a supported cipher. */
         cipher = cipher_by_number(cipher_type);          cipher = cipher_by_number(cipher_type);
         if (cipher == NULL) {          if (cipher == NULL) {
                 debug("Unsupported RSA1 cipher %d", cipher_type);                  debug("Unsupported RSA1 cipher %d", cipher_type);
                   buffer_free(&copy);
                 goto fail;                  goto fail;
         }          }
         /* Initialize space for decrypted data. */          /* Initialize space for decrypted data. */
         buffer_init(&decrypted);          buffer_init(&decrypted);
         cp = buffer_append_space(&decrypted, buffer_len(blob));          cp = buffer_append_space(&decrypted, buffer_len(&copy));
   
         /* Rest of the buffer is encrypted.  Decrypt it using the passphrase. */          /* Rest of the buffer is encrypted.  Decrypt it using the passphrase. */
         cipher_set_key_string(&ciphercontext, cipher, passphrase,          cipher_set_key_string(&ciphercontext, cipher, passphrase,
             CIPHER_DECRYPT);              CIPHER_DECRYPT);
         cipher_crypt(&ciphercontext, cp,          cipher_crypt(&ciphercontext, cp,
             buffer_ptr(blob), buffer_len(blob));              buffer_ptr(&copy), buffer_len(&copy));
         cipher_cleanup(&ciphercontext);          cipher_cleanup(&ciphercontext);
         memset(&ciphercontext, 0, sizeof(ciphercontext));          memset(&ciphercontext, 0, sizeof(ciphercontext));
         buffer_clear(blob);          buffer_free(&copy);
   
         check1 = buffer_get_char(&decrypted);          check1 = buffer_get_char(&decrypted);
         check2 = buffer_get_char(&decrypted);          check2 = buffer_get_char(&decrypted);
Line 676 
Line 683 
     const char *passphrase, char **commentp)      const char *passphrase, char **commentp)
 {  {
         Key *pub, *prv;          Key *pub, *prv;
         Buffer pubcopy;  
   
         buffer_init(&pubcopy);  
         buffer_append(&pubcopy, buffer_ptr(buffer), buffer_len(buffer));  
         /* it's a SSH v1 key if the public key part is readable */          /* it's a SSH v1 key if the public key part is readable */
         pub = key_parse_public_rsa1(&pubcopy, commentp);          pub = key_parse_public_rsa1(buffer, commentp);
         buffer_free(&pubcopy);  
         if (pub == NULL) {          if (pub == NULL) {
                 prv = key_parse_private_type(buffer, KEY_UNSPEC,                  prv = key_parse_private_type(buffer, KEY_UNSPEC,
                     passphrase, NULL);                      passphrase, NULL);

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.92