mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
SOP: Allow for multiple user-ids during key generation
This commit is contained in:
parent
8e3b61b76e
commit
fb1c0d6ff3
1 changed files with 40 additions and 2 deletions
|
@ -18,10 +18,20 @@ package org.pgpainless.sop.commands;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
|
import org.pgpainless.algorithm.KeyFlag;
|
||||||
|
import org.pgpainless.key.generation.KeyRingBuilderInterface;
|
||||||
|
import org.pgpainless.key.generation.KeySpec;
|
||||||
|
import org.pgpainless.key.generation.type.KeyType;
|
||||||
|
import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
|
||||||
|
import org.pgpainless.key.generation.type.xdh.XDHCurve;
|
||||||
import org.pgpainless.sop.Print;
|
import org.pgpainless.sop.Print;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
@ -37,12 +47,40 @@ public class GenerateKey implements Runnable {
|
||||||
boolean armor = true;
|
boolean armor = true;
|
||||||
|
|
||||||
@CommandLine.Parameters(description = "User-ID, eg. \"Alice <alice@example.com>\"")
|
@CommandLine.Parameters(description = "User-ID, eg. \"Alice <alice@example.com>\"")
|
||||||
String userId;
|
List<String> userId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing(userId);
|
KeyRingBuilderInterface.WithAdditionalUserIdOrPassphrase builder = PGPainless.generateKeyRing()
|
||||||
|
.withSubKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
|
.withKeyFlags(KeyFlag.SIGN_DATA)
|
||||||
|
.withDefaultAlgorithms())
|
||||||
|
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
|
||||||
|
.withKeyFlags(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE)
|
||||||
|
.withDefaultAlgorithms())
|
||||||
|
.withPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
|
.withKeyFlags(KeyFlag.CERTIFY_OTHER)
|
||||||
|
.withDefaultAlgorithms())
|
||||||
|
.withPrimaryUserId(userId.get(0));
|
||||||
|
|
||||||
|
if (userId.isEmpty()) {
|
||||||
|
print_ln("At least one user-id expected.");
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < userId.size(); i++) {
|
||||||
|
builder.withAdditionalUserId(userId.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
|
calendar.add(Calendar.YEAR, 3);
|
||||||
|
Date expiration = calendar.getTime();
|
||||||
|
|
||||||
|
PGPSecretKeyRing secretKeys = builder.setExpirationDate(expiration)
|
||||||
|
.withoutPassphrase()
|
||||||
|
.build();
|
||||||
|
|
||||||
print_ln(Print.toString(secretKeys.getEncoded(), armor));
|
print_ln(Print.toString(secretKeys.getEncoded(), armor));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue