client.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2002 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "fe-common/core/printtext.h"
#include "fe-common/core/keyboard.h"
+#include "core.h"
+
/* Lists supported ciphers */
void silc_client_list_ciphers()
silc_free(pkcs);
}
-/* Displays input prompt on command line and takes input data from user */
-
-char *silc_client_get_input(const char *prompt)
-{
- char input[2048];
- int fd;
-
- fd = open("/dev/tty", O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "silc: %s\n", strerror(errno));
- return NULL;
- }
-
- memset(input, 0, sizeof(input));
-
- printf("%s", prompt);
- fflush(stdout);
-
- if ((read(fd, input, sizeof(input))) < 0) {
- fprintf(stderr, "silc: %s\n", strerror(errno));
- return NULL;
- }
-
- if (strlen(input) <= 1)
- return NULL;
-
- if (strchr(input, '\n'))
- *strchr(input, '\n') = '\0';
-
- return strdup(input);
-}
-
/* Returns identifier string for public key generation. */
char *silc_client_create_identifier()
SilcPrivateKey prv_key;
SilcRng rng;
unsigned char *key;
- uint32 key_len;
+ SilcUInt32 key_len;
char line[256];
char *pkfile = NULL, *prvfile = NULL;
if (!pkcs_name) {
again_name:
- pkcs_name =
- silc_client_get_input("PKCS name (l to list names) [rsa]: ");
+ pkcs_name = silc_get_input("PKCS name (l to list names) [rsa]: ", FALSE);
if (!pkcs_name)
pkcs_name = strdup("rsa");
if (!bits) {
char *length = NULL;
- length =
- silc_client_get_input("Key length in bits [1024]: ");
+ length = silc_get_input("Key length in bits [1024]: ", FALSE);
if (!length)
bits = 1024;
else
"RN=Jon Johnson, E=jon@dummy.com): ");
while (!identifier) {
- identifier = silc_client_get_input(line);
+ identifier = silc_get_input(line, FALSE);
if (!identifier && def)
identifier = strdup(def);
}
memset(line, 0, sizeof(line));
snprintf(line, sizeof(line), "Public key filename [%s] ",
SILC_CLIENT_PUBLIC_KEY_NAME);
- pkfile = silc_client_get_input(line);
+ pkfile = silc_get_input(line, FALSE);
if (!pkfile)
pkfile = SILC_CLIENT_PUBLIC_KEY_NAME;
} else {
memset(line, 0, sizeof(line));
snprintf(line, sizeof(line), "Public key filename [%s] ",
SILC_CLIENT_PRIVATE_KEY_NAME);
- prvfile = silc_client_get_input(line);
+ prvfile = silc_get_input(line, FALSE);
if (!prvfile)
prvfile = SILC_CLIENT_PRIVATE_KEY_NAME;
} else {
/* Generate keys */
silc_pkcs_alloc(pkcs_name, &pkcs);
- pkcs->pkcs->init(pkcs->context, bits, rng);
+ silc_pkcs_generate_key(pkcs, bits, rng);
/* Save public key into file */
key = silc_pkcs_get_public_key(pkcs, &key_len);
memset(file_public_key, 0, sizeof(file_public_key));
memset(file_private_key, 0, sizeof(file_private_key));
+ identifier = silc_client_create_identifier();
+
pw = getpwuid(getuid());
if (!pw) {
fprintf(stderr, "silc: %s\n", strerror(errno));
+ if (identifier)
+ silc_free(identifier);
return FALSE;
}
- identifier = silc_client_create_identifier();
-
/* We'll take home path from /etc/passwd file to be sure. */
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/", pw->pw_dir);
- snprintf(servfilename, sizeof(servfilename) - 1, "%s/.silc/serverkeys",
- pw->pw_dir);
- snprintf(clientfilename, sizeof(clientfilename) - 1, "%s/.silc/clientkeys",
- pw->pw_dir);
+ snprintf(filename, sizeof(filename) - 1, "%s/", get_irssi_dir());
+ snprintf(servfilename, sizeof(servfilename) - 1, "%s/serverkeys",
+ get_irssi_dir());
+ snprintf(clientfilename, sizeof(clientfilename) - 1, "%s/clientkeys",
+ get_irssi_dir());
/*
* Check ~/.silc directory
return FALSE;
memset(filename, 0, sizeof(filename));
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%s",
- pw->pw_dir, SILC_CLIENT_PRIVATE_KEY_NAME);
+ snprintf(filename, sizeof(filename) - 1, "%s/%s",
+ get_irssi_dir(), SILC_CLIENT_PRIVATE_KEY_NAME);
if (silc_pkcs_load_private_key(filename, &client->private_key,
SILC_PKCS_FILE_BIN) == FALSE)
return FALSE;
memset(filename, 0, sizeof(filename));
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%s",
- pw->pw_dir, SILC_CLIENT_PUBLIC_KEY_NAME);
+ snprintf(filename, sizeof(filename) - 1, "%s/%s",
+ get_irssi_dir(), SILC_CLIENT_PUBLIC_KEY_NAME);
if (silc_pkcs_load_public_key(filename, &client->public_key,
SILC_PKCS_FILE_PEM) == FALSE)
SILC_PKCS_FILE_BIN) == FALSE)
return FALSE;
+ silc_pkcs_alloc(client->public_key->name, &client->pkcs);
+ silc_pkcs_public_key_set(client->pkcs, client->public_key);
+ silc_pkcs_private_key_set(client->pkcs, client->private_key);
+
return TRUE;
}
{
SilcPublicKey public_key;
SilcPublicKeyIdentifier ident;
- char *fingerprint;
+ char *fingerprint, *babbleprint;
unsigned char *pk;
- uint32 pk_len;
+ SilcUInt32 pk_len;
SilcPKCS pkcs;
int key_len = 0;
pk = silc_pkcs_public_key_encode(public_key, &pk_len);
fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
+ babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
if (silc_pkcs_alloc(public_key->name, &pkcs)) {
key_len = silc_pkcs_public_key_set(pkcs, public_key);
if (ident->country)
printf("Country : %s\n", ident->country);
printf("Fingerprint (SHA1) : %s\n", fingerprint);
+ printf("Babbleprint (SHA1) : %s\n", babbleprint);
fflush(stdout);
silc_free(fingerprint);
+ silc_free(babbleprint);
silc_free(pk);
silc_pkcs_public_key_free(public_key);
silc_pkcs_free_identifier(ident);