Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for Tomcat 10 #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<property name="name" value="tomcatjss"/>
<property name="version" value="7.6.1"/>
<property name="manifest-version" value="${version}-a1"/>
<property name="tomcat.major-version" value="9" />

<!--
Set the properties that control various build options
Expand All @@ -58,7 +59,7 @@
Set the properties related to the source tree
-->
<exec executable="pwd" failonerror="true" outputproperty="cwd"/>
<property name="src.dir" value="tomcat-9.0"/>
<property name="src.dir" value="tomcat-${tomcat.major-version}.0"/>
<property name="lib.dir" value="lib"/>
<property name="docs.dir" value="docs"/>

Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.50</version>
<version>${project.tomcat.version}</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>9.0.50</version>
<version>${project.tomcat.version}</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tomcatjss-tomcat-9.0</artifactId>
<artifactId>tomcatjss-tomcat-${project.tomcat.majorVersion}.0</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.tomcat.majorVersion>9</project.tomcat.majorVersion>
<project.tomcat.version>9.0.50</project.tomcat.version>
</properties>

<modules>
<module>core</module>
<module>tomcat-9.0</module>
<module>tomcat-${project.tomcat.majorVersion}.0</module>
<module>main</module>
</modules>

Expand Down
52 changes: 52 additions & 0 deletions tomcat-10.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.dogtagpki.tomcatjss</groupId>
<artifactId>tomcatjss-parent</artifactId>
<version>8.5.0-SNAPSHOT</version>
</parent>

<artifactId>tomcatjss-tomcat-10.0</artifactId>
<packaging>jar</packaging>

<dependencies>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>10.1.6</version>
</dependency>

<dependency>
<groupId>org.dogtagpki.jss</groupId>
<artifactId>jss-base</artifactId>
<version>5.5.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tomcatjss-core</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>

</project>
105 changes: 105 additions & 0 deletions tomcat-10.0/src/main/java/org/dogtagpki/tomcat/Http11NioProtocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.dogtagpki.tomcat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.tomcat.util.net.jss.TomcatJSS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Http11NioProtocol extends org.apache.coyote.http11.Http11NioProtocol {

public static Logger logger = LoggerFactory.getLogger(Http11NioProtocol.class);

TomcatJSS tomcatjss = TomcatJSS.getInstance();

public String getCertdbDir() {
return tomcatjss.getCertdbDir();
}

public void setCertdbDir(String certdbDir) {
tomcatjss.setCertdbDir(certdbDir);
}

public String getPasswordClass() {
return tomcatjss.getPasswordClass();
}

public void setPasswordClass(String passwordClass) {
tomcatjss.setPasswordClass(passwordClass);
}

public String getPasswordFile() {
return tomcatjss.getPasswordFile();
}

public void setPasswordFile(String passwordFile) {
tomcatjss.setPasswordFile(passwordFile);
}

public String getServerCertNickFile() {
return tomcatjss.getServerCertNickFile();
}

public void setServerCertNickFile(String serverCertNickFile) {
tomcatjss.setServerCertNickFile(serverCertNickFile);
}

public boolean getEnabledOCSP() {
return tomcatjss.getEnableOCSP();
}

public void setEnableOCSP(boolean enableOCSP) {
tomcatjss.setEnableOCSP(enableOCSP);
}

public String getOcspResponderURL() {
return tomcatjss.getOcspResponderURL();
}

public void setOcspResponderURL(String ocspResponderURL) {
tomcatjss.setOcspResponderURL(ocspResponderURL);
}

public String getOcspResponderCertNickname() {
return tomcatjss.getOcspResponderCertNickname();
}

public void setOcspResponderCertNickname(String ocspResponderCertNickname) {
tomcatjss.setOcspResponderCertNickname(ocspResponderCertNickname);
}

public int getOcspCacheSize() {
return tomcatjss.getOcspCacheSize();
}

public void setOcspCacheSize(int ocspCacheSize) {
tomcatjss.setOcspCacheSize(ocspCacheSize);
}

public int getOcspMinCacheEntryDuration() {
return tomcatjss.getOcspMinCacheEntryDuration();
}

public void setOcspMinCacheEntryDuration(int ocspMinCacheEntryDuration) {
tomcatjss.setOcspMinCacheEntryDuration(ocspMinCacheEntryDuration);
}

public int getOcspMaxCacheEntryDuration() {
return tomcatjss.getOcspMaxCacheEntryDuration();
}

public void setOcspMaxCacheEntryDuration(int ocspMaxCacheEntryDuration) {
tomcatjss.setOcspMaxCacheEntryDuration(ocspMaxCacheEntryDuration);
}

public int getOcspTimeout() {
return tomcatjss.getOcspTimeout();
}

public void setOcspTimeout(int ocspTimeout) {
tomcatjss.setOcspTimeout(ocspTimeout);
}
}
124 changes: 124 additions & 0 deletions tomcat-10.0/src/main/java/org/dogtagpki/tomcat/JSSContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package org.dogtagpki.tomcat;

