#include <assert.h>
#include <ctype.h>
+#include "putty.h"
#include "ssh.h"
#include "misc.h"
((unsigned long)(unsigned char)(cp)[2] << 8) | \
((unsigned long)(unsigned char)(cp)[3]))
-int openssh_encrypted(char *filename);
-struct ssh2_userkey *openssh_read(char *filename, char *passphrase);
-int openssh_write(char *filename, struct ssh2_userkey *key, char *passphrase);
+int openssh_encrypted(const Filename *filename);
+struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase);
+int openssh_write(const Filename *filename, struct ssh2_userkey *key,
+ char *passphrase);
-int sshcom_encrypted(char *filename, char **comment);
-struct ssh2_userkey *sshcom_read(char *filename, char *passphrase);
-int sshcom_write(char *filename, struct ssh2_userkey *key, char *passphrase);
+int sshcom_encrypted(const Filename *filename, char **comment);
+struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase);
+int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
+ char *passphrase);
/*
* Given a key type, determine whether we know how to import it.
/*
* Determine whether a foreign key is encrypted.
*/
-int import_encrypted(char *filename, int type, char **comment)
+int import_encrypted(const Filename *filename, int type, char **comment)
{
if (type == SSH_KEYTYPE_OPENSSH) {
- *comment = dupstr(filename); /* OpenSSH doesn't do key comments */
+ /* OpenSSH doesn't do key comments */
+ *comment = dupstr(filename_to_str(filename));
return openssh_encrypted(filename);
}
if (type == SSH_KEYTYPE_SSHCOM) {
/*
* Import an SSH1 key.
*/
-int import_ssh1(char *filename, int type, struct RSAKey *key, char *passphrase)
+int import_ssh1(const Filename *filename, int type,
+ struct RSAKey *key, char *passphrase)
{
return 0;
}
/*
* Import an SSH2 key.
*/
-struct ssh2_userkey *import_ssh2(char *filename, int type, char *passphrase)
+struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
+ char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH)
return openssh_read(filename, passphrase);
/*
* Export an SSH1 key.
*/
-int export_ssh1(char *filename, int type, struct RSAKey *key, char *passphrase)
+int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
+ char *passphrase)
{
return 0;
}
/*
* Export an SSH2 key.
*/
-int export_ssh2(char *filename, int type,
+int export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH)
(c) == '+' || (c) == '/' || (c) == '=' \
)
-extern int base64_decode_atom(char *atom, unsigned char *out);
-extern int base64_lines(int datalen);
-extern void base64_encode_atom(unsigned char *data, int n, char *out);
-extern void base64_encode(FILE *fp, unsigned char *data, int datalen, int cpl);
-
/*
* Read an ASN.1/BER identifier and length pair.
*
int keyblob_len, keyblob_size;
};
-struct openssh_key *load_openssh_key(char *filename)
+struct openssh_key *load_openssh_key(const Filename *filename)
{
struct openssh_key *ret;
FILE *fp;
ret->encrypted = 0;
memset(ret->iv, 0, sizeof(ret->iv));
- fp = fopen(filename, "r");
+ fp = f_open(*filename, "r");
if (!fp) {
errmsg = "Unable to open key file";
goto error;
return NULL;
}
-int openssh_encrypted(char *filename)
+int openssh_encrypted(const Filename *filename)
{
struct openssh_key *key = load_openssh_key(filename);
int ret;
return ret;
}
-struct ssh2_userkey *openssh_read(char *filename, char *passphrase)
+struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase)
{
struct openssh_key *key = load_openssh_key(filename);
struct ssh2_userkey *retkey;
char *modptr;
int modlen;
+ blob = NULL;
+
if (!key)
return NULL;
return retval;
}
-int openssh_write(char *filename, struct ssh2_userkey *key, char *passphrase)
+int openssh_write(const Filename *filename, struct ssh2_userkey *key,
+ char *passphrase)
{
unsigned char *pubblob, *privblob, *spareblob;
int publen, privlen, sparelen;
* And save it. We'll use Unix line endings just in case it's
* subsequently transferred in binary mode.
*/
- fp = fopen(filename, "wb"); /* ensure Unix line endings */
+ fp = f_open(*filename, "wb"); /* ensure Unix line endings */
if (!fp)
goto error;
fputs(header, fp);
int keyblob_len, keyblob_size;
};
-struct sshcom_key *load_sshcom_key(char *filename)
+struct sshcom_key *load_sshcom_key(const Filename *filename)
{
struct sshcom_key *ret;
FILE *fp;
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;
- fp = fopen(filename, "r");
+ fp = f_open(*filename, "r");
if (!fp) {
errmsg = "Unable to open key file";
goto error;
* Header lines can end in a trailing backslash for
* continuation.
*/
- while ((len = strlen(p)) > sizeof(buffer) - (p-buffer) -1 ||
+ while ((len = strlen(p)) > (int)(sizeof(buffer) - (p-buffer) -1) ||
p[len-1] != '\n' || p[len-2] == '\\') {
- if (len > (p-buffer) + sizeof(buffer)-2) {
+ if (len > (int)((p-buffer) + sizeof(buffer)-2)) {
errmsg = "Header line too long to deal with";
goto error;
}
return NULL;
}
-int sshcom_encrypted(char *filename, char **comment)
+int sshcom_encrypted(const Filename *filename, char **comment)
{
struct sshcom_key *key = load_sshcom_key(filename);
int pos, len, answer;
return len+4;
}
-struct ssh2_userkey *sshcom_read(char *filename, char *passphrase)
+struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase)
{
struct sshcom_key *key = load_sshcom_key(filename);
char *errmsg;
return ret;
}
-int sshcom_write(char *filename, struct ssh2_userkey *key, char *passphrase)
+int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
+ char *passphrase)
{
unsigned char *pubblob, *privblob;
int publen, privlen;
* And save it. We'll use Unix line endings just in case it's
* subsequently transferred in binary mode.
*/
- fp = fopen(filename, "wb"); /* ensure Unix line endings */
+ fp = f_open(*filename, "wb"); /* ensure Unix line endings */
if (!fp)
goto error;
fputs("---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----\n", fp);
{
int slen = 60; /* starts at 60 due to "Comment: " */
char *c = key->comment;
- while (strlen(c) > slen) {
+ while ((int)strlen(c) > slen) {
fprintf(fp, "%.*s\\\n", slen, c);
c += slen;
slen = 70; /* allow 70 chars on subsequent lines */