security-truststore.jsp 13.3 KB
Newer Older
1
<%@ page errorPage="error.jsp"%>
2 3
<%@ page import="org.jivesoftware.openfire.keystore.TrustStore"%>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType"%>
4
<%@ page import="org.jivesoftware.util.ParamUtils"%>
5
<%@ page import="java.util.Collections" %>
6 7 8 9
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.security.cert.X509Certificate" %>
10
<%@ page import="org.jivesoftware.openfire.XMPPServer" %>
11
<%@ taglib uri="admin" prefix="admin" %>
12 13
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
14 15 16 17 18 19
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<jsp:useBean id="now" class="java.util.Date"/>
<%  webManager.init(request, response, session, application, out );

20 21 22
    final boolean delete          = ParamUtils.getBooleanParameter( request, "delete" );
    final String alias            = ParamUtils.getParameter( request, "alias" );

23
    final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" );
24 25 26

    final Map<String, String> errors = new HashMap<>();

27
    ConnectionType connectionType = null;
28
    TrustStore trustStore = null;
29 30
    try
    {
31 32
        connectionType = ConnectionType.valueOf( connectionTypeText );
        trustStore = XMPPServer.getInstance().getCertificateStoreManager().getTrustStore( connectionType );
33
        if ( trustStore == null )
34
        {
35
            errors.put( "trustStore", "Unable to get an instance." );
36 37
        }
    }
38
    catch ( RuntimeException ex )
39
    {
40
        errors.put( "connectionType", ex.getMessage() );
41 42 43 44
    }

    if ( errors.isEmpty() )
    {
45
        pageContext.setAttribute( "connectionType", connectionType );
46 47
        pageContext.setAttribute( "trustStore", trustStore );

48
        final Set<ConnectionType> sameStoreConnectionTypes = Collections.EMPTY_SET; // TODO FIXME: SSLConfig.getInstance().getOtherPurposesForSameStore( connectionType );
49
        pageContext.setAttribute( "sameStoreConnectionTypes", sameStoreConnectionTypes );
50

51 52
        final Map<String, X509Certificate> certificates = trustStore.getAllCertificates();
        pageContext.setAttribute( "certificates", certificates );
53

54 55 56 57 58
        if ( delete )
        {
            if ( alias == null )
            {
                errors.put( "alias", "The alias has not been specified." );
59
            }
60 61 62 63
            else
            {
                try
                {
64
                    trustStore.delete( alias );
65 66

                    // Log the event
67 68
                    webManager.logEvent( "deleted SSL cert from " + connectionType + " with alias " + alias, null );
                    response.sendRedirect( "security-keystore.jsp?connectionType=" + connectionType+ "&deletesuccess=true" );
69 70 71 72 73 74
                    return;
                }
                catch ( Exception e )
                {
                    errors.put( "delete", e.getMessage() );
                }
75 76 77
            }
        }
    }
78 79

    pageContext.setAttribute( "errors", errors );
80 81 82
%>

<html>
83
    <head>
84
        <title><fmt:message key="certificate-management.connectionType.${connectionType}.title"/></title>
85 86
        <meta name="pageID" content="security-certificate-store-management"/>
        <meta name="subPageID" content="sidebar-certificate-store-${fn:toLowerCase(connectionType)}-trust-store"/>
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
        <style>
            .info-header {
                background-color: #eee;
                font-size: 10pt;
            }
            .info-table {
                margin-right: 12px;
            }
            .info-table .c1 {
                text-align: right;
                vertical-align: top;
                color: #666;
                font-weight: bold;
                font-size: 9pt;
                white-space: nowrap;
            }
            .info-table .c2 {
                font-size: 9pt;
                width: 90%;
            }
        </style>
    </head>
    <body>
        <c:forEach var="err" items="${errors}">
            <admin:infobox type="error">
                <c:choose>
                    <c:when test="${err.key eq 'type'}">
                        <c:out value="${err.key}"/>
                        <c:if test="${not empty err.value}">
                            : <c:out value="${err.value}"/>
                        </c:if>
                    </c:when>

                    <c:otherwise>
                        <c:out value="${err.key}"/>
                        <c:if test="${not empty err.value}">
                            : <c:out value="${err.value}"/>
                        </c:if>
                    </c:otherwise>
                </c:choose>
            </admin:infobox>
        </c:forEach>

        <c:if test="${param.deletesuccess}">
            <admin:infobox type="success"><fmt:message key="ssl.certificates.deleted"/></admin:infobox>
        </c:if>
        <c:if test="${param.importsuccess}">
            <admin:infobox type="success"><fmt:message key="ssl.certificates.added_updated"/></admin:infobox>
        </c:if>

137
        <c:if test="${connectionType != null}">
138
            <p>
139
                <fmt:message key="certificate-management.connectionType.${connectionType}.description"/>
