Longer default PKCS keys
authorPekka Riikonen <priikone@silcnet.org>
Tue, 22 Apr 2014 12:25:37 +0000 (15:25 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 22 Apr 2014 12:25:37 +0000 (15:25 +0300)
This commit changes the default PKCS key length from 2048 bits to 4096
bits.  It adds warnings to both SILC client and SILC server in start up
in case the existing key is shorter than 4096 to encourage people to
generate new key longer key pair.

This commit also changes the default SKE DH group from 1024 to 1536 bits.
The old group is still supported.

18 files changed:
apps/irssi/src/silc/core/clientutil.c
apps/irssi/src/silc/core/silc-core.h
apps/silcd/server_query.c
apps/silcd/serverconfig.c
apps/silcd/silcd.c
lib/silcapputil/silcapputil.c
lib/silcapputil/silcapputil.h
lib/silcclient/client_attrs.c
lib/silcclient/tests/test_silcclient.c
lib/silccore/silcauth.c
lib/silccore/silcmessage.c
lib/silccore/tests/test_silcmessage.c
lib/silccrypt/silcpk.h
lib/silccrypt/silcpkcs1.c
lib/silccrypt/tests/test_silcpkcs.c
lib/silcserver/tests/test_silcserver.c
lib/silcske/groups.c
lib/silcske/silcske.c

index 66c8eb9a987e9c617ac9eef0d0836f1ff9dee1c2..9717d393519a2e2ce4c691159cd93fd2ade629e6 100644 (file)
@@ -367,6 +367,15 @@ int silc_client_load_keys(SilcClient client)
   if (!ret)
     SILC_LOG_ERROR(("Could not load key pair"));
 
+  if (silc_pkcs_private_key_get_len(irssi_privkey) < 4096) {
+    fprintf(stdout,
+            "warning: Your private key %s length is under 4096 bits. It is "
+           "recommended to use at least 4096 bits. Consider generating a "
+           "new key pair.\n", prv);
+    printf("Press <Enter> to continue...\n");
+    getchar();
+  }
+
   return ret;
 }
 
index 1f6365a3cdb9a3685f63fdf53e6a639b5b9edfbb..f1f1541f562d1c5cdafc780d32d272cb73e19545 100644 (file)
@@ -23,7 +23,7 @@
 
 /* Default settings for creating key pair */
 #define SILC_CLIENT_DEF_PKCS "rsa"
-#define SILC_CLIENT_DEF_PKCS_LEN 2048
+#define SILC_CLIENT_DEF_PKCS_LEN 4096
 
 extern SilcClient silc_client;
 extern SilcHash sha1hash;
index 5cc2decfbee9481af2ac00e3e45234462b82dda4..15a536ac88e232db62dd13dc4a41fdfde878cbb0 100644 (file)
@@ -2005,7 +2005,7 @@ SilcBuffer silc_server_query_reply_attrs(SilcServer server,
   SilcAttributeObjPk pk;
   SilcAttributeObjService service;
   unsigned char *tmp;
-  unsigned char sign[2048 + 1];
+  unsigned char sign[65536 + 1];
   SilcUInt32 sign_len;
 
   SILC_LOG_DEBUG(("Constructing Requested Attributes"));
index 6a3cbf050269c627160f689616f4b3062759bed5..187f5e9855a538b4b5c188d3fa0a0541ecbfee68 100644 (file)
@@ -2,9 +2,10 @@
 
   serverconfig.c
 
-  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
+  Authors: Giovanni Giacobbi <giovanni@giacobbi.net>
+           Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2014 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
@@ -655,6 +656,14 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
       SILC_SERVER_LOG_ERROR(("Error: Could not load private key file."));
       return SILC_CONFIG_EPRINTLINE;
     }
+
+    /* Warn if key length is < 4096 (some versions created 4095 bit keys). */
+    if (silc_pkcs_private_key_get_len(server_info->private_key) < 4095) {
+      fprintf(stderr,
+              "warning: Your server private key %s length is under 4096 bits. "
+             "It is recommended to use at least 4096 bits. Consider "
+             "generating a new server key pair.\n", file_tmp);
+    }
   }
   else
     return SILC_CONFIG_EINTERNAL;
index de4ad03a6579fbefb9157ca69caf0eb24e2e4e8b..529af0b4f3550f42945c616ece16ed7e2346c9b1 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2014 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
@@ -60,7 +60,7 @@ static struct option long_opts[] =
 static char *opt_keypath = NULL;
 static char *opt_pkcs = "rsa";
 static char *opt_identifier = NULL;
-static int opt_bits = 2048;
+static int opt_bits = 4096;
 
 /* Prints out the usage of silc client */
 
