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

[WFCORE-7033] signature verification #6222

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class ModelDescriptionConstants {
public static final String CAPABILITY_REFERENCE = "capability-reference";
public static final String CAPABILITY_REFERENCE_PATTERN_ELEMENTS = "capability-reference-pattern-elements";
public static final String CAPABILITY_REGISTRY = "capability-registry";
public static final String CERTIFICATE_INFO = "certificate-info";
public static final String CHILD_TYPE = "child-type";
public static final String CHILDREN = "children";
public static final String CLASSIFICATION = "classification";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<module name="org.jboss.as.domain-http-interface" />
<module name="org.jboss.modules" />
<module name="org.wildfly.security.manager" />
<module name="org.jboss.xnio"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.core.instmgr;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTACHED_STREAMS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILESYSTEM_PATH;
import static org.wildfly.core.instmgr.InstMgrConstants.CERTIFICATE_CONTENT;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.core.instmgr.logging.InstMgrLogger;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;

/**
* Operation handler to import a certificate used to validate components installed during updates.
* The certificate has to be an ASCII-armored PGP public certificate.
*/
public class InstMgrCertificateImportHandler extends InstMgrOperationStepHandler {
public static final String OPERATION_NAME = "certificate-import";

protected static final AttributeDefinition CERT_FILE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.CERT_FILE, ModelType.INT)
.setStorageRuntime()
.setRequired(false)
.addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE)
.addArbitraryDescriptor(ATTACHED_STREAMS, ModelNode.TRUE)
.build();
protected static final AttributeDefinition CERT_CONTENT = SimpleAttributeDefinitionBuilder.create(CERTIFICATE_CONTENT, ModelType.STRING)
.setStorageRuntime()
.setRequired(false)
.build();

public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER)
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setReplyType(ModelType.OBJECT)
.setRuntimeOnly()
.setReplyValueType(ModelType.OBJECT)
.addParameter(CERT_FILE)
.build();

InstMgrCertificateImportHandler(InstMgrService imService, InstallationManagerFactory imf) {
super(imService, imf);
}

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
try {
Path serverHome = imService.getHomeDir();
MavenOptions mavenOptions = new MavenOptions(null, false);
InstallationManager installationManager = imf.create(serverHome, mavenOptions);

final Integer streamIndex = CERT_FILE.resolveModelAttribute(context, operation).asIntOrNull();
final String certificateContent = CERT_CONTENT.resolveModelAttribute(context, operation).asStringOrNull();

if (streamIndex != null && certificateContent != null) {
throw InstMgrLogger.ROOT_LOGGER.mutuallyExclusiveOptions(CERT_FILE.getName(), CERT_CONTENT.getName());
}

if (streamIndex != null) {
try (InputStream is = context.getAttachmentStream(streamIndex)) {
installationManager.acceptTrustedCertificates(is);
}
} else if (certificateContent != null) {
try (InputStream is = new ByteArrayInputStream(certificateContent.getBytes(StandardCharsets.UTF_8))) {
installationManager.acceptTrustedCertificates(is);
}
} else {
// throw exception
}
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, OperationContext.Stage.RUNTIME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.core.instmgr;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTACHED_STREAMS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILESYSTEM_PATH;
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_DESCRIPTION;
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_FINGERPRINT;
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_KEY_ID;
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_STATUS;

import java.io.InputStream;
import java.nio.file.Path;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.TrustCertificate;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;

/**
* Operation handler to parse the certificate file and read the certificate information. Expects am ASCII-armored PGP public key.
*/
public class InstMgrCertificateParseHandler extends InstMgrOperationStepHandler {
public static final String OPERATION_NAME = "certificate-parse";

protected static final AttributeDefinition CERT_FILE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.CERT_FILE, ModelType.INT)
.setStorageRuntime()
.setRequired(true)
.addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE)
.addArbitraryDescriptor(ATTACHED_STREAMS, ModelNode.TRUE)
.build();

public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER)
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setReplyType(ModelType.OBJECT)
.setRuntimeOnly()
.setReplyValueType(ModelType.OBJECT)
.addParameter(CERT_FILE)
.build();

