arduino-libraries / NTPClient

Connect to a NTP server
542 stars 372 forks source link

Added method to set random local port #116

Closed luigigubello closed 4 years ago

luigigubello commented 4 years ago

Added method to set a (pseudo)random local port, so that the board needs not to use always the same embedded local port for receiving NTP packets.

At the moment, the variable port is a constant embedded value used by the board for receiving NTP packets via unencrypted UDP connection. Changing randomly port to receive NTP packets doesn't improve cryptographic security and it is not the final solution, but it adds a layer to make harder the attacker's job.

How to use

void setup() {
  ...
}
void loop() {
  timeClient.setRandomPort();
  timeClient.update();
}

How it works

setRandomPort() sets a pseudorandom port and NTPClient::update() launches NTPClient.begin(port) if port is different by default value NTP_DEFAULT_LOCAL_PORT