version 1.6, 2000/05/05 18:53:42 |
version 1.6.2.3, 2000/11/08 21:30:51 |
|
|
/* |
/* |
|
* read_bignum(): |
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
|
* |
|
* As far as I am concerned, the code I have written for this software |
|
* can be used freely for any purpose. Any derived versions of this |
|
* software must be clearly marked as such, and if the derived work is |
|
* incompatible with the protocol description in the RFC file, it must be |
|
* called by a name other than "ssh" or "Secure Shell". |
|
* |
|
* |
* Copyright (c) 2000 Markus Friedl. All rights reserved. |
* Copyright (c) 2000 Markus Friedl. All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
* 3. All advertising materials mentioning features or use of this software |
|
* must display the following acknowledgement: |
|
* This product includes software developed by Markus Friedl. |
|
* 4. The name of the author may not be used to endorse or promote products |
|
* derived from this software without specific prior written permission. |
|
* |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
/* |
|
* read_bignum(): |
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
|
*/ |
|
|
|
#include "includes.h" |
#include "includes.h" |
#include "ssh.h" |
#include "ssh.h" |
|
|
#include "dsa.h" |
#include "dsa.h" |
#include "uuencode.h" |
#include "uuencode.h" |
|
|
|
RCSID("$OpenBSD$"); |
|
|
#define SSH_DSS "ssh-dss" |
#define SSH_DSS "ssh-dss" |
|
|
Key * |
Key * |
|
|
return 0; |
return 0; |
} |
} |
|
|
#define FPRINT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" |
|
|
|
/* |
/* |
* Generate key fingerprint in ascii format. |
* Generate key fingerprint in ascii format. |
* Based on ideas and code from Bjoern Groenvall <bg@sics.se> |
* Based on ideas and code from Bjoern Groenvall <bg@sics.se> |
|
|
char * |
char * |
key_fingerprint(Key *k) |
key_fingerprint(Key *k) |
{ |
{ |
static char retval[80]; |
static char retval[(EVP_MAX_MD_SIZE+1)*3]; |
unsigned char *blob = NULL; |
unsigned char *blob = NULL; |
int len = 0; |
int len = 0; |
int nlen, elen; |
int nlen, elen; |
|
|
fatal("key_fingerprint: bad key type %d", k->type); |
fatal("key_fingerprint: bad key type %d", k->type); |
break; |
break; |
} |
} |
|
retval[0] = '\0'; |
|
|
if (blob != NULL) { |
if (blob != NULL) { |
unsigned char d[16]; |
int i; |
EVP_MD_CTX md; |
unsigned char digest[EVP_MAX_MD_SIZE]; |
EVP_DigestInit(&md, EVP_md5()); |
EVP_MD *md = EVP_md5(); |
EVP_DigestUpdate(&md, blob, len); |
EVP_MD_CTX ctx; |
EVP_DigestFinal(&md, d, NULL); |
EVP_DigestInit(&ctx, md); |
snprintf(retval, sizeof(retval), FPRINT, |
EVP_DigestUpdate(&ctx, blob, len); |
d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], |
EVP_DigestFinal(&ctx, digest, NULL); |
d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); |
for(i = 0; i < md->md_size; i++) { |
|
char hex[4]; |
|
snprintf(hex, sizeof(hex), "%02x:", digest[i]); |
|
strlcat(retval, hex, sizeof(retval)); |
|
} |
|
retval[strlen(retval) - 1] = '\0'; |
memset(blob, 0, len); |
memset(blob, 0, len); |
xfree(blob); |
xfree(blob); |
} |
} |
|
|
blob = xmalloc(len); |
blob = xmalloc(len); |
n = uudecode(cp, blob, len); |
n = uudecode(cp, blob, len); |
if (n < 0) { |
if (n < 0) { |
error("uudecode %s failed", cp); |
error("key_read: uudecode %s failed", cp); |
return 0; |
return 0; |
} |
} |
k = dsa_key_from_blob(blob, n); |
k = dsa_key_from_blob(blob, n); |
if (k == NULL) |
if (k == NULL) { |
return 0; |
error("key_read: dsa_key_from_blob %s failed", cp); |
|
return 0; |
|
} |
xfree(blob); |
xfree(blob); |
if (ret->dsa != NULL) |
if (ret->dsa != NULL) |
DSA_free(ret->dsa); |
DSA_free(ret->dsa); |
|
|
k->dsa = NULL; |
k->dsa = NULL; |
key_free(k); |
key_free(k); |
bits = BN_num_bits(ret->dsa->p); |
bits = BN_num_bits(ret->dsa->p); |
cp = strchr(cp, '='); |
/* advance cp: skip whitespace and data */ |
if (cp == NULL) |
while (*cp == ' ' || *cp == '\t') |
return 0; |
cp++; |
*cpp = cp + 1; |
while (*cp != '\0' && *cp != ' ' && *cp != '\t') |
|
cp++; |
|
*cpp = cp; |
break; |
break; |
default: |
default: |
fatal("key_read: bad key type: %d", ret->type); |
fatal("key_read: bad key type: %d", ret->type); |
|
|
break; |
break; |
} |
} |
return "unknown"; |
return "unknown"; |
|
} |
|
unsigned int |
|
key_size(Key *k){ |
|
switch (k->type) { |
|
case KEY_RSA: |
|
return BN_num_bits(k->rsa->n); |
|
break; |
|
case KEY_DSA: |
|
return BN_num_bits(k->dsa->p); |
|
break; |
|
} |
|
return 0; |
} |
} |