key.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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, 2001 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
#pragma ident "%Z%%M% %I% %E% SMI"
#include "xmalloc.h"
#include "key.h"
#include "rsa.h"
#include "ssh-dss.h"
#include "ssh-rsa.h"
#include "uuencode.h"
#include "buffer.h"
#include "bufaux.h"
#include "log.h"
Key *
{
Key *k;
k = xmalloc(sizeof(*k));
k->flags = 0;
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
fatal("key_new: RSA_new failed");
fatal("key_new: BN_new failed");
fatal("key_new: BN_new failed");
break;
case KEY_DSA:
fatal("key_new: DSA_new failed");
fatal("key_new: BN_new failed");
fatal("key_new: BN_new failed");
fatal("key_new: BN_new failed");
fatal("key_new: BN_new failed");
break;
case KEY_UNSPEC:
break;
default:
break;
}
return k;
}
Key *
key_new_private(int type)
{
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
fatal("key_new_private: BN_new failed");
fatal("key_new_private: BN_new failed");
fatal("key_new_private: BN_new failed");
fatal("key_new_private: BN_new failed");
fatal("key_new_private: BN_new failed");
fatal("key_new_private: BN_new failed");
break;
case KEY_DSA:
fatal("key_new_private: BN_new failed");
break;
case KEY_UNSPEC:
break;
default:
break;
}
return k;
}
void
{
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
break;
case KEY_DSA:
break;
case KEY_UNSPEC:
break;
default:
break;
}
xfree(k);
}
int
{
return 0;
switch (a->type) {
case KEY_RSA1:
case KEY_RSA:
break;
case KEY_DSA:
break;
default:
break;
}
return 0;
}
static u_char *
{
*dgst_raw_length = 0;
switch (dgst_type) {
case SSH_FP_MD5:
break;
case SSH_FP_SHA1:
break;
default:
fatal("key_fingerprint_raw: bad digest type %d",
}
switch (k->type) {
case KEY_RSA1:
break;
case KEY_DSA:
case KEY_RSA:
break;
case KEY_UNSPEC:
return retval;
break;
default:
break;
}
} else {
fatal("key_fingerprint_raw: blob is null");
}
return retval;
}
static char *
{
char *retval;
int i;
retval[0] = '\0';
for (i = 0; i < dgst_raw_len; i++) {
char hex[4];
}
return retval;
}
static char *
{
'n', 'p', 'r', 's', 't', 'v', 'z', 'x' };
char *retval;
retval[j++] = 'x';
for (i = 0; i < rounds; i++) {
seed) % 6;
if ((i + 1) < rounds) {
retval[j++] = '-';
}
} else {
idx1 = 16;
}
}
retval[j++] = 'x';
retval[j++] = '\0';
return retval;
}
char *
{
if (!dgst_raw)
fatal("key_fingerprint: null from key_fingerprint_raw()");
switch (dgst_rep) {
case SSH_FP_HEX:
break;
case SSH_FP_BUBBLEBABBLE:
break;
default:
fatal("key_fingerprint_ex: bad digest representation %d",
dgst_rep);
break;
}
return retval;
}
/*
* Reads a multiple-precision integer in decimal from the buffer, and advances
* the pointer. The integer must already be initialized. This function is
* permitted to modify the buffer. This leaves *cpp to point just beyond the
* last processed (and maybe modified) character. Note that this may modify
* the buffer containing the number.
*/
static int
{
int old;
/* Skip any leading whitespace. */
;
/* Check that it begins with a decimal digit. */
return 0;
/* Save starting position. */
/* Move forward until all decimal digits skipped. */
;
/* Save the old terminating character, and replace it by \0. */
*cp = 0;
/* Parse the number. */
return 0;
/* Restore old terminating character. */
/* Move beyond the number and return success. */
return 1;
}
static int
{
error("write_bignum: BN_bn2dec() failed");
return 0;
}
return 1;
}
/* returns 1 ok, -1 error */
int
{
Key *k;
int success = -1;
case KEY_RSA1:
/* Get number of bits. */
return -1; /* Bad bit count... */
if (bits == 0)
return -1;
/* Get public exponent, public modulus. */
return -1;
return -1;
success = 1;
break;
case KEY_UNSPEC:
case KEY_RSA:
case KEY_DSA:
debug3("key_read: no space");
return -1;
}
*space = '\0';
*space = ' ';
if (type == KEY_UNSPEC) {
debug3("key_read: no key found");
return -1;
}
if (*cp == '\0') {
debug3("key_read: short string");
return -1;
}
/* is a key, but different type */
debug3("key_read: type mismatch");
return -1;
}
if (n < 0) {
return -1;
}
k = key_from_blob(blob, n);
if (k == NULL) {
return -1;
}
error("key_read: type mismatch: encoding error");
key_free(k);
return -1;
}
/*XXXX*/
success = 1;
#ifdef DEBUG_PK
#endif
} else {
success = 1;
#ifdef DEBUG_PK
#endif
}
/*XXXX*/
key_free(k);
if (success != 1)
break;
/* advance cp: skip whitespace and data */
cp++;
cp++;
break;
default:
break;
}
return success;
}
int
{
int n, success = 0;
char *uu;
/* size of modulus 'n' */
success = 1;
} else {
error("key_write: failed for RSA key");
}
if (n > 0) {
success = 1;
}
}
return success;
}
char *
{
switch (k->type) {
case KEY_RSA1:
return "RSA1";
break;
case KEY_RSA:
return "RSA";
break;
case KEY_DSA:
return "DSA";
break;
}
return "unknown";
}
char *
key_ssh_name(Key *k)
{
switch (k->type) {
case KEY_RSA:
return "ssh-rsa";
break;
case KEY_DSA:
return "ssh-dss";
break;
}
return "ssh-unknown";
}
{
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
return BN_num_bits(k->rsa->n);
break;
case KEY_DSA:
return BN_num_bits(k->dsa->p);
break;
}
return 0;
}
static RSA *
{
fatal("rsa_generate_private_key: key generation failed.");
return private;
}
static DSA*
{
fatal("dsa_generate_private_key: DSA_generate_parameters failed");
if (!DSA_generate_key(private))
fatal("dsa_generate_private_key: DSA_generate_key failed.");
fatal("dsa_generate_private_key: NULL.");
return private;
}
Key *
{
switch (type) {
case KEY_DSA:
break;
case KEY_RSA:
case KEY_RSA1:
break;
default:
}
return k;
}
Key *
key_from_private(Key *k)
{
switch (k->type) {
case KEY_DSA:
break;
case KEY_RSA:
case KEY_RSA1:
break;
default:
break;
}
return n;
}
int
key_type_from_name(char *name)
{
return KEY_RSA1;
return KEY_RSA;
return KEY_DSA;
return KEY_RSA;
return KEY_DSA;
return KEY_NULL;
}
return KEY_UNSPEC;
}
int
key_names_valid2(const char *names)
{
char *s, *cp, *p;
return 0;
switch (key_type_from_name(p)) {
case KEY_RSA1:
case KEY_UNSPEC:
xfree(s);
return 0;
}
}
xfree(s);
return 1;
}
Key *
{
Buffer b;
char *ktype;
#ifdef DEBUG_PK
#endif
buffer_init(&b);
switch (type) {
case KEY_RSA:
#ifdef DEBUG_PK
#endif
break;
case KEY_DSA:
#ifdef DEBUG_PK
#endif
break;
case KEY_UNSPEC:
break;
default:
break;
}
rlen = buffer_len(&b);
buffer_free(&b);
return key;
}
int
{
Buffer b;
int len;
error("key_to_blob: key == NULL");
return 0;
}
buffer_init(&b);
case KEY_DSA:
break;
case KEY_RSA:
break;
default:
buffer_free(&b);
return 0;
}
len = buffer_len(&b);
}
buffer_free(&b);
return len;
}
int
{
case KEY_DSA:
break;
case KEY_RSA:
break;
default:
return -1;
break;
}
}
/*
* key_verify returns 1 for a correct signature, 0 for an incorrect signature
* and -1 on error.
*/
int
{
if (signaturelen == 0)
return -1;
case KEY_DSA:
break;
case KEY_RSA:
break;
default:
return -1;
break;
}
}
/* Converts a private to a public key */
Key *
key_demote(Key *k)
{
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
fatal("key_demote: RSA_new failed");
fatal("key_demote: BN_dup failed");
fatal("key_demote: BN_dup failed");
break;
case KEY_DSA:
fatal("key_demote: DSA_new failed");
fatal("key_demote: BN_dup failed");
fatal("key_demote: BN_dup failed");
fatal("key_demote: BN_dup failed");
fatal("key_demote: BN_dup failed");
break;
default:
break;
}
return (pk);
}