Retry failed signed key rotation; start rotation when registered (#1772)

This commit is contained in:
Scott Nonnenberg 2017-11-16 16:19:24 -08:00 committed by GitHub
parent 81565b1ac6
commit fd5fa666f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 26 deletions

View file

@ -99,19 +99,20 @@
console.log('listening for registration events'); console.log('listening for registration events');
Whisper.events.on('registration_done', function() { Whisper.events.on('registration_done', function() {
console.log('handling registration event'); console.log('handling registration event');
Whisper.RotateSignedPreKeyListener.init(Whisper.events);
connect(true); connect(true);
}); });
var appView = window.owsDesktopApp.appView = new Whisper.AppView({el: $('body')}); var appView = window.owsDesktopApp.appView = new Whisper.AppView({el: $('body')});
Whisper.WallClockListener.init(Whisper.events); Whisper.WallClockListener.init(Whisper.events);
Whisper.RotateSignedPreKeyListener.init(Whisper.events);
Whisper.ExpiringMessagesListener.init(Whisper.events); Whisper.ExpiringMessagesListener.init(Whisper.events);
if (Whisper.Import.isIncomplete()) { if (Whisper.Import.isIncomplete()) {
console.log('Import was interrupted, showing import error screen'); console.log('Import was interrupted, showing import error screen');
appView.openImporter(); appView.openImporter();
} else if (Whisper.Registration.everDone()) { } else if (Whisper.Registration.everDone()) {
Whisper.RotateSignedPreKeyListener.init(Whisper.events);
connect(); connect();
appView.openInbox({ appView.openInbox({
initialLoadComplete: initialLoadComplete initialLoadComplete: initialLoadComplete

View file

@ -37995,19 +37995,26 @@ var TextSecureServer = (function() {
keyId : res.keyId, keyId : res.keyId,
publicKey : res.keyPair.pubKey, publicKey : res.keyPair.pubKey,
signature : res.signature signature : res.signature
}).then(function() {
textsecure.storage.put('signedKeyId', signedKeyId + 1);
textsecure.storage.remove('signedKeyRotationRejected');
return store.storeSignedPreKey(res.keyId, res.keyPair).then(function() {
return cleanSignedPreKeys();
});
}).catch(function(e) {
if (e instanceof Error && e.name == 'HTTPError' && e.code >= 400 && e.code <= 599) {
var rejections = 1 + textsecure.storage.get('signedKeyRotationRejected', 0);
textsecure.storage.put('signedKeyRotationRejected', rejections);
console.log('Signed key rotation rejected count:', rejections);
}
}); });
}).then(function() {
textsecure.storage.put('signedKeyId', signedKeyId + 1);
textsecure.storage.remove('signedKeyRotationRejected');
return store.storeSignedPreKey(res.keyId, res.keyPair).then(function() {
return cleanSignedPreKeys();
});
}).catch(function(e) {
console.log(
'rotateSignedPrekey error:',
e && e.stack ? e.stack : e
);
if (e instanceof Error && e.name == 'HTTPError' && e.code >= 400 && e.code <= 599) {
var rejections = 1 + textsecure.storage.get('signedKeyRotationRejected', 0);
textsecure.storage.put('signedKeyRotationRejected', rejections);
console.log('Signed key rotation rejected count:', rejections);
}
throw e;
}); });
}.bind(this)); }.bind(this));
}, },

View file

@ -17,7 +17,10 @@
function run() { function run() {
console.log('Rotating signed prekey...'); console.log('Rotating signed prekey...');
getAccountManager().rotateSignedPreKey(); getAccountManager().rotateSignedPreKey().catch(function() {
console.log('rotateSignedPrekey() failed. Trying again in five seconds');
setTimeout(runWhenOnline, 5000);
});
scheduleNextRotation(); scheduleNextRotation();
setTimeoutForNextRun(); setTimeoutForNextRun();
} }
@ -26,6 +29,7 @@
if (navigator.onLine) { if (navigator.onLine) {
run(); run();
} else { } else {
console.log('We are offline; keys will be rotated when we are next online');
var listener = function() { var listener = function() {
window.removeEventListener('online', listener); window.removeEventListener('online', listener);
run(); run();
@ -52,8 +56,15 @@
timeout = setTimeout(runWhenOnline, waitTime); timeout = setTimeout(runWhenOnline, waitTime);
} }
var initComplete;
Whisper.RotateSignedPreKeyListener = { Whisper.RotateSignedPreKeyListener = {
init: function(events) { init: function(events) {
if (initComplete) {
console.log('Rotate signed prekey listener: Already initialized');
return;
}
initComplete = true;
if (Whisper.Registration.isDone()) { if (Whisper.Registration.isDone()) {
setTimeoutForNextRun(); setTimeoutForNextRun();
} }

View file

@ -132,19 +132,26 @@
keyId : res.keyId, keyId : res.keyId,
publicKey : res.keyPair.pubKey, publicKey : res.keyPair.pubKey,
signature : res.signature signature : res.signature
}).then(function() {
textsecure.storage.put('signedKeyId', signedKeyId + 1);
textsecure.storage.remove('signedKeyRotationRejected');
return store.storeSignedPreKey(res.keyId, res.keyPair).then(function() {
return cleanSignedPreKeys();
});
}).catch(function(e) {
if (e instanceof Error && e.name == 'HTTPError' && e.code >= 400 && e.code <= 599) {
var rejections = 1 + textsecure.storage.get('signedKeyRotationRejected', 0);
textsecure.storage.put('signedKeyRotationRejected', rejections);
console.log('Signed key rotation rejected count:', rejections);
}
}); });
}).then(function() {
textsecure.storage.put('signedKeyId', signedKeyId + 1);
textsecure.storage.remove('signedKeyRotationRejected');
return store.storeSignedPreKey(res.keyId, res.keyPair).then(function() {
return cleanSignedPreKeys();
});
}).catch(function(e) {
console.log(
'rotateSignedPrekey error:',
e && e.stack ? e.stack : e
);
if (e instanceof Error && e.name == 'HTTPError' && e.code >= 400 && e.code <= 599) {
var rejections = 1 + textsecure.storage.get('signedKeyRotationRejected', 0);
textsecure.storage.put('signedKeyRotationRejected', rejections);
console.log('Signed key rotation rejected count:', rejections);
}
throw e;
}); });
}.bind(this)); }.bind(this));
}, },