Commit 2ebe8e70 authored by Finn Herzfeld's avatar Finn Herzfeld 🌵

Merge branch 'master' of gitlab.com:thefinn93/signald

parents f17e92b1 39395a99
Pipeline #3600 passed with stages
in 4 minutes and 12 seconds
......@@ -212,7 +212,14 @@ Trust's a safety number or fingerprint.
|-------|------|----------|-------------|
| `username` | `string` | yes | The local account to use to check the identity |
| `recipientNumber` | `string` | yes | The full number to look up. |
| `fingerprint` | `string` | yes | the safety number or fingerprint to trust. |
| `fingerprint` | `string` | yes | The safety number or fingerprint to trust. |
| `trustLevel` | `string` | no | The level at which to trust the identity. |
If `trustLevel` is not specified, defaults to `TRUSTED_VERIFIED`. Possible values are:
- `TRUSTED_VERIFIED`
- `TRUSTED_UNVERIFIED`
- `UNTRUSTED`
### `version`
......
......@@ -41,6 +41,7 @@ class JsonRequest {
public JsonQuote quote;
public int expiresInSeconds;
public String fingerprint;
public String trustLevel;
public ContactInfo contact;
public String captcha;
public String name;
......
......@@ -1896,8 +1896,9 @@ class Manager {
*
* @param name username of the identity
* @param fingerprint Fingerprint
* @param level level at with to trust the identity
*/
public boolean trustIdentityVerified(String name, byte[] fingerprint) {
public boolean trustIdentity(String name, byte[] fingerprint, TrustLevel level) {
List<JsonIdentityKeyStore.Identity> ids = signalProtocolStore.getIdentities(name);
if (ids == null) {
return false;
......@@ -1907,9 +1908,9 @@ class Manager {
continue;
}
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), level);
try {
sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
sendVerifiedMessage(name, id.getIdentityKey(), level);
} catch (IOException | UntrustedIdentityException e) {
logger.catching(e);
}
......@@ -1924,8 +1925,9 @@ class Manager {
*
* @param name username of the identity
* @param safetyNumber Safety number
* @param level level to trust the identity
*/
public boolean trustIdentityVerifiedSafetyNumber(String name, String safetyNumber) {
public boolean trustIdentitySafetyNumber(String name, String safetyNumber, TrustLevel level) {
List<JsonIdentityKeyStore.Identity> ids = signalProtocolStore.getIdentities(name);
if (ids == null) {
return false;
......@@ -1935,9 +1937,9 @@ class Manager {
continue;
}
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), level);
try {
sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
sendVerifiedMessage(name, id.getIdentityKey(), level);
} catch (IOException | UntrustedIdentityException e) {
logger.catching(e);
}
......
......@@ -17,6 +17,7 @@
package io.finn.signald;
import org.asamk.signal.*;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.signalservice.internal.util.Base64;
......@@ -33,10 +34,6 @@ import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserExce
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
import org.asamk.signal.storage.contacts.ContactInfo;
import org.asamk.signal.AttachmentInvalidException;
import org.asamk.signal.UserAlreadyExists;
import org.asamk.signal.GroupNotFoundException;
import org.asamk.signal.NotAGroupMemberException;
import org.asamk.signal.util.Hex;
import java.io.IOException;
......@@ -460,22 +457,32 @@ public class SocketHandler implements Runnable {
private void trust(JsonRequest request) throws IOException, NoSuchAccountException {
Manager m = Manager.get(request.username);
TrustLevel trustLevel = TrustLevel.TRUSTED_VERIFIED;
if(request.fingerprint == null) {
this.reply("input_error", new JsonStatusMessage(0, "Fingerprint must be a string!", request), request.id);
return;
}
if(request.trustLevel != null) {
try {
trustLevel = TrustLevel.valueOf(request.trustLevel.toUpperCase());
} catch(IllegalArgumentException e) {
this.reply("input_error",
new JsonStatusMessage(0, "Invalid TrustLevel", request), request.id);
return;
}
}
String fingerprint = request.fingerprint.replaceAll(" ", "");
if (fingerprint.length() == 66) {
byte[] fingerprintBytes;
fingerprintBytes = Hex.toByteArray(fingerprint.toLowerCase(Locale.ROOT));
boolean res = m.trustIdentityVerified(request.recipientNumber, fingerprintBytes);
boolean res = m.trustIdentity(request.recipientNumber, fingerprintBytes, trustLevel);
if (!res) {
this.reply("trust_failed", new JsonStatusMessage(0, "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct.", request), request.id);
} else {
this.reply("trusted_fingerprint", new JsonStatusMessage(0, "Successfully trusted fingerprint", request), request.id);
}
} else if (fingerprint.length() == 60) {
boolean res = m.trustIdentityVerifiedSafetyNumber(request.recipientNumber, fingerprint);
boolean res = m.trustIdentitySafetyNumber(request.recipientNumber, fingerprint, trustLevel);
if (!res) {
this.reply("trust_failed", new JsonStatusMessage(0, "Failed to set the trust for the safety number of this number, make sure the number and the safety number are correct.", request), request.id);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment