mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-30 00:02:06 +01:00
Improvements to SOP
This commit is contained in:
parent
3cd64b61ca
commit
83917f320f
5 changed files with 28 additions and 6 deletions
|
@ -17,10 +17,29 @@ package org.pgpainless.sop;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.pgpainless.util.ArmorUtils;
|
import org.pgpainless.util.ArmorUtils;
|
||||||
|
|
||||||
public class Print {
|
public class Print {
|
||||||
|
|
||||||
|
public static String toString(PGPSecretKeyRing keyRing, boolean armor) throws IOException {
|
||||||
|
if (armor) {
|
||||||
|
return ArmorUtils.toAsciiArmoredString(keyRing);
|
||||||
|
} else {
|
||||||
|
return new String(keyRing.getEncoded(), "UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(PGPPublicKeyRing keyRing, boolean armor) throws IOException {
|
||||||
|
if (armor) {
|
||||||
|
return ArmorUtils.toAsciiArmoredString(keyRing);
|
||||||
|
} else {
|
||||||
|
return new String(keyRing.getEncoded(), "UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String toString(byte[] bytes, boolean armor) throws IOException {
|
public static String toString(byte[] bytes, boolean armor) throws IOException {
|
||||||
if (armor) {
|
if (armor) {
|
||||||
return ArmorUtils.toAsciiArmoredString(bytes);
|
return ArmorUtils.toAsciiArmoredString(bytes);
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class Armor implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try (PushbackInputStream pbIn = new PushbackInputStream(System.in); ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) {
|
try (PushbackInputStream pbIn = new PushbackInputStream(System.in);
|
||||||
|
ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) {
|
||||||
byte[] start = new byte[14];
|
byte[] start = new byte[14];
|
||||||
int read = pbIn.read(start);
|
int read = pbIn.read(start);
|
||||||
pbIn.unread(read);
|
pbIn.unread(read);
|
||||||
|
|
|
@ -105,9 +105,7 @@ public class Encrypt implements Runnable {
|
||||||
for (int i = 0; i < signWith.length; i++) {
|
for (int i = 0; i < signWith.length; i++) {
|
||||||
try (FileInputStream fileIn = new FileInputStream(signWith[i])) {
|
try (FileInputStream fileIn = new FileInputStream(signWith[i])) {
|
||||||
PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(fileIn);
|
PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(fileIn);
|
||||||
signOpt.addInlineSignature(protector, secretKey,
|
signOpt.addInlineSignature(protector, secretKey, parseType(type));
|
||||||
type == Type.text || type == Type.mime ?
|
|
||||||
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT : DocumentSignatureType.BINARY_DOCUMENT);
|
|
||||||
} catch (IOException | PGPException e) {
|
} catch (IOException | PGPException e) {
|
||||||
err_ln("Cannot read secret key from file " + signWith[i].getName());
|
err_ln("Cannot read secret key from file " + signWith[i].getName());
|
||||||
err_ln(e.getMessage());
|
err_ln(e.getMessage());
|
||||||
|
@ -131,4 +129,8 @@ public class Encrypt implements Runnable {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DocumentSignatureType parseType(Type type) {
|
||||||
|
return type == Type.binary ? DocumentSignatureType.BINARY_DOCUMENT : DocumentSignatureType.CANONICAL_TEXT_DOCUMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class ExtractCert implements Runnable {
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(System.in);
|
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(System.in);
|
||||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||||
|
|
||||||
print_ln(Print.toString(publicKeys.getEncoded(), armor));
|
print_ln(Print.toString(publicKeys, armor));
|
||||||
} catch (IOException | PGPException e) {
|
} catch (IOException | PGPException e) {
|
||||||
err_ln("Error extracting certificate from keys;");
|
err_ln("Error extracting certificate from keys;");
|
||||||
err_ln(e.getMessage());
|
err_ln(e.getMessage());
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class GenerateKey implements Runnable {
|
||||||
.withoutPassphrase()
|
.withoutPassphrase()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
print_ln(Print.toString(secretKeys.getEncoded(), armor));
|
print_ln(Print.toString(secretKeys, armor));
|
||||||
|
|
||||||
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | PGPException | IOException e) {
|
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | PGPException | IOException e) {
|
||||||
err_ln("Error creating OpenPGP key:");
|
err_ln("Error creating OpenPGP key:");
|
||||||
|
|
Loading…
Reference in a new issue