summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2013-01-23 12:10:52 -0600
committerEndi Sukma Dewata <edewata@redhat.com>2013-01-31 02:00:51 -0500
commitae6e575f56917107b2a3de7997bc13e203c2c856 (patch)
treebd970ba33cbea1119e80eae4bea94b9304e9a89a /base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
parentb8ab7e67986e8f801550729fe71dd02b9448a66c (diff)
downloadpki-ticket-474-5.tar.gz
pki-ticket-474-5.tar.xz
pki-ticket-474-5.zip
Session-based nonces.ticket-474-5
Previously nonces were stored in a global map which might not scale well due to some issues: 1. The map uses the nonces as map keys. There were possible nonce collisions which required special handling. 2. The collision handling code was not thread safe. There were possible race conditions during concurrent modifications. 3. The map was shared and size limited. If there were a lot of users using the system, valid nonces could get pruned. 4. The map maps the nonces to client certificates. This limits the possible authentication methods that can be supported. Now the code has been modified such that each user has a private map in the user's session to store the nonces. Additional locking has been implemented to protect against concurrent modifications. The map now uses the target of the operation as the map key, eliminating possible collisions and allowing the use of other authentication methods. Since this is a private map, it's not affected by the number of users using the system. Ticket #474
Diffstat (limited to 'base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java')
-rw-r--r--base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java25
1 files changed, 11 insertions, 14 deletions
diff --git a/base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java b/base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
index 4d0fc38b2..d4785e957 100644
--- a/base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
+++ b/base/common/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Random;
import javax.servlet.ServletException;
@@ -29,7 +30,6 @@ import javax.ws.rs.core.UriInfo;
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
-import com.netscape.certsrv.base.Nonces;
import com.netscape.certsrv.ca.ICertificateAuthority;
import com.netscape.certsrv.cert.CertEnrollmentRequest;
import com.netscape.certsrv.cert.CertRequestInfo;
@@ -54,7 +54,6 @@ public class CertRequestDAO extends CMSRequestDAO {
private IRequestQueue queue;
private ICertificateAuthority ca;
IProfileSubsystem ps;
- private Nonces nonces = null;
private Random random = null;
public static final String ATTR_SERIALNO = "serialNumber";
@@ -65,7 +64,6 @@ public class CertRequestDAO extends CMSRequestDAO {
queue = ca.getRequestQueue();
if (ca.noncesEnabled()) {
random = new Random();
- nonces = ca.getNonces();
}
ps = (IProfileSubsystem) CMS.getSubsystem(IProfileSubsystem.ID);
}
@@ -141,20 +139,19 @@ public class CertRequestDAO extends CMSRequestDAO {
String profileId = request.getExtDataInString("profileId");
IProfile profile = ps.getProfile(profileId);
CertReviewResponse info = CertReviewResponseFactory.create(request, profile, uriInfo, locale);
- if (ca.noncesEnabled()) {
- addNonce(info, servletRequest);
- }
- return info;
- }
- private void addNonce(CertReviewResponse info, HttpServletRequest servletRequest) throws EBaseException {
- if (nonces != null) {
+ if (ca.noncesEnabled()) {
+ // generate nonce
long n = random.nextLong();
- long m = nonces.addNonce(n, Processor.getSSLClientCertificate(servletRequest));
- if ((n + m) != 0) {
- info.setNonce(Long.toString(m));
- }
+
+ // store nonce in session
+ Map<Object, Long> nonces = ca.getNonces(servletRequest, "cert-request");
+ nonces.put(info.getRequestId().toBigInteger(), n);
+
+ // return nonce to client
+ info.setNonce(Long.toString(n));
}
+ return info;
}
/**