Skip to content

Commit

Permalink
updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Mar 29, 2021
1 parent 09d0c5d commit 4fd0238
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void reInitialize(JSONObject bundle, String password, String userId, Stri
// OWN SENDER KEYS
for (int i = 0; i < senderKeys.length(); i++) {
JSONObject senderKeyJson = senderKeys.getJSONObject(i);
reinitMyStickySession(senderKeyJson);
reinitMyStickySession(userId, senderKeyJson);

// PROGRESS
progress += 1;
Expand Down Expand Up @@ -510,16 +510,16 @@ public String decryptTextPairwise(String senderId, boolean isStickyKey, String c
/***
* This method is used to create a sticky session and get the EncryptingSenderKey of a user for a party.
*
* @param userId
* @param stickId - String, the stickId of the sticky session
* @return JSONObject - contains the following:
* * id - int, the sender key id
* * chainKey - String
* * public - String, signature key public key
* * cipher - String, signature key encrypted private key
*/
public JSONObject getEncryptingSenderKey(String stickId) {
public JSONObject getEncryptingSenderKey(String userId, String stickId) {
try {
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "");
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
Expand All @@ -544,14 +544,13 @@ public JSONObject getEncryptingSenderKey(String stickId) {
* This method is used to get a user's sender key (DecryptingSenderKey) of a sticky session (or a standard group session)
* in order to share it with other members of a party.
*
* @param senderId - userId (or oneTimeId)
* @param targetId - target userId (or oneTimeId)
* @param stickId - the id of the sticky session (or standard session)
* @param isSticky - boolean, indicates whether the sender key is for a sticky session or a standard group session
* @return encrypted sender key to the target - String
*/
public String getSenderKey(String targetId, String stickId, Boolean isSticky) throws IOException, InvalidMessageException, LegacyMessageException {
String senderId = isSticky ? PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "")
: PreferenceManager.getDefaultSharedPreferences(context).getString("oneTimeId", "");
public String getSenderKey(String senderId, String targetId, String stickId, Boolean isSticky) throws IOException, InvalidMessageException, LegacyMessageException {
SenderKeyDistributionMessage senderKeyDistributionMessage = null;
if (isSticky)
senderKeyDistributionMessage = new SenderKeyDistributionMessage(Base64.decode(DatabaseFactory.getStickyKeyDatabase(context).getStickyKey(stickId)));
Expand Down Expand Up @@ -622,15 +621,14 @@ public String decryptStickyKey(String senderId, String cipher, int identityKeyId
/***
* This method is used to make an encryption in a sticky session.
*
* @param senderId - userId (or oneTimeId)
* @param stickId - id of the sticky session
* @param text - plaintext to be encrypted
* @param isSticky - boolean indicating whether this encryption is for a sticky session
* @return ciphertext
*/
public String encryptText(String stickId, String text, Boolean isSticky) {
public String encryptText(String senderId, String stickId, String text, Boolean isSticky) {
try {
String senderId = isSticky ? PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "")
: PreferenceManager.getDefaultSharedPreferences(context).getString("oneTimeId", "");
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(senderId, 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
Expand Down Expand Up @@ -677,6 +675,7 @@ public String decryptText(String senderId, String stickId, String cipher, Boolea
/***
* This method is used to encrypt files in a sticky session
*
* @param senderId - userId
* @param stickId - id of the sticky session
* @param filePath - path of the file to be encrypted
* @param contentMedia - type of the file
Expand All @@ -686,9 +685,9 @@ public String decryptText(String senderId, String stickId, String cipher, Boolea
* * uri: path of the encrypted file
* * cipher: (fileKey||fileHash) encrypted
*/
public JSONObject encryptFile(String stickId, String filePath, String contentMedia, Boolean isSticky) throws JSONException {
public JSONObject encryptFile(String senderId, String stickId, String filePath, String contentMedia, Boolean isSticky) throws JSONException {
HashMap<String, String> hashMap = encryptMedia(filePath, contentMedia);
String cipherText = encryptText(stickId, hashMap.get("secret"), isSticky);
String cipherText = encryptText(senderId, stickId, hashMap.get("secret"), isSticky);
JSONObject map = new JSONObject();
map.put("uri", hashMap.get("uri"));
map.put("cipher", cipherText);
Expand Down Expand Up @@ -733,11 +732,11 @@ public Boolean sessionExists(String senderId, String stickId) {
/***
* This method is used to get the current chain step of a sticky session.
*
* @param userId
* @param stickId - id of the sticky session
* @return the chain step - int
*/
public int getChainStep(String stickId) {
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "");
public int getChainStep(String userId, String stickId) {
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
Expand All @@ -753,11 +752,11 @@ public int getChainStep(String stickId) {
/***
* This method is used to ratchet the chain of a sticky session, in order to be matching across all devices.
*
* @param userId
* @param stickId - id of the sticky sesison
* @param steps - number of steps
*/
public void ratchetChain(String stickId, int steps) throws NoSessionException {
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "");
public void ratchetChain(String userId, String stickId, int steps) throws NoSessionException {
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 0);
SenderKeyName senderKeyName = new SenderKeyName(stickId, signalProtocolAddress);
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
Expand All @@ -768,6 +767,7 @@ public void ratchetChain(String stickId, int steps) throws NoSessionException {
/**
* This method is used to re-establish a user's own sticky session.
*
* @param userId
* @param senderKey - JSONObject, contains the following:
* * id - int, id of the key
* * chainKey - String
Expand All @@ -776,8 +776,7 @@ public void ratchetChain(String stickId, int steps) throws NoSessionException {
* * stickId - String, id of the sticky session
* * identityKeyId - int, id of the identity key used to encrypt the private signature key
*/
public void reinitMyStickySession(JSONObject senderKey) throws IOException, InvalidKeyException, NoSessionException, JSONException {
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "");
public void reinitMyStickySession(String userId, JSONObject senderKey) throws IOException, InvalidKeyException, NoSessionException, JSONException {
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 0);
SenderKeyName senderKeyName = new SenderKeyName(senderKey.getString("stickId"), signalProtocolAddress);
SenderKeyStore senderKeyStore = new MySenderKeyStore(context);
Expand Down
10 changes: 5 additions & 5 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(this.userId, memberId, stickId, true);
const key = await this.StickProtocol.getSenderKey(memberId, stickId, true);
keys[memberId] = {identityKeyId, preKeyId, key, stickId, forUser: memberId}
} else {
let encryptingSenderKey = await this.StickProtocol.getEncryptingSenderKey(this.userId, stickId, true)
let encryptingSenderKey = await this.StickProtocol.getEncryptingSenderKey(stickId)
encryptingSenderKey['preKeyId'] = preKeyId
encryptingSenderKey['identityKeyId'] = identityKeyId
encryptingSenderKey['stickId'] = 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(this.userId, memberId, stickId, true);
const key = await this.StickProtocol.getSenderKey(memberId, stickId, true);
const body = {preKeyId, key, stickId, forUser: memberId}
await axios.post(`${this.URL}/api/upload-sk/`, body, this.httpConfig)
}
Expand All @@ -227,7 +227,7 @@ export default class StickProtocolHandlers {
*/
async syncChain(step, stickId) {
if (step) {
const currentStep = await this.StickProtocol.getChainStep(this.userId, stickId)
const currentStep = await this.StickProtocol.getChainStep(stickId)
if (step > currentStep) {
await this.StickProtocol.ratchetChain(stickId, step - currentStep)
}
Expand Down Expand Up @@ -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(this.userOneTimeId, member.oneTimeId, stickId, false);
keysToUpload[member.oneTimeId] = await this.StickProtocol.getSenderKey(member.oneTimeId, stickId, false);
}
}
}
Expand Down

0 comments on commit 4fd0238

Please sign in to comment.