import java.security.KeyManagementException;
import java.security.SecureRandom;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

import org.apache.tomcat.util.net.jss.TomcatJSS;
import org.mozilla.jss.JSSProvider;
import org.mozilla.jss.provider.javax.crypto.JSSKeyManager;
import org.mozilla.jss.provider.javax.crypto.JSSTrustManager;
import org.mozilla.jss.ssl.javax.JSSEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JSSContext implements org.apache.tomcat.util.net.SSLContext {
public static Logger logger = LoggerFactory.getLogger(JSSContext.class);

private javax.net.ssl.SSLContext ctx;
private String alias;

private JSSKeyManager jkm;
private JSSTrustManager jtm;

public JSSContext(String alias) {
logger.debug("JSSContext(" + alias + ")");
this.alias = alias;

/* These KeyManagers and TrustManagers aren't used with the SSLEngine;
* they're only used to implement certain function calls below. */
try {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("NssX509", "Mozilla-JSS");
jkm = (JSSKeyManager) kmf.getKeyManagers()[0];

TrustManagerFactory tmf = TrustManagerFactory.getInstance("NssX509", "Mozilla-JSS");
jtm = (JSSTrustManager) tmf.getTrustManagers()[0];
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public void init(KeyManager[] kms, TrustManager[] tms, SecureRandom sr) throws KeyManagementException {
logger.debug("JSSContext.init(...)");

try {
String provider = "SunJSSE";
if (JSSProvider.ENABLE_JSSENGINE) {
provider = "Mozilla-JSS";
}

ctx = javax.net.ssl.SSLContext.getInstance("TLS", provider);
ctx.init(kms, tms, sr);
} catch (Exception e) {
throw new KeyManagementException(e.getMessage(), e);
}
}

@Override
public javax.net.ssl.SSLEngine createSSLEngine() {
logger.debug("JSSContext.createSSLEngine()");
javax.net.ssl.SSLEngine eng = ctx.createSSLEngine();

TomcatJSS instance = TomcatJSS.getInstance();

if (eng instanceof JSSEngine) {
JSSEngine j_eng = (JSSEngine) eng;
j_eng.setCertFromAlias(alias);
if(instance != null) {
j_eng.setListeners(instance.getSocketListeners());
}
}

return eng;
}

@Override
public javax.net.ssl.SSLSessionContext getServerSessionContext() {
logger.debug("JSSContext.getServerSessionContext()");
return ctx.getServerSessionContext();
}

@Override
public javax.net.ssl.SSLServerSocketFactory getServerSocketFactory() {
logger.debug("JSSContext.getServerSocketFactory()");
return ctx.getServerSocketFactory();
}

@Override
public javax.net.ssl.SSLParameters getSupportedSSLParameters() {
logger.debug("JSSContext.getSupportedSSLParameters()");
return ctx.getSupportedSSLParameters();
}

@Override
public java.security.cert.X509Certificate[] getCertificateChain(java.lang.String alias) {
logger.debug("JSSContext.getCertificateChain(" + alias + ")");

try {
return jkm.getCertificateChain(alias);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
logger.debug("JSSContext.getAcceptedIssuers()");

try {
return jtm.getAcceptedIssuers();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public void destroy() {
logger.debug("JSSContext.destroy()");
}
}
Loading