Clean up UUID-handling to prepare for future
This commit is contained in:
parent
5369950c1d
commit
3f58a9b762
7 changed files with 55 additions and 31 deletions
|
@ -65,6 +65,32 @@ function initialize({ events, storage, navigator, logger }) {
|
|||
// Keeping this entrypoint around so more inialize() calls just kick the timing
|
||||
scheduleNext = scheduleNextRotation;
|
||||
|
||||
async function saveCert({ certificate, key }) {
|
||||
const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate);
|
||||
const decodedContainer = textsecure.protobuf.SenderCertificate.decode(
|
||||
arrayBuffer
|
||||
);
|
||||
const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode(
|
||||
decodedContainer.certificate
|
||||
);
|
||||
|
||||
// We don't want to send a protobuf-generated object across IPC, so we make
|
||||
// our own object.
|
||||
const toSave = {
|
||||
expires: decodedCert.expires.toNumber(),
|
||||
serialized: arrayBuffer,
|
||||
};
|
||||
await storage.put(key, toSave);
|
||||
}
|
||||
|
||||
async function removeOldKey() {
|
||||
const oldCertKey = 'senderCertificateWithUuid';
|
||||
const oldUuidCert = storage.get(oldCertKey);
|
||||
if (oldUuidCert) {
|
||||
await storage.remove(oldCertKey);
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
logger.info('refreshSenderCertificate: Getting new certificate...');
|
||||
try {
|
||||
|
@ -76,29 +102,23 @@ function initialize({ events, storage, navigator, logger }) {
|
|||
password: PASSWORD,
|
||||
});
|
||||
|
||||
const { certificate } = await server.getSenderCertificate();
|
||||
const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate);
|
||||
const decodedContainer = textsecure.protobuf.SenderCertificate.decode(
|
||||
arrayBuffer
|
||||
);
|
||||
const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode(
|
||||
decodedContainer.certificate
|
||||
);
|
||||
const omitE164 = true;
|
||||
const [
|
||||
{ certificate },
|
||||
{ certificate: certificateWithNoE164 },
|
||||
] = await Promise.all([
|
||||
server.getSenderCertificate(),
|
||||
server.getSenderCertificate(omitE164),
|
||||
]);
|
||||
|
||||
// We don't want to send a protobuf-generated object across IPC, so we make
|
||||
// our own object.
|
||||
const toSave = {
|
||||
expires: decodedCert.expires.toNumber(),
|
||||
serialized: arrayBuffer,
|
||||
};
|
||||
|
||||
storage.put('senderCertificate', toSave);
|
||||
|
||||
const oldCertKey = 'senderCertificateWithUuid';
|
||||
const oldUuidCert = storage.get(oldCertKey);
|
||||
if (oldUuidCert) {
|
||||
await storage.remove(oldCertKey);
|
||||
}
|
||||
await Promise.all([
|
||||
saveCert({ certificate, key: 'senderCertificate' }),
|
||||
saveCert({
|
||||
certificate: certificateWithNoE164,
|
||||
key: 'senderCertificateNoE164',
|
||||
}),
|
||||
removeOldKey(),
|
||||
]);
|
||||
|
||||
scheduledTime = null;
|
||||
scheduleNextRotation();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue