version 1.62.2.1, 2006/09/30 04:06:50 |
version 1.63, 2006/03/13 10:26:52 |
|
|
/* $OpenBSD$ */ |
|
/* |
/* |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#include "includes.h" |
|
RCSID("$OpenBSD$"); |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/param.h> |
|
#include <sys/uio.h> |
|
|
|
#include <openssl/err.h> |
#include <openssl/err.h> |
#include <openssl/evp.h> |
#include <openssl/evp.h> |
#include <openssl/pem.h> |
#include <openssl/pem.h> |
|
|
#include <errno.h> |
|
#include <fcntl.h> |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
|
|
#include "xmalloc.h" |
|
#include "cipher.h" |
#include "cipher.h" |
|
#include "xmalloc.h" |
#include "buffer.h" |
#include "buffer.h" |
|
#include "bufaux.h" |
#include "key.h" |
#include "key.h" |
#include "ssh.h" |
#include "ssh.h" |
#include "log.h" |
#include "log.h" |
|
|
return 0; |
return 0; |
} |
} |
fp = fdopen(fd, "w"); |
fp = fdopen(fd, "w"); |
if (fp == NULL) { |
if (fp == NULL ) { |
error("fdopen %s failed: %s.", filename, strerror(errno)); |
error("fdopen %s failed: %s.", filename, strerror(errno)); |
close(fd); |
close(fd); |
return 0; |
return 0; |
|
|
case KEY_RSA1: |
case KEY_RSA1: |
return key_save_private_rsa1(key, filename, passphrase, |
return key_save_private_rsa1(key, filename, passphrase, |
comment); |
comment); |
|
break; |
case KEY_DSA: |
case KEY_DSA: |
case KEY_RSA: |
case KEY_RSA: |
return key_save_private_pem(key, filename, passphrase, |
return key_save_private_pem(key, filename, passphrase, |
comment); |
comment); |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
|
|
|
|
Key * |
Key * |
key_load_private_type(int type, const char *filename, const char *passphrase, |
key_load_private_type(int type, const char *filename, const char *passphrase, |
char **commentp, int *perm_ok) |
char **commentp) |
{ |
{ |
int fd; |
int fd; |
|
|
|
|
if (fd < 0) |
if (fd < 0) |
return NULL; |
return NULL; |
if (!key_perm_ok(fd, filename)) { |
if (!key_perm_ok(fd, filename)) { |
if (perm_ok != NULL) |
|
*perm_ok = 0; |
|
error("bad permissions: ignore key: %s", filename); |
error("bad permissions: ignore key: %s", filename); |
close(fd); |
close(fd); |
return NULL; |
return NULL; |
} |
} |
if (perm_ok != NULL) |
|
*perm_ok = 1; |
|
switch (type) { |
switch (type) { |
case KEY_RSA1: |
case KEY_RSA1: |
return key_load_private_rsa1(fd, filename, passphrase, |
return key_load_private_rsa1(fd, filename, passphrase, |
commentp); |
commentp); |
/* closes fd */ |
/* closes fd */ |
|
break; |
case KEY_DSA: |
case KEY_DSA: |
case KEY_RSA: |
case KEY_RSA: |
case KEY_UNSPEC: |
case KEY_UNSPEC: |
return key_load_private_pem(fd, type, passphrase, commentp); |
return key_load_private_pem(fd, type, passphrase, commentp); |
/* closes fd */ |
/* closes fd */ |
|
break; |
default: |
default: |
close(fd); |
close(fd); |
break; |
break; |