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

Use Vert.x as the basis for all HTTP #3506

Merged
merged 1 commit into from
Aug 17, 2019
Merged
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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
displayName: 'Maven Build'
inputs:
goals: 'install'
options: '-B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-dynamodb -Ddynamodb-local.port=8000 -Dnative-image.xmx=6g -Dnative -Dno-format'
options: '-B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-dynamodb -Ddynamodb-local.port=8000 -Dnative-image.xmx=6g -Dnative -Dno-format'

- job: Windows_Build
timeoutInMinutes: 60
Expand Down
68 changes: 37 additions & 31 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
<opentracing-tracerresolver.version>0.1.5</opentracing-tracerresolver.version>
<opentracing-concurrent.version>0.2.0</opentracing-concurrent.version>
<jaeger.version>0.34.0</jaeger.version>
<undertow.version>2.0.23.Final</undertow.version>
<xnio.version>3.7.2.Final</xnio.version>
<quarkus-http.version>3.0.0.Alpha2</quarkus-http.version>
<jboss-servlet-api_4.0_spec.version>1.0.0.Final</jboss-servlet-api_4.0_spec.version>
<microprofile-config-api.version>1.3</microprofile-config-api.version>
<microprofile-context-propagation.version>1.0-RC1</microprofile-context-propagation.version>
Expand Down Expand Up @@ -152,6 +151,7 @@
<!-- Used for integration tests, to make sure webjars work-->
<bootstrap.version>3.1.0</bootstrap.version>
<keycloak.version>6.0.1</keycloak.version>
<quarkus-keycloak.version>1.0.0.Alpha1</quarkus-keycloak.version>
<subethasmtp.version>3.1.7</subethasmtp.version>
<hibernate-quarkus-local-cache.version>0.1.0</hibernate-quarkus-local-cache.version>
<kogito.version>0.2.0</kogito.version>
Expand All @@ -160,6 +160,7 @@
<flapdoodle.mongo.version>2.2.0</flapdoodle.mongo.version>
<wiremock.version>2.23.2</wiremock.version>
<spring.version>5.1.8.RELEASE</spring.version>
<mvel2.version>2.4.4.Final</mvel2.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -843,14 +844,31 @@
<version>${tika.version}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>${undertow.version}</version>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-core</artifactId>
<version>${quarkus-http.version}</version>
</dependency>

