tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1623695 - /tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
Date Tue, 09 Sep 2014 08:48:42 GMT
Author: markt
Date: Tue Sep  9 08:48:41 2014
New Revision: 1623695

URL: http://svn.apache.org/r1623695
Log:
Switch creation of the SHA-1 digest required to generate a WebSocket upgrade to use the ConcurrentMessageDigest
rather than using a dedicated Queue.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java?rev=1623695&r1=1623694&r2=1623695&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java Tue Sep  9 08:48:41
2014
@@ -18,16 +18,12 @@ package org.apache.tomcat.websocket.serv
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
@@ -40,6 +36,7 @@ import javax.websocket.HandshakeResponse
 import javax.websocket.server.ServerEndpointConfig;
 
 import org.apache.tomcat.util.codec.binary.Base64;
+import org.apache.tomcat.util.security.ConcurrentMessageDigest;
 import org.apache.tomcat.websocket.Constants;
 import org.apache.tomcat.websocket.Transformation;
 import org.apache.tomcat.websocket.TransformationFactory;
@@ -52,8 +49,6 @@ public class UpgradeUtil {
     private static final byte[] WS_ACCEPT =
             "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".getBytes(
                     StandardCharsets.ISO_8859_1);
-    private static final Queue<MessageDigest> sha1Helpers =
-            new ConcurrentLinkedQueue<>();
 
     private UpgradeUtil() {
         // Utility class. Hide default constructor.
@@ -300,19 +295,9 @@ public class UpgradeUtil {
     }
 
 
-    private static String getWebSocketAccept(String key) throws ServletException {
-        MessageDigest sha1Helper = sha1Helpers.poll();
-        if (sha1Helper == null) {
-            try {
-                sha1Helper = MessageDigest.getInstance("SHA1");
-            } catch (NoSuchAlgorithmException e) {
-                throw new ServletException(e);
-            }
-        }
-        sha1Helper.reset();
-        sha1Helper.update(key.getBytes(StandardCharsets.ISO_8859_1));
-        String result = Base64.encodeBase64String(sha1Helper.digest(WS_ACCEPT));
-        sha1Helpers.add(sha1Helper);
-        return result;
+    private static String getWebSocketAccept(String key) {
+        byte[] digest = ConcurrentMessageDigest.digestSHA1(
+                key.getBytes(StandardCharsets.ISO_8859_1), WS_ACCEPT);
+        return Base64.encodeBase64String(digest);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message