我m currently having an intense problem.
I can
似乎无法为使用我的 servlet 的客户创建单独的会话。
我的 servlet 的关键在于它为各个会话提供了一个 diffie hellman 密钥交换。这是按预期工作的,但是当另一个用户同时按下添加令牌按钮时。之前生成的值将被覆盖,因此我的服务器一次只能服务一个人。
如何使用我的 diffie hellman servlet 为我的客户创建多个会话?提前致谢。
下面是我的代码片段。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if(null == request.getRequestedSessionId())
{
//create new session
System.out.println("No session id found , generating a new session ID");
session = request.getSession(true);
System.out.println("session id generated is "+session.getId());
@SuppressWarnings("deprecation")
String encodedURL = response.encodeUrl("/MyServletProject/DHServlet");
System.out.println("res.encodeURL(\"/DHServlet\");="+encodedURL);
response.sendRedirect(encodedURL);
return;
}else
{
System.out.println("session id = "+request.getRequestedSessionId());
System.out.println("no redirect required");
}
processRequest(request,response);
}
我的 diffie hellman 密钥交换
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// PrintWriter out2=response.getWriter();
DH getDH = new DH();
try {
System.out.println("Session id requested is "+request.getRequestedSessionId());
long pValue = getDH.getSafePrime();
long gValue = getDH.getGenValue(pValue);
System.out.println("pValue is "+pValue);
System.out.println("gValue us "+gValue);
long serverSK = getDH.generateSKA();
BigInteger safePrimeValue = BigInteger.valueOf(pValue);
BigInteger generatorValue = BigInteger.valueOf(gValue);
System.out.println("the safe Prime is "+safePrimeValue);
System.out.println("the generator value is "+generatorValue);
BigInteger serverPK = getDH.generatePkB(generatorValue, safePrimeValue, serverSK);
// System.out.println(publicKeyFromClient);
String getTimeOnServer = Time.getTime();
String SPValue = safePrimeValue.toString();
String genValue = generatorValue.toString();
String sPublicKey = serverPK.toString();
// long pkFromClient = Long.parseLong(publicKeyFromClient);
//BigInteger pkC = BigInteger.valueOf(pkFromClient);
System.out.println("the erver public key is "+sPublicKey);
out.print("1"+":"+getTimeOnServer+":"+genValue+":"+SPValue+":"+sPublicKey);
pkClient=sPublicKey.toString();
SpValue = SPValue.toString();
sCValue=Long.toString(serverSK);
} finally {
out.close();
}
}