Skip to content
Snippets Groups Projects
Verified Commit 56406d27 authored by Torsten Grote's avatar Torsten Grote
Browse files

Add wipe option to mailbox-cli to test wiping and setup

parent 40e0a405
Branches
Tags
1 merge request!52Use existence of DB folder to signal if the mailbox is set up or not
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import static java.util.Collections.list
plugins { plugins {
id 'application' id 'application'
id 'idea' id 'idea'
...@@ -83,6 +89,66 @@ processResources { ...@@ -83,6 +89,66 @@ processResources {
dependsOn unpackTorBinaries dependsOn unpackTorBinaries
} }
void jarFactory(Jar jarTask, jarArchitecture) {
jarTask.doFirst {
println 'Building ' + jarArchitecture + ' version has started'
}
jarTask.manifest {
attributes(
'Main-Class': application.mainClassName
)
}
jarTask.setArchiveClassifier(jarArchitecture)
jarTask.from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
{
it.duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
String[] architectures = ["linux-aarch64", "linux-armhf", "linux-x86_64"]
for (String arch : architectures) {
if (arch != jarArchitecture) {
exclude "obfs4proxy_" + arch + ".zip"
exclude "tor_" + arch + ".zip"
}
}
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
}
jarTask.with jar
jarTask.doLast {
// Rename the original jar
File jar = jarTask.archivePath
String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
File srcFile = new File(srcPath)
jar.renameTo(srcFile)
JarFile srcJarFile = new JarFile(srcFile)
OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
// Read and sort the entries
Map<String, JarEntry> entries = new TreeMap<>()
for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
// Write the sorted entries
for (JarEntry srcEntry : entries.values()) {
JarEntry destEntry = new JarEntry(srcEntry.getName())
destEntry.setTime(0)
destStream.putNextEntry(destEntry)
InputStream srcStream = srcJarFile.getInputStream(srcEntry)
int read
byte[] buf = new byte[4096]
while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
destStream.write(buf, 0, read)
}
destStream.closeEntry()
srcStream.close()
}
destStream.close()
srcJarFile.close()
println 'Building ' + jarArchitecture + ' version has finished'
}
}
task x86LinuxJar(type: Jar) {
jarFactory(it, 'linux-x86_64')
}
tasks.withType(Test) { tasks.withType(Test) {
systemProperty 'java.library.path', 'libs' systemProperty 'java.library.path', 'libs'
} }
...@@ -31,6 +31,7 @@ import org.briarproject.mailbox.core.db.TransactionManager ...@@ -31,6 +31,7 @@ import org.briarproject.mailbox.core.db.TransactionManager
import org.briarproject.mailbox.core.lifecycle.LifecycleManager import org.briarproject.mailbox.core.lifecycle.LifecycleManager
import org.briarproject.mailbox.core.setup.QrCodeEncoder import org.briarproject.mailbox.core.setup.QrCodeEncoder
import org.briarproject.mailbox.core.setup.SetupManager import org.briarproject.mailbox.core.setup.SetupManager
import org.briarproject.mailbox.core.setup.WipeManager
import org.briarproject.mailbox.core.system.InvalidIdException import org.briarproject.mailbox.core.system.InvalidIdException
import org.slf4j.LoggerFactory.getLogger import org.slf4j.LoggerFactory.getLogger
import java.util.logging.Level.ALL import java.util.logging.Level.ALL
...@@ -44,6 +45,10 @@ class Main : CliktCommand( ...@@ -44,6 +45,10 @@ class Main : CliktCommand(
name = "briar-mailbox", name = "briar-mailbox",
help = "Command line interface for the Briar Mailbox" help = "Command line interface for the Briar Mailbox"
) { ) {
private val wipe by option(
"--wipe",
help = "Deletes entire mailbox, will require new setup",
).flag(default = false)
private val debug by option("--debug", "-d", help = "Enable printing of debug messages").flag( private val debug by option("--debug", "-d", help = "Enable printing of debug messages").flag(
default = false default = false
) )
...@@ -69,6 +74,9 @@ class Main : CliktCommand( ...@@ -69,6 +74,9 @@ class Main : CliktCommand(
@Inject @Inject
internal lateinit var setupManager: SetupManager internal lateinit var setupManager: SetupManager
@Inject
internal lateinit var wipeManager: WipeManager
@Inject @Inject
internal lateinit var qrCodeEncoder: QrCodeEncoder internal lateinit var qrCodeEncoder: QrCodeEncoder
...@@ -104,17 +112,36 @@ class Main : CliktCommand( ...@@ -104,17 +112,36 @@ class Main : CliktCommand(
lifecycleManager.startServices() lifecycleManager.startServices()
lifecycleManager.waitForStartup() lifecycleManager.waitForStartup()
if (setupToken != null) try { if (wipe) {
// FIXME this can cause a deadlock
// see: https://code.briarproject.org/briar/briar-mailbox/-/issues/76
val wipeResult = lifecycleManager.wipeMailbox()
lifecycleManager.stopServices()
lifecycleManager.waitForShutdown()
if (wipeResult) {
println("Mailbox wiped successfully \\o/")
exitProcess(0)
} else {
println("ERROR: Mailbox was not wiped cleanly")
exitProcess(1)
}
} else if (setupToken != null) {
try {
setupManager.setToken(setupToken, null) setupManager.setToken(setupToken, null)
} catch (e: InvalidIdException) { } catch (e: InvalidIdException) {
System.err.println("Invalid setup token") System.err.println("Invalid setup token")
exitProcess(1) exitProcess(1)
} }
}
val ownerTokenExists = db.read { txn -> val ownerTokenExists = db.read { txn ->
setupManager.getOwnerToken(txn) != null setupManager.getOwnerToken(txn) != null
} }
if (!ownerTokenExists) { if (!ownerTokenExists) {
// TODO remove before release
val token = setupToken ?: db.read { setupManager.getSetupToken(it) }
println("curl -v -H \"Authorization: Bearer $token\" -X PUT http://localhost:8000/setup")
// FIXME: We need to wait for the hidden service address to become available
// If not set up, show QR code for manual setup // If not set up, show QR code for manual setup
qrCodeEncoder.getQrCodeBitMatrix()?.let { qrCodeEncoder.getQrCodeBitMatrix()?.let {
println(QrCodeRenderer.getQrString(it)) println(QrCodeRenderer.getQrString(it))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment