Skip to content

Commit

Permalink
Modifying methods to be public to match package division
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte authored and AsamK committed Feb 26, 2017
1 parent d91e20e commit a5aeec8
Showing 18 changed files with 158 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/asamk/signal/GroupNotFoundException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.asamk.signal;

import org.asamk.signal.util.Base64;
import org.freedesktop.dbus.exceptions.DBusExecutionException;

public class GroupNotFoundException extends DBusExecutionException {
9 changes: 7 additions & 2 deletions src/main/java/org/asamk/signal/Main.java
Original file line number Diff line number Diff line change
@@ -21,6 +21,11 @@
import net.sourceforge.argparse4j.inf.*;
import org.apache.http.util.TextUtils;
import org.asamk.Signal;
import org.asamk.signal.storage.contacts.ContactInfo;
import org.asamk.signal.storage.groups.GroupInfo;
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
import org.asamk.signal.util.Base64;
import org.asamk.signal.util.Hex;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.exceptions.DBusException;
@@ -635,9 +640,9 @@ public void handle(Signal.MessageReceived s) {
}

private static void printIdentityFingerprint(Manager m, String theirUsername, JsonIdentityKeyStore.Identity theirId) {
String digits = formatSafetyNumber(m.computeSafetyNumber(theirUsername, theirId.identityKey));
String digits = formatSafetyNumber(m.computeSafetyNumber(theirUsername, theirId.getIdentityKey()));
System.out.println(String.format("%s: %s Added: %s Fingerprint: %s Safety Number: %s", theirUsername,
theirId.trustLevel, theirId.added, Hex.toStringCondensed(theirId.getFingerprint()), digits));
theirId.getTrustLevel(), theirId.getDateAdded(), Hex.toStringCondensed(theirId.getFingerprint()), digits));
}

