updates.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 9 Apr 2001 10:48:00 +0000 (10:48 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 9 Apr 2001 10:48:00 +0000 (10:48 +0000)
CHANGES
apps/silc/clientutil.c
apps/silc/clientutil.h
apps/silc/silc.c
lib/silccrypt/rsa.c
lib/silccrypt/silcpkcs.c
lib/silccrypt/silcpkcs.h

diff --git a/CHANGES b/CHANGES
index 816493ffea4a56b0cd723f4403d9452a980ce607..305ac07b9affb58f89961a35cf38c5e97c07ef4d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,16 @@
+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
index e37eba5309834361db4322b2be924b9bb70b15f0..95a37422e75a815a0bc0a4d900899f28c3fef5b9 100644 (file)
@@ -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);
 
index 9d796f34b9cc0fc6c4c156b6afbfb4425e8c0e7b..b42151989e49b0aac8559a3f4b644c301599a314 100644 (file)
@@ -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
index 5a64e7c9d1c0c7d54c717697daf08a9a05ed2145..0ff3e1ed0b7112a346e151dc8b43e5de1142ac24 100644 (file)
@@ -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);
   }
 
index 5607dfc2db41ca0576ae62ae17f4be263bdddac1..3382f23d4828bae6827004b2e428db3f97b6f8b1 100644 (file)
@@ -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
index 1f9cb8afef1c16e735d545ef25f29a6eee0084dd..f8c9e80905c875c2e046cfa341eea633ae3a3013 100644 (file)
@@ -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;
index baaff0c68decd32b878637111e63cd3aa7a756f7..50c1354a2693594f681f410104aba2ed3321c949 100644 (file)
@@ -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);