aws: replaced mbedtls with our flb_crypto
#include <fluent-bit/flb_http_client.h>
#include <fluent-bit/flb_aws_credentials.h>
#include <fluent-bit/flb_aws_util.h>
+#include <fluent-bit/flb_random.h>
#include <fluent-bit/flb_jsmn.h>
-#include <mbedtls/ctr_drbg.h>
-#include "mbedtls/entropy.h"
#include <stdlib.h>
#include <time.h>
#include <string.h>
@@ -653,67 +652,32 @@ error:
/* Generates string which can serve as a unique session name */
char *flb_sts_session_name() {
- mbedtls_ctr_drbg_context ctr_drbg;
- mbedtls_entropy_context entropy;
- char *personalization = NULL;
- time_t now;
- unsigned char *random_data = NULL;
+ unsigned char *random_data[SESSION_NAME_RANDOM_BYTE_LEN];
char *session_name = NULL;
int ret;
- personalization = flb_malloc(sizeof(char) * 27);
- if (!personalization) {
- goto error;
- }
-
- now = time(NULL);
- ctime_r(&now, personalization);
+ #pragma message ("MBEDTLS REPLACEMENT : FILL THE GAP (generate unique session name)")
- mbedtls_entropy_init(&entropy);
- mbedtls_ctr_drbg_init(&ctr_drbg);
+ ret = flb_random_bytes(random_data, SESSION_NAME_RANDOM_BYTE_LEN);
- ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
- (const unsigned char *) personalization,
- strlen(personalization));
if (ret != 0) {
- goto error;
- }
-
- random_data = flb_malloc(sizeof(unsigned char) *
- SESSION_NAME_RANDOM_BYTE_LEN);
- if (!random_data) {
- goto error;
- }
+ flb_errno();
- ret = mbedtls_ctr_drbg_random(&ctr_drbg, random_data,
- SESSION_NAME_RANDOM_BYTE_LEN);
- if (ret != 0) {
- goto error;
+ return NULL;
}
session_name = flb_malloc(sizeof(char) *
(SESSION_NAME_RANDOM_BYTE_LEN + 1));
if (!session_name) {
- goto error;
+ flb_errno();
+
+ return NULL;
}
bytes_to_string(random_data, session_name, SESSION_NAME_RANDOM_BYTE_LEN);
session_name[SESSION_NAME_RANDOM_BYTE_LEN] = '\0';
- flb_free(random_data);
- flb_free(personalization);
-
return session_name;
-
-error:
- flb_errno();
- if (personalization) {
- flb_free(personalization);
- }
- if (random_data) {
- flb_free(random_data);
- }
- return NULL;
}
/* converts random bytes to a string we can safely put in a URL */
