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() { ...@@ -42,6 +42,10 @@ String.prototype.hexstrdump = function() {
}; };
Date.prototype.utc = function(){ Date.prototype.utc = function(){
return new Date();
};
Date.prototype.utcZero = function(){
return new Date(this.getTime() + this.getTimezoneOffset()*60*1000); return new Date(this.getTime() + this.getTimezoneOffset()*60*1000);
}; };
......
...@@ -28,10 +28,11 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -28,10 +28,11 @@ function KeyService (conn, conf, PublicKeyService) {
var Key = conn.model('Key'); var Key = conn.model('Key');
var MINIMUM_ZERO_START = 1; 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 LINK_QUANTITY_MIN = 1;
var MAX_STEPS = 1; var MAX_STEPS = 1;
var MAX_LINK_VALIDITY = 3600*24*30; // 30 days var MAX_LINK_VALIDITY = 3600*24*30; // 30 days
var MAX_TIMESTAMP_DELAY = 30; // in seconds
this.load = function (done) { this.load = function (done) {
done(); done();
...@@ -103,6 +104,7 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -103,6 +104,7 @@ function KeyService (conn, conf, PublicKeyService) {
} }
this.submitKeyBlock = function (kb, done) { this.submitKeyBlock = function (kb, done) {
var now = new Date();
var block = new KeyBlock(kb); var block = new KeyBlock(kb);
block.issuer = kb.pubkey.fingerprint; block.issuer = kb.pubkey.fingerprint;
var currentBlock = null; var currentBlock = null;
...@@ -134,6 +136,11 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -134,6 +136,11 @@ function KeyService (conn, conf, PublicKeyService) {
next('PreviousIssuer does not target current block'); next('PreviousIssuer does not target current block');
return; 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 // Check the challenge depending on issuer
checkProofOfWork(block, next); checkProofOfWork(block, next);
}, },
...@@ -1342,7 +1349,7 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -1342,7 +1349,7 @@ function KeyService (conn, conf, PublicKeyService) {
async.whilst( async.whilst(
function(){ return !pow.match(powRegexp); }, function(){ return !pow.match(powRegexp); },
function (next) { function (next) {
var newTS = new Date().timestamp(); var newTS = new Date().utcZero().timestamp();
if (newTS == block.timestamp) { if (newTS == block.timestamp) {
block.nonce++; block.nonce++;
} else { } 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