<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${undertow.version}</version>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-vertx-backend</artifactId>
<version>${quarkus-http.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-core</artifactId>
<version>${quarkus-http.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-servlet</artifactId>
<version>${quarkus-http.version}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.annotation</groupId>
Expand All @@ -859,9 +877,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
<version>${undertow.version}</version>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-websockets-jsr</artifactId>
<version>${quarkus-http.version}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.annotation</groupId>
Expand Down Expand Up @@ -1473,23 +1491,6 @@
<artifactId>arc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
<version>${xnio.version}</version>
<exclusions>
<exclusion>
<groupId>org.wildfly.client</groupId>
<artifactId>wildfly-client-config</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<version>${xnio.version}</version>
</dependency>

<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
Expand Down Expand Up @@ -2042,9 +2043,9 @@
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-undertow-adapter</artifactId>
<version>${keycloak.version}</version>
<groupId>io.quarkus.keycloak</groupId>
<artifactId>quarkus-keycloak-adapter</artifactId>
<version>${quarkus-keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
Expand Down Expand Up @@ -2100,6 +2101,11 @@
<artifactId>jbpm-flow</artifactId>
<version>${kogito.version}</version>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>${mvel2.version}</version>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>jbpm-bpmn2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.SmallRyeConfig;

Expand All @@ -35,12 +36,12 @@ private static void handleObject(String prefix, Object o, SmallRyeConfig config)

try {
Class cls = o.getClass();
if (!cls.getName().endsWith("Config")) {
if (!cls.getName().endsWith("Config") && !cls.getName().endsWith("Configuration")) {
return;
}
for (Field field : cls.getFields()) {
for (Field field : cls.getDeclaredFields()) {
ConfigItem configItem = field.getDeclaredAnnotation(ConfigItem.class);
if (configItem == null) {
if (configItem == null || field.getType().isAnnotationPresent(ConfigGroup.class)) {
Object newInstance = field.getType().newInstance();
field.set(o, newInstance);
handleObject(prefix + "." + dashify(field.getName()), newInstance, config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
package io.quarkus.runtime.configuration.ssl;

import static java.lang.Math.min;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509ExtendedKeyManager;

import org.jboss.logging.Logger;
import org.wildfly.common.iteration.CodePointIterator;
import org.wildfly.security.pem.Pem;
import org.wildfly.security.pem.PemEntry;
import org.wildfly.security.ssl.CipherSuiteSelector;
import org.wildfly.security.ssl.Protocol;
import org.wildfly.security.ssl.ProtocolSelector;
import org.wildfly.security.ssl.SSLContextBuilder;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
Expand All @@ -50,163 +20,13 @@ public class ServerSslConfig {
* The cipher suites to use. If none is given, a reasonable default is selected.
*/
@ConfigItem
public Optional<CipherSuiteSelector> cipherSuites;
public List<String> cipherSuites;

/**
* The list of protocols to explicitly enable.
*/
@DefaultConverter
@ConfigItem(defaultValue = "TLSv1.3,TLSv1.2")
public List<Protocol> protocols;

/**
* The SSL provider name to use. If none is given, the platform default is used.
*/
@ConfigItem
public Optional<String> providerName;

/**
* The SSL session cache size. If not given, the platform default is used.
*/
@ConfigItem
public OptionalInt sessionCacheSize;

/**
* The SSL session cache timeout. If not given, the platform default is used.
*/
@ConfigItem
public Optional<Duration> sessionTimeout;

/**
* Get an {@code SSLContext} for this server configuration.
*
* @return the {@code SSLContext}, or {@code null} if SSL should not be configured
* @throws GeneralSecurityException if something failed in the context setup
*/
public SSLContext toSSLContext() throws GeneralSecurityException, IOException {
//TODO: static fields break config
Logger log = Logger.getLogger("io.quarkus.configuration.ssl");
final Optional<Path> certFile = certificate.file;
final Optional<Path> keyFile = certificate.keyFile;
final Optional<Path> keyStoreFile = certificate.keyStoreFile;
final String keystorePassword = certificate.keyStorePassword;
final KeyStore keyStore;
if (certFile.isPresent() && keyFile.isPresent()) {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, keystorePassword.toCharArray());
final Path certPath = certFile.get();
final Iterator<PemEntry<?>> certItr = Pem.parsePemContent(load(certPath));
final ArrayList<X509Certificate> certList = new ArrayList<>();
while (certItr.hasNext()) {
final PemEntry<?> item = certItr.next();
final X509Certificate cert = item.tryCast(X509Certificate.class);
if (cert != null) {
certList.add(cert);
} else {
log.warnf("Ignoring non-certificate in certificate file \"%s\" (the type was %s)", certPath,
item.getEntry().getClass());
}
}
if (certList.isEmpty()) {
log.warnf("No certificate found in file \"%s\"", certPath);
}
final Path keyPath = keyFile.get();
final Iterator<PemEntry<?>> keyItr = Pem.parsePemContent(load(keyPath));
final PrivateKey privateKey;
for (;;) {
if (!keyItr.hasNext()) {
log.warnf("No key found in file \"%s\"", keyPath);
return null;
}
final PemEntry<?> next = keyItr.next();
final PrivateKey entryKey = next.tryCast(PrivateKey.class);
if (entryKey != null) {
privateKey = entryKey;
break;
}
log.warnf("Ignoring non-key in key file \"%s\" (the type was %s)", keyPath, next.getEntry().getClass());
}
if (keyItr.hasNext()) {
log.warnf("Ignoring extra content in key file \"%s\"", keyPath);
}
//Entry password needs to match the keystore password
keyStore.setEntry("default", new KeyStore.PrivateKeyEntry(privateKey, certList.toArray(new X509Certificate[0])),
new KeyStore.PasswordProtection(keystorePassword.toCharArray()));
} else if (keyStoreFile.isPresent()) {
final Path keyStorePath = keyStoreFile.get();
final Optional<String> keyStoreFileType = certificate.keyStoreFileType;
final String type;
if (keyStoreFileType.isPresent()) {
type = keyStoreFileType.get();
} else {
final String pathName = keyStorePath.toString();
if (pathName.endsWith(".jks")) {
type = "jks";
} else if (pathName.endsWith(".jceks")) {
type = "jceks";
} else if (pathName.endsWith(".p12") || pathName.endsWith(".pkcs12") || pathName.endsWith(".pfx")) {
type = "pkcs12";
} else {
// not sure, just guess
type = "jks";
}
}
keyStore = KeyStore.getInstance(type);

final InputStream keystoreAsResource = this.getClass().getClassLoader()
.getResourceAsStream(keyStorePath.toString());

if (keystoreAsResource != null) {
try (InputStream is = keystoreAsResource) {
keyStore.load(is, null);
}
} else {
try (InputStream is = Files.newInputStream(keyStorePath)) {
keyStore.load(is, null);
}
}

} else {
return null;
}
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keystorePassword.toCharArray());
final SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.setCipherSuiteSelector(cipherSuites.orElse(CipherSuiteSelector.openSslDefault()));
ProtocolSelector protocolSelector;
if (protocols.isEmpty()) {
protocolSelector = ProtocolSelector.defaultProtocols();
} else {
protocolSelector = ProtocolSelector.empty().add(protocols.toArray(new Protocol[0]));
}
sslContextBuilder.setProtocolSelector(protocolSelector);
sslContextBuilder.setKeyManager((X509ExtendedKeyManager) keyManagerFactory.getKeyManagers()[0]);
if (sessionCacheSize.isPresent()) {
sslContextBuilder.setSessionCacheSize(sessionCacheSize.getAsInt());
}
if (sessionTimeout.isPresent()) {
sslContextBuilder.setSessionTimeout((int) min(Integer.MAX_VALUE, sessionTimeout.get().getSeconds()));
}
if (providerName.isPresent()) {
sslContextBuilder.setProviderName(providerName.get());
}
return sslContextBuilder.build().create();
}
public List<String> protocols;

static CodePointIterator load(final Path path) throws IOException {
final int size = Math.toIntExact(Files.size(path));
char[] chars = new char[size];
int c = 0;
try (InputStream is = Files.newInputStream(path)) {
try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
while (c < size) {
final int res = isr.read(chars, c, size - c);
if (res == -1)
break;
c += res;
}
}
}
return CodePointIterator.ofChars(chars, 0, c);
}
}
4 changes: 2 additions & 2 deletions core/test-extension/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
12 changes: 2 additions & 10 deletions core/test-extension/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,8 @@
<artifactId>svm</artifactId>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
<groupId>io.quarkus.http</groupId>
<artifactId>quarkus-http-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Loading