Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Mar 29, 2021
1 parent 4fd0238 commit 4a07707
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -527,6 +528,9 @@ public JSONObject getEncryptingSenderKey(String userId, String stickId) {
SenderKeyDistributionMessage senderKeyDistributionMessage = groupSessionBuilder.create(senderKeyName);
DatabaseFactory.getStickyKeyDatabase(context).insertStickyKey(stickId, Base64.encodeBytes(senderKeyDistributionMessage.serialize()));
SenderKeyState senderKeyState = senderKeyStore.loadSenderKey(senderKeyName).getSenderKeyState();
Log.d("PRIVATE KEY LENGTHXXX", Integer.toString(Base64.encodeBytes(senderKeyState.getSigningKeyPrivate().serialize()).length()));
Log.d("PUBLIC KEY LENGTHXXX", Integer.toString(Base64.encodeBytes(senderKeyState.getSigningKeyPublic().serialize()).length()));
Log.d("CHAIN KEY LENGTHXXX", Integer.toString(Base64.encodeBytes(senderKeyState.getSenderChainKey().getSeed()).length()));
String cipher = encryptTextPairwise(userId, Base64.encodeBytes(senderKeyState.getSigningKeyPrivate().serialize()));
JSONObject map = new JSONObject();
map.put("id", senderKeyState.getKeyId());
Expand Down Expand Up @@ -579,6 +583,8 @@ public void initSession(String senderId, String stickId, String cipherSenderKey,
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(senderId, 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
GroupSessionBuilder groupSessionBuilder = new GroupSessionBuilder(senderKeyStore);
if (identityKeyId == -1)
identityKeyId = Preferences.getActiveIdentityKeyId(context);
String senderKey = decryptStickyKey(senderId, cipherSenderKey, identityKeyId);
if (senderKey != null) {
SenderKeyDistributionMessage senderKeyDistributionMessage = new SenderKeyDistributionMessage(Base64.decode(senderKey));
Expand Down Expand Up @@ -679,8 +685,7 @@ public String decryptText(String senderId, String stickId, String cipher, Boolea
* @param stickId - id of the sticky session
* @param filePath - path of the file to be encrypted
* @param contentMedia - type of the file
* @param isSticky - boolean indicating whether this encryption is for a sticky sesison
*
* @param isSticky - boolean indicating whether this encryption is for a sticky session
* @return JSONObject - contains the following:
* * uri: path of the encrypted file
* * cipher: (fileKey||fileHash) encrypted
Expand Down
22 changes: 11 additions & 11 deletions client-handlers/StickProtocolHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ export default class StickProtocolHandlers {
const preKeyId = bundles[memberId].preKeyId
const identityKeyId = bundles[memberId].identityKeyId
if (memberId !== this.userId) {
const key = await this.StickProtocol.getSenderKey(memberId, stickId, true);
const key = await this.StickProtocol.getSenderKey(this.userId, memberId, stickId, true);
keys[memberId] = {identityKeyId, preKeyId, key, stickId, forUser: memberId}
} else {
let encryptingSenderKey = await this.StickProtocol.getEncryptingSenderKey(stickId)
let encryptingSenderKey = await this.StickProtocol.getEncryptingSenderKey(this.userId, stickId)
encryptingSenderKey['preKeyId'] = preKeyId
encryptingSenderKey['identityKeyId'] = identityKeyId
encryptingSenderKey['stickId'] = stickId
Expand Down Expand Up @@ -156,10 +156,10 @@ export default class StickProtocolHandlers {
dispatch({type: 'DOWNLOADED', payload: entityId});
} else { // otherwise initialize the session
if (memberId !== userId)
await this.StickProtocol.initSession(memberId, stickId, response.data.senderKey.key, true, response.data.senderKey.identityKeyId)
await this.StickProtocol.initSession(memberId, stickId, response.data.senderKey.key, response.data.senderKey.identityKeyId)
else {
response.data.senderKey.stickId = stickId
await this.StickProtocol.reinitMyStickySession(response.data.senderKey)
await this.StickProtocol.reinitMyStickySession(this.userId, response.data.senderKey)
}
await dispatch({type: 'PENDING_SESSION_DONE', payload: stickId})
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export default class StickProtocolHandlers {
const phone = pkb.phone
if (memberId.length === 36 && stickId.length >= 36) {
// Get the sender key and upload it
const key = await this.StickProtocol.getSenderKey(memberId, stickId, true);
const key = await this.StickProtocol.getSenderKey(this.userId, memberId, stickId, true);
const body = {preKeyId, key, stickId, forUser: memberId}
await axios.post(`${this.URL}/api/upload-sk/`, body, this.httpConfig)
}
Expand All @@ -227,9 +227,9 @@ export default class StickProtocolHandlers {
*/
async syncChain(step, stickId) {
if (step) {
const currentStep = await this.StickProtocol.getChainStep(stickId)
const currentStep = await this.StickProtocol.getChainStep(this.userId, stickId)
if (step > currentStep) {
await this.StickProtocol.ratchetChain(stickId, step - currentStep)
await this.StickProtocol.ratchetChain(this.userId, stickId, step - currentStep)
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export default class StickProtocolHandlers {
}
const response = await axios.post(`${this.URL}/api/fetch-sk/`, body, this.httpConfig);
if (response.data.senderKey)
await this.StickProtocol.initSession(oneTimeId, stickId, response.data.senderKey, false)
await this.StickProtocol.initSession(oneTimeId, stickId, response.data.senderKey)
}

/**
Expand All @@ -279,7 +279,7 @@ export default class StickProtocolHandlers {
if (member.id !== this.userId) {
const oneTimeId = member.oneTimeId;
await this.checkPairwiseSession(member.id, oneTimeId); // check pairwise session and create one if needed
const exists = await this.StickProtocol.sessionExists(oneTimeId, stickId, false)
const exists = await this.StickProtocol.sessionExists(oneTimeId, stickId)

// if there is no session, add the member's oneTimeId to the list of sessions that the user needs to init
if (!exists)
Expand All @@ -296,7 +296,7 @@ export default class StickProtocolHandlers {
}, this.httpConfig)
for (let i = 0; i < keysToFetch.length; i++) {
if (response.data.senderKeys[keysToFetch[i]]) {
await this.StickProtocol.initSession(keysToFetch[i], chatId, response.data.senderKeys[keysToFetch[i]], false)
await this.StickProtocol.initSession(keysToFetch[i], chatId, response.data.senderKeys[keysToFetch[i]])
}
}
}
Expand All @@ -314,7 +314,7 @@ export default class StickProtocolHandlers {
const member = members[i]
if (member.id !== this.userId) {
if (!res.data.members[member.oneTimeId].exists) {
keysToUpload[member.oneTimeId] = await this.StickProtocol.getSenderKey(member.oneTimeId, stickId, false);
keysToUpload[member.oneTimeId] = await this.StickProtocol.getSenderKey(this.userOneTimeId, member.oneTimeId, stickId, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion client-handlers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stick-protocol-handlers",
"version": "1.0.8",
"version": "1.0.10",
"description": "UNDER DEVELOPMENT!",
"main": "StickProtocolHandlers.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion server/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = stick-protocol-server
version = 1.1.54
version = 1.1.55
description = Stick protocol server for Django.
long_description = file: README.rst
long_description_content_type = text/x-rst
Expand Down

0 comments on commit 4a07707

Please sign in to comment.