private static void printGroup(GroupInfo group, boolean detailed) {
136 changes: 98 additions & 38 deletions src/main/java/org/asamk/signal/Manager.java
Original file line number Diff line number Diff line change
@@ -16,18 +16,70 @@
*/
package org.asamk.signal;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE;
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidObjectException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.apache.http.util.TextUtils;
import org.asamk.Signal;
import org.whispersystems.libsignal.*;
import org.asamk.signal.storage.contacts.ContactInfo;
import org.asamk.signal.storage.contacts.JsonContactsStore;
import org.asamk.signal.storage.groups.GroupInfo;
import org.asamk.signal.storage.groups.JsonGroupStore;
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
import org.asamk.signal.storage.protocol.JsonSignalProtocolStore;
import org.asamk.signal.storage.thread.JsonThreadStore;
import org.asamk.signal.storage.thread.ThreadInfo;
import org.asamk.signal.util.Base64;
import org.asamk.signal.util.Util;
import org.whispersystems.libsignal.DuplicateMessageException;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.InvalidVersionException;
import org.whispersystems.libsignal.LegacyMessageException;
import org.whispersystems.libsignal.NoSessionException;
import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.libsignal.ecc.ECPublicKey;
@@ -44,36 +96,44 @@
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.messages.*;
import org.whispersystems.signalservice.api.messages.multidevice.*;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsInputStream;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream;
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.RequestMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.TrustStore;
import org.whispersystems.signalservice.api.push.exceptions.*;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import org.whispersystems.signalservice.internal.push.SignalServiceUrl;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static java.nio.file.attribute.PosixFilePermission.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;

class Manager implements Signal {
private final static String URL = "https://textsecure-service.whispersystems.org";
@@ -1532,11 +1592,11 @@ public boolean trustIdentityVerified(String name, byte[] fingerprint) {
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
if (!Arrays.equals(id.identityKey.serialize(), fingerprint)) {
if (!Arrays.equals(id.getIdentityKey().serialize(), fingerprint)) {
continue;
}

signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_VERIFIED);
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
save();
return true;
}
@@ -1555,11 +1615,11 @@ public boolean trustIdentityVerifiedSafetyNumber(String name, String safetyNumbe
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
if (!safetyNumber.equals(computeSafetyNumber(name, id.identityKey))) {
if (!safetyNumber.equals(computeSafetyNumber(name, id.getIdentityKey()))) {
continue;
}

signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_VERIFIED);
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
save();
return true;
}
@@ -1577,8 +1637,8 @@ public boolean trustIdentityAllKeys(String name) {
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
if (id.trustLevel == TrustLevel.UNTRUSTED) {
signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_UNVERIFIED);
if (id.getTrustLevel() == TrustLevel.UNTRUSTED) {
signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
}
}
save();
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.asamk.signal;

import org.asamk.signal.util.Base64;
import org.freedesktop.dbus.exceptions.DBusExecutionException;

public class NotAGroupMemberException extends DBusExecutionException {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.contacts;

import com.fasterxml.jackson.annotation.JsonProperty;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.contacts;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -21,15 +21,15 @@ public class JsonContactsStore {

private static final ObjectMapper jsonProcessor = new ObjectMapper();

void updateContact(ContactInfo contact) {
public void updateContact(ContactInfo contact) {
contacts.put(contact.number, contact);
}

ContactInfo getContact(String number) {
public ContactInfo getContact(String number) {
return contacts.get(number);
}

List<ContactInfo> getContacts() {
public List<ContactInfo> getContacts() {
return new ArrayList<>(contacts.values());
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.groups;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.groups;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -13,6 +13,8 @@
import java.util.List;
import java.util.Map;

import org.asamk.signal.util.Base64;

public class JsonGroupStore {
@JsonProperty("groups")
@JsonSerialize(using = JsonGroupStore.MapToListSerializer.class)
@@ -23,16 +25,16 @@ public class JsonGroupStore {

private static final ObjectMapper jsonProcessor = new ObjectMapper();

void updateGroup(GroupInfo group) {
public void updateGroup(GroupInfo group) {
groups.put(Base64.encodeBytes(group.groupId), group);
}

GroupInfo getGroup(byte[] groupId) {
public GroupInfo getGroup(byte[] groupId) {
GroupInfo g = groups.get(Base64.encodeBytes(groupId));
return g;
}

List<GroupInfo> getGroups() {
public List<GroupInfo> getGroups() {
return new ArrayList<>(groups.values());
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.asamk.signal;
package org.asamk.signal.storage.protocol;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;

import org.asamk.signal.TrustLevel;
import org.asamk.signal.util.Base64;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
@@ -13,7 +16,7 @@
import java.io.IOException;
import java.util.*;

class JsonIdentityKeyStore implements IdentityKeyStore {
public class JsonIdentityKeyStore implements IdentityKeyStore {

private final Map<String, List<Identity>> trustedKeys = new HashMap<>();

@@ -177,6 +180,18 @@ public boolean isTrusted() {
return trustLevel == TrustLevel.TRUSTED_UNVERIFIED ||
trustLevel == TrustLevel.TRUSTED_VERIFIED;
}

public IdentityKey getIdentityKey() {
return this.identityKey;
}

public TrustLevel getTrustLevel() {
return this.trustLevel;
}

public Date getDateAdded() {
return this.added;
}

public byte[] getFingerprint() {
return identityKey.getPublicKey().serialize();
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.asamk.signal;
package org.asamk.signal.storage.protocol;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;

import org.asamk.signal.util.Base64;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.PreKeyStore;
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.asamk.signal;
package org.asamk.signal.storage.protocol;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;

import org.asamk.signal.util.Base64;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SessionStore;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.asamk.signal;
package org.asamk.signal.storage.protocol;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import org.asamk.signal.TrustLevel;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyIdException;
@@ -15,7 +17,7 @@
import java.util.List;
import java.util.Map;

class JsonSignalProtocolStore implements SignalProtocolStore {
public class JsonSignalProtocolStore implements SignalProtocolStore {

@JsonProperty("preKeys")
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.asamk.signal;
package org.asamk.signal.storage.protocol;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;

import org.asamk.signal.util.Base64;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyStore;
Loading

0 comments on commit a5aeec8

Please sign in to comment.