Wip: Implement result parsing for decrypt, inline-detach and inline-verify

This commit is contained in:
Paul Schaub 2023-01-12 14:58:42 +01:00
parent d079a345d2
commit 909e28432d
4 changed files with 52 additions and 7 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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<String> commandList = new ArrayList<>();
private final List<String> 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<Signatures> 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) {

View file

@ -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<String> commandList = new ArrayList<>();
private final List<String> 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<List<Verification>> 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<Verification> verificationList = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null) {
verificationList.add(Verification.fromString(line.trim()));
}
return verificationList;
}
};
} catch (IOException e) {