@@ -702,6 +702,12 @@ int main(int argc, char **argv)
     silc_pkcs_register_default();
     silc_hash_register_default();
     silc_hmac_register_default();
+
+    if (opt_bits < 4096)
+      fprintf(stderr,
+              "warning: You have specified key length under 4096 bits. It is "
+             "recommended to use at least 4096 bits.\n");
+
     if (!silc_create_key_pair(opt_pkcs, opt_bits, pubfile, prvfile,
                              opt_identifier, "", NULL, NULL, FALSE))
       exit(1);
index 833f40e29b4d230eeb1d1b24120b43d2fb746b13..9c7f136f1559d08f1ee0b6eb5ac9f268a69434d2 100644 (file)
@@ -108,13 +108,13 @@ New pair of keys will be created.  Please, answer to following questions.\n\
   if (!key_len_bits) {
     if (interactive) {
       char *length = NULL;
-      length = silc_get_input("Key length in key_len_bits [2048]: ", FALSE);
+      length = silc_get_input("Key length in key_len_bits [4096]: ", FALSE);
       if (length)
        key_len_bits = atoi(length);
       silc_free(length);
     }
     if (!key_len_bits)
-      key_len_bits = 2048;
+      key_len_bits = 4096;
   }
 
   if (!identifier) {
index f4858d2ad6c31ef8d70a101a560989b28714c5d3..fa1c750f58fc08df899a35ffcdf17ca32677fea9 100644 (file)
@@ -54,7 +54,7 @@
  *    This routine can be used to generate new public key and private key
  *    pair.  The `pkcs_name' is the name of public key algorithm, or if
  *    NULL it defaults to "rsa".  The `key_len_bits' is the key length
- *    in bits and if zero (0) it defaults to 2048 bits.  The `pub_filename'
+ *    in bits and if zero (0) it defaults to 4096 bits.  The `pub_filename'
  *    and `prv_filename' is the public key and private key filenames.
  *    The `pub_identifier' is the public key identifier (for example:
  *    "UN=foobar, HN=hostname"), or if NULL the routine generates it
