Get timestamps in milliseconds.

Avoid NS overflow

Change-Id: I666416784503ff6268668590366228b440e88570
diff --git a/gatekeeper.cpp b/gatekeeper.cpp
index 9f81163..77e14e2 100644
--- a/gatekeeper.cpp
+++ b/gatekeeper.cpp
@@ -16,6 +16,8 @@
 #include <UniquePtr.h>
 #include <gatekeeper/gatekeeper.h>
 
+#include <endian.h>
+
 namespace gatekeeper {
 
 void GateKeeper::Enroll(const EnrollRequest &request, EnrollResponse *response) {
@@ -81,7 +83,7 @@
     secure_id_t user_id = password_handle->user_id;
     secure_id_t authenticator_id = password_handle->authenticator_id;
 
-    uint64_t timestamp = GetNanosecondsSinceBoot() / 1000 / 1000;
+    uint64_t timestamp = GetMillisecondsSinceBoot();
 
     if (DoVerify(password_handle, request.provided_password)) {
         // Signature matches
@@ -151,7 +153,7 @@
     token->user_id = user_id;
     token->authenticator_id = authenticator_id;
     token->authenticator_type = htonl(HW_AUTH_PASSWORD);
-    token->timestamp = htonl(timestamp);
+    token->timestamp = htobe64(timestamp);
 
     const uint8_t *auth_token_key = NULL;
     uint32_t key_len = 0;
diff --git a/include/gatekeeper/gatekeeper.h b/include/gatekeeper/gatekeeper.h
index 1cd302f..4a5edc0 100644
--- a/include/gatekeeper/gatekeeper.h
+++ b/include/gatekeeper/gatekeeper.h
@@ -102,11 +102,11 @@
             const uint32_t length) const = 0;
 
     /**
-     * Get the time since boot in nanoseconds.
+     * Get the time since boot in milliseconds.
      *
      * Should return 0 on error.
      */
-    virtual uint64_t GetNanosecondsSinceBoot() const = 0;
+    virtual uint64_t GetMillisecondsSinceBoot() const = 0;
 
 private:
     /**
diff --git a/include/gatekeeper/soft_gatekeeper.h b/include/gatekeeper/soft_gatekeeper.h
index b635d79..d4b4251 100644
--- a/include/gatekeeper/soft_gatekeeper.h
+++ b/include/gatekeeper/soft_gatekeeper.h
@@ -82,11 +82,11 @@
         memset(signature, 0, signature_length);
     }
 
-    virtual uint64_t GetNanosecondsSinceBoot() const {
+    virtual uint64_t GetMillisecondsSinceBoot() const {
         struct timespec time;
-        int res = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
+        int res = clock_gettime(CLOCK_BOOTTIME, &time);
         if (res < 0) return 0;
-        return time.tv_nsec;
+        return (time.tv_sec * 1000) + (time.tv_nsec / 1000 / 1000);
     }
 private:
     UniquePtr<uint8_t> key_;