mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Return a Manager from ProvisioningManager and RegistrationManager when finished
This commit is contained in:
parent
a7b414a870
commit
2935b96070
4 changed files with 49 additions and 23 deletions
|
@ -92,7 +92,7 @@ public class ProvisioningManager {
|
||||||
return new DeviceLinkInfo(deviceUuid, identityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
|
return new DeviceLinkInfo(deviceUuid, identityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
|
public Manager finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
|
||||||
var ret = accountManager.finishNewDeviceRegistration(identityKey, false, true, registrationId, deviceName);
|
var ret = accountManager.finishNewDeviceRegistration(identityKey, false, true, registrationId, deviceName);
|
||||||
|
|
||||||
var username = ret.getNumber();
|
var username = ret.getNumber();
|
||||||
|
@ -114,17 +114,21 @@ public class ProvisioningManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (var account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
|
SignalAccount account = null;
|
||||||
|
try {
|
||||||
|
account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
|
||||||
username,
|
username,
|
||||||
ret.getUuid(),
|
ret.getUuid(),
|
||||||
password,
|
password,
|
||||||
ret.getDeviceId(),
|
ret.getDeviceId(),
|
||||||
ret.getIdentity(),
|
ret.getIdentity(),
|
||||||
registrationId,
|
registrationId,
|
||||||
profileKey)) {
|
profileKey);
|
||||||
account.save();
|
account.save();
|
||||||
|
|
||||||
try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
Manager m = null;
|
||||||
|
try {
|
||||||
|
m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m.refreshPreKeys();
|
m.refreshPreKeys();
|
||||||
|
@ -144,12 +148,22 @@ public class ProvisioningManager {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.close(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
account.save();
|
account.save();
|
||||||
}
|
|
||||||
|
|
||||||
return username;
|
final var result = m;
|
||||||
|
account = null;
|
||||||
|
m = null;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
if (m != null) {
|
||||||
|
m.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (account != null) {
|
||||||
|
account.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class RegistrationManager implements Closeable {
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifyAccount(
|
public Manager verifyAccount(
|
||||||
String verificationCode, String pin
|
String verificationCode, String pin
|
||||||
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
|
@ -169,14 +169,24 @@ public class RegistrationManager implements Closeable {
|
||||||
account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
|
account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
|
||||||
TrustLevel.TRUSTED_VERIFIED);
|
TrustLevel.TRUSTED_VERIFIED);
|
||||||
|
|
||||||
try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
Manager m = null;
|
||||||
|
try {
|
||||||
|
m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
|
||||||
|
|
||||||
m.refreshPreKeys();
|
m.refreshPreKeys();
|
||||||
|
|
||||||
m.close(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
account.save();
|
account.save();
|
||||||
|
|
||||||
|
final var result = m;
|
||||||
|
account = null;
|
||||||
|
m = null;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
if (m != null) {
|
||||||
|
m.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VerifyAccountResponse verifyAccountWithCode(
|
private VerifyAccountResponse verifyAccountWithCode(
|
||||||
|
|
|
@ -38,8 +38,9 @@ public class LinkCommand implements ProvisioningCommand {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
writer.println("{}", m.getDeviceLinkUri());
|
writer.println("{}", m.getDeviceLinkUri());
|
||||||
var username = m.finishDeviceLink(deviceName);
|
try (var manager = m.finishDeviceLink(deviceName)) {
|
||||||
writer.println("Associated with: {}", username);
|
writer.println("Associated with: {}", manager.getUsername());
|
||||||
|
}
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
throw new UserErrorException("Link request timed out, please try again.");
|
throw new UserErrorException("Link request timed out, please try again.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ public class VerifyCommand implements RegistrationCommand {
|
||||||
var pin = ns.getString("pin");
|
var pin = ns.getString("pin");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m.verifyAccount(verificationCode, pin);
|
final var manager = m.verifyAccount(verificationCode, pin);
|
||||||
|
manager.close();
|
||||||
} catch (LockedException e) {
|
} catch (LockedException e) {
|
||||||
throw new UserErrorException(
|
throw new UserErrorException(
|
||||||
"Verification failed! This number is locked with a pin. Hours remaining until reset: "
|
"Verification failed! This number is locked with a pin. Hours remaining until reset: "
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue