diff --git a/external-sop/src/main/java/sop/external/ExternalSOP.java b/external-sop/src/main/java/sop/external/ExternalSOP.java index 70acf5b..6ce8485 100644 --- a/external-sop/src/main/java/sop/external/ExternalSOP.java +++ b/external-sop/src/main/java/sop/external/ExternalSOP.java @@ -98,12 +98,12 @@ public class ExternalSOP implements SOP { @Override public InlineVerify inlineVerify() { - return new InlineVerifyExternal(binaryName, properties); + return new InlineVerifyExternal(binaryName, properties, tempDirProvider); } @Override public InlineDetach inlineDetach() { - return new InlineDetachExternal(binaryName, properties); + return new InlineDetachExternal(binaryName, properties, tempDirProvider); } @Override diff --git a/external-sop/src/main/java/sop/external/operation/DecryptExternal.java b/external-sop/src/main/java/sop/external/operation/DecryptExternal.java index d0ad5d8..b90e657 100644 --- a/external-sop/src/main/java/sop/external/operation/DecryptExternal.java +++ b/external-sop/src/main/java/sop/external/operation/DecryptExternal.java @@ -163,7 +163,7 @@ public class DecryptExternal implements Decrypt { reader.close(); } - return new DecryptionResult(sessionKey, verifications); // TODO + return new DecryptionResult(sessionKey, verifications); } }; } catch (IOException e) { diff --git a/external-sop/src/main/java/sop/external/operation/InlineDetachExternal.java b/external-sop/src/main/java/sop/external/operation/InlineDetachExternal.java index f8ebe09..0ed3e18 100644 --- a/external-sop/src/main/java/sop/external/operation/InlineDetachExternal.java +++ b/external-sop/src/main/java/sop/external/operation/InlineDetachExternal.java @@ -10,6 +10,9 @@ import sop.exception.SOPGPException; import sop.external.ExternalSOP; import sop.operation.InlineDetach; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -19,10 +22,12 @@ import java.util.Properties; public class InlineDetachExternal implements InlineDetach { + private final ExternalSOP.TempDirProvider tempDirProvider; private final List commandList = new ArrayList<>(); private final List envList; - public InlineDetachExternal(String binary, Properties environment) { + public InlineDetachExternal(String binary, Properties environment, ExternalSOP.TempDirProvider tempDirProvider) { + this.tempDirProvider = tempDirProvider; commandList.add(binary); commandList.add("inline-detach"); envList = ExternalSOP.propertiesToEnv(environment); @@ -36,6 +41,12 @@ public class InlineDetachExternal implements InlineDetach { @Override public ReadyWithResult message(InputStream messageInputStream) throws IOException, SOPGPException.BadData { + File tempDir = tempDirProvider.provideTempDirectory(); + + File signaturesOut = new File(tempDir, "signatures"); + signaturesOut.delete(); + commandList.add("--signatures-out=" + signaturesOut.getAbsolutePath()); + String[] command = commandList.toArray(new String[0]); String[] env = envList.toArray(new String[0]); @@ -65,7 +76,21 @@ public class InlineDetachExternal implements InlineDetach { ExternalSOP.finish(process); - return null; // TODO + FileInputStream signaturesOutIn = new FileInputStream(signaturesOut); + ByteArrayOutputStream signaturesBuffer = new ByteArrayOutputStream(); + while ((r = signaturesOutIn.read(buf)) > 0) { + signaturesBuffer.write(buf, 0, r); + } + signaturesOutIn.close(); + signaturesOut.delete(); + + final byte[] sigBytes = signaturesBuffer.toByteArray(); + return new Signatures() { + @Override + public void writeTo(OutputStream signatureOutputStream) throws IOException { + signatureOutputStream.write(sigBytes); + } + }; } }; } catch (IOException e) { diff --git a/external-sop/src/main/java/sop/external/operation/InlineVerifyExternal.java b/external-sop/src/main/java/sop/external/operation/InlineVerifyExternal.java index b18cc4c..17e3ff9 100644 --- a/external-sop/src/main/java/sop/external/operation/InlineVerifyExternal.java +++ b/external-sop/src/main/java/sop/external/operation/InlineVerifyExternal.java @@ -11,8 +11,12 @@ import sop.external.ExternalSOP; import sop.operation.InlineVerify; import sop.util.UTCUtil; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; @@ -21,12 +25,14 @@ import java.util.Properties; public class InlineVerifyExternal implements InlineVerify { + private final ExternalSOP.TempDirProvider tempDirProvider; private final List commandList = new ArrayList<>(); private final List envList; private int certCounter = 0; - public InlineVerifyExternal(String binary, Properties environment) { + public InlineVerifyExternal(String binary, Properties environment, ExternalSOP.TempDirProvider tempDirProvider) { + this.tempDirProvider = tempDirProvider; commandList.add(binary); commandList.add("inline-verify"); envList = ExternalSOP.propertiesToEnv(environment); @@ -54,6 +60,12 @@ public class InlineVerifyExternal implements InlineVerify { @Override public ReadyWithResult> data(InputStream data) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData { + File tempDir = tempDirProvider.provideTempDirectory(); + + File verificationsOut = new File(tempDir, "verifications-out"); + verificationsOut.delete(); + commandList.add("--verifications-out=" + verificationsOut.getAbsolutePath()); + String[] command = commandList.toArray(new String[0]); String[] env = envList.toArray(new String[0]); @@ -84,7 +96,15 @@ public class InlineVerifyExternal implements InlineVerify { ExternalSOP.finish(process); - return null; // TODO + FileInputStream verificationsOutIn = new FileInputStream(verificationsOut); + BufferedReader reader = new BufferedReader(new InputStreamReader(verificationsOutIn)); + List verificationList = new ArrayList<>(); + String line; + while ((line = reader.readLine()) != null) { + verificationList.add(Verification.fromString(line.trim())); + } + + return verificationList; } }; } catch (IOException e) {