140 141 142
            </p>

            <table border="0" width="100%">
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
                <tr>
                    <td valign="top" width="60%">
                        <table cellpadding="2" cellspacing="2" border="0" class="info-table">
                            <thead>
                            <tr><th colspan="2" class="info-header">Store Configuration</th></tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td class="c1">File location:</td>
                                <td class="c2"><c:out value="${trustStore.configuration.file}"/></td>
                            </tr>
                            <tr>
                                <td class="c1">Type:</td>
                                <td class="c2"><c:out value="${trustStore.configuration.type}"/></td>
                            </tr>
                            <tr>
                                <td class="c1">Password:</td>
                                <td class="c2"><c:out value="${trustStore.configuration.password}"/></td>
                            </tr>
                            </tbody>
                        </table>
                    </td>
                    <td valign="top" width="40%">
                        <c:if test="${not empty sameStoreConnectionTypes}">
                            <admin:infobox type="info">
                                This store is re-used for these additional purposes. Any changes to this store will also affect that functionality!
                                <ul style="margin-top: 1em;">
                                    <c:forEach var="sameStorePurpose" items="${sameStoreConnectionTypes}">
                                        <li><fmt:message key="certificate-management.connectionType.${sameStorePurpose}.title"/></li>
                                    </c:forEach>
                                </ul>
                            </admin:infobox>
                        </c:if>
                    </td>
                </tr>
178 179 180 181 182
            </table>


            <p>
                <fmt:message key="ssl.certificates.truststore.link-to-import">
183
                    <fmt:param value="<a href='import-truststore-certificate.jsp?connectionType=${connectionType}'>"/>
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
                    <fmt:param value="</a>"/>
                </fmt:message>
            </p>

            <table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
                <thead>
                    <tr>
                        <th>
                            <fmt:message key="ssl.signing-request.organization"/> <small>(<fmt:message key="ssl.certificates.alias"/>)</small>
                        </th>
                        <th width="20%">
                            <fmt:message key="ssl.certificates.valid-between"/>
                        </th>
                        <th>
                            <fmt:message key="ssl.certificates.algorithm"/>
                        </th>
                        <th width="1%">
                            <fmt:message key="global.delete"/>
                        </th>
                    </tr>
                </thead>

                <tbody>
                    <c:choose>
208
                        <c:when test="${empty certificates}">
209 210 211 212 213
                            <tr valign="top">
                                <td colspan="5"><em>(<fmt:message key="global.none"/>)</em></td>
                            </tr>
                        </c:when>
                        <c:otherwise>
214
                            <c:forEach var="certificateEntry" items="${certificates}">
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
                                <c:set var="certificate" value="${certificateEntry.value}"/>
                                <c:set var="alias" value="${certificateEntry.key}"/>

                                <c:set var="organization" value=""/>
                                <c:set var="commonname" value=""/>
                                <c:forEach var="subjectPart" items="${admin:split(certificate.subjectX500Principal.name, '(?<!\\\\\\\\),')}">
                                    <c:set var="keyValue" value="${fn:split(subjectPart, '=')}"/>
                                    <c:set var="key" value="${fn:toUpperCase(keyValue[0])}"/>
                                    <c:set var="value" value="${admin:replaceAll(keyValue[1], '\\\\\\\\(.)', '$1')}"/>
                                    <c:choose>
                                        <c:when test="${key eq 'O'}">
                                            <c:set var="organization" value="${organization} ${value}"/>
                                        </c:when>
                                        <c:when test="${key eq 'CN'}">
                                            <c:set var="commonname" value="${value}"/>
                                        </c:when>
                                    </c:choose>
                                </c:forEach>

                                <tr valign="top">
                                    <td>
236
                                        <a href="security-certificate-details.jsp?connectionType=${connectionType}&alias=${alias}&isTrustStore=true" title="<fmt:message key='session.row.cliked'/>">
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
                                            <c:choose>
                                                <c:when test="${empty fn:trim(organization)}">
                                                    <c:out value="${commonname}"/>
                                                </c:when>
                                                <c:otherwise>
                                                    <c:out value="${organization}"/>
                                                </c:otherwise>
                                            </c:choose>
                                        </a>
                                        <small>(<c:out value="${alias}"/>)</small>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${certificate.notAfter lt now or certificate.notBefore gt now}">
                                        <span style="color: red;">
                                            <fmt:formatDate type="DATE" dateStyle="MEDIUM" value="${certificate.notBefore}"/>
                                            -
                                            <fmt:formatDate type="DATE" dateStyle="MEDIUM" value="${certificate.notAfter}"/>
                                        </span>
                                            </c:when>
                                            <c:otherwise>
                                        <span>
                                            <fmt:formatDate type="DATE" dateStyle="MEDIUM" value="${certificate.notBefore}"/>
                                            -
                                            <fmt:formatDate type="DATE" dateStyle="MEDIUM" value="${certificate.notAfter}"/>
                                        </span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td width="2%">
                                        <c:out value="${certificate.publicKey.algorithm}"/>
                                    </td>
                                    <td width="1" align="center">
270
                                        <a href="security-truststore.jsp?connectionType=${connectionType}&alias=${alias}&delete=true"
271 272 273 274 275 276 277 278 279 280 281 282
                                           title="<fmt:message key="global.click_delete"/>"
                                           onclick="return confirm('<fmt:message key="ssl.certificates.confirm_delete"/>');"
                                                ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:otherwise>
                    </c:choose>
                </tbody>
            </table>
        </c:if>
    </body>
283
</html>