Save encrypted logs to disk on debug builds.

This commit is contained in:
akwizgran
2021-09-22 18:12:16 +01:00
parent 1d04bbcb4f
commit 719e3c6138
30 changed files with 610 additions and 53 deletions

View File

@@ -10,4 +10,6 @@ public interface FeatureFlags {
boolean shouldEnableProfilePictures();
boolean shouldEnableDisappearingMessages();
boolean shouldEnablePersistentLogs();
}

View File

@@ -1,8 +1,16 @@
package org.briarproject.bramble.api;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Hashtable;
import java.util.Map;
import javax.annotation.Nullable;
import static org.briarproject.bramble.util.StringUtils.fromHexString;
import static org.briarproject.bramble.util.StringUtils.toHexString;
@NotNullByDefault
public abstract class StringMap extends Hashtable<String, String> {
protected StringMap(Map<String, String> m) {
@@ -52,4 +60,19 @@ public abstract class StringMap extends Hashtable<String, String> {
public void putLong(String key, long value) {
put(key, String.valueOf(value));
}
@Nullable
public byte[] getBytes(String key) {
String s = get(key);
if (s == null) return null;
try {
return fromHexString(s);
} catch (IllegalArgumentException e) {
return null;
}
}
public void putBytes(String key, byte[] value) {
put(key, toHexString(value));
}
}

View File

@@ -0,0 +1,46 @@
package org.briarproject.bramble.api.logging;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.settings.Settings;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.logging.Handler;
import java.util.logging.Logger;
@NotNullByDefault
public interface PersistentLogManager {
/**
* The namespace of the (@link Settings) where the log key is stored.
*/
String LOG_SETTINGS_NAMESPACE = "log";
/**
* The {@link Settings} key under which the log key is stored.
*/
String LOG_KEY_KEY = "logKey";
/**
* Creates and returns a persistent log handler that stores its logs in
* the given directory.
*/
Handler createLogHandler(File dir) throws IOException;
/**
* Creates a persistent log handler that stores its logs in the given
* directory and adds the handler to the given logger, replacing any
* existing persistent log handler.
*/
void addLogHandler(File dir, Logger logger) throws IOException;
/**
* Returns a {@link Scanner} for reading the persistent log entries stored
* in the given directory.
*
* @param old True if the previous session's log should be loaded, or false
* if the current session's log should be loaded
*/
Scanner getPersistentLog(File dir, boolean old) throws IOException;
}

View File

@@ -8,11 +8,24 @@ import java.io.File;
@NotNullByDefault
public interface DevConfig {
/**
* Returns the public key for encrypting feedback and crash reports.
*/
PublicKey getDevPublicKey();
/**
* Returns the onion address for submitting feedback and crash reports.
*/
String getDevOnionAddress();
/**
* Returns the directory for storing unsent feedback and crash reports.
*/
File getReportDir();
File getLogcatFile();
/**
* Returns the temporary file for passing the encrypted app log from the
* main process to the crash reporter process.
*/
File getTemporaryLogFile();
}

View File

@@ -1,7 +1,10 @@
package org.briarproject.bramble.util;
import java.io.File;
import java.util.Collection;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import static java.util.logging.Level.FINE;
@@ -57,4 +60,13 @@ public class LogUtils {
String type) {
logger.log(level, type + " " + f.getAbsolutePath() + " " + f.length());
}
public static String formatLog(Formatter formatter,
Collection<LogRecord> logRecords) {
StringBuilder sb = new StringBuilder();
for (LogRecord record : logRecords) {
sb.append(formatter.format(record)).append('\n');
}
return sb.toString();
}
}