Class OmemoKeyUtil<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_ECPub,T_Bundle>
java.lang.Object
org.jivesoftware.smackx.omemo.util.OmemoKeyUtil<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_ECPub,T_Bundle>
- Type Parameters:
T_IdKeyPair- IdentityKeyPair classT_IdKey- IdentityKey classT_PreKey- PreKey classT_SigPreKey- SignedPreKey classT_Sess- Session classT_ECPub- Elliptic Curve PublicKey classT_Bundle- Bundle class
- Direct Known Subclasses:
SignalOmemoKeyUtil
public abstract class OmemoKeyUtil<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_ECPub,T_Bundle>
extends Object
Class that is used to convert bytes to keys and vice versa.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intaddInBounds(int value, int added) Add integers modulo MAX_VALUE.abstract T_BundlebundleFromOmemoBundle(OmemoBundleElement bundle, OmemoDevice contact, int keyId) Build a crypto-lib specific PreKeyBundle (T_Bundle) using a PreKey from the OmemoBundleElement 'bundle'.abstract T_ECPubellipticCurvePublicKeyFromBytes(byte[] data) Deserialize an elliptic curve public key from bytes.abstract T_IdKeyPairGenerate a new IdentityKeyPair.generateOmemoPreKeys(int startId, int count) Generate 'count' new PreKeys beginning with id 'startId'.abstract T_SigPreKeygenerateOmemoSignedPreKey(T_IdKeyPair identityKeyPair, int signedPreKeyId) Generate a new signed preKey.abstract OmemoFingerprintgetFingerprintOfIdentityKey(T_IdKey identityKey) Return the fingerprint of an identityKey.abstract OmemoFingerprintgetFingerprintOfIdentityKeyPair(T_IdKeyPair identityKeyPair) Returns the fingerprint of the public key of an identityKeyPair.abstract byte[]identityKeyForBundle(T_IdKey identityKey) Prepare an identityKey for transport in an OmemoBundleElement (serialize it).abstract T_IdKeyidentityKeyFromBytes(byte[] data) Deserialize an identityKey from a byte array.abstract T_IdKeyExtract the public identityKey from an identityKeyPair.abstract T_IdKeyPairidentityKeyPairFromBytes(byte[] data) Deserialize an identityKeyPair from a byte array.abstract byte[]identityKeyPairToBytes(T_IdKeyPair identityKeyPair) serialize an identityKeyPair into bytes.abstract byte[]identityKeyToBytes(T_IdKey identityKey) Serialize an identityKey into bytes.abstract byte[]preKeyForBundle(T_PreKey preKey) Prepare a preKey for transport in an OmemoBundleElement.abstract T_PreKeypreKeyFromBytes(byte[] bytes) Deserialize a preKey from a byte array.preKeyPublicFromBytes(byte[] data) Deserialize a public preKey from bytes.abstract byte[]preKeyPublicKeyForBundle(T_ECPub preKey) Prepare an elliptic curve preKey for transport in an OmemoBundleElement.preKeyPublicKeysForBundle(Map<Integer, T_PreKey> preKeyHashMap) Prepare a whole bunche of preKeys for transport.abstract byte[]preKeyToBytes(T_PreKey preKey) Serialize a preKey into a byte array.abstract T_SessrawSessionFromBytes(byte[] data) Deserialize a raw OMEMO Session from bytes.abstract byte[]rawSessionToBytes(T_Sess session) Serialize a raw OMEMO session into a byte array.abstract T_SigPreKeysignedPreKeyFromBytes(byte[] data) Deserialize a signedPreKey from a byte array.abstract intsignedPreKeyIdFromKey(T_SigPreKey signedPreKey) return the id of the given signedPreKey.abstract byte[]signedPreKeyPublicForBundle(T_SigPreKey signedPreKey) Prepare a public signedPreKey for transport in a bundle.signedPreKeyPublicFromBytes(byte[] data) Deserialize a public signedPreKey from bytes.abstract byte[]signedPreKeySignatureFromKey(T_SigPreKey signedPreKey) Extract the signature from a signedPreKey.abstract byte[]signedPreKeyToBytes(T_SigPreKey sigPreKey) Serialize a signedPreKey into a byte array.
-
Field Details
-
BUNDLE
public final OmemoKeyUtil<T_IdKeyPair,T_IdKey, BUNDLET_PreKey, T_SigPreKey, T_Sess, T_ECPub, T_Bundle>.Bundle
-
-
Constructor Details
-
OmemoKeyUtil
public OmemoKeyUtil()
-
-
Method Details
-
identityKeyPairFromBytes
Deserialize an identityKeyPair from a byte array.- Parameters:
data- byte array- Returns:
- IdentityKeyPair (T_IdKeyPair)
- Throws:
CorruptedOmemoKeyException- if the key is damaged of malformed
-
identityKeyFromBytes
Deserialize an identityKey from a byte array.- Parameters:
data- byte array- Returns:
- identityKey (T_IdKey)
- Throws:
CorruptedOmemoKeyException- if the key is damaged or malformed
-
identityKeyToBytes
Serialize an identityKey into bytes.- Parameters:
identityKey- idKey- Returns:
- byte array representation of the identity key.
-
ellipticCurvePublicKeyFromBytes
public abstract T_ECPub ellipticCurvePublicKeyFromBytes(byte[] data) throws CorruptedOmemoKeyException Deserialize an elliptic curve public key from bytes.- Parameters:
data- bytes- Returns:
- elliptic curve public key (T_ECPub)
- Throws:
CorruptedOmemoKeyException- if the key is damaged or malformed
-
preKeyPublicFromBytes
Deserialize a public preKey from bytes.- Parameters:
data- preKey as bytes- Returns:
- deserialized preKey
- Throws:
CorruptedOmemoKeyException- if the key is damaged or malformed
-
preKeyToBytes
Serialize a preKey into a byte array.- Parameters:
preKey- preKey- Returns:
- byte[]
-
preKeyFromBytes
Deserialize a preKey from a byte array.- Parameters:
bytes- byte array- Returns:
- deserialized preKey
- Throws:
IOException- when something goes wrong
-
generateOmemoPreKeys
Generate 'count' new PreKeys beginning with id 'startId'. These preKeys are published and can be used by contacts to establish sessions with us.- Parameters:
startId- start idcount- how many keys do we want to generate- Returns:
- Map of new preKeys
-
generateOmemoSignedPreKey
public abstract T_SigPreKey generateOmemoSignedPreKey(T_IdKeyPair identityKeyPair, int signedPreKeyId) throws CorruptedOmemoKeyException Generate a new signed preKey.- Parameters:
identityKeyPair- identityKeyPair used to sign the preKeysignedPreKeyId- id that the preKey will have- Returns:
- deserialized signed preKey
- Throws:
CorruptedOmemoKeyException- when the identityKeyPair is invalid
-
signedPreKeyPublicFromBytes
Deserialize a public signedPreKey from bytes.- Parameters:
data- bytes- Returns:
- deserialized signed preKey
- Throws:
CorruptedOmemoKeyException- if the key is damaged or malformed
-
signedPreKeyFromBytes
Deserialize a signedPreKey from a byte array.- Parameters:
data- byte array- Returns:
- deserialized signed preKey
- Throws:
IOException- when something goes wrong
-
signedPreKeyToBytes
Serialize a signedPreKey into a byte array.- Parameters:
sigPreKey- signedPreKey- Returns:
- byte array
-
bundleFromOmemoBundle
public abstract T_Bundle bundleFromOmemoBundle(OmemoBundleElement bundle, OmemoDevice contact, int keyId) throws CorruptedOmemoKeyException Build a crypto-lib specific PreKeyBundle (T_Bundle) using a PreKey from the OmemoBundleElement 'bundle'. The PreKeyBundle will contain the identityKey, signedPreKey and signature, as well as a preKey from the OmemoBundleElement.- Parameters:
bundle- OmemoBundleElementcontact- Contact that the bundle belongs tokeyId- id of the preKey that will be selected from the OmemoBundleElement and that the PreKeyBundle will contain- Returns:
- PreKeyBundle (T_PreKey)
- Throws:
CorruptedOmemoKeyException- if some key is damaged or malformed
-
signedPreKeySignatureFromKey
Extract the signature from a signedPreKey.- Parameters:
signedPreKey- signedPreKey- Returns:
- signature as byte array
-
generateOmemoIdentityKeyPair
Generate a new IdentityKeyPair. We should always have only one pair and usually keep this for a long time.- Returns:
- deserialized identity key pair
-
signedPreKeyIdFromKey
return the id of the given signedPreKey.- Parameters:
signedPreKey- key- Returns:
- id of the key
-
identityKeyPairToBytes
serialize an identityKeyPair into bytes.- Parameters:
identityKeyPair- identityKeyPair- Returns:
- byte array
-
identityKeyFromPair
Extract the public identityKey from an identityKeyPair.- Parameters:
pair- keyPair- Returns:
- public key of the pair
-
identityKeyForBundle
Prepare an identityKey for transport in an OmemoBundleElement (serialize it).- Parameters:
identityKey- identityKey that will be transported- Returns:
- key as byte array
-
preKeyPublicKeyForBundle
Prepare an elliptic curve preKey for transport in an OmemoBundleElement.- Parameters:
preKey- key- Returns:
- key as byte array
-
preKeyForBundle
Prepare a preKey for transport in an OmemoBundleElement.- Parameters:
preKey- preKey- Returns:
- key as byte array
-
preKeyPublicKeysForBundle
Prepare a whole bunche of preKeys for transport.- Parameters:
preKeyHashMap- HashMap of preKeys- Returns:
- HashMap of byte arrays but with the same keyIds as key
-
signedPreKeyPublicForBundle
Prepare a public signedPreKey for transport in a bundle.- Parameters:
signedPreKey- signedPreKey- Returns:
- signedPreKey as byte array
-
getFingerprintOfIdentityKey
Return the fingerprint of an identityKey.- Parameters:
identityKey- identityKey- Returns:
- fingerprint of the key
-
getFingerprintOfIdentityKeyPair
Returns the fingerprint of the public key of an identityKeyPair.- Parameters:
identityKeyPair- IdentityKeyPair.- Returns:
- fingerprint of the public key.
-
rawSessionFromBytes
Deserialize a raw OMEMO Session from bytes.- Parameters:
data- bytes- Returns:
- raw OMEMO Session
- Throws:
IOException- when something goes wrong
-
rawSessionToBytes
Serialize a raw OMEMO session into a byte array.- Parameters:
session- raw session- Returns:
- byte array
-
addInBounds
Add integers modulo MAX_VALUE.- Parameters:
value- base integeradded- value that is added to the base value- Returns:
- (value plus added) modulo Integer.MAX_VALUE
-