Package org.jgroups.protocols
Class ASYM_ENCRYPT
- All Implemented Interfaces:
Lifecycle
Encrypts and decrypts communication in JGroups by using a secret key distributed to all cluster members by the
key server (coordinator) using asymmetric (public/private key) encryption.
The secret key is identical for all cluster members and is used to encrypt messages when sending and decrypt them when receiving messages. This protocol is typically placed under
The current keyserver (always the coordinator) generates a secret key. When a new member joins, it asks the keyserver for the secret key. The keyserver encrypts the secret key with the joiner's public key and the joiner decrypts it with its private key and then installs it and starts encrypting and decrypting messages with the secret key.
View changes that identify a new keyserver will result in a new secret key being generated and then distributed to all cluster members. This overhead can be substantial in an application with a reasonable member churn.
This protocol is suited for an application that does not ship with a known key but instead it is generated and distributed by the keyserver. Since messages can only get encrypted and decrypted when the secret key was received from the keyserver, messages are dropped when the secret key hasn't been installed yet.
The secret key is identical for all cluster members and is used to encrypt messages when sending and decrypt them when receiving messages. This protocol is typically placed under
NAKACK2.The current keyserver (always the coordinator) generates a secret key. When a new member joins, it asks the keyserver for the secret key. The keyserver encrypts the secret key with the joiner's public key and the joiner decrypts it with its private key and then installs it and starts encrypting and decrypting messages with the secret key.
View changes that identify a new keyserver will result in a new secret key being generated and then distributed to all cluster members. This overhead can be substantial in an application with a reasonable member churn.
This protocol is suited for an application that does not ship with a known key but instead it is generated and distributed by the keyserver. Since messages can only get encrypted and decrypted when the secret key was received from the keyserver, messages are dropped when the secret key hasn't been installed yet.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Cipherprotected booleanprotected booleanprotected static final shortprotected KeyExchangeprotected KeyPairprotected Addressprotected booleanprotected static final ThreadLocal<Address> protected booleanFields inherited from class org.jgroups.protocols.Encrypt
asym_algorithm, asym_keylength, cipher_pool_size, decoding_ciphers, DEFAULT_SYM_ALGO, encoding_ciphers, key_map, key_map_max_size, msg_factory, provider, secret_key, secure_random, sym_algorithm, sym_iv_length, sym_keylength, sym_version, viewFields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected MessageaddKeysToMessage(Message msg, boolean copy, boolean add_secret_keys, Address serialize_only) Adds the public and/or encrypted shared keys to the payload of msg.protected ASYM_ENCRYPT.ProcessingaddMetadata(Message msg, boolean add_secret_keys, Address include_secret_key_only_for, boolean attach_fetch_key_header) protected voidcacheGroupKey(byte[] version) Cache the current shared key to decrypt messages encrypted with the old shared group keyprotected static voidprotected voidcreateNewKey(String message) protected SecretKeyInitialise the symmetric key if none is supplied in a keystoreprotected SecretKeySpecdecodeKey(byte[] encodedKey) An event is to be sent down the stack.A message is sent down the stack.protected booleanprotected byte[]encryptSecretKey(Key secret_key, PublicKey public_key) Encrypts the current secret key with the requester's public key (the requester will decrypt it with its private key)protected static Addressbooleanbooleanprotected byte[]booleanprotected voidhandleView(View v) voidinit()Called after a protocol has been created and before the protocol is started.protected voidGenerates the public/private key pair from the init paramsprotected voidinstallPublicKeys(Address sender, byte[] buf, int offset, int length) protected voidinstallSharedGroupKey(Address sender, SecretKey key, byte[] version) booleankeyPair()keyServerAddr(Address ks) protected PublicKeymakePublicKey(byte[] encodedKey) Used to reconstitute public key sent in byte form from peerprotected booleanprocessEncryptMessage(Message msg, EncryptHeader hdr, boolean retval) List of events that are provided to layers below (they will be handled when sent from down below)protected voidremoveKeysFromMessageAndInstall(Message msg, byte[] version) Removes the public and/or private keys from the payload of msg and installs them.protected static ByteArrayserializeKeys(Map<Address, byte[]> keys) protected voidserializeKeys(ByteArrayDataOutputStream out, boolean serialize_shared_keys, Address serialize_only) Serializes all public keys and their corresponding encrypted shared group keys into a buffersetChangeKeyOnCoordLeave(boolean c) setChangeKeyOnLeave(boolean c) Sets the key store entry used to configure this protocol.setUseExternalKeyExchange(boolean u) protected ASYM_ENCRYPT.ProcessingskipDownMessage(Message msg) Processes a message with a GMS header (e.g.protected booleanskipUpMessage(Message msg) Checks if the message contains a public key (and adds it to pub_map if present) or an encrypted group key (and installs it if present)voidstart()This method is called on aJChannel.connect(String); starts work.protected voidunserializeAndInstallKeys(Address sender, byte[] version, ByteArrayDataInputStream in) Unserializes public keys and installs them to pub_map, then reads encrypted shared keys and install our ownunserializeKeys(Address sender, byte[] buf, int offset, int length) An event was received from the protocol below.A single message was received.voidup(MessageBatch batch) Sends up a multiple messages in aMessageBatch.Methods inherited from class org.jgroups.protocols.Encrypt
_decrypt, asymAlgorithm, asymAlgorithm, asymKeylength, asymKeylength, code, createCipher, decrypt, encrypt, getAlgorithm, getModeAndPadding, handleEncryptedMessage, initCipher, initSymCiphers, inView, makeIv, msgFactory, printCachedGroupKeys, secretKey, secureRandom, secureRandom, simIvLength, symAlgorithm, symAlgorithm, symIvLength, symKeyAlgorithm, symKeylength, symKeylength, symVersion, versionMethods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, stop, toString
-
Field Details
-
GMS_ID
protected static final short GMS_ID -
change_key_on_leave
protected boolean change_key_on_leave -
change_key_on_coord_leave
protected boolean change_key_on_coord_leave -
use_external_key_exchange
protected boolean use_external_key_exchange -
key_exchange
-
key_server_addr
-
send_group_keys
protected volatile boolean send_group_keys -
key_pair
-
asym_cipher
-
pub_map
-
srv_addr
-
-
Constructor Details
-
ASYM_ENCRYPT
public ASYM_ENCRYPT()
-
-
Method Details
-
setKeyStoreEntry
Description copied from class:EncryptSets the key store entry used to configure this protocol.- Specified by:
setKeyStoreEntryin classEncrypt<KeyStore.PrivateKeyEntry>- Parameters:
entry- a key store entry
-
getChangeKeyOnLeave
public boolean getChangeKeyOnLeave() -
setChangeKeyOnLeave
-
getChangeKeyOnCoordLeave
public boolean getChangeKeyOnCoordLeave() -
setChangeKeyOnCoordLeave
-
getUseExternalKeyExchange
public boolean getUseExternalKeyExchange() -
setUseExternalKeyExchange
-
keyPair
-
asymCipher
-
keyServerAddr
-
keyServerAddr
-
providedDownServices
Description copied from class:ProtocolList of events that are provided to layers below (they will be handled when sent from down below)- Overrides:
providedDownServicesin classProtocol
-
getPublicKeys
-
getKeyServerAddress
-
isKeyServer
public boolean isKeyServer() -
init
Description copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent. -
start
Description copied from class:ProtocolThis method is called on aJChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top. -
down
Description copied from class:ProtocolAn event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down().- Overrides:
downin classEncrypt<KeyStore.PrivateKeyEntry>
-
down
Description copied from class:ProtocolA message is sent down the stack. Protocols may examine the message and do something (e.g. add a header) with it, before passing it down.- Overrides:
downin classEncrypt<KeyStore.PrivateKeyEntry>
-
up
Description copied from class:ProtocolAn event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally, the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()or c) the event (or another event) is sent up the stack usingup_prot.up().- Overrides:
upin classEncrypt<KeyStore.PrivateKeyEntry>
-
up
Description copied from class:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.- Overrides:
upin classEncrypt<KeyStore.PrivateKeyEntry>
-
up
Description copied from class:ProtocolSends up a multiple messages in aMessageBatch. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages.The default processing below sends messages up the stack individually, based on a matching criteria (calling
Protocol.accept(Message)), and - if true - callsProtocol.up(org.jgroups.Event)for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped.Subclasses should check if there are any messages destined for them (e.g. using
MessageBatch.iterator(Predicate)), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.- Overrides:
upin classEncrypt<KeyStore.PrivateKeyEntry>- Parameters:
batch- The message batch
-
dropMulticastMessageFromNonMember
-
fetchAndSetKeyExchange
-
cacheServerAddress
-
getCachedServerAddress
-
skipDownMessage
Processes a message with a GMS header (e.g. by adding the secret key to a JOIN response) and returns true if the message should be passed down (not encrypted) or false if the message needs to be encrypted- Returns:
- Processing
ASYM_ENCRYPT.Processing.DROPif the message needs to be dropped,ASYM_ENCRYPT.Processing.SKIPif the message needs to be skipped (not encrypted), orASYM_ENCRYPT.Processing.PROCESSif the message needs to be processed (= encrypted)
-
skipUpMessage
Checks if the message contains a public key (and adds it to pub_map if present) or an encrypted group key (and installs it if present) -
processEncryptMessage
-
installPublicKeys
-
addMetadata
protected ASYM_ENCRYPT.Processing addMetadata(Message msg, boolean add_secret_keys, Address include_secret_key_only_for, boolean attach_fetch_key_header) -
addKeysToMessage
protected Message addKeysToMessage(Message msg, boolean copy, boolean add_secret_keys, Address serialize_only) Adds the public and/or encrypted shared keys to the payload of msg. If msg already has a payload, the message will be copied and the new payload consists of the keys and the original payload- Parameters:
msg- The original message- Returns:
- A copy of the message
-
removeKeysFromMessageAndInstall
Removes the public and/or private keys from the payload of msg and installs them. If there is some payload left (the original payload), the offset of the message will be changed. Otherwise, the payload will be nulled, to re-create the original message -
serializeKeys
protected void serializeKeys(ByteArrayDataOutputStream out, boolean serialize_shared_keys, Address serialize_only) throws Exception Serializes all public keys and their corresponding encrypted shared group keys into a buffer- Throws:
Exception
-
unserializeAndInstallKeys
protected void unserializeAndInstallKeys(Address sender, byte[] version, ByteArrayDataInputStream in) Unserializes public keys and installs them to pub_map, then reads encrypted shared keys and install our own -
serializeKeys
- Throws:
Exception
-
unserializeKeys
-
createSecretKey
Initialise the symmetric key if none is supplied in a keystore- Throws:
Exception
-
initKeyPair
Generates the public/private key pair from the init params- Throws:
Exception
-
handleView
- Overrides:
handleViewin classEncrypt<KeyStore.PrivateKeyEntry>
-
createNewKey
-
cacheGroupKey
Cache the current shared key to decrypt messages encrypted with the old shared group key- Throws:
Exception
-
encryptSecretKey
Encrypts the current secret key with the requester's public key (the requester will decrypt it with its private key)- Throws:
Exception
-
decodeKey
- Throws:
Exception
-
makePublicKey
Used to reconstitute public key sent in byte form from peer -
getIv
-