CVS update: JGroups/src/org/jgroups/protocols ENCRYPT.java
"Bela Ban" <[email protected]>
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/08/17 08:34:11
Modified: src/org/jgroups/protocols ENCRYPT.java
Log:
fixed concurrent access to cipher (https://jira.jboss.org/browse/JGRP-1228)
Revision Changes Path
1.60 +22 -5 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.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- ENCRYPT.java 15 Jun 2010 06:44:35 -0000 1.59
+++ ENCRYPT.java 17 Aug 2010 08:34:11 -0000 1.60
@@ -1,8 +1,9 @@
-// $Id: ENCRYPT.java,v 1.59 2010/06/15 06:44:35 belaban Exp $
+// $Id: ENCRYPT.java,v 1.60 2010/08/17 08:34:11 belaban Exp $
package org.jgroups.protocols;
import org.jgroups.*;
+import org.jgroups.annotations.GuardedBy;
import org.jgroups.annotations.Property;
import org.jgroups.stack.Protocol;
import org.jgroups.util.QueueClosedException;
@@ -23,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;
/**
* ENCRYPT layer. Encrypt and decrypt the group communication in JGroups
@@ -165,8 +168,13 @@
// needed because we do simultaneous encode/decode with these ciphers - which
// would be a threading issue
Cipher symEncodingCipher;
+
+ @GuardedBy("decrypt_lock")
Cipher symDecodingCipher;
+ /** To synchronize access to symDecodingCipher */
+ protected final Lock decrypt_lock=new ReentrantLock();
+
// version filed for secret key
private String symVersion=null;
// dhared secret key to encrypt/decrypt messages
@@ -718,13 +726,22 @@
}
}
- private static Message _decrypt(Cipher cipher, Message msg, boolean decrypt_entire_msg) throws Exception {
+ private Message _decrypt(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());
@@ -920,7 +937,7 @@
* @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);
}
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev