|
From: <pe...@us...> - 2003-12-16 23:17:10
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/signers/servlet
In directory sc8-pr-cvs1:/tmp/cvs-serv31629/src/java/org/neuclear/signers/servlet
Modified Files:
DemoSigningServlet.java SigningServlet.java
Log Message:
Work done on the SigningServlet. The two phase web model is now only an option.
Allowing much quicker signing, using the GuiDialogueAgent.
The screen has also been cleaned up and displays the xml to be signed.
The GuiDialogueAgent now optionally remembers passphrases and has a checkbox to support this.
The PassPhraseAgent's now have a UserCancelsException, which allows the agent to tell the application if the user specifically
cancels the signing process.
Index: DemoSigningServlet.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/signers/servlet/DemoSigningServlet.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** DemoSigningServlet.java 15 Dec 2003 14:38:30 -0000 1.15
--- DemoSigningServlet.java 16 Dec 2003 23:17:06 -0000 1.16
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.16 2003/12/16 23:17:06 pelle
+ * Work done on the SigningServlet. The two phase web model is now only an option.
+ * Allowing much quicker signing, using the GuiDialogueAgent.
+ * The screen has also been cleaned up and displays the xml to be signed.
+ * The GuiDialogueAgent now optionally remembers passphrases and has a checkbox to support this.
+ * The PassPhraseAgent's now have a UserCancelsException, which allows the agent to tell the application if the user specifically
+ * cancels the signing process.
+ *
* Revision 1.15 2003/12/15 14:38:30 pelle
* Added EnsureHostRequestFilter to commons, to only allow requests from a particular IP
***************
*** 179,187 ****
--- 187,198 ----
import org.neuclear.commons.NeuClearException;
+ import org.neuclear.commons.Utility;
import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent;
import org.neuclear.commons.crypto.passphraseagents.ServletPassPhraseAgent;
import org.neuclear.commons.crypto.signers.Signer;
import org.neuclear.commons.crypto.signers.TestCaseSigner;
+ import org.neuclear.commons.crypto.Base64;
import org.neuclear.xml.XMLException;
+ import org.neuclear.id.SignatureRequest;
import javax.servlet.ServletConfig;
***************
*** 210,215 ****
agent.clear();
}
! protected void writePassphraseDialogue(final PrintWriter out) {
out.println("Passphrase: <input name=\"passphrase\" type=\"password\" size=\"40\">");
}
--- 221,238 ----
agent.clear();
}
! protected boolean isReadyToSign(HttpServletRequest request) {
! return !Utility.isEmpty(request.getParameter("sign"));
! }
! protected void printSecondStageForm(HttpServletRequest request, final PrintWriter out, SignatureRequest sigreq, final String endpoint) {
! out.println("<table><tr><td ><h4>Do you wish to sign this?</h4></td></tr>");
! out.print("<tr><td><form action=\"");
! out.print(request.getRequestURL());
! out.print("\" method=\"POST\"><input name=\"neuclear-request\" value=\"");
! out.print(Base64.encode(sigreq.getEncoded().getBytes()));
! out.print("\" type=\"hidden\">\n <input name=\"endpoint\" value=\"");
! out.print(endpoint);
! out.println("\" type=\"hidden\"/>\n");
out.println("Passphrase: <input name=\"passphrase\" type=\"password\" size=\"40\">");
+ out.println(" <input type=\"submit\" name=\"sign\" value=\"Sign\"></form></td></tr></table>");
}
Index: SigningServlet.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/signers/servlet/SigningServlet.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** SigningServlet.java 15 Dec 2003 23:33:05 -0000 1.23
--- SigningServlet.java 16 Dec 2003 23:17:07 -0000 1.24
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.24 2003/12/16 23:17:07 pelle
+ * Work done on the SigningServlet. The two phase web model is now only an option.
+ * Allowing much quicker signing, using the GuiDialogueAgent.
+ * The screen has also been cleaned up and displays the xml to be signed.
+ * The GuiDialogueAgent now optionally remembers passphrases and has a checkbox to support this.
+ * The PassPhraseAgent's now have a UserCancelsException, which allows the agent to tell the application if the user specifically
+ * cancels the signing process.
+ *
* Revision 1.23 2003/12/15 23:33:05 pelle
* added ServletTools.getInitParam() which first tries the ServletConfig, then the context config.
***************
*** 233,236 ****
--- 241,245 ----
import org.neuclear.commons.crypto.Base64;
import org.neuclear.commons.crypto.passphraseagents.GuiDialogAgent;
+ import org.neuclear.commons.crypto.passphraseagents.UserCancelsException;
import org.neuclear.commons.crypto.signers.*;
import org.neuclear.commons.servlets.ServletTools;
***************
*** 254,261 ****
import java.io.FileNotFoundException;
import java.security.GeneralSecurityException;
public class SigningServlet extends XMLInputStreamServlet {
! public final void init(final ServletConfig config) throws ServletException {
super.init(config);
context = config.getServletContext();
--- 263,272 ----
import java.io.FileNotFoundException;
import java.security.GeneralSecurityException;
+ import java.util.regex.Matcher;
+ import java.util.regex.Pattern;
public class SigningServlet extends XMLInputStreamServlet {
! public void init(final ServletConfig config) throws ServletException {
super.init(config);
context = config.getServletContext();
***************
*** 296,332 ****
response.setContentType("text/html");
final PrintWriter out = response.getWriter();
! ServletTools.printHeader(out, request, title);
final String endpoint = request.getParameter("endpoint");
final NamedObjectBuilder named = sigreq.getUnsigned();
boolean isSigned = false;
- if (!Utility.isEmpty(request.getParameter("sign"))) {
- final String parent = NSTools.getSignatoryURI(named.getName());
- out.println("Signing with " + parent + "...");
- out.flush();
- try {
- context.log("SIGN: Signing with " + parent);
- final SignedNamedObject signed = named.sign(signer);
- isSigned = true;
- out.println("Signed<br>");
- out.println("<br>Verifying...");
- out.flush();
- out.println("SIGN: " + signed.getName() + " Verified<br>");
-
- } catch (InvalidNamedObjectException e) {
- System.out.println("<br><font color=\"red\"><b>ERROR: Invalid Identity</b></font><br>");
- out.println("<br><font color=\"red\"><b>ERROR: Invalid Identity</b></font><br>");
- isSigned = false;
- } catch (InvalidPassphraseException e) {
- System.out.println("<br><font color=\"red\"><b>ERROR: Wrong Passphrase</b></font><br>");
- out.println("<br><font color=\"red\"><b>ERROR: Wrong Passphrase</b></font><br>");
- isSigned = false;
- } catch (NonExistingSignerException e) {
- System.out.println("<br><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font><br>");
- out.println("<br><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font><br>");
- isSigned = false;
- }
-
- }
out.println("<table bgcolor=\"#708070\"><tr><td><h4 style=\"color: white\">");
if (isSigned)
--- 307,315 ----
response.setContentType("text/html");
final PrintWriter out = response.getWriter();
! ServletTools.printHeader(out, request, getTitle());
final String endpoint = request.getParameter("endpoint");
final NamedObjectBuilder named = sigreq.getUnsigned();
boolean isSigned = false;
out.println("<table bgcolor=\"#708070\"><tr><td><h4 style=\"color: white\">");
if (isSigned)
***************
*** 343,362 ****
out.println(sigreq.getDescription());
}
!
out.println("</td></tr></table>");
if (!isSigned) {
! out.println("<table><tr><td ><h4>Do you wish to sign this?</h4></td></tr>");
! out.print("<tr><td><form action=\"");
! out.print(request.getRequestURL());
! out.print("\" method=\"POST\"><input name=\"neuclear-request\" value=\"");
! out.print(Base64.encode(sigreq.getEncoded().getBytes()));
! out.print("\" type=\"hidden\">\n <input name=\"endpoint\" value=\"");
! out.print(endpoint);
! out.println("\" type=\"hidden\"/>\n");
! writePassphraseDialogue(out);
! out.println(" <input type=\"submit\" name=\"sign\" value=\"Sign\"></form></td></tr></table>");
} else if (!Utility.isEmpty(endpoint)) {
! out.print("<tr><td>Signed, returning to site...<form action=\"");
out.print(endpoint);
out.print("\" method=\"POST\"><input name=\"neuclear-request\" value=\"");
--- 326,364 ----
out.println(sigreq.getDescription());
}
! out.println("</td></tr><tr><td style=\"background:lightgrey;color:black\"><tt>");
! Matcher matcher=xmlescape.matcher(named.asXML());
! out.println(matcher.replaceAll("<"));
out.println("</td></tr></table>");
+ if (isReadyToSign(request)) {
+ final String parent = NSTools.getSignatoryURI(named.getName());
+
+ out.println("<div id=\"log\" style=\"background:#003;color:#EEE\"><tt><ul><li>Signing with " + parent + "...</li>");
+ out.flush();
+ try {
+ isSigned = sign(named, out);
+
+ } catch (InvalidNamedObjectException e) {
+ // System.out.println("<br><font color=\"red\"><b>ERROR: Invalid Identity</b></font><br>");
+ out.println("<li><font color=\"red\"><b>ERROR: Invalid Identity</b></font></li>");
+ isSigned = false;
+ } catch (UserCancelsException e) {
+ // System.out.println("<br><font color=\"red\"><b>ERROR: User Cancellation</b></font><br>");
+ out.println("<li><font color=\"red\"><b>User Cancellation</b></font></li>");
+ isSigned = false;
+ } catch (NonExistingSignerException e) {
+ // System.out.println("<br><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font><br>");
+ out.println("<li><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font></li>");
+ isSigned = false;
+ }
+ out.println("</ul></tt></div>");
+
+ }
if (!isSigned) {
! printSecondStageForm(request, out, sigreq, endpoint);
} else if (!Utility.isEmpty(endpoint)) {
! out.print("<tr><td>Returning to site: ");
! out.print(endpoint);
! out.print("<form action=\"");
out.print(endpoint);
out.print("\" method=\"POST\"><input name=\"neuclear-request\" value=\"");
***************
*** 376,384 ****
}
! protected void writePassphraseDialogue(final PrintWriter out) {
}
protected javax.servlet.ServletContext context;
private Signer signer;
private String title;
}
--- 378,420 ----
}
! private boolean sign(final NamedObjectBuilder named, final PrintWriter out) throws NeuClearException, XMLException {
! boolean isSigned;
! try {
! context.log("SIGN: Signing with " + signer);
! final SignedNamedObject signed = named.sign(signer);
! isSigned = true;
! out.println("<li>Signed</li>");
! out.println("<li>" + signed.getName() + " Verified</li>");
! out.flush();
! } catch (InvalidPassphraseException e) {
! out.println("<li><font color=\"red\"><b>ERROR: Wrong Passphrase</b></font></li>");
! isSigned = sign(named,out);
! }
! return isSigned;
! }
!
! protected void printSecondStageForm(HttpServletRequest request, final PrintWriter out, SignatureRequest sigreq, final String endpoint) {
! out.println("<table><tr><td ><h4>Do you wish to sign this?</h4></td></tr></table>");
! }
!
! /**
! * Return True when ready to sign.
! * Multirequest signers, need to verify that the correct request parameters are available.
! * @param request
! * @return
! */
! protected boolean isReadyToSign(HttpServletRequest request) {
! return true;
}
+ protected String getTitle() {
+ return title;
+ }
+
+
+
protected javax.servlet.ServletContext context;
private Signer signer;
private String title;
+ static private Pattern xmlescape=Pattern.compile("(\\<)");
}
|