mirror of
https://github.com/coturn/coturn.git
synced 2025-10-25 21:11:00 +02:00
Avoid writing potentially uninitialized data to aes_128 key file (#1500)
This commit is contained in:
parent
17926fe70b
commit
a32d1a2704
@ -1740,32 +1740,40 @@ void encrypt_aes_128(unsigned char *in, const unsigned char *mykey) {
|
|||||||
unsigned char *base64_encoded = base64encode(total, totalSize);
|
unsigned char *base64_encoded = base64encode(total, totalSize);
|
||||||
printf("%s\n", base64_encoded);
|
printf("%s\n", base64_encoded);
|
||||||
}
|
}
|
||||||
void generate_aes_128_key(char *filePath, unsigned char *returnedKey) {
|
static void generate_aes_128_key(char *filePath, unsigned char *returnedKey) {
|
||||||
int i;
|
|
||||||
int part;
|
|
||||||
FILE *fptr;
|
|
||||||
char key[16];
|
char key[16];
|
||||||
|
|
||||||
|
// TODO: Document why this is called...?
|
||||||
turn_srandom();
|
turn_srandom();
|
||||||
|
|
||||||
for (i = 0; i < 16; i++) {
|
for (size_t i = 0; i < 16; ++i) {
|
||||||
part = (rand() % 3);
|
// TODO: This could be sped up by breaking the
|
||||||
if (part == 0) {
|
// returned random value into multiple 8bit values
|
||||||
|
// instead of getting a new multi-byte random value
|
||||||
|
// for each key index.
|
||||||
|
switch (turn_random() % 3) {
|
||||||
|
case 0:
|
||||||
key[i] = (turn_random() % 10) + 48;
|
key[i] = (turn_random() % 10) + 48;
|
||||||
}
|
continue;
|
||||||
|
case 1:
|
||||||
else if (part == 1) {
|
|
||||||
key[i] = (turn_random() % 26) + 65;
|
key[i] = (turn_random() % 26) + 65;
|
||||||
}
|
continue;
|
||||||
|
default:
|
||||||
else if (part == 2) {
|
|
||||||
key[i] = (turn_random() % 26) + 97;
|
key[i] = (turn_random() % 26) + 97;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fptr = fopen(filePath, "w");
|
FILE *fptr = fopen(filePath, "w");
|
||||||
for (i = 0; i < 16; i++) {
|
if (!fptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < 16; ++i) {
|
||||||
fputc(key[i], fptr);
|
fputc(key[i], fptr);
|
||||||
}
|
}
|
||||||
STRCPY((char *)returnedKey, key);
|
memcpy(returnedKey, key, 16);
|
||||||
|
// Note: Don't put a nul-terminator at the end.
|
||||||
|
// this function is only ever called with returnedKey
|
||||||
|
// as fixed size char arrays of size 16.
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -393,7 +393,6 @@ struct ctr_state {
|
|||||||
unsigned int num;
|
unsigned int num;
|
||||||
unsigned char ecount[16];
|
unsigned char ecount[16];
|
||||||
};
|
};
|
||||||
void generate_aes_128_key(char *filePath, unsigned char *returnedKey);
|
|
||||||
unsigned char *base64encode(const void *b64_encode_this, int encode_this_many_bytes);
|
unsigned char *base64encode(const void *b64_encode_this, int encode_this_many_bytes);
|
||||||
void encrypt_aes_128(unsigned char *in, const unsigned char *mykey);
|
void encrypt_aes_128(unsigned char *in, const unsigned char *mykey);
|
||||||
unsigned char *base64decode(const void *b64_decode_this, int decode_this_many_bytes);
|
unsigned char *base64decode(const void *b64_decode_this, int decode_this_many_bytes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user