Modifying methods to be public to match package division

This commit is contained in:
Pim Otte 2017-02-23 16:49:14 +01:00 committed by AsamK
parent d91e20e1f8
commit a5aeec8902
18 changed files with 158 additions and 66 deletions

View file

@ -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 {

View file

@ -21,6 +21,11 @@ import net.sourceforge.argparse4j.impl.Arguments;
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 class Main {
}
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) {

View file

@ -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.SignalServiceMessageReceiver;
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 @@ class Manager implements Signal {
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 @@ class Manager implements Signal {
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 @@ class Manager implements Signal {
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();

View file

@ -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 {

View file

@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.contacts;
import com.fasterxml.jackson.annotation.JsonProperty;

View file

@ -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());
}

View file

@ -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;

View file

@ -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.HashMap;
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());
}

View file

@ -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 org.whispersystems.libsignal.state.IdentityKeyStore;
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 @@ class JsonIdentityKeyStore implements IdentityKeyStore {
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();

View file

@ -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;

View file

@ -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;

View file

@ -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 org.whispersystems.libsignal.state.SignedPreKeyRecord;
import java.util.List;
import java.util.Map;
class JsonSignalProtocolStore implements SignalProtocolStore {
public class JsonSignalProtocolStore implements SignalProtocolStore {
@JsonProperty("preKeys")
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)

View file

@ -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;

View file

@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.thread;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
@ -21,15 +21,15 @@ public class JsonThreadStore {
private static final ObjectMapper jsonProcessor = new ObjectMapper();
void updateThread(ThreadInfo thread) {
public void updateThread(ThreadInfo thread) {
threads.put(thread.id, thread);
}
ThreadInfo getThread(String id) {
public ThreadInfo getThread(String id) {
return threads.get(id);
}
List<ThreadInfo> getThreads() {
public List<ThreadInfo> getThreads() {
return new ArrayList<>(threads.values());
}

View file

@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.storage.thread;
import com.fasterxml.jackson.annotation.JsonProperty;

View file

@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.util;
/**
* <p>Encodes and decodes to and from Base64 notation.</p>

View file

@ -1,4 +1,4 @@
package org.asamk.signal;
package org.asamk.signal.util;
public class Hex {

View file

@ -1,11 +1,11 @@
package org.asamk.signal;
package org.asamk.signal.util;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
class Util {
public class Util {
public static String getSecret(int size) {
byte[] secret = getSecretBytes(size);
return Base64.encodeBytes(secret);