Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 61739b4

Browse files
authored
Merge pull request #88 from mikaleppanen/entropy
Added support for entropy poll to randomize source ports.
2 parents 485353b + 42b1085 commit 61739b4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

main.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sstream>
1919
#include <vector>
2020
#include "mbed-trace/mbed_trace.h"
21+
#include "mbedtls/entropy_poll.h"
2122

2223
#include "security.h"
2324

@@ -256,19 +257,29 @@ void blinky() { status_led = !status_led; }
256257
// Entry point to the program
257258
int main() {
258259

259-
#ifndef MBEDTLS_ENTROPY_HARDWARE_ALT
260+
unsigned int seed;
261+
size_t len;
262+
263+
#ifdef MBEDTLS_ENTROPY_HARDWARE_ALT
264+
// Used to randomize source port
265+
mbedtls_hardware_poll(NULL, (unsigned char *) &seed, sizeof seed, &len);
266+
267+
#elif defined MBEDTLS_TEST_NULL_ENTROPY
260268

261-
#ifdef MBEDTLS_TEST_NULL_ENTROPY
262269
#warning "mbedTLS security feature is disabled. Connection will not be secure !! Implement proper hardware entropy for your selected hardware."
270+
// Used to randomize source port
271+
mbedtls_null_entropy_poll( NULL,(unsigned char *) &seed, sizeof seed, &len);
263272

264273
#else
265274

266275
#error "This hardware does not have entropy, endpoint will not register to Connector.\
267276
You need to enable NULL ENTROPY for your application, but if this configuration change is made then no security is offered by mbed TLS.\
268277
Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app.json macros to register your endpoint."
269-
#endif
270278
271279
#endif
280+
281+
srand(seed);
282+
272283
status_ticker.attach_us(blinky, 250000);
273284
274285
// Keep track of the main thread

simpleclient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class MbedClient: public M2MInterfaceObserver {
9191
void *handler=NULL) {
9292
// Randomizing listening port for Certificate mode connectivity
9393
_server_address = server_address;
94-
srand(time(NULL));
9594
uint16_t port = rand() % 65535 + 12345;
9695

9796
// create mDS interface object, this is the base object everything else attaches to

0 commit comments

Comments
 (0)