我m currently having an intense problem.
I can
似乎能够为使用我的servlet的客户创建单独的会话。
我的servlet的关键点在于它为各个会话提供了难以理解的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);
}
我的难以置信的密钥交换
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();
}
}