OTP door lock

luca 14/09/2013 12

Today I’m going to show you how to make an Arduino door lock that can be opened with an OTP code generated by your smartphone.

Video

First, a short video about the project (english subtitles are available):

OTP

OTP (one-time password) is an access code you can use only one time: its main advantage is that – even if someone steals your code when you use it – it doesn’t work anymore.

Usually OTP codes also have a temporal validity, i.e. they can be used for a short period (tipically 30 seconds); those codes are called TOTP (time-based one-time password). OTP codes are widely used for secure access to home-banking websites, remote connections (VPN)…

In the past, the TOTP codes were usually generated by hardware tokens

but recently software tokens, that are smartphones applications, are becoming common:

OATH and Google Authenticator

Open Authentication (OATH) is an industry-wide collaboration to define open standards for strong authentication mechanisms. One of those standards (RFC 6238) defines an algorithm to generate TOTP codes.

The algorithm starts with a secret key (shared secret) and the actual timestamp (the number of seconds from the date 01/01/1970). With the use of an hash function (HMAC-SHA-1) on the key-timestamp pair and a truncate function on the result, you get a code of 6 numbers:

The algorithm requires therefore that the token (which generates the codes) and the server (which validates them)

  • share the same secret key
  • are in sync

Google Authenticator is an opensource application you can use to obtain TOTP codes that are compliant to the algorithm described by the RFC.

It’s available for Android, iOS and Blackberry smartphones:

Google Authenticator genrates OTP codes with a validity of 30 seconds and requires a private key of 10 characters.

In the next page, I’m going to show you how to generate and validate TOTP codes with Arduino…

Pages: 1 2

12 Comments »

  1. Ivan 19/09/2013 at 12:25 - Reply

    # 1!!!!

  2. Burke 01/11/2013 at 21:08 - Reply

    Great article.

  3. customdev 05/03/2014 at 23:13 - Reply

    I have the sketch up and running. Everything compiles and uploads beautifully.

    However I am having synchronization problems. Which time zone are we to use? I cannot tell rather my phone simply uses the GMT as its system clock or rather it is GMT adjusted with an offset for my time zone.

    I have tried using both GMT and GMT adjusted for my time zone with less than 5 seconds of difference between the Arduino’s time and the phone’s time. Either way the codes generated never match up.

    • luca 15/03/2014 at 10:46 - Reply

      Hi! Google Authenticator uses GMT even if your phone displays time in your timezone, so you have to configure arduino with the same timezone.

  4. Chrisitan 15/05/2014 at 12:12 - Reply

    Ottimo articolo fa venir voglia di utilizzare questa serratura….

  5. customdev 26/11/2014 at 06:03 - Reply

    hi,i have configured arduino with the same timezone as GMT,but the codes generated never match up

    • luca 26/11/2014 at 11:06 - Reply

      Hi! make sure you’re using the same shared secret, it must work

  6. Nonnino 05/12/2014 at 16:57 - Reply

    Salve!!! Grazie per la condivisione del progetto.
    Volevo chiederLe cosa si intende per:
    “Choose an account name:”, presente nel sito http://www.lucadentella.it/OTP/. Si intende un nome fittizio?
    Alle righe 64 e 65 dello sketch è presente una specifica data e ora, mi chiedevo se andava cambiata. Come avrà capito il mio problema è la mancata sincronizzazione dei due codici OTP. Potrebbe spiegarmi come impostare la sincronizzazione dei codici?

    • luca 06/12/2014 at 11:54 - Reply

      ciao! il nome è fittizio ed è quello che poi comparirà nella app sul cellulare. Nell’esempio va inserito “a mano” l’orario corrente appunto alle righe 64-65 dello sketch, altrimenti si potrebbe leggere l’orario da un RTC…

      • Nonnino 08/12/2014 at 19:18 - Reply

        Grazie mille per la risposta, modificherò le righe dello sketch. Se non ho capito male, la data e l’ora, da impostare alle righe 64-65 è la stessa di quando viene premuto il pulsante “GO” e viene generata la chiave nel sito http://www.lucadentella.it/OTP/. Giusto?? :-) Grazie di nuovo!!!

        • luca 13/12/2014 at 17:31 - Reply

          in realtà data/ora devono essere quelle attuali di quando si compila e carica lo sketch su Arduino

Leave A Response »