Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed May 16, 2021
1 parent 900a70b commit 510733e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ public void reInitialize(JSONObject bundle, String password, String userId, Prog
}
}

public void decryptPreKeys(JSONArray preKeys) throws Exception {
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString("userId", "");
HashMap<String, String> serviceMap = new HashMap();
serviceMap.put("service", passwordKey);
String password = keychain.getGenericPassword(userId, serviceMap);
SignalProtocolStore store = new MyProtocolStore(context);
for (int i = 0; i < preKeys.length(); i++) {
JSONObject preKeyJson = preKeys.getJSONObject(i);
ECPublicKey prePubKey = Curve.decodePoint(Base64.decode(preKeyJson.getString("public")), 0);
byte[] cipher = pbDecrypt(preKeyJson.getString("cipher"), preKeyJson.getString("salt"), password);
ECPrivateKey prePrivKey = Curve.decodePrivatePoint(cipher);
ECKeyPair preKey = new ECKeyPair(prePubKey, prePrivKey);
PreKeyRecord pkRecord = new PreKeyRecord(preKeyJson.getInt("id"), preKey);
store.storePreKey(preKeyJson.getInt("id"), pkRecord);
}
}

/***
* This method is used to create the initial password hash using Argon2, from a provided password
* and salt, at login.
Expand Down Expand Up @@ -530,7 +547,7 @@ 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();
String key = Base64.encodeBytes(senderKeyState.getSenderChainKey().getSeed()) + Base64.encodeBytes(senderKeyState.getSigningKeyPrivate().serialize()) + Base64.encodeBytes(senderKeyState.getSigningKeyPublic().serialize());
String key = Base64.encodeBytes(senderKeyState.getSenderChainKey().getSeed()) + Base64.encodeBytes(senderKeyState.getSigningKeyPrivate().serialize()) + Base64.encodeBytes(senderKeyState.getSigningKeyPublic().serialize());
String encryptKey = encryptTextPairwise(userId, key);
JSONObject map = new JSONObject();
map.put("id", senderKeyState.getKeyId());
Expand Down Expand Up @@ -741,11 +758,11 @@ public void ratchetChain(String userId, String stickId, int steps) throws NoSess
*
* @param userId
* @param senderKey - JSONObject, contains the following:
* * id - int, id of the key
* * key - encrypted sender key (chainKey || signaturePrivateKey || signaturePublicKey)
* * stickId - String, id of the sticky session
* * identityKeyId - int, id of the identity key used to encrypt the private signature key
* * step - represents the age of the sticky session
* * id - int, id of the key
* * key - encrypted sender key (chainKey || signaturePrivateKey || signaturePublicKey)
* * stickId - String, id of the sticky session
* * identityKeyId - int, id of the identity key used to encrypt the private signature key
* * step - represents the age of the sticky session
*/
public void reinitMyStickySession(String userId, JSONObject senderKey) throws IOException, InvalidKeyException, NoSessionException, JSONException {
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(userId, 0);
Expand Down Expand Up @@ -792,7 +809,7 @@ public String decryptStickyKey(String senderId, String cipher, int identityKeyId
int activeIdentityKeyId = Preferences.getActiveIdentityKeyId(context);
// Swap identity key if needed
if (activeIdentityKeyId != identityKeyId)
swapIdentityKey(identityKeyId);
swapIdentityKey(identityKeyId);
String key = decryptTextPairwise(senderId, true, cipher);
// Reverse identity key back if was swapped
if (activeIdentityKeyId != identityKeyId)
Expand Down Expand Up @@ -825,11 +842,11 @@ public void swapIdentityKey(int keyId) {
*
* @param identityKeyAge - lifetime of an identity key in millis (ex.: TimeUnit.DAYS.toMillis(7))
* @return identity key as a JSONObject containing the following:
* * id - int, id of the identity key
* * public - String, public part of the key
* * cipher - String, private part encrypted
* * salt - String, salt used to encrypt the private part
* * timestamp - Long, unix timestamp
* * id - int, id of the identity key
* * public - String, public part of the key
* * cipher - String, private part encrypted
* * salt - String, salt used to encrypt the private part
* * timestamp - Long, unix timestamp
*/
public JSONObject refreshIdentityKey(long identityKeyAge) throws Exception {
long activeDuration = System.currentTimeMillis() - Preferences.getActiveIdentityKeyTimestamp(context);
Expand Down Expand Up @@ -860,12 +877,12 @@ public JSONObject refreshIdentityKey(long identityKeyAge) throws Exception {
*
* @param signedPreKeyAge - lifetime of a signed prekey in millis (ex.: TimeUnit.DAYS.toMillis(7))
* @return signed prekey as a JSONObject containing the following:
* * id - int, id of the identity key
* * public - String, public part of the key
* * cipher - String, private part encrypted
* * salt - String, salt used to encrypt the private part
* * signature - String
* * timestamp - Long, unix timestamp
* * id - int, id of the identity key
* * public - String, public part of the key
* * cipher - String, private part encrypted
* * salt - String, salt used to encrypt the private part
* * signature - String
* * timestamp - Long, unix timestamp
*/
public JSONObject refreshSignedPreKey(long signedPreKeyAge) throws Exception {
long activeDuration = System.currentTimeMillis() - Preferences.getActiveSignedPreKeyTimestamp(context);
Expand Down Expand Up @@ -1026,8 +1043,8 @@ public byte[] pbDecrypt(String encryptedIvText, String salt, String pass) throws
*
* @param filePath - file to be encrypted
* @return HashMap - contains the following:
* * uri: path of the encrypted file
* * blob secret: (fileKey||fileHash)
* * uri: path of the encrypted file
* * blob secret: (fileKey||fileHash)
*/
public HashMap<String, String> encryptBlob(String filePath) {
try {
Expand Down
2 changes: 1 addition & 1 deletion ios/StickProtocol/StickProtocol.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |spec|


spec.name = "StickProtocol"
spec.version = "1.1.69"
spec.version = "1.1.70"
spec.summary = "End-to-End Encryption protocol for Social Networks based on the Signal Protocol"
spec.swift_version = "5.0"

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.66
version = 1.1.67
description = Stick protocol server for Django.
long_description = file: README.rst
long_description_content_type = text/x-rst
Expand Down
1 change: 1 addition & 0 deletions server/stick_protocol/stick_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def get_standard_sender_keys(self, data, user, group):
key = None
if senderKey:
key = senderKey.key
senderKey.delete()
senderKeys[id] = key
return {'authorized': True, 'senderKeys': senderKeys}

Expand Down

0 comments on commit 510733e

Please sign in to comment.