CVS update: JGroups/src/org/jgroups/protocols ENCRYPT.java

"Dennis Reed" <[email protected]>
Newsgroups gmane.comp.java.javagroups.cvs
Message-ID <[email protected]>
  User: dereed  
  Date: 10/08/26 19:09:07

  Modified:    src/org/jgroups/protocols Tag: JGroups_2_6_13_GA_JGRP-1228
                        ENCRYPT.java
  Log:
  [JBPAPP-4948] Port JGRP-1228/JBPAPP-4947 to EAP 5.0
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.38.4.1.4.1 +19 -6     JGroups/src/org/jgroups/protocols/ENCRYPT.java
  
  Index: ENCRYPT.java
  ===================================================================
  RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/protocols/ENCRYPT.java,v
  retrieving revision 1.38.4.1
  retrieving revision 1.38.4.1.4.1
  diff -u -r1.38.4.1 -r1.38.4.1.4.1
  --- ENCRYPT.java	12 Mar 2008 07:28:27 -0000	1.38.4.1
  +++ ENCRYPT.java	26 Aug 2010 19:09:07 -0000	1.38.4.1.4.1
  @@ -1,4 +1,4 @@
  -// $Id: ENCRYPT.java,v 1.38.4.1 2008/03/12 07:28:27 belaban Exp $
  +// $Id: ENCRYPT.java,v 1.38.4.1.4.1 2010/08/26 19:09:07 dereed Exp $
   
   package org.jgroups.protocols;
   
  @@ -24,6 +24,8 @@
   import java.util.concurrent.BlockingQueue;
   import java.util.concurrent.LinkedBlockingQueue;
   import java.util.concurrent.TimeUnit;
  +import java.util.concurrent.locks.Lock;
  +import java.util.concurrent.locks.ReentrantLock;
   
   
   /**
  @@ -159,6 +161,8 @@
       /** determines whether to encrypt the entire message, or just the buffer */
       private boolean encrypt_entire_message=false;
   
  +    /** To prevent concurrent access to the decrypting cypher */
  +    protected final Lock decrypt_lock=new ReentrantLock();
   
       public ENCRYPT()
       {
  @@ -843,13 +847,22 @@
       }
   
   
  -    private static Message _decrypt(Cipher cipher, Message msg, boolean decrypt_entire_msg) throws Exception {
  +    private Message _decrypt(final Cipher cipher, Message msg, boolean decrypt_entire_msg) throws Exception {
  +        byte[] decrypted_msg;
  +
  +        decrypt_lock.lock();
  +        try {
  +            decrypted_msg=cipher.doFinal(msg.getRawBuffer(), msg.getOffset(), msg.getLength());
  +        }
  +        finally {
  +            decrypt_lock.unlock();
  +        }
  +
           if(!decrypt_entire_msg) {
  -            msg.setBuffer(cipher.doFinal(msg.getRawBuffer(), msg.getOffset(), msg.getLength()));
  +            msg.setBuffer(decrypted_msg);
               return msg;
           }
   
  -        byte[] decrypted_msg=cipher.doFinal(msg.getRawBuffer(), msg.getOffset(), msg.getLength());
           Message ret=(Message)Util.streamableFromByteBuffer(Message.class, decrypted_msg);
           if(ret.getDest() == null)
               ret.setDest(msg.getDest());
  @@ -1093,13 +1106,13 @@
        * @return
        * @throws Exception
        */
  -    private static byte[] encryptMessage(Cipher cipher, byte[] plain, int offset, int length) throws Exception
  +    private synchronized byte[] encryptMessage(Cipher cipher, byte[] plain, int offset, int length) throws Exception
       {
           return cipher.doFinal(plain, offset, length);
       }
   
   
  -    private SecretKeySpec decodeKey(byte[] encodedKey) throws Exception
  +    private synchronized SecretKeySpec decodeKey(byte[] encodedKey) throws Exception
       {
           // try and decode secrey key sent from keyserver
           byte[] keyBytes = asymCipher.doFinal(encodedKey);
  
  
  

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.