Search in sources :

Example 1 with CommandExecutor

use of org.jreleaser.util.command.CommandExecutor in project jreleaser by jreleaser.

the class Cosign method signBlob.

public void signBlob(Path keyFile, byte[] password, Path input, Path destinationDir) throws SigningException {
    context.getLogger().info("{}", context.relativizeToBasedir(input));
    ByteArrayInputStream in = new ByteArrayInputStream(password);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Command command = tool.asCommand().arg("sign-blob").arg("--key").arg(keyFile.toAbsolutePath().toString()).arg(input.toAbsolutePath().toString());
    try {
        executeCommand(() -> new CommandExecutor(context.getLogger(), true).executeCommandWithInputCapturing(command, in, out));
    } catch (CommandException e) {
        throw new SigningException(RB.$("ERROR_unexpected_error_signing", input.toAbsolutePath()), e);
    }
    try {
        Path signature = destinationDir.resolve(input.getFileName() + ".sig");
        Files.write(signature, out.toByteArray());
    } catch (IOException e) {
        throw new SigningException(RB.$("ERROR_unexpected_error_signing", input), e);
    }
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) Command(org.jreleaser.util.command.Command) CommandExecutor(org.jreleaser.util.command.CommandExecutor) SigningException(org.jreleaser.util.signing.SigningException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandException(org.jreleaser.util.command.CommandException) IOException(java.io.IOException)

Example 2 with CommandExecutor

use of org.jreleaser.util.command.CommandExecutor in project jreleaser by jreleaser.

the class Cosign method checkPassword.

public boolean checkPassword(Path keyFile, byte[] password) {
    ByteArrayInputStream in = new ByteArrayInputStream(password);
    Command command = tool.asCommand().arg("public-key").arg("--key").arg(keyFile.toAbsolutePath().toString());
    try {
        executeCommand(() -> new CommandExecutor(context.getLogger(), true).executeCommandWithInput(command, in));
        return true;
    } catch (CommandException e) {
        context.getLogger().debug(RB.$("ERROR_password_incorrect"));
    }
    return false;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Command(org.jreleaser.util.command.Command) CommandExecutor(org.jreleaser.util.command.CommandExecutor) CommandException(org.jreleaser.util.command.CommandException)

Example 3 with CommandExecutor

use of org.jreleaser.util.command.CommandExecutor in project jreleaser by jreleaser.

the class Cosign method verifyBlob.

public void verifyBlob(Path keyFile, Path signature, Path input) throws SigningException {
    context.getLogger().debug("{}", context.relativizeToBasedir(signature));
    Command command = tool.asCommand().arg("verify-blob").arg("--key").arg(keyFile.toAbsolutePath().toString()).arg("--signature").arg(signature.toAbsolutePath().toString()).arg(input.toAbsolutePath().toString());
    try {
        executeCommand(() -> new CommandExecutor(context.getLogger(), true).executeCommand(command));
    } catch (CommandException e) {
        throw new SigningException(RB.$("ERROR_signing_verify_signature", context.relativizeToBasedir(signature)), e);
    }
}
Also used : Command(org.jreleaser.util.command.Command) CommandExecutor(org.jreleaser.util.command.CommandExecutor) SigningException(org.jreleaser.util.signing.SigningException) CommandException(org.jreleaser.util.command.CommandException)

Example 4 with CommandExecutor

use of org.jreleaser.util.command.CommandExecutor in project jreleaser by jreleaser.

the class Cosign method generateKeyPair.

public Path generateKeyPair(byte[] password) throws SigningException {
    Command command = tool.asCommand().arg("generate-key-pair");
    Path homeDir = resolveJReleaserHomeDir();
    try {
        executeCommand(() -> new CommandExecutor(context.getLogger(), true).environment("COSIGN_PASSWORD", new String(password)).executeCommand(homeDir, command));
    } catch (CommandException e) {
        throw new SigningException(RB.$("ERROR_unexpected_generate_key_pair"), e);
    }
    context.getLogger().info(RB.$("cosign.generated.keys.at"), homeDir.toAbsolutePath());
    return homeDir.resolve("cosign.key");
}
Also used : Path(java.nio.file.Path) Command(org.jreleaser.util.command.Command) CommandExecutor(org.jreleaser.util.command.CommandExecutor) SigningException(org.jreleaser.util.signing.SigningException) CommandException(org.jreleaser.util.command.CommandException)

Example 5 with CommandExecutor

use of org.jreleaser.util.command.CommandExecutor in project jreleaser by jreleaser.

the class Upx method compress.

public void compress(Path parent, List<String> args) throws CommandException {
    Command command = tool.asCommand().args(args);
    executeCommand(() -> new CommandExecutor(context.getLogger()).executeCommand(parent, command));
}
Also used : Command(org.jreleaser.util.command.Command) CommandExecutor(org.jreleaser.util.command.CommandExecutor)

Aggregations

Command (org.jreleaser.util.command.Command)6 CommandExecutor (org.jreleaser.util.command.CommandExecutor)6 CommandException (org.jreleaser.util.command.CommandException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 SigningException (org.jreleaser.util.signing.SigningException)3 Path (java.nio.file.Path)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1