Class Encrypt<E extends java.security.KeyStore.Entry>

    • Field Detail

      • DEFAULT_SYM_ALGO

        protected static final java.lang.String DEFAULT_SYM_ALGO
        See Also:
        Constant Field Values
      • provider

        protected java.lang.String provider
      • asym_algorithm

        protected java.lang.String asym_algorithm
      • sym_algorithm

        protected java.lang.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 java.util.concurrent.BlockingQueue<javax.crypto.Cipher> encoding_ciphers
      • decoding_ciphers

        protected volatile java.util.concurrent.BlockingQueue<javax.crypto.Cipher> decoding_ciphers
      • sym_version

        protected volatile byte[] sym_version
      • secret_key

        protected volatile java.security.Key secret_key
      • key_map

        protected java.util.Map<AsciiString,​java.security.Key> key_map
      • secure_random

        protected java.security.SecureRandom secure_random
    • Constructor Detail

      • Encrypt

        public Encrypt()
    • Method Detail

      • 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 java.security.Key secretKey()
      • symAlgorithm

        public java.lang.String symAlgorithm()
      • symAlgorithm

        public <T extends Encrypt<E>> T symAlgorithm​(java.lang.String alg)
      • symKeyAlgorithm

        public java.lang.String symKeyAlgorithm()
      • simIvLength

        public int simIvLength()
      • symIvLength

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

        public java.lang.String asymAlgorithm()
      • asymAlgorithm

        public <T extends Encrypt<E>> T asymAlgorithm​(java.lang.String alg)
      • symVersion

        public byte[] symVersion()
      • secureRandom

        public java.security.SecureRandom secureRandom()
      • secureRandom

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

        public java.lang.String version()
      • printCachedGroupKeys

        public java.lang.String printCachedGroupKeys()
      • init

        public void init()
                  throws java.lang.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:
        java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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​(java.lang.String algorithm,
                                      java.security.Key secret)
                               throws java.lang.Exception
        Initialises the ciphers for both encryption and decryption using the generated or supplied secret key
        Throws:
        java.lang.Exception
      • createCipher

        protected javax.crypto.Cipher createCipher​(java.lang.String algorithm)
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • initCipher

        protected static void initCipher​(javax.crypto.Cipher cipher,
                                         int mode,
                                         java.security.Key secret_key,
                                         byte[] iv)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • makeIv

        protected byte[] makeIv()
      • handleEncryptedMessage

        protected java.lang.Object handleEncryptedMessage​(Message msg)
                                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • handleView

        protected void handleView​(View view)
      • inView

        protected boolean inView​(Address sender,
                                 java.lang.String error_msg)
      • decrypt

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

        protected Message _decrypt​(javax.crypto.Cipher cipher,
                                   java.security.Key key,
                                   Message msg,
                                   EncryptHeader hdr)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encrypt

        protected Message encrypt​(Message msg)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • code

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

        protected static java.lang.String getAlgorithm​(java.lang.String s)
      • getModeAndPadding

        protected static java.lang.String getModeAndPadding​(java.lang.String s)