Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Manu review: use signObject() everywhere it can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 7, 2018
1 parent 014599b commit 038dd3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class CryptoTestHelper(val mTestHelper: CommonTestHelper) {
fun createFakeMegolmBackupAuthData(): MegolmBackupAuthData {
return MegolmBackupAuthData(
publicKey = "abcdefg",
signatures = HashMap<String, Any>().apply {
signatures = HashMap<String, Map<String, String>>().apply {
this["something"] = HashMap<String, String>().apply {
this["ed25519:something"] = "hijklmnop"
}
Expand Down
40 changes: 17 additions & 23 deletions matrix-sdk/src/main/java/org/matrix/androidsdk/crypto/MXCrypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -1513,17 +1513,25 @@ public Map<String, Object> encryptMessage(Map<String, Object> payloadFields, Lis

/**
* Sign Object
* // TODO Also use this method internally
* <p>
* Example:
* <pre>
* {
* "[MY_USER_ID]": {
* "ed25519:[MY_DEVICE_ID]": "sign(str)"
* }
* }
* </pre>
*
* @param str
* @return
* @param strToSign the String to sign and to include in the Map
* @return a Map (see example)
*/
public Map<String, Object> signObject(String str) {
Map<String, Object> result = new HashMap<>();
public Map<String, Map<String, String>> signObject(String strToSign) {
Map<String, Map<String, String>> result = new HashMap<>();

Map<String, Object> content = new HashMap<>();
Map<String, String> content = new HashMap<>();

content.put("ed25519:" + mMyDevice.deviceId, mOlmDevice.signMessage(str));
content.put("ed25519:" + mMyDevice.deviceId, mOlmDevice.signMessage(strToSign));

result.put(mMyDevice.userId, content);

Expand Down Expand Up @@ -1864,15 +1872,7 @@ public void run() {
private void uploadDeviceKeys(ApiCallback<KeysUploadResponse> callback) {
// Prepare the device keys data to send
// Sign it
String signature = mOlmDevice.signJSON(mMyDevice.signalableJSONDictionary());

Map<String, String> submap = new HashMap<>();
submap.put("ed25519:" + mMyDevice.deviceId, signature);

Map<String, Map<String, String>> map = new HashMap<>();
map.put(mSession.getMyUserId(), submap);

mMyDevice.signatures = map;
mMyDevice.signatures = signObject(JsonUtils.getCanonicalizedJsonString(mMyDevice.signalableJSONDictionary()));

// For now, we set the device id explicitly, as we may not be using the
// same one as used in login.
Expand Down Expand Up @@ -2156,13 +2156,7 @@ private void uploadOneTimeKeys(final ApiCallback<KeysUploadResponse> callback) {
k.put("key", curve25519Map.get(key_id));

// the key is also signed
String signature = mOlmDevice.signJSON(k);
Map<String, String> submap = new HashMap<>();
submap.put("ed25519:" + mMyDevice.deviceId, signature);

Map<String, Map<String, String>> map = new HashMap<>();
map.put(mSession.getMyUserId(), submap);
k.put("signatures", map);
k.put("signatures", signObject(JsonUtils.getCanonicalizedJsonString(k)));

oneTimeJson.put("signed_curve25519:" + key_id, k);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ public String signMessage(String message) {
return null;
}

/**
* Signs a JSON dictionary with the ed25519 key for this account.
* The signature is done on canonical version of the JSON.
*
* @param JSONDictionary the JSON to be signed.
* @return the base64-encoded signature
*/
public String signJSON(Map<String, Object> JSONDictionary) {
return signMessage(JsonUtils.getCanonicalizedJsonString(JSONDictionary));
}

/**
* @return The current (unused, unpublished) one-time keys for this account.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class MegolmBackupAuthData(
/**
* Signatures of the public key.
*/
val signatures: MutableMap<String, Any>? = null
val signatures: Map<String, Map<String, String>>? = null
) {
/**
* Same as the parent [MXJSONModel JSONDictionary] but return only
Expand Down

0 comments on commit 038dd3f

Please sign in to comment.