mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Adapt latest pgpainless changes
This commit is contained in:
parent
920817b257
commit
e7c2181516
2 changed files with 23 additions and 5 deletions
|
@ -149,7 +149,6 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
@Override
|
@Override
|
||||||
public byte[] sign(SignElement element, OpenPgpV4Fingerprint signingKeyFingerprint)
|
public byte[] sign(SignElement element, OpenPgpV4Fingerprint signingKeyFingerprint)
|
||||||
throws MissingOpenPgpKeyPairException, IOException, SmackOpenPgpException {
|
throws MissingOpenPgpKeyPairException, IOException, SmackOpenPgpException {
|
||||||
InputStream fromPlain = element.toInputStream();
|
|
||||||
PGPSecretKeyRing signingKeyRing;
|
PGPSecretKeyRing signingKeyRing;
|
||||||
try {
|
try {
|
||||||
signingKeyRing = store.getSecretKeyRings(owner).getSecretKeyRing(signingKeyFingerprint.getKeyId());
|
signingKeyRing = store.getSecretKeyRings(owner).getSecretKeyRing(signingKeyFingerprint.getKeyId());
|
||||||
|
@ -157,17 +156,23 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
throw new MissingOpenPgpKeyPairException(owner, signingKeyFingerprint, e);
|
throw new MissingOpenPgpKeyPairException(owner, signingKeyFingerprint, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return signImpl(element, signingKeyRing, store.getSecretKeyProtector());
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] signImpl(SignElement element, PGPSecretKeyRing signingKey, SecretKeyRingProtector secretKeyRingProtector)
|
||||||
|
throws IOException, SmackOpenPgpException {
|
||||||
ByteArrayOutputStream toSigned = new ByteArrayOutputStream();
|
ByteArrayOutputStream toSigned = new ByteArrayOutputStream();
|
||||||
OutputStream signer;
|
OutputStream signer;
|
||||||
try {
|
try {
|
||||||
signer = PGPainless.createEncryptor().onOutputStream(toSigned)
|
signer = PGPainless.createEncryptor().onOutputStream(toSigned)
|
||||||
.doNotEncrypt()
|
.doNotEncrypt()
|
||||||
.signWith(store.getSecretKeyProtector(), signingKeyRing)
|
.signWith(secretKeyRingProtector, signingKey)
|
||||||
.noArmor();
|
.noArmor();
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
throw new SmackOpenPgpException(e);
|
throw new SmackOpenPgpException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputStream fromPlain = element.toInputStream();
|
||||||
Streams.pipeAll(fromPlain, signer);
|
Streams.pipeAll(fromPlain, signer);
|
||||||
|
|
||||||
fromPlain.close();
|
fromPlain.close();
|
||||||
|
@ -178,16 +183,20 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] encrypt(CryptElement element, MultiMap<BareJid, OpenPgpV4Fingerprint> encryptionKeyFingerprints)
|
public byte[] encrypt(CryptElement element, MultiMap<BareJid, OpenPgpV4Fingerprint> encryptionKeyFingerprints)
|
||||||
throws MissingOpenPgpPublicKeyException, IOException, SmackOpenPgpException {
|
throws IOException, SmackOpenPgpException {
|
||||||
PGPPublicKeyRing[] allRecipientsKeys = getEncryptionKeys(encryptionKeyFingerprints);
|
PGPPublicKeyRing[] allRecipientsKeys = getEncryptionKeys(encryptionKeyFingerprints);
|
||||||
|
return encryptImpl(element, allRecipientsKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] encryptImpl(CryptElement element, PGPPublicKeyRing[] encryptionKeys)
|
||||||
|
throws IOException, SmackOpenPgpException {
|
||||||
InputStream fromPlain = element.toInputStream();
|
InputStream fromPlain = element.toInputStream();
|
||||||
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
|
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
|
||||||
OutputStream encryptor;
|
OutputStream encryptor;
|
||||||
try {
|
try {
|
||||||
encryptor = PGPainless.createEncryptor()
|
encryptor = PGPainless.createEncryptor()
|
||||||
.onOutputStream(encrypted)
|
.onOutputStream(encrypted)
|
||||||
.toRecipients(allRecipientsKeys)
|
.toRecipients(encryptionKeys)
|
||||||
.usingSecureAlgorithms()
|
.usingSecureAlgorithms()
|
||||||
.doNotSign()
|
.doNotSign()
|
||||||
.noArmor();
|
.noArmor();
|
||||||
|
@ -260,7 +269,7 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
||||||
try {
|
try {
|
||||||
fromEncrypted = PGPainless.createDecryptor()
|
fromEncrypted = PGPainless.createDecryptor()
|
||||||
.onInputStream(encryptedBytes)
|
.onInputStream(encryptedBytes)
|
||||||
.decryptWith(decryptionKeys, protector)
|
.decryptWith(protector, decryptionKeys)
|
||||||
.verifyWith(verificationKeys)
|
.verifyWith(verificationKeys)
|
||||||
.ignoreMissingPublicKeys()
|
.ignoreMissingPublicKeys()
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -121,6 +121,15 @@ public interface OpenPgpProvider {
|
||||||
|
|
||||||
byte[] symmetricallyEncryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException;
|
byte[] symmetricallyEncryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt a symmetrically encrypted array of data using the provided password.
|
||||||
|
*
|
||||||
|
* @param bytes symmetrically encrypted data
|
||||||
|
* @param password password for decryption
|
||||||
|
* @return decrypted data
|
||||||
|
* @throws SmackOpenPgpException if the password is incorrect
|
||||||
|
* @throws IOException io is dangerous
|
||||||
|
*/
|
||||||
byte[] symmetricallyDecryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException;
|
byte[] symmetricallyDecryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue