From 3832955edb58fa9ae7ebf5f4ef8c5511fe714ec6 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 9 Apr 2001 10:48:00 +0000 Subject: [PATCH] updates. --- CHANGES | 13 +++++++++++++ apps/silc/clientutil.c | 4 +++- apps/silc/clientutil.h | 1 + apps/silc/silc.c | 19 ++++++++++++++++++- lib/silccrypt/rsa.c | 6 +++--- lib/silccrypt/silcpkcs.c | 2 ++ lib/silccrypt/silcpkcs.h | 25 +++++++++++++++++++------ 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 816493ff..305ac07b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,16 @@ +Mon Apr 9 16:54:44 EEST 2001 Pekka Riikonen + + * 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 * Made the key generation options to the silcd program. Added diff --git a/apps/silc/clientutil.c b/apps/silc/clientutil.c index e37eba53..95a37422 100644 --- a/apps/silc/clientutil.c +++ b/apps/silc/clientutil.c @@ -727,8 +727,10 @@ int silc_client_show_key(char *keyfile) 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); diff --git a/apps/silc/clientutil.h b/apps/silc/clientutil.h index 9d796f34..b4215198 100644 --- a/apps/silc/clientutil.h +++ b/apps/silc/clientutil.h @@ -41,5 +41,6 @@ int silc_client_create_key_pair(char *pkcs_name, int bits, 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 diff --git a/apps/silc/silc.c b/apps/silc/silc.c index 5a64e7c9..0ff3e1ed 100644 --- a/apps/silc/silc.c +++ b/apps/silc/silc.c @@ -59,6 +59,7 @@ static struct option long_opts[] = { "create-key-pair", 0, NULL, 'C' }, { "pkcs", 1, NULL, 10 }, { "bits", 1, NULL, 11 }, + { "show-key", 1, NULL, 'S' }, { NULL, 0, NULL, 0 } }; @@ -75,7 +76,9 @@ static char *opt_config_file = NULL; 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 */ @@ -109,6 +112,7 @@ Usage: silc [options]\n\ -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"); } @@ -125,7 +129,7 @@ int main(int argc, char **argv) { 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) @@ -210,6 +214,11 @@ SILC Secure Internet Live Conferencing, version %s\n", if (optarg) opt_bits = atoi(optarg); break; + case 'S': + opt_show_key = TRUE; + if (optarg) + opt_keyfile = strdup(optarg); + break; default: exit(0); @@ -239,6 +248,14 @@ SILC Secure Internet Live Conferencing, version %s\n", /* 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); } diff --git a/lib/silccrypt/rsa.c b/lib/silccrypt/rsa.c index 5607dfc2..3382f23d 100644 --- a/lib/silccrypt/rsa.c +++ b/lib/silccrypt/rsa.c @@ -224,7 +224,7 @@ SILC_PKCS_API_SET_PUBLIC_KEY(rsa) 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); @@ -234,14 +234,14 @@ SILC_PKCS_API_SET_PUBLIC_KEY(rsa) 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 diff --git a/lib/silccrypt/silcpkcs.c b/lib/silccrypt/silcpkcs.c index 1f9cb8af..f8c9e809 100644 --- a/lib/silccrypt/silcpkcs.c +++ b/lib/silccrypt/silcpkcs.c @@ -916,6 +916,7 @@ int silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key, if (byte != SILC_PKCS_PUBLIC_KEYFILE_BEGIN[i]) { memset(old, 0, data_len); silc_free(old); + return FALSE; } } data = cp; @@ -968,6 +969,7 @@ int silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key, if (byte != SILC_PKCS_PRIVATE_KEYFILE_BEGIN[i]) { memset(old, 0, data_len); silc_free(old); + return FALSE; } } data = cp; diff --git a/lib/silccrypt/silcpkcs.h b/lib/silccrypt/silcpkcs.h index baaff0c6..50c1354a 100644 --- a/lib/silccrypt/silcpkcs.h +++ b/lib/silccrypt/silcpkcs.h @@ -31,7 +31,7 @@ typedef struct SilcPKCSObjectStruct { 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)(); @@ -78,6 +78,17 @@ typedef struct { 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" @@ -125,8 +136,8 @@ unsigned char *silc_##pkcs##_get_public_key(void *context, \ 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) @@ -172,9 +183,9 @@ char *silc_pkcs_get_supported(); 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); @@ -197,6 +208,8 @@ int silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash, 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); -- 2.24.0