import-certificate.jsp 5.44 KB
Newer Older
1 2
<%@ page import="org.jivesoftware.util.CertificateManager,
                org.jivesoftware.util.ParamUtils,
3 4
                org.jivesoftware.openfire.XMPPServer,
                org.jivesoftware.openfire.net.SSLConfig,
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                java.io.ByteArrayInputStream,
                java.util.HashMap,
                java.util.Map"
         errorPage="error.jsp"%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

<%--
  Created by IntelliJ IDEA.
  User: gato
  Date: Nov 7, 2006
  Time: 10:03:19 AM
  To change this template use File | Settings | File Templates.
--%>
<% // Get parameters:
    boolean save = ParamUtils.getParameter(request, "save") != null;
    String privateKey = ParamUtils.getParameter(request, "private-key");
    String certificate = ParamUtils.getParameter(request, "certificate");

    Map<String, Object> errors = new HashMap<String, Object>();
    if (save) {
        if (privateKey == null || "".equals(privateKey)) {
            errors.put("privateKey", "privateKey");
        }
        if (certificate == null || "".equals(certificate)) {
            errors.put("certificate", "certificate");
        }
        if (errors.isEmpty()) {
            try {
                // Create an alias for the signed certificate
                String domain = XMPPServer.getInstance().getServerInfo().getName();
                int index = 1;
                String alias = domain + "_" + index;
                while (SSLConfig.getKeyStore().containsAlias(alias)) {
                    index = index + 1;
                    alias = domain + "_" + index;
                }
                // Import certificate
                CertificateManager.installCert(SSLConfig.getKeyStore(), SSLConfig.getTrustStore(),
                        SSLConfig.getKeyPassword(), alias, new ByteArrayInputStream(privateKey.getBytes()),
                        new ByteArrayInputStream(certificate.getBytes()), true, true);
                // Save keystore
                SSLConfig.saveStores();
                response.sendRedirect("ssl-certificates.jsp?importsuccess=true");
                return;
            }
            catch (Exception e) {
                e.printStackTrace();
                errors.put("import", e);
            }
        }
    }
%>

<html>
  <head>
      <title><fmt:message key="ssl.import.certificate.title"/></title>
      <meta name="pageID" content="ssl-certificates"/>
  </head>
  <body>

  <%  if (errors.containsKey("privateKey")) { %>

      <div class="jive-error">
      <table cellpadding="0" cellspacing="0" border="0">
      <tbody>
          <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
          <td class="jive-icon-label">
          <fmt:message key="ssl.import.certificate.error.private-key" />
          </td></tr>
      </tbody>
      </table>
      </div><br>

  <%  } else if (errors.containsKey("certificate")) { %>

      <div class="jive-error">
  <table cellpadding="0" cellspacing="0" border="0">
  <tbody>
      <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
      <td class="jive-icon-label">
      <fmt:message key="ssl.import.certificate.error.certificate" />
      </td></tr>
  </tbody>
  </table>
  </div><br>

  <%  } else if (errors.containsKey("import")) {
          Exception e = (Exception)errors.get("import");
  %>

      <div class="jive-error">
      <table cellpadding="0" cellspacing="0" border="0">
      <tbody>
          <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
          <td class="jive-icon-label">
          <fmt:message key="ssl.import.certificate.error.import" />
          <%  if (e != null && e.getMessage() != null) { %>
              <fmt:message key="ssl.certificates.error_messenge" />: <%= e.getMessage() %>
          <%  } %>
          </td></tr>
      </tbody>
      </table>
      </div><br>
  <% } %>

  <p>
  <fmt:message key="ssl.import.certificate.info" />
  </p>

  <!-- BEGIN 'Import Private Key and Certificate' -->
  <form action="import-certificate.jsp" method="post" name="f">
      <div class="jive-contentBoxHeader">
          <fmt:message key="ssl.import.certificate.boxtitle" />
      </div>
      <div class="jive-contentBox">
          <table cellpadding="3" cellspacing="0" border="0">
          <tbody>
              <tr valign="top">
                  <td width="1%" nowrap class="c1">
                      <fmt:message key="ssl.import.certificate.private-key" />
                  </td>
                  <td width="99%">
                      <textarea name="private-key" cols="60" rows="5" wrap="virtual"></textarea>
                  </td>
              </tr>
              <tr valign="top">
                  <td width="1%" nowrap class="c1">
                      <fmt:message key="ssl.import.certificate.certificate" />
                  </td>
                  <td width="99%">
                      <textarea name="certificate" cols="60" rows="5" wrap="virtual"></textarea>
                  </td>
              </tr>
          </tbody>
          </table>
      </div>
      <input type="submit" name="save" value="<fmt:message key="global.save" />">
  </form>
  <!-- END 'Import Private Key and Certificate' -->

  </body>
</html>