Skip to content

Commit

Permalink
Use fake CDSI client.
Browse files Browse the repository at this point in the history
  • Loading branch information
dworkin committed Jul 13, 2024
1 parent fd7a983 commit 3f10734
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.whispersystems.signalservice.api.services;

import org.signal.libsignal.attest.AttestationDataException;
import org.signal.libsignal.sgxsession.SgxCommunicationFailureException;

import java.time.Instant;
import java.util.Arrays;

public class CdsiClient {
public long created;

public CdsiClient(byte[] mrenclave, byte[] attestationMsg, Instant currentInstant) throws AttestationDataException {
if (!Arrays.equals(attestationMsg, "CDSI".getBytes())) {
throw new AttestationDataException("Bad fake");
}

created = currentInstant.toEpochMilli();
}

public byte[] initialRequest() {
return "Client".getBytes();
}

public void completeHandshake(byte[] handshakeResponse) throws SgxCommunicationFailureException {
if (!Arrays.equals(handshakeResponse, "Ready".getBytes())) {
throw new SgxCommunicationFailureException("Bad fake");
}
}

public byte[] establishedSend(byte[] plaintext) {
return plaintext;
}

public byte[] establishedRecv(byte[] ciphertext) {
return ciphertext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.signal.cdsi.proto.ClientRequest;
import org.signal.cdsi.proto.ClientResponse;
import org.signal.libsignal.attest.AttestationDataException;
import org.signal.libsignal.cds2.Cds2Client;
import org.signal.libsignal.protocol.logging.Log;
import org.signal.libsignal.protocol.util.Pair;
import org.signal.libsignal.sgxsession.SgxCommunicationFailureException;
Expand Down Expand Up @@ -58,7 +57,7 @@ final class CdsiSocket {
private final OkHttpClient okhttp;
private final String mrEnclave;

private Cds2Client client;
private CdsiClient client;

CdsiSocket(SignalServiceConfiguration configuration, String mrEnclave) {
this.cdsiUrl = chooseUrl(configuration.getSignalCdsiUrls());
Expand Down Expand Up @@ -116,7 +115,7 @@ public void onMessage(WebSocket webSocket, okio.ByteString bytes) {
throw new IOException("Received a message before we were open!");

case WAITING_FOR_CONNECTION:
client = new Cds2Client(Hex.fromStringCondensed(mrEnclave), bytes.toByteArray(), Instant.now());
client = new CdsiClient(Hex.fromStringCondensed(mrEnclave), bytes.toByteArray(), Instant.now());

Log.d(TAG, "[onMessage] Sending initial handshake...");
webSocket.send(okio.ByteString.of(client.initialRequest()));
Expand Down

0 comments on commit 3f10734

Please sign in to comment.