Search in sources :

Example 1 with CommandException

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

the class Signer method verify.

private static boolean verify(JReleaserContext context, FilePair filePair) throws SigningException {
    context.getLogger().setPrefix("verify");
    try {
        context.getLogger().debug("{}", context.relativizeToBasedir(filePair.signatureFile));
        GpgCommandSigner commandSigner = initCommandSigner(context);
        return commandSigner.verify(filePair.signatureFile, filePair.inputFile);
    } catch (CommandException e) {
        throw new SigningException(RB.$("ERROR_signing_verify_signature", context.relativizeToBasedir(filePair.inputFile)), e);
    } finally {
        context.getLogger().restorePrefix();
    }
}
Also used : SigningException(org.jreleaser.util.signing.SigningException) GpgCommandSigner(org.jreleaser.util.signing.GpgCommandSigner) CommandException(org.jreleaser.util.command.CommandException)

Example 2 with CommandException

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

the class GpgCommandSigner method sign.

public byte[] sign(byte[] in) throws CommandException {
    try {
        Path input = Files.createTempFile("jreleaser", "sign-input");
        Files.write(input, in, WRITE);
        Path output = Files.createTempDirectory("jreleaser-" + UUID.randomUUID()).resolve(UUID.randomUUID().toString());
        sign(input, output);
        return Files.readAllBytes(output);
    } catch (IOException e) {
        throw new CommandException(RB.$("ERROR_unexpected_error"), e);
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) CommandException(org.jreleaser.util.command.CommandException)

Example 3 with CommandException

use of org.jreleaser.util.command.CommandException 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 4 with CommandException

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

the class DownloadableTool method verify.

private boolean verify(Path executable) {
    Command command = new Command(executable.toString()).arg(properties.getProperty(COMMAND_VERSION));
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        executeCommandCapturing(command, out);
        String verify = properties.getProperty(COMMAND_VERIFY).trim();
        Map<String, Object> props = props();
        verify = resolveTemplate(verify, props);
        Pattern pattern = Pattern.compile(verify);
        return pattern.matcher(out.toString()).find();
    } catch (CommandException e) {
        if (null != e.getCause()) {
            logger.debug(e.getCause().getMessage());
        } else {
            logger.debug(e.getMessage());
        }
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) Command(org.jreleaser.util.command.Command) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandException(org.jreleaser.util.command.CommandException)

Example 5 with CommandException

use of org.jreleaser.util.command.CommandException 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)

Aggregations

CommandException (org.jreleaser.util.command.CommandException)9 Command (org.jreleaser.util.command.Command)5 SigningException (org.jreleaser.util.signing.SigningException)5 CommandExecutor (org.jreleaser.util.command.CommandExecutor)4 Path (java.nio.file.Path)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)1 ToolException (org.jreleaser.sdk.tool.ToolException)1 Upx (org.jreleaser.sdk.tool.Upx)1 GpgCommandSigner (org.jreleaser.util.signing.GpgCommandSigner)1