changeset 770:7861950f7637

Make RSA Keysize definiable
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 10 Jul 2014 19:14:22 +0200
parents 44257ecdae6d
children 2798f1869eee
files common/listutil.c common/pubkey-release.h common/pubkey-test.h
diffstat 3 files changed, 15 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/common/listutil.c	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/listutil.c	Thu Jul 10 19:14:22 2014 +0200
@@ -98,9 +98,13 @@
     int ret = -1;
     pk_context pub_key_ctx;
     char *p;
-    /* Fixed key size of 3072 implies the sizes*/
-    const size_t sig_b64_size = 512;
-    size_t sig_size = 384;
+
+    /* Modulus / 8 are the necessary bytes. */
+#ifndef TRUSTBRIDGE_RSA_KEY_SIZE
+# error "Key size undefined"
+#endif
+    const size_t sig_b64_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8 * 4 / 3;
+    size_t sig_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8;
 
     char signature_b64[sig_b64_size + 1];
     unsigned char signature[sig_size];
@@ -123,7 +127,7 @@
     ret = base64_decode(signature, &sig_size,
                         (unsigned char *)signature_b64, sig_b64_size);
 
-    if (ret != 0 || sig_size != 384) {
+    if (ret != 0 || sig_size != TRUSTBRIDGE_RSA_KEY_SIZE / 8) {
 /*        printf("failed to decode signature\n"); */
         return -1;
     }
@@ -137,23 +141,6 @@
     sha256((unsigned char *)p, size - sig_b64_size - 4, hash, 0);
 
     pk_init(&pub_key_ctx);
-#if 0
-    {
-        int i;
-        FILE *foo = fopen("/tmp/testdump", "w");
-        FILE *foo2 = fopen("/tmp/rawdump", "w");
-        for (i=0; i< (int)(size - sig_b64_size - 2); i++)
-            fprintf (foo, "%c", p[i]);
-        for (i=0; i< (int)(size); i++)
-            fprintf (foo2, "%c", data[i]);
-        fclose(foo);
-        printf ("Hash: \n");
-        for (i=0; i<32; i++) {
-            printf ("%x", hash[i]);
-        }
-        printf("\n");
-    }
-#endif
 
     ret = pk_parse_public_key(&pub_key_ctx, public_key_pem,
                               public_key_pem_size);
--- a/common/pubkey-release.h	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/pubkey-release.h	Thu Jul 10 19:14:22 2014 +0200
@@ -7,6 +7,10 @@
  */
 #ifndef PUBKEY_RELEASE_H
 #define PUBKEY_RELEASE_H
+
+/**@def The size of the RSA modulus */
+#define TRUSTBRIDGE_RSA_KEY_SIZE 3072
+
 static const unsigned char public_key_pem[] =
 "-----BEGIN PUBLIC KEY-----\n"
 "MIIDIjANBgkqhkiG9w0BAQEFAAOCAw8AMIIDCgKCAYEArUZK1sMV8cWeP48nExEh\n"
--- a/common/pubkey-test.h	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/pubkey-test.h	Thu Jul 10 19:14:22 2014 +0200
@@ -8,6 +8,9 @@
 #ifndef PUBKEY_TEST_H
 #define PUBKEY_TEST_H
 
+/**@def The size of the RSA modulus */
+#define TRUSTBRIDGE_RSA_KEY_SIZE 3072
+
 /* PEM encoded public key */
 static const unsigned char public_key_pem[] =
 "-----BEGIN PUBLIC KEY-----\n"

http://wald.intevation.org/projects/trustbridge/