Mercurial > trustbridge
comparison common/listutil.c @ 1395:a2574a029322
Fix Base 64 signature size calculation.
If the signature byte size is not equally dividable
by three the base 64 encoding needs three additional bytes.
The value is now fixed to avoid such errors in the future.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 26 Jan 2015 13:17:32 +0100 |
parents | 8d27c6d226cd |
children |
comparison
equal
deleted
inserted
replaced
1394:8d27c6d226cd | 1395:a2574a029322 |
---|---|
123 | 123 |
124 /* Modulus / 8 are the necessary bytes. */ | 124 /* Modulus / 8 are the necessary bytes. */ |
125 #ifndef TRUSTBRIDGE_RSA_KEY_SIZE | 125 #ifndef TRUSTBRIDGE_RSA_KEY_SIZE |
126 # error "Key size undefined" | 126 # error "Key size undefined" |
127 #endif | 127 #endif |
128 const size_t sig_b64_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8 * 4 / 3; | 128 const size_t sig_b64_size = TRUSTBRIDGE_RSA_B64_SIZE; |
129 size_t sig_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8; | 129 size_t sig_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8; |
130 | 130 |
131 char signature_b64[sig_b64_size + 1]; | 131 char signature_b64[sig_b64_size + 1]; |
132 unsigned char signature[sig_size]; | 132 unsigned char signature[sig_size]; |
133 /* Hash algroithm is sha256 */ | 133 /* Hash algroithm is sha256 */ |
142 /* Fetch the signature from the first line od data */ | 142 /* Fetch the signature from the first line od data */ |
143 p = strchr(data, '\r'); | 143 p = strchr(data, '\r'); |
144 if (p == 0 || (unsigned int)(p - (data + 2)) != sig_b64_size) | 144 if (p == 0 || (unsigned int)(p - (data + 2)) != sig_b64_size) |
145 { | 145 { |
146 DEBUGPRINTF("Invalid data. Signature might be too long.\n"); | 146 DEBUGPRINTF("Invalid data. Signature might be too long.\n"); |
147 DEBUGPRINTF("Should: %u is: %u\n", sig_b64_size, (unsigned int)(p - (data + 2))); | 147 DEBUGPRINTF("Should: %u is: %u\n", (unsigned int) sig_b64_size, (unsigned int)(p - (data + 2))); |
148 return -1; | 148 return -1; |
149 } | 149 } |
150 strncpy(signature_b64, data + 2, sig_b64_size); | 150 strncpy(signature_b64, data + 2, sig_b64_size); |
151 signature_b64[sig_b64_size] = '\0'; | 151 signature_b64[sig_b64_size] = '\0'; |
152 | 152 |