import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.zip.ZipEntry;
}
private SignalServiceAccountManager getSignalServiceAccountManager() {
- return new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, account.getUsername(), account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
+ return new SignalServiceAccountManager(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
}
private IdentityKey getIdentity() {
accountManager = getSignalServiceAccountManager();
try {
- if (account.isRegistered() && accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
- refreshPreKeys();
- account.save();
+ if (account.isRegistered()) {
+ if (accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
+ refreshPreKeys();
+ account.save();
+ }
+ if (account.getUuid() == null) {
+ account.setUuid(accountManager.getOwnUuid());
+ account.save();
+ }
}
} catch (AuthorizationFailedException e) {
System.err.println("Authorization failed, was the number registered elsewhere?");
throw new IOException("Received invalid profileKey", e);
}
}
- account = SignalAccount.createLinkedAccount(dataPath, username, account.getPassword(), ret.getDeviceId(), ret.getIdentity(), account.getSignalProtocolStore().getLocalRegistrationId(), account.getSignalingKey(), profileKey);
+ account = SignalAccount.createLinkedAccount(dataPath, username, ret.getUuid(), account.getPassword(), ret.getDeviceId(), ret.getIdentity(), account.getSignalProtocolStore().getLocalRegistrationId(), account.getSignalingKey(), profileKey);
refreshPreKeys();
verificationCode = verificationCode.replace("-", "");
account.setSignalingKey(KeyUtils.createSignalingKey());
// TODO make unrestricted unidentified access configurable
- accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, capabilities);
+ UUID uuid = accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, capabilities);
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
account.setRegistered(true);
+ account.setUuid(uuid);
account.setRegistrationLockPin(pin);
refreshPreKeys();
return account;
}
- public static SignalAccount createLinkedAccount(String dataPath, String username, String password, int deviceId, IdentityKeyPair identityKey, int registrationId, String signalingKey, ProfileKey profileKey) throws IOException {
+ public static SignalAccount createLinkedAccount(String dataPath, String username, UUID uuid, String password, int deviceId, IdentityKeyPair identityKey, int registrationId, String signalingKey, ProfileKey profileKey) throws IOException {
IOUtils.createPrivateDirectories(dataPath);
SignalAccount account = new SignalAccount();
account.openFileChannel(getFileName(dataPath, username));
account.username = username;
+ account.uuid = uuid;
account.password = password;
account.profileKey = profileKey;
account.deviceId = deviceId;
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
}
+ JsonNode uuidNode = rootNode.get("uuid");
+ if (uuidNode != null && !uuidNode.isNull()) {
+ try {
+ uuid = UUID.fromString(uuidNode.asText());
+ } catch (IllegalArgumentException e) {
+ throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
+ }
+ }
JsonNode node = rootNode.get("deviceId");
if (node != null) {
deviceId = node.asInt();
}
ObjectNode rootNode = jsonProcessor.createObjectNode();
rootNode.put("username", username)
+ .put("uuid", uuid == null ? null : uuid.toString())
.put("deviceId", deviceId)
.put("isMultiDevice", isMultiDevice)
.put("password", password)
return uuid;
}
+ public void setUuid(final UUID uuid) {
+ this.uuid = uuid;
+ }
+
public SignalServiceAddress getSelfAddress() {
return new SignalServiceAddress(uuid, username);
}