Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Feb 8, 2021
1 parent 74f56a3 commit 797c249
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
Binary file modified android/.idea/caches/build_file_checksums.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -314,34 +314,6 @@ public boolean isInitialized() {
return localId != 0;
}

static public void initSessionJSON(JSONObject bundle) {
try {
SignalProtocolStore store = new MySignalProtocolStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(bundle.getString("userId"), bundle.getInt("deviceId"));
SessionBuilder sessionBuilder = new SessionBuilder(store, signalProtocolAddress);
ECPublicKey preKey = Curve.decodePoint(Base64.decode(bundle.getString("preKey")), 0);
ECPublicKey signedPreKey = Curve.decodePoint(Base64.decode(bundle.getString("signedPreKey")), 0);
ECPublicKey identityKey = Curve.decodePoint(Base64.decode(bundle.getString("identityKey")), 0);
IdentityKey identityPublicKey = new IdentityKey(identityKey);

PreKeyBundle preKeyBundle = new PreKeyBundle(
bundle.getInt("localId"),
bundle.getInt("deviceId"),
bundle.getInt("preKeyId"),
preKey,
bundle.getInt("signedPreKeyId"),
signedPreKey,
Base64.decode(bundle.getString("signature")),
identityPublicKey
);
sessionBuilder.process(preKeyBundle);
} catch (UntrustedIdentityException | InvalidKeyException e) {
e.printStackTrace();
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}

public void initSession(JSONObject bundle) {
try {
SignalProtocolStore store = new MySignalProtocolStore(context);
Expand Down Expand Up @@ -374,7 +346,7 @@ public boolean checkPairwiseSession(String oneTimeId) {
return store.containsSession(signalProtocolAddress);
}

static private String encryptTextPairwise(String userId, int deviceId, String text) {
public String encryptTextPairwise(String userId, int deviceId, String text) {
try {
SignalProtocolStore store = new MySignalProtocolStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, deviceId);
Expand Down Expand Up @@ -410,7 +382,7 @@ public JSONObject getEncryptingSenderKey(String userId, String stickId, Boolean
}


static public String getSenderKey(String senderId, String targetId, String stickId, Boolean isSticky) throws IOException, InvalidMessageException, LegacyMessageException {
public String getSenderKey(String senderId, String targetId, String stickId, Boolean isSticky) throws IOException, InvalidMessageException, LegacyMessageException {

SenderKeyDistributionMessage senderKeyDistributionMessage = null;
if (isSticky)
Expand All @@ -426,7 +398,7 @@ static public String getSenderKey(String senderId, String targetId, String stick
}


static public int getChainStep(String userId, String stickId) {
public int getChainStep(String userId, String stickId) {
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 1);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
Expand All @@ -439,7 +411,7 @@ static public int getChainStep(String userId, String stickId) {
}
}

static public String encryptText(String userId, String stickId, String text, Boolean isSticky) {
public String encryptText(String userId, String stickId, String text, Boolean isSticky) {
try {
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, isSticky ? 1 : 0);
Expand All @@ -455,7 +427,7 @@ static public String encryptText(String userId, String stickId, String text, Boo
return null;
}

static public Boolean isSessionEmpty(String senderId, String stickId, Boolean isSticky) {
public Boolean isSessionEmpty(String senderId, String stickId, Boolean isSticky) {
SenderKeyStore mySenderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(senderId, isSticky ? 1 : 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
Expand All @@ -471,7 +443,7 @@ public void reinitMyGroupSenderSession(JSONObject senderKey) throws IOException,
}


static public void initGroupSenderSession(String senderId, String stickId, String cipherSenderKey, Boolean isSticky) {
public void initGroupSenderSession(String senderId, String stickId, String cipherSenderKey, Boolean isSticky) {
try {
if (cipherSenderKey != null) {
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
Expand All @@ -489,7 +461,7 @@ static public void initGroupSenderSession(String senderId, String stickId, Strin
}
}

static public String decryptText(String senderId, String stickId, String cipher, Boolean isSticky) {
public String decryptText(String senderId, String stickId, String cipher, Boolean isSticky) {
if (cipher.length() < 4)
return null;
try {
Expand Down Expand Up @@ -519,7 +491,7 @@ public void deleteSession(String stickId, String senderId) {
}


private static String decryptTextPairwise(String senderId, int deviceId, boolean isStickyKey, String cipher) {
public String decryptTextPairwise(String senderId, int deviceId, boolean isStickyKey, String cipher) {
try {
SignalProtocolStore store = new MySignalProtocolStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(senderId, deviceId);
Expand Down Expand Up @@ -552,7 +524,7 @@ private static String decryptTextPairwise(String senderId, int deviceId, boolean
}
}

static public HashMap<String, String> encryptMedia(String filePath, String contentType) {
public HashMap<String, String> encryptMedia(String filePath, String contentType) {
try {
File file = new File(filePath);
InputStream is = new FileInputStream(file);
Expand Down Expand Up @@ -664,7 +636,7 @@ public String decryptFile(String senderId, String stickId, String filePath, Stri
return path;
}

private HashMap<String, String> pbEncrypt(byte[] text, String pass) throws Exception {
public HashMap<String, String> pbEncrypt(byte[] text, String pass) throws Exception {
// synchronized (LOCK) {
// Generate salt
SecureRandom randomSalt = new SecureRandom();
Expand Down Expand Up @@ -713,7 +685,7 @@ private HashMap<String, String> pbEncrypt(byte[] text, String pass) throws Excep
// }
}

private byte[] pbDecrypt(String encryptedIvText, String salt, String pass) throws Exception {
public byte[] pbDecrypt(String encryptedIvText, String salt, String pass) throws Exception {
int ivSize = 16;
byte[] encryptedIvTextBytes = Base64.decode(encryptedIvText);

Expand Down Expand Up @@ -750,11 +722,11 @@ private byte[] pbDecrypt(String encryptedIvText, String salt, String pass) throw
}


private void cacheUri(String id, String uri) {
public void cacheUri(String id, String uri) {
DatabaseFactory.getFileDatabase(context).insertUri(id, uri);
}

private String getUri(String id) {
public String getUri(String id) {
String uri = DatabaseFactory.getFileDatabase(context).getUri(id);
return uri;
}
Expand Down

0 comments on commit 797c249

Please sign in to comment.