Deprecate old signaling key concept

This commit is contained in:
Moxie Marlinspike 2018-12-06 09:19:53 -08:00
parent 05087a833c
commit c2f2146872
2 changed files with 18 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2013 Open WhisperSystems
*
* This program is free software: you can redistribute it and/or modify
@ -42,21 +42,15 @@ public class EncryptedOutgoingMessage {
private static final int MAC_SIZE = 10;
private final byte[] serialized;
private final String serializedAndEncoded;
public EncryptedOutgoingMessage(Envelope outgoingMessage, String signalingKey)
throws CryptoEncodingException
{
byte[] plaintext = outgoingMessage.toByteArray();
SecretKeySpec cipherKey = getCipherKey (signalingKey);
SecretKeySpec macKey = getMacKey(signalingKey);
byte[] plaintext = outgoingMessage.toByteArray();
SecretKeySpec cipherKey = getCipherKey (signalingKey);
SecretKeySpec macKey = getMacKey(signalingKey);
this.serialized = getCiphertext(plaintext, cipherKey, macKey);
this.serializedAndEncoded = Base64.encodeBytes(this.serialized);
}
public String toEncodedString() {
return serializedAndEncoded;
this.serialized = getCiphertext(plaintext, cipherKey, macKey);
}
public byte[] toByteArray() {

View File

@ -31,6 +31,7 @@ import org.whispersystems.websocket.messages.WebSocketResponseMessage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.ws.rs.WebApplicationException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Optional;
@ -111,9 +112,18 @@ public class WebSocketConnection implements DispatchChannel {
final boolean requery)
{
try {
EncryptedOutgoingMessage encryptedMessage = new EncryptedOutgoingMessage(message, device.getSignalingKey());
Optional<byte[]> body = Optional.ofNullable(encryptedMessage.toByteArray());
ListenableFuture<WebSocketResponseMessage> response = client.sendRequest("PUT", "/api/v1/message", null, body);
String header;
Optional<byte[]> body;
if (Util.isEmpty(device.getSignalingKey())) {
header = "X-Signal-Key: false";
body = Optional.ofNullable(message.toByteArray());
} else {
header = "X-Signal-Key: true";
body = Optional.ofNullable(new EncryptedOutgoingMessage(message, device.getSignalingKey()).toByteArray());
}
ListenableFuture<WebSocketResponseMessage> response = client.sendRequest("PUT", "/api/v1/message", Collections.singletonList(header), body);
Futures.addCallback(response, new FutureCallback<WebSocketResponseMessage>() {
@Override