Commit 43817783 authored by Cédric Moreau's avatar Cédric Moreau

Added UTC+0 timestamp constraint for new keyblocks

parent 63737d0e
......@@ -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);
};
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment