From 4381778397d711d5ba7e6d8f024e726a60419208 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 24 Aug 2014 17:40:30 +0200 Subject: [PATCH] Added UTC+0 timestamp constraint for new keyblocks --- app/lib/common.js | 4 ++++ app/service/KeychainService.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/lib/common.js b/app/lib/common.js index 42b47767..0442a60d 100644 --- a/app/lib/common.js +++ b/app/lib/common.js @@ -42,6 +42,10 @@ String.prototype.hexstrdump = function() { }; Date.prototype.utc = function(){ + return new Date(); +}; + +Date.prototype.utcZero = function(){ return new Date(this.getTime() + this.getTimezoneOffset()*60*1000); }; diff --git a/app/service/KeychainService.js b/app/service/KeychainService.js index 9b0d4f9b..76f6fef0 100644 --- a/app/service/KeychainService.js +++ b/app/service/KeychainService.js @@ -28,10 +28,11 @@ function KeyService (conn, conf, PublicKeyService) { var Key = conn.model('Key'); var MINIMUM_ZERO_START = 1; - var PROOF_OF_WORK_PERIOD = 1 // Value 1 allows for continuous single-member writing with minimum difficulty + var PROOF_OF_WORK_PERIOD = 1; // Value 1 allows for continuous single-member writing with minimum difficulty var LINK_QUANTITY_MIN = 1; var MAX_STEPS = 1; var MAX_LINK_VALIDITY = 3600*24*30; // 30 days + var MAX_TIMESTAMP_DELAY = 30; // in seconds this.load = function (done) { done(); @@ -103,6 +104,7 @@ function KeyService (conn, conf, PublicKeyService) { } this.submitKeyBlock = function (kb, done) { + var now = new Date(); var block = new KeyBlock(kb); block.issuer = kb.pubkey.fingerprint; var currentBlock = null; @@ -134,6 +136,11 @@ function KeyService (conn, conf, PublicKeyService) { next('PreviousIssuer does not target current block'); return; } + // Test timestamp + if (Math.abs(block.timestamp - now.utcZero().timestamp()) > MAX_TIMESTAMP_DELAY) { + next('Timestamp does not match this node\'s time'); + return; + } // Check the challenge depending on issuer checkProofOfWork(block, next); }, @@ -1342,7 +1349,7 @@ function KeyService (conn, conf, PublicKeyService) { async.whilst( function(){ return !pow.match(powRegexp); }, function (next) { - var newTS = new Date().timestamp(); + var newTS = new Date().utcZero().timestamp(); if (newTS == block.timestamp) { block.nonce++; } else { -- 2.22.0