mirror of
https://github.com/ARMmbed/mbedtls.git
synced 2025-06-26 23:14:07 +08:00
Remove the generic file read functions and simply the early data read
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
This commit is contained in:
parent
eaebedb30b
commit
f8fe11d14d
@ -718,47 +718,6 @@ exit:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
|
||||||
|
|
||||||
#define MBEDTLS_ERR_FILE_IO_ERROR -2
|
|
||||||
|
|
||||||
static int ssl_read_file_text(const char *path,
|
|
||||||
unsigned char **buffer, size_t *length)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
long size;
|
|
||||||
|
|
||||||
if ((f = fopen(path, "rb")) == NULL) {
|
|
||||||
return MBEDTLS_ERR_FILE_IO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
if ((size = ftell(f)) == -1) {
|
|
||||||
fclose(f);
|
|
||||||
return MBEDTLS_ERR_FILE_IO_ERROR;
|
|
||||||
}
|
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
|
|
||||||
*length = (size_t) size;
|
|
||||||
if (*length + 1 == 0 ||
|
|
||||||
(*buffer = mbedtls_calloc(1, *length + 1)) == NULL) {
|
|
||||||
fclose(f);
|
|
||||||
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fread(*buffer, 1, *length, f) != *length) {
|
|
||||||
fclose(f);
|
|
||||||
return MBEDTLS_ERR_FILE_IO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
(*buffer)[*length] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
||||||
@ -784,10 +743,6 @@ int main(int argc, char *argv[])
|
|||||||
size_t cid_renego_len = 0;
|
size_t cid_renego_len = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
|
||||||
unsigned char *early_data = NULL;
|
|
||||||
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ALPN)
|
#if defined(MBEDTLS_SSL_ALPN)
|
||||||
const char *alpn_list[ALPN_LIST_SIZE];
|
const char *alpn_list[ALPN_LIST_SIZE];
|
||||||
#endif
|
#endif
|
||||||
@ -2011,11 +1966,18 @@ usage:
|
|||||||
|
|
||||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
||||||
int early_data_enabled = MBEDTLS_SSL_EARLY_DATA_DISABLED;
|
int early_data_enabled = MBEDTLS_SSL_EARLY_DATA_DISABLED;
|
||||||
size_t early_data_len;
|
FILE *early_data_fp = NULL;
|
||||||
if (strlen(opt.early_data_file) > 0 &&
|
size_t early_data_len = 0;
|
||||||
ssl_read_file_text(opt.early_data_file,
|
if (strlen(opt.early_data_file) > 0) {
|
||||||
&early_data, &early_data_len) == 0) {
|
if ((early_data_fp = fopen(opt.early_data_file, "rb")) == NULL) {
|
||||||
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
|
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
|
||||||
|
opt.early_data_file);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
early_data_len = fread(buf, 1, sizeof(buf), early_data_fp);
|
||||||
|
if (early_data_len > 0) {
|
||||||
|
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mbedtls_ssl_conf_early_data(&conf, early_data_enabled);
|
mbedtls_ssl_conf_early_data(&conf, early_data_enabled);
|
||||||
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
||||||
@ -3076,10 +3038,9 @@ exit:
|
|||||||
mbedtls_ssl_session_free(&saved_session);
|
mbedtls_ssl_session_free(&saved_session);
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
||||||
if (early_data != NULL) {
|
if (early_data_fp != NULL) {
|
||||||
mbedtls_platform_zeroize(early_data, early_data_len);
|
fclose(early_data_fp);
|
||||||
}
|
}
|
||||||
mbedtls_free(early_data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (session_data != NULL) {
|
if (session_data != NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user