mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Added helper method for generating signed PreKeys.
This commit is contained in:
parent
f0c22d593f
commit
0a23b5fcd5
@ -16,7 +16,6 @@ import org.whispersystems.libaxolotl.state.SessionRecord;
|
||||
import org.whispersystems.libaxolotl.state.SessionState;
|
||||
import org.whispersystems.libaxolotl.state.SessionStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.util.Hex;
|
||||
import org.whispersystems.libaxolotl.util.KeyHelper;
|
||||
import org.whispersystems.libaxolotl.util.Medium;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
@ -2,9 +2,11 @@ package org.whispersystems.libaxolotl.util;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
@ -87,4 +89,22 @@ public class KeyHelper {
|
||||
return new PreKeyRecord(Medium.MAX_VALUE, keyPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a signed PreKey
|
||||
*
|
||||
* @param identityKeyPair The local client's identity key pair.
|
||||
* @param signedPreKeyId The PreKey id to assign the generated signed PreKey
|
||||
*
|
||||
* @return the generated signed PreKey
|
||||
* @throws InvalidKeyException when the provided identity key is invalid
|
||||
*/
|
||||
public static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair, int signedPreKeyId)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
ECKeyPair keyPair = Curve.generateKeyPair(true);
|
||||
byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
|
||||
|
||||
return new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user