+Mon Apr 9 16:54:44 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+ * Added silc_pkcs_decode_identifier to decode the public key's
+ identifier. Affected file lib/silccrypt/silpkcs.[ch].
+ Added also silc_pkcs_free_identifier. Added also new context
+ SilcPublicKeyIdentifier.
+
+ * Added -S option to the silc client. It is used to dump the
+ contents of the specified public key file.
+
+ * Changed the PKCS api to return the public key length when
+ setting the public key.
+
Sun Apr 8 19:30:56 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
* Made the key generation options to the silcd program. Added
if (silc_pkcs_load_public_key(keyfile, &public_key,
SILC_PKCS_FILE_PEM) == FALSE)
if (silc_pkcs_load_public_key(keyfile, &public_key,
- SILC_PKCS_FILE_BIN) == FALSE)
+ SILC_PKCS_FILE_BIN) == FALSE) {
+ fprintf(stderr, "Could not load public key file `%s'\n", keyfile);
return FALSE;
+ }
ident = silc_pkcs_decode_identifier(public_key->identifier);
SilcPrivateKey *ret_prv_key);
int silc_client_check_silc_dir();
int silc_client_load_keys(SilcClient client);
+int silc_client_show_key(char *keyfile);
#endif
{ "create-key-pair", 0, NULL, 'C' },
{ "pkcs", 1, NULL, 10 },
{ "bits", 1, NULL, 11 },
+ { "show-key", 1, NULL, 'S' },
{ NULL, 0, NULL, 0 }
};
static bool opt_no_silcrc = FALSE;
static bool opt_create_keypair = FALSE;
+static bool opt_show_key = FALSE;
static char *opt_pkcs = NULL;
+static char *opt_keyfile = NULL;
static int opt_bits = 0;
/* SILC Client operations */
-C, --create-key-pair Create new public key pair\n\
--pkcs=PKCS Set the PKCS of the public key pair\n\
--bits=VALUE Set length of the public key pair\n\
+ -S, --show-key=FILE Show the contents of the public key\n\
\n");
}
{
while ((opt =
getopt_long(argc, argv,
- "s:p:n:c:b:k:f:qdhVC",
+ "s:p:n:c:b:k:f:qdhVCS:",
long_opts, &option_index)) != EOF)
{
switch(opt)
if (optarg)
opt_bits = atoi(optarg);
break;
+ case 'S':
+ opt_show_key = TRUE;
+ if (optarg)
+ opt_keyfile = strdup(optarg);
+ break;
default:
exit(0);
/* Create new key pair and exit */
silc_client_create_key_pair(opt_pkcs, opt_bits,
NULL, NULL, NULL, NULL, NULL);
+ silc_free(opt_pkcs);
+ exit(0);
+ }
+
+ if (opt_show_key == TRUE) {
+ /* Dump the key */
+ silc_client_show_key(opt_keyfile);
+ silc_free(opt_keyfile);
exit(0);
}
if (e_len > key_len) {
silc_mp_clear(&key->e);
silc_mp_clear(&key->n);
- return FALSE;
+ return 0;
}
silc_mp_bin2mp(key_data + 4, e_len, &key->e);
if (e_len + n_len > key_len) {
silc_mp_clear(&key->e);
silc_mp_clear(&key->n);
- return FALSE;
+ return 0;
}
silc_mp_bin2mp(key_data + 4 + e_len + 4, n_len, &key->n);
key->bits = n_len * 8;
- return TRUE;
+ return key->bits;
}
/* Set private key. This derives the public key from the private
if (byte != SILC_PKCS_PUBLIC_KEYFILE_BEGIN[i]) {
memset(old, 0, data_len);
silc_free(old);
+ return FALSE;
}
}
data = cp;
if (byte != SILC_PKCS_PRIVATE_KEYFILE_BEGIN[i]) {
memset(old, 0, data_len);
silc_free(old);
+ return FALSE;
}
}
data = cp;
void (*clear_keys)(void *);
unsigned char *(*get_public_key)(void *, uint32 *);
unsigned char *(*get_private_key)(void *, uint32 *);
- int (*set_public_key)(void *, unsigned char *, uint32);
+ uint32 (*set_public_key)(void *, unsigned char *, uint32);
int (*set_private_key)(void *, unsigned char *, uint32);
uint32 (*context_len)();
uint32 (*data_context_len)();
uint32 prv_len;
} *SilcPrivateKey;
+/* Decoded SILC Public Key identifier. Note that some of the fields
+ may be NULL. */
+typedef struct {
+ char *username;
+ char *host;
+ char *realname;
+ char *email;
+ char *org;
+ char *country;
+} *SilcPublicKeyIdentifier;
+
/* Public and private key file headers */
#define SILC_PKCS_PUBLIC_KEYFILE_BEGIN "-----BEGIN SILC PUBLIC KEY-----\n"
#define SILC_PKCS_PUBLIC_KEYFILE_END "\n-----END SILC PUBLIC KEY-----\n"
unsigned char *silc_##pkcs##_get_private_key(void *context, \
uint32 *ret_len)
#define SILC_PKCS_API_SET_PUBLIC_KEY(pkcs) \
-int silc_##pkcs##_set_public_key(void *context, unsigned char *key_data, \
- uint32 key_len)
+uint32 silc_##pkcs##_set_public_key(void *context, unsigned char *key_data, \
+ uint32 key_len)
#define SILC_PKCS_API_SET_PRIVATE_KEY(pkcs) \
int silc_##pkcs##_set_private_key(void *context, unsigned char *key_data, \
uint32 key_len)
uint32 silc_pkcs_get_key_len(SilcPKCS self);
unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, uint32 *len);
unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, uint32 *len);
-int silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
-int silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
- uint32 pk_len);
+uint32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
+uint32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
+ uint32 pk_len);
int silc_pkcs_private_key_set(SilcPKCS pkcs, SilcPrivateKey private_key);
int silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
uint32 prv_len);
uint32 data_len);
char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
char *email, char *org, char *country);
+SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
+void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
SilcPublicKey silc_pkcs_public_key_alloc(char *name, char *identifier,
unsigned char *pk,
uint32 pk_len);