InstMgrCertificateParseHandler(InstMgrService imService, InstallationManagerFactory imf) {
super(imService, imf);
}

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
try {
Path serverHome = imService.getHomeDir();
MavenOptions mavenOptions = new MavenOptions(null, false);
InstallationManager installationManager = imf.create(serverHome, mavenOptions);

try (InputStream is = context.getAttachmentStream(CERT_FILE.resolveModelAttribute(context, operation).asInt())) {
final TrustCertificate tc = installationManager.parseCertificate(is);

final ModelNode entry = new ModelNode();
entry.get(CERT_KEY_ID).set(tc.getKeyID());
entry.get(CERT_FINGERPRINT).set(tc.getFingerprint());
entry.get(CERT_DESCRIPTION).set(tc.getDescription());
entry.get(CERT_STATUS).set(tc.getStatus());
context.getResult().set(entry);
}
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, OperationContext.Stage.RUNTIME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.core.instmgr;

import static org.wildfly.core.instmgr.InstMgrConstants.CERT_KEY_ID;

import java.nio.file.Path;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;

/**
* Operation handler to remove one of imported component certificates. The certificate is identified by it's ID (in hex format).
* Once the certificate is removed, the user will have to re-import it to apply and updates including a component
* signed by that certificate.
*/
public class InstMgrCertificateRemoveHandler extends InstMgrOperationStepHandler {
public static final String OPERATION_NAME = "certificate-remove";

protected static final AttributeDefinition KEY_ID = SimpleAttributeDefinitionBuilder.create(CERT_KEY_ID, ModelType.STRING)
.setStorageRuntime()
.setRequired(true)
.build();

public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER)
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setReplyType(ModelType.OBJECT)
.setRuntimeOnly()
.setReplyValueType(ModelType.OBJECT)
.addParameter(KEY_ID)
.build();

InstMgrCertificateRemoveHandler(InstMgrService imService, InstallationManagerFactory imf) {
super(imService, imf);
}

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String keyId = KEY_ID.resolveModelAttribute(context, operation).asString();
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
try {
Path serverHome = imService.getHomeDir();
MavenOptions mavenOptions = new MavenOptions(null, false);
InstallationManager installationManager = imf.create(serverHome, mavenOptions);

installationManager.revokeTrustedCertificate(keyId);
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, OperationContext.Stage.RUNTIME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public interface InstMgrConstants {
Path PREPARED_SERVER_SUBPATH = Paths.get("installation-manager")
.resolve("prepared-server");

String CERT_DESCRIPTION = "description";
String CERT_FINGERPRINT = "fingerprint";
String CERT_KEY_ID = "key-id";
String CERT_STATUS = "status";
String CERT_FILE = "cert-file";
String CERTIFICATE = "certificate";
String CERTIFICATE_CONTENT = "certificate-content";
String CERTIFICATES = "certificates";
String CHANNEL = "channel";
String CHANNELS = "channels";
String CHANNEL_NAME = "name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.wildfly.core.instmgr.logging.InstMgrLogger;
import org.wildfly.installationmanager.ArtifactChange;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.MissingSignatureException;
import org.wildfly.installationmanager.Repository;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;
Expand Down Expand Up @@ -177,6 +178,8 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo
throw new OperationFailedException(e.getLocalizedMessage());
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (MissingSignatureException e) {
throw InstMgrLogger.ROOT_LOGGER.componentSignedWithUnknownCertificate(e.getDescription(), e);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jboss.dmr.ModelType;
import org.wildfly.core.instmgr.logging.InstMgrLogger;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.MissingSignatureException;
import org.wildfly.installationmanager.Repository;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;
Expand Down Expand Up @@ -147,6 +148,8 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
throw new OperationFailedException(e.getLocalizedMessage());
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (MissingSignatureException e) {
throw InstMgrLogger.ROOT_LOGGER.componentSignedWithUnknownCertificate(e.getDescription(), e);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jboss.dmr.ModelType;
import org.wildfly.core.instmgr.logging.InstMgrLogger;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.MissingSignatureException;
import org.wildfly.installationmanager.Repository;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;
Expand Down Expand Up @@ -189,6 +190,8 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
throw new OperationFailedException(e.getLocalizedMessage());
} catch (OperationFailedException | RuntimeException e) {
throw e;
} catch (MissingSignatureException e) {
throw InstMgrLogger.ROOT_LOGGER.componentSignedWithUnknownCertificate(e.getDescription(), e);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Loading
Loading