mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Initial implementation of 'change-key-password' command of SOP-07
This commit is contained in:
parent
618d123a7b
commit
7e1377a28c
9 changed files with 317 additions and 0 deletions
|
@ -8,6 +8,7 @@ import sop.Ready;
|
|||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.external.operation.ArmorExternal;
|
||||
import sop.external.operation.ChangeKeyPasswordExternal;
|
||||
import sop.external.operation.DearmorExternal;
|
||||
import sop.external.operation.DecryptExternal;
|
||||
import sop.external.operation.DetachedSignExternal;
|
||||
|
@ -22,6 +23,7 @@ import sop.external.operation.ListProfilesExternal;
|
|||
import sop.external.operation.RevokeKeyExternal;
|
||||
import sop.external.operation.VersionExternal;
|
||||
import sop.operation.Armor;
|
||||
import sop.operation.ChangeKeyPassword;
|
||||
import sop.operation.Dearmor;
|
||||
import sop.operation.Decrypt;
|
||||
import sop.operation.DetachedSign;
|
||||
|
@ -168,6 +170,11 @@ public class ExternalSOP implements SOP {
|
|||
return new RevokeKeyExternal(binaryName, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeKeyPassword changeKeyPassword() {
|
||||
return new ChangeKeyPasswordExternal(binaryName, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dearmor dearmor() {
|
||||
return new DearmorExternal(binaryName, properties);
|
||||
|
|
57
external-sop/src/main/java/sop/external/operation/ChangeKeyPasswordExternal.java
vendored
Normal file
57
external-sop/src/main/java/sop/external/operation/ChangeKeyPasswordExternal.java
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.external.ExternalSOP;
|
||||
import sop.operation.ChangeKeyPassword;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ChangeKeyPasswordExternal implements ChangeKeyPassword {
|
||||
private final List<String> commandList = new ArrayList<>();
|
||||
private final List<String> envList;
|
||||
|
||||
private int keyPasswordCounter = 0;
|
||||
|
||||
public ChangeKeyPasswordExternal(String binary, Properties environment) {
|
||||
this.commandList.add(binary);
|
||||
this.commandList.add("decrypt");
|
||||
this.envList = ExternalSOP.propertiesToEnv(environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeKeyPassword noArmor() {
|
||||
this.commandList.add("--no-armor");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeKeyPassword oldKeyPassphrase(String oldPassphrase) {
|
||||
this.commandList.add("--old-key-password=@ENV:KEY_PASSWORD_" + keyPasswordCounter);
|
||||
this.envList.add("KEY_PASSWORD_" + keyPasswordCounter + "=" + oldPassphrase);
|
||||
keyPasswordCounter++;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeKeyPassword newKeyPassphrase(String newPassphrase) {
|
||||
this.commandList.add("--new-key-password=@ENV:KEY_PASSWORD_" + keyPasswordCounter);
|
||||
this.envList.add("KEY_PASSWORD_" + keyPasswordCounter + "=" + newPassphrase);
|
||||
keyPasswordCounter++;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ready keys(InputStream inputStream) throws SOPGPException.KeyIsProtected, SOPGPException.BadData {
|
||||
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, inputStream);
|
||||
}
|
||||
}
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import sop.testsuite.operation.RevokeKeyTest;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class ExternalRevokeKeyTest extends RevokeKeyTest {
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue