mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Store storage key from keys sync message
This commit is contained in:
parent
80e15ad54e
commit
c3c1802b4d
2 changed files with 40 additions and 0 deletions
|
@ -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.DeviceGroupsOutputStream;
|
||||
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.SentTranscriptMessage;
|
||||
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.push.SignalServiceAddress;
|
||||
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.PhoneNumberFormatter;
|
||||
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() {
|
||||
// TODO support UUID capable sender certificates
|
||||
// byte[] certificate = accountManager.getSenderCertificateForPhoneNumberPrivacy();
|
||||
|
@ -2017,6 +2031,13 @@ public class Manager implements Closeable {
|
|||
// 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()) {
|
||||
// TODO
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.whispersystems.libsignal.util.Pair;
|
|||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.storage.StorageKey;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -71,6 +72,7 @@ public class SignalAccount implements Closeable {
|
|||
private String password;
|
||||
private String registrationLockPin;
|
||||
private MasterKey pinMasterKey;
|
||||
private StorageKey storageKey;
|
||||
private String signalingKey;
|
||||
private ProfileKey profileKey;
|
||||
private int preKeyIdOffset;
|
||||
|
@ -265,6 +267,10 @@ public class SignalAccount implements Closeable {
|
|||
pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
|
||||
? null
|
||||
: 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")) {
|
||||
signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
|
||||
}
|
||||
|
@ -398,6 +404,8 @@ public class SignalAccount implements Closeable {
|
|||
.put("registrationLockPin", registrationLockPin)
|
||||
.put("pinMasterKey",
|
||||
pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
|
||||
.put("storageKey",
|
||||
storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
|
||||
.put("signalingKey", signalingKey)
|
||||
.put("preKeyIdOffset", preKeyIdOffset)
|
||||
.put("nextSignedPreKeyId", nextSignedPreKeyId)
|
||||
|
@ -533,6 +541,17 @@ public class SignalAccount implements Closeable {
|
|||
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() {
|
||||
return signalingKey;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue