Added command line options for success and dump file, window size
This commit is contained in:
parent
e230a883cd
commit
1092a4e4a4
13 changed files with 138 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
*.blf
|
||||
.sonarlint/
|
||||
|
||||
# copied from brainflyer gitignore
|
||||
|
||||
|
|
|
@ -6,4 +6,8 @@ D
|
|||
L
|
||||
src/bf/libs/ec_pubkey_fast.c,5/9/5995e3430cea453ad68838818ad7fc05c86b119f
|
||||
K
|
||||
src/bf/libs/ripemd160_256.c,4/b/4b8d4ad995cb3950cece8de680eb57ef0fe2921f
|
||||
src/bf/libs/ripemd160_256.c,4/b/4b8d4ad995cb3950cece8de680eb57ef0fe2921f
|
||||
E
|
||||
src/bf/Brainflyer.cpp,5/0/50c7097d8cf446876a37bb356d2bc4dec9444c86
|
||||
A
|
||||
src/comm/Comm.cpp,1/7/17d68a7335dbcfc6e373b75382c4c139a9c31446
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
~
|
||||
squid:S899#"BDo something with the "boolean" value returned by "createNewFile".(Šþä”ùÿÿÿÿ8ëÌœœ±,H˜<48>RMINORZ
VULNERABILITY
|
||||
x
|
||||
squid:S899"BDo something with the "boolean" value returned by "createNewFile".(É©•i8ºú›œ±,H–<48>RMINORZ
VULNERABILITY
|
|
@ -1,3 +1,3 @@
|
|||
|
||||
ˆsquid:S3776"RRefactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.(’°ÅýüÿÿÿÿHÓ˜RCRITICALZ
|
||||
ˆsquid:S3776"RRefactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.(’°ÅýüÿÿÿÿHò˜RCRITICALZ
|
||||
CODE_SMELL
|
|
@ -1,11 +1,9 @@
|
|||
|
||||
Œ
|
||||
squid:S135Ÿ"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHî˜RMINORZ
|
||||
CODE_SMELL
|
||||
„squid:S3776‚"RRefactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.(¨îïƒHï˜RCRITICALZ
|
||||
squid:S135É"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHö˜RMINORZ
|
||||
CODE_SMELL
|
||||
Œ
|
||||
squid:S135Ç"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHð˜RMINORZ
|
||||
squid:S135¡"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHõ˜RMINORZ
|
||||
CODE_SMELL
|
||||
ºsquid:S1186¶"€Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.(ÌÔ’Â8÷Í’ƒ±,Hñ˜RCRITICALZ
|
||||
„squid:S3776„"RRefactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.(¨îïƒHô˜RCRITICALZ
|
||||
CODE_SMELL
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
l
|
||||
squid:S106"9Replace this use of System.out or System.err by a logger.(çðôW8’Žë›±,H©<48>RMAJORZ
|
||||
CODE_SMELL
|
|
@ -12,4 +12,16 @@ Bsrc/main/java/org/btcollider/cnc/keysrv/keytree/KeyTreeServer.java,a/b/ab959de
|
|||
h
|
||||
8src/main/java/org/btcollider/cnc/comm/CommException.java,8/f/8fe1dc8959c76b2c26853ccd55ee1f4bcebcbcfe
|
||||
g
|
||||
7src/main/java/org/btcollider/cnc/comm/ClientWorker.java,f/b/fb0de740b71d2edb598c4f3deb39da1c59c1ec4f
|
||||
7src/main/java/org/btcollider/cnc/comm/ClientWorker.java,f/b/fb0de740b71d2edb598c4f3deb39da1c59c1ec4f
|
||||
p
|
||||
@src/main/java/org/btcollider/cnc/keysrv/keytree/KTConcierge.java,6/b/6bd08b7785854103940143964721a29b585a0574
|
||||
b
|
||||
2src/main/java/org/btcollider/cnc/dto/KeyRange.java,9/6/96b215a1323591b6d4c32541aebd0f6c1683b246
|
||||
v
|
||||
Fsrc/main/java/org/btcollider/cnc/keysrv/multistage/KeyRangeBuffer.java,f/5/f54562b1bb37a29e09c1a61428a7b375be679412
|
||||
y
|
||||
Isrc/main/java/org/btcollider/cnc/keysrv/multistage/MultiStagedServer.java,7/8/78bca5a517888f548ba402e13adef75c72b18987
|
||||
f
|
||||
6src/main/java/org/btcollider/cnc/keysrv/KSFactory.java,1/3/136c36f2bf1690ff10397e07c3d82baa9b298770
|
||||
M
|
||||
src/main/resources/log4j2.xml,3/6/36b9f0d33e4b7e602e3cd701314fae81543db66f
|
|
@ -18,19 +18,23 @@
|
|||
using namespace std;
|
||||
|
||||
#define BATCH_MAX 4096
|
||||
#define WIN_SIZE 21
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
util::bytestr key("db53d9bbd1f3a83b094eeca7dd970bd85b492fa2");
|
||||
|
||||
if (argc < 3) {
|
||||
if (argc < 4) {
|
||||
cout << "Invalid argument count" << endl;
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cout << "Computing private key for " << key << endl;
|
||||
|
||||
int win_size = stoi(argv[3]);
|
||||
cout << "Window size: " << win_size << endl;
|
||||
|
||||
cout << "Initializing precomputation table" << endl;
|
||||
// init with window size 16, not reading from file
|
||||
if (secp256k1_ec_pubkey_precomp_table(WIN_SIZE, nullptr) != 0) {
|
||||
if (secp256k1_ec_pubkey_precomp_table(win_size, nullptr) != 0) {
|
||||
cout << "Initialization of precomputation table failed" << endl;
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,16 @@ public class CnC {
|
|||
public static final int MAX_BITS = 62;
|
||||
|
||||
public static void main(String[] args) {
|
||||
KeyServer kts = KSFactory.build(54, 30, 90, TimeUnit.MINUTES, 0.62f);
|
||||
CommServer server = new CommServer(PORT, kts);
|
||||
if (args.length != 2) {
|
||||
System.out.println("USAGE: java -jar cnc.jar <succFile Path> <dumpFile Path>");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
String succFile = args[0];
|
||||
String dumpFile = args[1];
|
||||
|
||||
KeyServer kts = KSFactory.build(54, 30, 90, TimeUnit.MINUTES, 0.65f);
|
||||
CommServer server = new CommServer(PORT, kts, succFile, dumpFile);
|
||||
try {
|
||||
server.listen();
|
||||
} catch (CommException e) {
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.btcollider.cnc.comm;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -20,10 +22,14 @@ public class ClientWorker implements Runnable {
|
|||
private KeyServer keyServer;
|
||||
private BufferedReader in;
|
||||
private PrintWriter out;
|
||||
private String succFile;
|
||||
private String dumpFile;
|
||||
|
||||
public ClientWorker(Socket clientSocket, KeyServer keyServer) {
|
||||
public ClientWorker(Socket clientSocket, KeyServer keyServer, String succFile, String dumpFile) {
|
||||
this.clientSocket = clientSocket;
|
||||
this.keyServer = keyServer;
|
||||
this.succFile = succFile;
|
||||
this.dumpFile = dumpFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +66,15 @@ public class ClientWorker implements Runnable {
|
|||
case "RES":
|
||||
retrieveResult();
|
||||
break;
|
||||
case "DMP":
|
||||
try {
|
||||
keyServer.dump(new FileOutputStream(dumpFile));
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error("Dump file not found", e);
|
||||
} catch (IOException e) {
|
||||
log.error("Couldn't dump key state to dump file {}", dumpFile, e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
}
|
||||
|
@ -136,6 +151,7 @@ public class ClientWorker implements Runnable {
|
|||
log.info("Found private key {}", suc);
|
||||
writeKey(suc);
|
||||
out.println("ACK");
|
||||
System.exit(0);
|
||||
break;
|
||||
default:
|
||||
assert (false);
|
||||
|
@ -147,10 +163,10 @@ public class ClientWorker implements Runnable {
|
|||
}
|
||||
|
||||
private void writeKey(String key) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("~/cwkey"))) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(succFile))) {
|
||||
writer.write(key);
|
||||
} catch (IOException e) {
|
||||
log.error("Couldn't write key {} to keyfile", key, e);
|
||||
log.error("Couldn't write key {} to success file {}", key, succFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.btcollider.cnc.comm;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.btcollider.cnc.keysrv.KeyServer;
|
||||
|
@ -15,10 +18,50 @@ public class CommServer {
|
|||
private int port;
|
||||
private ServerSocket serverSocket;
|
||||
private KeyServer keyServer;
|
||||
private String succFile;
|
||||
private String dumpFile;
|
||||
|
||||
public CommServer(int port, KeyServer keyServer) {
|
||||
public CommServer(int port, KeyServer keyServer, String succFile, String dumpFile) {
|
||||
this.port = port;
|
||||
this.keyServer = keyServer;
|
||||
|
||||
|
||||
try {
|
||||
(new File(succFile)).createNewFile();
|
||||
} catch (IOException e1) {
|
||||
log.error("Error while trying to create success file at: {}", e1);
|
||||
}
|
||||
try {
|
||||
(new File(dumpFile)).createNewFile();
|
||||
} catch (IOException e1) {
|
||||
log.error("Error while trying to create dump file at: {}", e1);
|
||||
}
|
||||
|
||||
if (!Files.isWritable(Paths.get(succFile))) {
|
||||
log.warn("Success file path is not writeable: {}", succFile);
|
||||
try {
|
||||
this.succFile = Files.createTempFile("btcollider", ".succ").toFile().getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
log.error("Couldn't create temporary success file", e);
|
||||
}
|
||||
log.warn("Temporary success file created. Path is: {}", this.succFile);
|
||||
} else {
|
||||
this.succFile = succFile;
|
||||
log.info("Success file path is: {}", this.succFile);
|
||||
}
|
||||
|
||||
if (!Files.isWritable(Paths.get(dumpFile))) {
|
||||
log.warn("Dump file path is not writeable: {}", dumpFile);
|
||||
try {
|
||||
this.dumpFile = Files.createTempFile("btcollider", ".dump").toFile().getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
log.error("Couldn't create temporary dump file", e);
|
||||
}
|
||||
log.warn("Temporary dump file created. Path is: {}", this.dumpFile);
|
||||
} else {
|
||||
this.dumpFile = dumpFile;
|
||||
log.info("Dump file path is: {}", this.dumpFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void listen() throws CommException {
|
||||
|
@ -32,7 +75,7 @@ public class CommServer {
|
|||
try {
|
||||
Socket socket = serverSocket.accept();
|
||||
log.debug("Got connection from {}", socket.getInetAddress());
|
||||
es.execute(new ClientWorker(socket, keyServer));
|
||||
es.execute(new ClientWorker(socket, keyServer, succFile, dumpFile));
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Couldn't establish connections on socket", e);
|
||||
|
|
|
@ -30,7 +30,7 @@ public class KSFactory {
|
|||
|
||||
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit,
|
||||
long pruneKey) {
|
||||
if (depth == 25) {
|
||||
if (depth <= 25) {
|
||||
return new KeyTreeServer(index, depth, timeUnit.toMillis(maxWorkSpan), pruneKey);
|
||||
} else {
|
||||
return new MultiStagedServer(index, depth, timeUnit.toMillis(maxWorkSpan), pruneKey);
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="%d{HH:mm:ss.SSS} %-5level %logger{2} - %msg%n" />
|
||||
</Console>
|
||||
<RollingFile name="File" fileName="logs/cnc.log"
|
||||
filePattern="logs/$${date:yyyy-MM}/cnc-%d{MM-dd-yyyy}-%i.log.gz">
|
||||
|
||||
<PatternLayout
|
||||
pattern="%d{HH:mm:ss.SSS} %-5level %logger{2} - %msg%n" />
|
||||
|
||||
<Policies>
|
||||
<OnStartupTriggeringPolicy />
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB" />
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="File" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Loading…
Reference in a new issue