mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-27 12:39:04 +00:00
Rename EncryptedMessage
This commit is contained in:
@@ -14,23 +14,13 @@
|
||||
* 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 org.whispersystems.textsecure.crypto.protocol;
|
||||
package org.whispersystems.textsecure.crypto;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.whispersystems.textsecure.crypto.IdentityKeyPair;
|
||||
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
||||
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.crypto.MessageMac;
|
||||
import org.whispersystems.textsecure.crypto.PublicKey;
|
||||
import org.whispersystems.textsecure.crypto.SessionCipher;
|
||||
import org.whispersystems.textsecure.crypto.SessionCipher.SessionCipherContext;
|
||||
import org.whispersystems.textsecure.crypto.TransportDetails;
|
||||
import org.whispersystems.textsecure.storage.CanonicalRecipientAddress;
|
||||
import org.whispersystems.textsecure.util.Conversions;
|
||||
import org.whispersystems.textsecure.util.Hex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -41,7 +31,7 @@ import java.nio.ByteBuffer;
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
|
||||
public class EncryptedMessage {
|
||||
public class MessageCipher {
|
||||
|
||||
public static final int SUPPORTED_VERSION = 2;
|
||||
public static final int CRADLE_AGREEMENT_VERSION = 2;
|
||||
@@ -65,9 +55,9 @@ public class EncryptedMessage {
|
||||
private final IdentityKeyPair localIdentityKey;
|
||||
private final TransportDetails transportDetails;
|
||||
|
||||
public EncryptedMessage(Context context, MasterSecret masterSecret,
|
||||
IdentityKeyPair localIdentityKey,
|
||||
TransportDetails transportDetails)
|
||||
public MessageCipher(Context context, MasterSecret masterSecret,
|
||||
IdentityKeyPair localIdentityKey,
|
||||
TransportDetails transportDetails)
|
||||
{
|
||||
this.context = context.getApplicationContext();
|
||||
this.masterSecret = masterSecret;
|
||||
@@ -19,10 +19,7 @@ package org.whispersystems.textsecure.crypto;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.spongycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
|
||||
import org.spongycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
|
||||
import org.whispersystems.textsecure.storage.CanonicalRecipientAddress;
|
||||
import org.whispersystems.textsecure.storage.InvalidKeyIdException;
|
||||
import org.whispersystems.textsecure.storage.LocalKeyRecord;
|
||||
@@ -59,7 +56,7 @@ public class SessionCipher {
|
||||
public static final int CIPHER_KEY_LENGTH = 16;
|
||||
public static final int MAC_KEY_LENGTH = 20;
|
||||
|
||||
public static final int ENCRYPTED_MESSAGE_OVERHEAD = EncryptedMessage.HEADER_LENGTH + MessageMac.MAC_LENGTH;
|
||||
public static final int ENCRYPTED_MESSAGE_OVERHEAD = MessageCipher.HEADER_LENGTH + MessageMac.MAC_LENGTH;
|
||||
|
||||
public SessionCipherContext getEncryptionContext(Context context,
|
||||
MasterSecret masterSecret,
|
||||
@@ -309,7 +306,7 @@ public class SessionCipher {
|
||||
IdentityKey remoteIdentityKey = records.getSessionRecord().getIdentityKey();
|
||||
|
||||
if (isInitiallyExchangedKeys(records, localKeyId, remoteKeyId) &&
|
||||
messageVersion >= EncryptedMessage.CRADLE_AGREEMENT_VERSION)
|
||||
messageVersion >= MessageCipher.CRADLE_AGREEMENT_VERSION)
|
||||
{
|
||||
return SharedSecretCalculator.calculateSharedSecret(localKeyPair, localIdentityKey,
|
||||
remoteKey, remoteIdentityKey);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.whispersystems.textsecure.crypto.protocol;
|
||||
|
||||
import org.whispersystems.textsecure.crypto.MessageCipher;
|
||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
||||
import org.whispersystems.textsecure.crypto.InvalidVersionException;
|
||||
@@ -34,14 +35,14 @@ import java.io.IOException;
|
||||
*/
|
||||
public class PreKeyBundleMessage {
|
||||
|
||||
private static final int VERSION_LENGTH = EncryptedMessage.VERSION_LENGTH;
|
||||
private static final int VERSION_LENGTH = MessageCipher.VERSION_LENGTH;
|
||||
private static final int IDENTITY_KEY_LENGTH = IdentityKey.SIZE;
|
||||
public static final int HEADER_LENGTH = IDENTITY_KEY_LENGTH + EncryptedMessage.HEADER_LENGTH;
|
||||
public static final int HEADER_LENGTH = IDENTITY_KEY_LENGTH + MessageCipher.HEADER_LENGTH;
|
||||
|
||||
private static final int VERSION_OFFSET = EncryptedMessage.VERSION_OFFSET;
|
||||
private static final int IDENTITY_KEY_OFFSET = VERSION_OFFSET + EncryptedMessage.VERSION_LENGTH;
|
||||
private static final int PUBLIC_KEY_OFFSET = IDENTITY_KEY_LENGTH + EncryptedMessage.NEXT_KEY_OFFSET;
|
||||
private static final int PREKEY_ID_OFFSET = IDENTITY_KEY_LENGTH + EncryptedMessage.RECEIVER_KEY_ID_OFFSET;
|
||||
private static final int VERSION_OFFSET = MessageCipher.VERSION_OFFSET;
|
||||
private static final int IDENTITY_KEY_OFFSET = VERSION_OFFSET + MessageCipher.VERSION_LENGTH;
|
||||
private static final int PUBLIC_KEY_OFFSET = IDENTITY_KEY_LENGTH + MessageCipher.NEXT_KEY_OFFSET;
|
||||
private static final int PREKEY_ID_OFFSET = IDENTITY_KEY_LENGTH + MessageCipher.RECEIVER_KEY_ID_OFFSET;
|
||||
|
||||
private final byte[] messageBytes;
|
||||
|
||||
@@ -57,9 +58,9 @@ public class PreKeyBundleMessage {
|
||||
this.messageBytes = Base64.decodeWithoutPadding(message);
|
||||
this.messageVersion = Conversions.highBitsToInt(this.messageBytes[VERSION_OFFSET]);
|
||||
|
||||
if (messageVersion > EncryptedMessage.SUPPORTED_VERSION)
|
||||
if (messageVersion > MessageCipher.SUPPORTED_VERSION)
|
||||
throw new InvalidVersionException("Key exchange with version: " + messageVersion +
|
||||
" but we only support: " + EncryptedMessage.SUPPORTED_VERSION);
|
||||
" but we only support: " + MessageCipher.SUPPORTED_VERSION);
|
||||
|
||||
this.supportedVersion = Conversions.lowBitsToInt(messageBytes[VERSION_OFFSET]);
|
||||
this.publicKey = new PublicKey(messageBytes, PUBLIC_KEY_OFFSET);
|
||||
@@ -77,11 +78,11 @@ public class PreKeyBundleMessage {
|
||||
|
||||
public PreKeyBundleMessage(IdentityKey identityKey, byte[] bundledMessage) {
|
||||
try {
|
||||
this.supportedVersion = EncryptedMessage.SUPPORTED_VERSION;
|
||||
this.messageVersion = EncryptedMessage.SUPPORTED_VERSION;
|
||||
this.supportedVersion = MessageCipher.SUPPORTED_VERSION;
|
||||
this.messageVersion = MessageCipher.SUPPORTED_VERSION;
|
||||
this.identityKey = identityKey;
|
||||
this.publicKey = new PublicKey(bundledMessage, EncryptedMessage.NEXT_KEY_OFFSET);
|
||||
this.preKeyId = Conversions.byteArrayToMedium(bundledMessage, EncryptedMessage.RECEIVER_KEY_ID_OFFSET);
|
||||
this.publicKey = new PublicKey(bundledMessage, MessageCipher.NEXT_KEY_OFFSET);
|
||||
this.preKeyId = Conversions.byteArrayToMedium(bundledMessage, MessageCipher.RECEIVER_KEY_ID_OFFSET);
|
||||
this.bundledMessage = bundledMessage;
|
||||
this.messageBytes = new byte[IDENTITY_KEY_LENGTH + bundledMessage.length];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user