Skip to content

Commit

Permalink
Add MLS api calls to WireAPI
Browse files Browse the repository at this point in the history
* Add some more MLS operations to CryptoMlsClient
* Fix type in protocol names
  • Loading branch information
spoonman01 committed Oct 31, 2024
1 parent 03b3cf7 commit b3be442
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 4 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>src/main/kotlin</source>
<source>target/generated-sources</source>
</sourceDirs>
</configuration>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/wire/xenon/WireAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wire.xenon;

import com.wire.xenon.assets.IAsset;
import com.wire.xenon.backend.KeyPackageUpdate;
import com.wire.xenon.backend.models.ClientUpdate;
import com.wire.xenon.backend.models.Conversation;
import com.wire.xenon.backend.models.QualifiedId;
import com.wire.xenon.backend.models.User;
Expand Down Expand Up @@ -55,4 +57,10 @@ public interface WireAPI {
boolean hasDevice(QualifiedId userId, String clientId);

void acceptConnection(QualifiedId user) throws Exception;

boolean isMlsEnabled(); // Calls GET /mls/public-keys and GET /feature-configs, checking if MLS is enabled on the backend

void uploadClientPublicKey(String clientId, ClientUpdate clientUpdate); // Calls PUT /clients/{clientId}

void uploadClientKeyPackages(String clientId, KeyPackageUpdate keyPackageUpdate); // Calls POST /mls/key-packages/self{client}
}
2 changes: 1 addition & 1 deletion src/main/java/com/wire/xenon/WireClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.wire.xenon.backend.models.QualifiedId;
import com.wire.xenon.backend.models.User;
import com.wire.xenon.crypto.Crypto;
import com.wire.xenon.crypto.mls.CryptoMlsClient;
import com.wire.xenon.crypto.CryptoMlsClient;
import com.wire.xenon.exceptions.HttpException;
import com.wire.xenon.models.AssetKey;
import com.wire.xenon.models.otr.*;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/wire/xenon/backend/KeyPackageUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

package com.wire.xenon.backend;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class KeyPackageUpdate {
@JsonProperty("key_packages")
public List<String> keyPackages;
}
43 changes: 43 additions & 0 deletions src/main/java/com/wire/xenon/backend/models/ClientUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

package com.wire.xenon.backend.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClientUpdate {
@JsonProperty("mls_public_keys")
public MlsPublicKeys mlsPublicKeys;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class MlsPublicKeys {
@JsonProperty("ecdsa_secp256r1_sha256")
public String ecdsaSecp256r1Sha256;
@JsonProperty("ecdsa_secp256r1_sha384")
public String ecdsaSecp256r1Sha384;
@JsonProperty("ecdsa_secp256r1_sha512")
public String ecdsaSecp256r1Sha512;
@JsonProperty("ed25519")
public String ed25519;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public class Conversation {
public enum Protocol {
@JsonProperty("proteus") PROTEUS,
@JsonProperty("mls") MLS,
@JsonProperty("mized") MIXED
@JsonProperty("mixed") MIXED
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.wire.xenon.crypto.mls
package com.wire.xenon.crypto

import com.wire.crypto.client.ClientId
import com.wire.crypto.client.CoreCryptoCentral
import com.wire.crypto.client.MLSClient
import com.wire.crypto.client.MLSGroupId
import com.wire.crypto.client.MlsMessage
import com.wire.crypto.client.Welcome
import kotlinx.coroutines.runBlocking
import java.io.Closeable
import java.util.*
Expand Down Expand Up @@ -35,7 +36,19 @@ class CryptoMlsClient : Closeable {
return decryptedMessage.message
}

// TODO handle conversation marked as complete, after both welcomeMessage and member-join events have been received
// https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/563053166/Use+case+being+added+to+a+conversation+MLS
fun welcomeMessage(welcome: ByteArray): ByteArray? {
val welcomeBundle = runBlocking { mlsClient.processWelcomeMessage(Welcome(welcome)) }
return welcomeBundle.id.value
}

fun validKeyPackageCount(): Long {
val decryptedMessage = runBlocking { mlsClient.validKeyPackageCount() }
return decryptedMessage.toLong()
}

override fun close() {
runBlocking { cryptoCentral.close() }
}
}
}

0 comments on commit b3be442

Please sign in to comment.