From 8727780b77adec4bbcc1d04a5cd09f3532dc373d Mon Sep 17 00:00:00 2001 From: catbref Date: Mon, 17 Jun 2019 09:36:40 +0100 Subject: [PATCH] Added XorUpdate utility to help prepare auto-updates. --- src/main/java/org/qora/XorUpdate.java | 58 +++++++++++++++++++ .../java/org/qora/controller/AutoUpdate.java | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/qora/XorUpdate.java diff --git a/src/main/java/org/qora/XorUpdate.java b/src/main/java/org/qora/XorUpdate.java new file mode 100644 index 00000000..1df8a7e3 --- /dev/null +++ b/src/main/java/org/qora/XorUpdate.java @@ -0,0 +1,58 @@ +package org.qora; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.qora.controller.AutoUpdate; + +public class XorUpdate { + + private static final byte XOR_VALUE = AutoUpdate.XOR_VALUE; + + public static void main(String args[]) { + if (args.length != 2) { + System.err.println("usage: XorUpdate "); + System.exit(1); + } + + Path inPath = Paths.get(args[0]); + if (!Files.isReadable(inPath)) { + System.err.println(String.format("Cannot open '%s'", args[0])); + System.exit(2); + } + + Path outPath = Paths.get(args[1]); + + try (InputStream in = Files.newInputStream(inPath); OutputStream out = Files.newOutputStream(outPath)) { + byte[] buffer = new byte[1024 * 1024]; + do { + int nread = in.read(buffer); + if (nread == -1) + break; + + for (int i = 0; i < nread; ++i) + buffer[i] ^= XOR_VALUE; + + out.write(buffer, 0, nread); + } while (true); + out.flush(); + } catch (IOException e) { + System.err.println(e.getLocalizedMessage()); + + try { + Files.deleteIfExists(outPath); + } catch (IOException e1) { + System.err.println(e.getLocalizedMessage()); + } + + System.exit(2); + } + + System.exit(0); + } + +} diff --git a/src/main/java/org/qora/controller/AutoUpdate.java b/src/main/java/org/qora/controller/AutoUpdate.java index 6d023e1f..756d2ff7 100644 --- a/src/main/java/org/qora/controller/AutoUpdate.java +++ b/src/main/java/org/qora/controller/AutoUpdate.java @@ -50,7 +50,7 @@ public class AutoUpdate extends Thread { private static final int EXPECTED_DATA_LENGTH = Transformer.TIMESTAMP_LENGTH + GIT_COMMIT_HASH_LENGTH + Transformer.SHA256_LENGTH; /** This byte value used to hide contents from deep-inspection firewalls in case they block updates. */ - private static final byte XOR_VALUE = (byte) 0x5a; + public static final byte XOR_VALUE = (byte) 0x5a; private static AutoUpdate instance;