Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/76#discussion_r37697819
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/OpenPGPKeyBasedEncryptor.java
---
@@ -139,75 +151,88 @@ public static PGPPublicKey getPublicKey(String
userId, String publicKeyring) thr
private String secretKeyring;
private char[] passphrase;
- OpenPGPDecryptCallback(final String provider, final String
keyring, final char[] passphrase) {
+ OpenPGPDecryptCallback(final String provider, final String keyring,
+ final char[] passphrase) {
this.provider = provider;
this.secretKeyring = keyring;
this.passphrase = passphrase;
}
@Override
- public void process(InputStream in, OutputStream out) throws
IOException {
- InputStream pgpin = PGPUtil.getDecoderStream(in);
- PGPObjectFactory pgpFactory = new PGPObjectFactory(pgpin);
+ public void process(InputStream in, OutputStream out)
+ throws IOException {
+ try (InputStream pgpin = PGPUtil.getDecoderStream(in)) {
+ PGPObjectFactory pgpFactory = new PGPObjectFactory(pgpin);
- Object obj = pgpFactory.nextObject();
- if (!(obj instanceof PGPEncryptedDataList)) {
- obj = pgpFactory.nextObject();
+ Object obj = pgpFactory.nextObject();
if (!(obj instanceof PGPEncryptedDataList)) {
- throw new ProcessException("Invalid OpenPGP data");
- }
- }
- PGPEncryptedDataList encList = (PGPEncryptedDataList) obj;
-
- PGPSecretKeyRingCollection pgpSecretKeyring;
- try {
- // open secret keyring file
- pgpSecretKeyring = new
PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(Files
- .newInputStream(Paths.get(secretKeyring))));
- } catch (Exception e) {
- throw new ProcessException("Invalid secret keyring - " +
e.getMessage());
- }
-
- try {
- PGPPrivateKey privateKey = null;
- PGPPublicKeyEncryptedData encData = null;
-
- // find the secret key in the encrypted data
- Iterator it = encList.getEncryptedDataObjects();
- while (privateKey == null && it.hasNext()) {
- obj = it.next();
- if (!(obj instanceof PGPPublicKeyEncryptedData)) {
+ obj = pgpFactory.nextObject();
+ if (!(obj instanceof PGPEncryptedDataList)) {
throw new ProcessException("Invalid OpenPGP data");
}
- encData = (PGPPublicKeyEncryptedData) obj;
- PGPSecretKey secretkey =
pgpSecretKeyring.getSecretKey(encData.getKeyID());
- if (secretkey != null) {
- privateKey =
secretkey.extractPrivateKey(passphrase, provider);
- }
}
- if (privateKey == null) {
- throw new ProcessException("Secret keyring does not
contain the key required to decrypt");
+ PGPEncryptedDataList encList = (PGPEncryptedDataList) obj;
+
+ PGPSecretKeyRingCollection pgpSecretKeyring;
+ try {
+ // open secret keyring file
+ pgpSecretKeyring = new PGPSecretKeyRingCollection(
+
PGPUtil.getDecoderStream(Files.newInputStream(Paths
--- End diff --
The InputStream returned by Files.newInputStream is leaked here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---