Package org.jgroups.protocols
Class Encrypt<E extends KeyStore.Entry>
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.Encrypt<E>
- All Implemented Interfaces:
Lifecycle
- Direct Known Subclasses:
ASYM_ENCRYPT,SYM_ENCRYPT
Super class of symmetric (
SYM_ENCRYPT) and asymmetric (ASYM_ENCRYPT) encryption protocols.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected intprotected intprotected BlockingQueue<Cipher> protected static final Stringprotected BlockingQueue<Cipher> protected Map<AsciiString, Key> protected intprotected MessageFactoryprotected Stringprotected Keyprotected SecureRandomprotected Stringprotected intprotected intprotected byte[]protected 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 Message_decrypt(Cipher cipher, Key key, Message msg, EncryptHeader hdr) asymAlgorithm(String alg) intasymKeylength(int len) protected byte[]code(byte[] buf, int offset, int length, byte[] iv, boolean decode) protected CiphercreateCipher(String algorithm) protected MessageDoes the actual work for decrypting - if version does not match current cipher then tries the previous cipherAn event is to be sent down the stack.A message is sent down the stack.protected Messageprotected static Stringprotected static Stringprotected Objectprotected voidhandleView(View view) voidinit()Called after a protocol has been created and before the protocol is started.protected static voidinitCipher(Cipher cipher, int mode, Key secret_key, byte[] iv) protected voidinitSymCiphers(String algorithm, Key secret) Initialises the ciphers for both encryption and decryption using the generated or supplied secret keyprotected booleanprotected byte[]makeIv()Allows callers to replace secure_random with impl of their choice, e.g.setKeyStoreEntry(E entry) Sets the key store entry used to configure this protocol.intsymAlgorithm(String alg) symIvLength(int len) intsymKeylength(int len) byte[]An event was received from the protocol below.A single message was received.voidup(MessageBatch batch) Sends up a multiple messages in aMessageBatch.version()Methods 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, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, toString
-
Field Details
-
DEFAULT_SYM_ALGO
- See Also:
-
provider
-
asym_algorithm
-
sym_algorithm
-
sym_iv_length
protected int sym_iv_length -
asym_keylength
protected int asym_keylength -
sym_keylength
protected int sym_keylength -
cipher_pool_size
protected int cipher_pool_size -
key_map_max_size
protected int key_map_max_size -
view
-
encoding_ciphers
-
decoding_ciphers
-
sym_version
protected volatile byte[] sym_version -
secret_key
-
key_map
-
secure_random
-
msg_factory
-
-
Constructor Details
-
Encrypt
public Encrypt()
-
-
Method Details
-
setKeyStoreEntry
Sets the key store entry used to configure this protocol.- Parameters:
entry- a key store entry
-
asymKeylength
public int asymKeylength() -
asymKeylength
-
symKeylength
public int symKeylength() -
symKeylength
-
secretKey
-
symAlgorithm
-
symAlgorithm
-
symKeyAlgorithm
-
simIvLength
public int simIvLength() -
symIvLength
-
asymAlgorithm
-
asymAlgorithm
-
symVersion
public byte[] symVersion() -
secureRandom
-
secureRandom
Allows callers to replace secure_random with impl of their choice, e.g. for performance reasons. -
msgFactory
-
version
-
printCachedGroupKeys
-
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. -
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(). -
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. -
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(). -
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. -
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. -
initSymCiphers
Initialises the ciphers for both encryption and decryption using the generated or supplied secret key- Throws:
Exception
-
createCipher
- Throws:
Exception
-
initCipher
protected static void initCipher(Cipher cipher, int mode, Key secret_key, byte[] iv) throws Exception - Throws:
Exception
-
makeIv
protected byte[] makeIv() -
handleEncryptedMessage
- Throws:
Exception
-
handleView
-
inView
-
decrypt
Does the actual work for decrypting - if version does not match current cipher then tries the previous cipher- Throws:
Exception
-
_decrypt
- Throws:
Exception
-
encrypt
- Throws:
Exception
-
code
protected byte[] code(byte[] buf, int offset, int length, byte[] iv, boolean decode) throws Exception - Throws:
Exception
-
getAlgorithm
-
getModeAndPadding
-