mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Support registration lock PIN
This commit is contained in:
parent
161ecc877d
commit
e057743232
3 changed files with 69 additions and 6 deletions
|
@ -19,8 +19,8 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.turasa:signal-service-java:2.7.1_unofficial_1'
|
compile 'com.github.turasa:signal-service-java:2.7.3_unofficial_1'
|
||||||
compile 'org.bouncycastle:bcprov-jdk15on:1.55'
|
compile 'org.bouncycastle:bcprov-jdk15on:1.59'
|
||||||
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
||||||
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.freedesktop.dbus.DBusSigHandler;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.libsignal.InvalidKeyException;
|
import org.whispersystems.libsignal.InvalidKeyException;
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
import org.whispersystems.signalservice.api.messages.*;
|
import org.whispersystems.signalservice.api.messages.*;
|
||||||
import org.whispersystems.signalservice.api.messages.calls.*;
|
import org.whispersystems.signalservice.api.messages.calls.*;
|
||||||
|
@ -46,6 +47,7 @@ import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptio
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||||
|
import org.whispersystems.signalservice.internal.push.LockedException;
|
||||||
import org.whispersystems.signalservice.internal.util.Base64;
|
import org.whispersystems.signalservice.internal.util.Base64;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -183,6 +185,39 @@ public class Main {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "setPin":
|
||||||
|
if (dBusConn != null) {
|
||||||
|
System.err.println("setPin is not yet implemented via dbus");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!m.isRegistered()) {
|
||||||
|
System.err.println("User is not registered.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String registrationLockPin = ns.getString("registrationLockPin");
|
||||||
|
m.setRegistrationLockPin(Optional.of(registrationLockPin));
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Set pin error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "removePin":
|
||||||
|
if (dBusConn != null) {
|
||||||
|
System.err.println("removePin is not yet implemented via dbus");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!m.isRegistered()) {
|
||||||
|
System.err.println("User is not registered.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
m.setRegistrationLockPin(Optional.<String>absent());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Remove pin error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "verify":
|
case "verify":
|
||||||
if (dBusConn != null) {
|
if (dBusConn != null) {
|
||||||
System.err.println("verify is not yet implemented via dbus");
|
System.err.println("verify is not yet implemented via dbus");
|
||||||
|
@ -197,7 +232,13 @@ public class Main {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
m.verifyAccount(ns.getString("verificationCode"));
|
String verificationCode = ns.getString("verificationCode");
|
||||||
|
String pin = ns.getString("pin");
|
||||||
|
m.verifyAccount(verificationCode, pin);
|
||||||
|
} catch (LockedException e) {
|
||||||
|
System.err.println("Verification failed! This number is locked with a pin. Hours remaining until reset: " + (e.getTimeRemaining() / 1000 / 60 / 60));
|
||||||
|
System.err.println("Use '--pin PIN_CODE' to specify the registration lock PIN");
|
||||||
|
return 3;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Verify error: " + e.getMessage());
|
System.err.println("Verify error: " + e.getMessage());
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -777,9 +818,17 @@ public class Main {
|
||||||
Subparser parserUpdateAccount = subparsers.addParser("updateAccount");
|
Subparser parserUpdateAccount = subparsers.addParser("updateAccount");
|
||||||
parserUpdateAccount.help("Update the account attributes on the signal server.");
|
parserUpdateAccount.help("Update the account attributes on the signal server.");
|
||||||
|
|
||||||
|
Subparser parserSetPin = subparsers.addParser("setPin");
|
||||||
|
parserSetPin.addArgument("registrationLockPin")
|
||||||
|
.help("The registration lock PIN, that will be required for new registrations (resets after 7 days of inactivity)");
|
||||||
|
|
||||||
|
Subparser parserRemovePin = subparsers.addParser("removePin");
|
||||||
|
|
||||||
Subparser parserVerify = subparsers.addParser("verify");
|
Subparser parserVerify = subparsers.addParser("verify");
|
||||||
parserVerify.addArgument("verificationCode")
|
parserVerify.addArgument("verificationCode")
|
||||||
.help("The verification code you received via sms or voice call.");
|
.help("The verification code you received via sms or voice call.");
|
||||||
|
parserVerify.addArgument("-p", "--pin")
|
||||||
|
.help("The registration lock PIN, that was set by the user (Optional)");
|
||||||
|
|
||||||
Subparser parserSend = subparsers.addParser("send");
|
Subparser parserSend = subparsers.addParser("send");
|
||||||
parserSend.addArgument("-g", "--group")
|
parserSend.addArgument("-g", "--group")
|
||||||
|
|
|
@ -116,6 +116,7 @@ class Manager implements Signal {
|
||||||
private String username;
|
private String username;
|
||||||
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
||||||
private String password;
|
private String password;
|
||||||
|
private String registrationLockPin;
|
||||||
private String signalingKey;
|
private String signalingKey;
|
||||||
private int preKeyIdOffset;
|
private int preKeyIdOffset;
|
||||||
private int nextSignedPreKeyId;
|
private int nextSignedPreKeyId;
|
||||||
|
@ -258,6 +259,8 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
username = getNotNullNode(rootNode, "username").asText();
|
username = getNotNullNode(rootNode, "username").asText();
|
||||||
password = getNotNullNode(rootNode, "password").asText();
|
password = getNotNullNode(rootNode, "password").asText();
|
||||||
|
JsonNode pinNode = rootNode.get("registrationLockPin");
|
||||||
|
registrationLockPin = pinNode == null ? null : pinNode.asText();
|
||||||
if (rootNode.has("signalingKey")) {
|
if (rootNode.has("signalingKey")) {
|
||||||
signalingKey = getNotNullNode(rootNode, "signalingKey").asText();
|
signalingKey = getNotNullNode(rootNode, "signalingKey").asText();
|
||||||
}
|
}
|
||||||
|
@ -326,6 +329,7 @@ class Manager implements Signal {
|
||||||
rootNode.put("username", username)
|
rootNode.put("username", username)
|
||||||
.put("deviceId", deviceId)
|
.put("deviceId", deviceId)
|
||||||
.put("password", password)
|
.put("password", password)
|
||||||
|
.put("registrationLockPin", registrationLockPin)
|
||||||
.put("signalingKey", signalingKey)
|
.put("signalingKey", signalingKey)
|
||||||
.put("preKeyIdOffset", preKeyIdOffset)
|
.put("preKeyIdOffset", preKeyIdOffset)
|
||||||
.put("nextSignedPreKeyId", nextSignedPreKeyId)
|
.put("nextSignedPreKeyId", nextSignedPreKeyId)
|
||||||
|
@ -374,7 +378,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccountAttributes() throws IOException {
|
public void updateAccountAttributes() throws IOException {
|
||||||
accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), true);
|
accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), true, registrationLockPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() throws IOException {
|
public void unregister() throws IOException {
|
||||||
|
@ -504,18 +508,28 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifyAccount(String verificationCode) throws IOException {
|
public void verifyAccount(String verificationCode, String pin) throws IOException {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
signalingKey = Util.getSecret(52);
|
signalingKey = Util.getSecret(52);
|
||||||
accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), true);
|
accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), true, pin);
|
||||||
|
|
||||||
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
||||||
registered = true;
|
registered = true;
|
||||||
|
registrationLockPin = pin;
|
||||||
|
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRegistrationLockPin(Optional<String> pin) throws IOException {
|
||||||
|
accountManager.setPin(pin);
|
||||||
|
if (pin.isPresent()) {
|
||||||
|
registrationLockPin = pin.get();
|
||||||
|
} else {
|
||||||
|
registrationLockPin = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshPreKeys() throws IOException {
|
private void refreshPreKeys() throws IOException {
|
||||||
List<PreKeyRecord> oneTimePreKeys = generatePreKeys();
|
List<PreKeyRecord> oneTimePreKeys = generatePreKeys();
|
||||||
SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(signalProtocolStore.getIdentityKeyPair());
|
SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(signalProtocolStore.getIdentityKeyPair());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue