Store storage key from keys sync message

This commit is contained in:
AsamK 2021-01-18 20:33:04 +01:00
parent 80e15ad54e
commit c3c1802b4d
2 changed files with 40 additions and 0 deletions

View file

@ -114,6 +114,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsInputStream; import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsInputStream;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream; import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo; import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo;
import org.whispersystems.signalservice.api.messages.multidevice.KeysMessage;
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage; import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage; import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
@ -123,6 +124,7 @@ import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException; import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
import org.whispersystems.signalservice.api.storage.StorageKey;
import org.whispersystems.signalservice.api.util.InvalidNumberException; import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter; import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import org.whispersystems.signalservice.api.util.SleepTimer; import org.whispersystems.signalservice.api.util.SleepTimer;
@ -1167,6 +1169,18 @@ public class Manager implements Closeable {
} }
} }
void requestSyncKeys() throws IOException {
SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.KEYS)
.build();
SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
try {
sendSyncMessage(message);
} catch (UntrustedIdentityException e) {
throw new AssertionError(e);
}
}
private byte[] getSenderCertificate() { private byte[] getSenderCertificate() {
// TODO support UUID capable sender certificates // TODO support UUID capable sender certificates
// byte[] certificate = accountManager.getSenderCertificateForPhoneNumberPrivacy(); // byte[] certificate = accountManager.getSenderCertificateForPhoneNumberPrivacy();
@ -2017,6 +2031,13 @@ public class Manager implements Closeable {
// TODO // TODO
} }
} }
if (syncMessage.getKeys().isPresent()) {
final KeysMessage keysMessage = syncMessage.getKeys().get();
if (keysMessage.getStorageService().isPresent()) {
final StorageKey storageKey = keysMessage.getStorageService().get();
account.setStorageKey(storageKey);
}
}
if (syncMessage.getConfiguration().isPresent()) { if (syncMessage.getConfiguration().isPresent()) {
// TODO // TODO
} }

View file

@ -41,6 +41,7 @@ import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess; import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.kbs.MasterKey; import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.storage.StorageKey;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -71,6 +72,7 @@ public class SignalAccount implements Closeable {
private String password; private String password;
private String registrationLockPin; private String registrationLockPin;
private MasterKey pinMasterKey; private MasterKey pinMasterKey;
private StorageKey storageKey;
private String signalingKey; private String signalingKey;
private ProfileKey profileKey; private ProfileKey profileKey;
private int preKeyIdOffset; private int preKeyIdOffset;
@ -265,6 +267,10 @@ public class SignalAccount implements Closeable {
pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull() pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
? null ? null
: new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText())); : new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText()));
JsonNode storageKeyNode = rootNode.get("storageKey");
storageKey = storageKeyNode == null || storageKeyNode.isNull()
? null
: new StorageKey(Base64.getDecoder().decode(storageKeyNode.asText()));
if (rootNode.has("signalingKey")) { if (rootNode.has("signalingKey")) {
signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText(); signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
} }
@ -398,6 +404,8 @@ public class SignalAccount implements Closeable {
.put("registrationLockPin", registrationLockPin) .put("registrationLockPin", registrationLockPin)
.put("pinMasterKey", .put("pinMasterKey",
pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize())) pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
.put("storageKey",
storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
.put("signalingKey", signalingKey) .put("signalingKey", signalingKey)
.put("preKeyIdOffset", preKeyIdOffset) .put("preKeyIdOffset", preKeyIdOffset)
.put("nextSignedPreKeyId", nextSignedPreKeyId) .put("nextSignedPreKeyId", nextSignedPreKeyId)
@ -533,6 +541,17 @@ public class SignalAccount implements Closeable {
this.pinMasterKey = pinMasterKey; this.pinMasterKey = pinMasterKey;
} }
public StorageKey getStorageKey() {
if (pinMasterKey != null) {
return pinMasterKey.deriveStorageServiceKey();
}
return storageKey;
}
public void setStorageKey(final StorageKey storageKey) {
this.storageKey = storageKey;
}
public String getSignalingKey() { public String getSignalingKey() {
return signalingKey; return signalingKey;
} }