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

public abstract class Encrypt<E extends KeyStore.Entry> extends Protocol
Super class of symmetric (SYM_ENCRYPT) and asymmetric (ASYM_ENCRYPT) encryption protocols.
  • Field Details

    • DEFAULT_SYM_ALGO

      protected static final String DEFAULT_SYM_ALGO
      See Also:
    • provider

      protected String provider
    • asym_algorithm

      protected String asym_algorithm
    • sym_algorithm

      protected String 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

      protected volatile View view
    • encoding_ciphers

      protected volatile BlockingQueue<Cipher> encoding_ciphers
    • decoding_ciphers

      protected volatile BlockingQueue<Cipher> decoding_ciphers
    • sym_version

      protected volatile byte[] sym_version
    • secret_key

      protected volatile Key secret_key
    • key_map

      protected Map<AsciiString,Key> key_map
    • secure_random

      protected SecureRandom secure_random
    • msg_factory

      protected MessageFactory msg_factory
  • Constructor Details

    • Encrypt

      public Encrypt()
  • Method Details

    • setKeyStoreEntry

      public abstract <T extends Encrypt<E>> T setKeyStoreEntry(E entry)
      Sets the key store entry used to configure this protocol.
      Parameters:
      entry - a key store entry
    • asymKeylength

      public int asymKeylength()
    • asymKeylength

      public <T extends Encrypt<E>> T asymKeylength(int len)
    • symKeylength

      public int symKeylength()
    • symKeylength

      public <T extends Encrypt<E>> T symKeylength(int len)
    • secretKey

      public Key secretKey()
    • symAlgorithm

      public String symAlgorithm()
    • symAlgorithm

      public <T extends Encrypt<E>> T symAlgorithm(String alg)
    • symKeyAlgorithm

      public String symKeyAlgorithm()
    • simIvLength

      public int simIvLength()
    • symIvLength

      public <T extends Encrypt<E>> T symIvLength(int len)
    • asymAlgorithm

      public String asymAlgorithm()
    • asymAlgorithm

      public <T extends Encrypt<E>> T asymAlgorithm(String alg)
    • symVersion

      public byte[] symVersion()
    • secureRandom

      public SecureRandom secureRandom()
    • secureRandom

      public <T extends Encrypt<E>> T secureRandom(SecureRandom sr)
      Allows callers to replace secure_random with impl of their choice, e.g. for performance reasons.
    • msgFactory

      public <T extends Encrypt<E>> T msgFactory(MessageFactory f)
    • version

      public String version()
    • printCachedGroupKeys

      public String printCachedGroupKeys()
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called 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.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • down

      public Object down(Event evt)
      Description copied from class: Protocol
      An 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 using down_prot.down().
      Overrides:
      down in class Protocol
    • down

      public Object down(Message msg)
      Description copied from class: Protocol
      A 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:
      down in class Protocol
    • up

      public Object up(Event evt)
      Description copied from class: Protocol
      An 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 using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
      Overrides:
      up in class Protocol
    • up

      public Object up(Message msg)
      Description copied from class: Protocol
      A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
      Overrides:
      up in class Protocol
    • up

      public void up(MessageBatch batch)
      Description copied from class: Protocol
      Sends up a multiple messages in a MessageBatch. 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 - calls Protocol.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:
      up in class Protocol
      Parameters:
      batch - The message batch
    • initSymCiphers

      protected void initSymCiphers(String algorithm, Key secret) throws Exception
      Initialises the ciphers for both encryption and decryption using the generated or supplied secret key
      Throws:
      Exception
    • createCipher

      protected Cipher createCipher(String algorithm) throws Exception
      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

      protected Object handleEncryptedMessage(Message msg) throws Exception
      Throws:
      Exception
    • handleView

      protected void handleView(View view)
    • inView

      protected boolean inView(Address sender, String error_msg)
    • decrypt

      protected Message decrypt(Cipher cipher, Message msg) throws Exception
      Does the actual work for decrypting - if version does not match current cipher then tries the previous cipher
      Throws:
      Exception
    • _decrypt

      protected Message _decrypt(Cipher cipher, Key key, Message msg, EncryptHeader hdr) throws Exception
      Throws:
      Exception
    • encrypt

      protected Message encrypt(Message msg) throws Exception
      Throws:
      Exception
    • code

      protected byte[] code(byte[] buf, int offset, int length, byte[] iv, boolean decode) throws Exception
      Throws:
      Exception
    • getAlgorithm

      protected static String getAlgorithm(String s)
    • getModeAndPadding

      protected static String getModeAndPadding(String s)