diff common/listutil.c @ 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 698b6a9bd75e
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);

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