index a7825270e4e450cd242f64b53def19c311a6d008..58eed45573b8f18e9cae95745b8111cc794a241f 100644 (file)
@@ -83,7 +83,7 @@ SilcBuffer silc_client_attributes_process(SilcClient client,
   SilcAttribute attribute;
   SilcAttributePayload attr;
   SilcAttributeObjPk pk;
-  unsigned char sign[2048 + 1];
+  unsigned char sign[65536 + 1];
   SilcUInt32 sign_len;
 
   SILC_LOG_DEBUG(("Process Requested Attributes"));
index 19ccbb9889b0c4832f541b096a8474a6aa2ffb1f..72cf2d57a28a1b4e39c83da77f85f3b41284649d 100644 (file)
@@ -111,9 +111,9 @@ int mybot_start(void)
                          &mybot->public_key,
                          &mybot->private_key)) {
     /* The keys don't exist.  Let's generate us a key pair then!  There's
-       nice ready routine for that too.  Let's do 2048 bit RSA key pair. */
+       nice ready routine for that too.  Let's do 4096 bit RSA key pair. */
     fprintf(stdout, "MyBot: Key pair does not exist, generating it.\n");
-    if (!silc_create_key_pair("rsa", 2048, "mybot.pub", "mybot.prv", NULL, "",
+    if (!silc_create_key_pair("rsa", 4096, "mybot.pub", "mybot.prv", NULL, "",
                              &mybot->public_key,
                              &mybot->private_key, FALSE)) {
       perror("Could not generated key pair");
index da2a502fe210c9c43e31a16c49aa464aa14abbcb..fca36ad4d6cef4a791a6c2b8fc5d7bc7b6945fe4 100644 (file)
@@ -274,7 +274,7 @@ silc_auth_public_key_auth_generate_wpub(SilcPublicKey public_key,
                                        SilcHash hash,
                                        const void *id, SilcIdType type)
 {
-  unsigned char auth_data[2048 + 1];
+  unsigned char auth_data[65536 + 1];
   SilcUInt32 auth_len;
   unsigned char *tmp;
   SilcUInt32 tmp_len;
index d1b43ee581bc03c7d0610ff431b13a79930129d5..1d70256b0a3e64acce0912e4fd35273cc6050b74 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2014 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
@@ -180,7 +180,7 @@ silc_message_signed_payload_encode(const unsigned char *message_payload,
                                   SilcHash hash)
 {
   SilcBuffer buffer, sign;
-  unsigned char auth_data[2048 + 1];
+  unsigned char auth_data[65536 + 1];
   SilcUInt32 auth_len;
   unsigned char *pk = NULL;
   SilcUInt32 pk_len = 0;
index 1f7d505229b8f0956bd3c9405801a82b392cd647..ea7695e572de84d33345062b8f63ce1b805f9493 100644 (file)
@@ -16,7 +16,7 @@ int main(int argc, char **argv)
   SilcMessagePayload message;
   SilcBuffer buf;
   const char *msg = "FOOBAR MESSAGE";
-  unsigned char *data, tmp[1023], *tmp2;
+  unsigned char *data, tmp[8192], *tmp2;
   SilcUInt32 data_len;
   SilcUInt16 flags;
   int i, n;
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
   if (!silc_load_key_pair("pubkey.pub", "privkey.prv", "",
                          &public_key, &private_key)) {
     SILC_LOG_DEBUG(("Create keypair"));
-    if (!silc_create_key_pair("rsa", 2048, "pubkey.pub", "privkey.prv",
+    if (!silc_create_key_pair("rsa", 4096, "pubkey.pub", "privkey.prv",
                              NULL, "", &public_key, &private_key, FALSE))
       goto err;
   }
index f62c628c9f0cc4d7b9967d05138c77451bf31e6b..1308c64a257fd145dea11df6581e434d78bfaba5 100644 (file)
@@ -114,8 +114,8 @@ typedef struct SilcSILCPrivateKeyStruct {
  *
  * EXAMPLE
  *
- *    // Generate RSA key pair with 2048 bit key length
- *    silc_pkcs_silc_generate_key("rsa", 2048, ident_string, rng,
+ *    // Generate RSA key pair with 4096 bit key length
+ *    silc_pkcs_silc_generate_key("rsa", 4096, ident_string, rng,
  *                                &public_key, &private_key);
  *
  ***/
index 514e6a21c20a1e975070572ec0e0a45c49a38ddd..f516d7410bf72e51eef3239d65e60c98cfc5701f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2007 Pekka Riikonen
+  Copyright (C) 2003 - 2014 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
@@ -491,7 +491,7 @@ SilcBool silc_pkcs1_encrypt(void *public_key,
   RsaPublicKey *key = public_key;
   SilcMPInt mp_tmp;
   SilcMPInt mp_dst;
-  unsigned char padded[2048 + 1];
+  unsigned char padded[65536 + 1];
   SilcUInt32 len = (key->bits + 7) / 8;
 
   if (sizeof(padded) < len)
@@ -534,7 +534,7 @@ SilcBool silc_pkcs1_decrypt(void *private_key,
   RsaPrivateKey *key = private_key;
   SilcMPInt mp_tmp;
   SilcMPInt mp_dst;
-  unsigned char *padded, unpadded[2048 + 1];
+  unsigned char *padded, unpadded[65536 + 1];
   SilcUInt32 padded_len;
 
   if (dst_size < (key->bits + 7) / 8)
@@ -591,7 +591,7 @@ SilcBool silc_pkcs1_sign(void *private_key,
                         SilcHash hash)
 {
   RsaPrivateKey *key = private_key;
-  unsigned char padded[2048 + 1], hashr[SILC_HASH_MAXLEN];
+  unsigned char padded[65536 + 1], hashr[SILC_HASH_MAXLEN];
   SilcMPInt mp_tmp;
   SilcMPInt mp_dst;
   SilcBufferStruct di;
@@ -802,7 +802,7 @@ SilcBool silc_pkcs1_sign_no_oid(void *private_key,
   RsaPrivateKey *key = private_key;
   SilcMPInt mp_tmp;
   SilcMPInt mp_dst;
-  unsigned char padded[2048 + 1], hashr[SILC_HASH_MAXLEN];
+  unsigned char padded[65536 + 1], hashr[SILC_HASH_MAXLEN];
   SilcUInt32 len = (key->bits + 7) / 8;
 
   SILC_LOG_DEBUG(("Sign"));
@@ -859,7 +859,7 @@ SilcBool silc_pkcs1_verify_no_oid(void *public_key,
   SilcBool ret = FALSE;
   SilcMPInt mp_tmp2;
   SilcMPInt mp_dst;
-  unsigned char *verify, unpadded[2048 + 1], hashr[SILC_HASH_MAXLEN];
+  unsigned char *verify, unpadded[65536 + 1], hashr[SILC_HASH_MAXLEN];
   SilcUInt32 verify_len, len = (key->bits + 7) / 8;
 
   SILC_LOG_DEBUG(("Verify signature"));
index 2e5f34e8d54d14bc0c9b24b463f8b274f292b00f..8a07c0ba81f1365565b49cc6ad3485ee2fa38ed9 100644 (file)
@@ -1,7 +1,7 @@
 /* Tests API in silcpkcs.h */
 #include "silc.h"
 
-int key_len = 2048;
+int key_len = 4096;
 const unsigned char p[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
 int p_len = 32;
 
@@ -16,7 +16,7 @@ int test()
   SilcPublicKeyIdentifier ident;
   SilcPrivateKey privkey;
   SilcBuffer buf;
-  unsigned char d[4096], d2[4096];
+  unsigned char d[8192], d2[8192];
   SilcUInt32 dlen, d2len;
   SilcHash sha1;
 
index a1953a64fae8e660eeffa104d563dbb3de1ea0b1..2b74d4113e03ef484786c88bd99fbf6ee267723a 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
   if (!silc_load_key_pair("test.pub", "test.prv", "",
                          &info->public_key,
                          &info->private_key)) {
-    if (!silc_create_key_pair("rsa", 2048, "test.pub", "test.prv", NULL, "",
+    if (!silc_create_key_pair("rsa", 4096, "test.pub", "test.prv", NULL, "",
                              &info->public_key,
                              &info->private_key, FALSE)) {
       goto err;
index dd6e68735ef95ee12737eb02ac1473359d6b01bf..f6333e8f0c0bc8717d729d6aa53cd8311b90cc00 100644 (file)
 
 /* Fixed and public Diffie Hellman Groups defined by the SKE
    protocol. These are equivalent to the OAKLEY Key Determination
-   protocol groups (taken from RFC 2412). */
+   protocol groups. */
 const struct SilcSKEDiffieHellmanGroupDefStruct silc_ske_groups[] =
 {
-  /* 1024 bits modulus (Mandatory group) */
-  { 1, "diffie-hellman-group1",
+  /* 1536 bits modulus (Optional group) (RFC 3526). */
+  { 2, "diffie-hellman-group2",
 
     "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
     "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
     "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
     "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
-    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
-    "FFFFFFFFFFFFFFFF",
+    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
+    "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
+    "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
+    "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF",
 
     "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68"
     "948127044533E63A0105DF531D89CD9128A5043CC71A026E"
     "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122"
     "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6"
-    "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0"
-    "FFFFFFFFFFFFFFFF",
+    "F71C35FDAD44CFD2D74F9208BE258FF324943328F6722D9E"
+    "E1003E5C50B1DF82CC6D241B0E2AE9CD348B1FD47E9267AF"
+    "C1B2AE91EE51D6CB0E3179AB1042A95DCF6A9483B84B4B36"
+    "B3861AA7255E4C0278BA36046511B993FFFFFFFFFFFFFFFF",
     "2" },
 
-  /* 1536 bits modulus (Optional group) */
-  { 2, "diffie-hellman-group2",
+  /* 1024 bits modulus (Mandatory group) (RFC 2412). */
+  { 1, "diffie-hellman-group1",
 
     "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
     "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
     "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
     "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
-    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
-    "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
-    "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
-    "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF",
+    "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
+    "FFFFFFFFFFFFFFFF",
 
     "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68"
     "948127044533E63A0105DF531D89CD9128A5043CC71A026E"
     "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122"
     "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6"
-    "F71C35FDAD44CFD2D74F9208BE258FF324943328F6722D9E"
-    "E1003E5C50B1DF82CC6D241B0E2AE9CD348B1FD47E9267AF"
-    "C1B2AE91EE51D6CB0E3179AB1042A95DCF6A9483B84B4B36"
-    "B3861AA7255E4C0278BA36046511B993FFFFFFFFFFFFFFFF",
+    "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0"
+    "FFFFFFFFFFFFFFFF",
     "2" },
 
   { 0, NULL, NULL, NULL }
index 43a68438af5c5d8b1072e097adddf90ad54bb775..36d36ac8d5e395c80b3a2fa8b54b23793ba8063b 100644 (file)
@@ -1457,7 +1457,7 @@ SILC_FSM_STATE(silc_ske_st_initiator_phase2)
 
   /* Compute signature data if we are doing mutual authentication */
   if (ske->private_key && ske->prop->flags & SILC_SKE_SP_FLAG_MUTUAL) {
-    unsigned char hash[SILC_HASH_MAXLEN], sign[2048 + 1];
+    unsigned char hash[SILC_HASH_MAXLEN], sign[65536 + 1];
     SilcUInt32 hash_len, sign_len;
 
     SILC_LOG_DEBUG(("We are doing mutual authentication"));
@@ -2294,7 +2294,7 @@ SILC_FSM_STATE(silc_ske_st_responder_phase5)
   SilcSKE ske = fsm_context;
   SilcSKEStatus status;
   SilcBuffer payload_buf;
-  unsigned char hash[SILC_HASH_MAXLEN], sign[2048 + 1], *pk;
+  unsigned char hash[SILC_HASH_MAXLEN], sign[65536 + 1], *pk;
   SilcUInt32 hash_len, sign_len, pk_len;
 
   SILC_LOG_DEBUG(("Start"));