Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Mailbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Mailbox
Commits
56406d27
Verified
Commit
56406d27
authored
Dec 10, 2021
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Add wipe option to mailbox-cli to test wiping and setup
parent
40e0a405
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!52
Use existence of DB folder to signal if the mailbox is set up or not
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mailbox-cli/build.gradle
+66
-0
66 additions, 0 deletions
mailbox-cli/build.gradle
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/Main.kt
+32
-5
32 additions, 5 deletions
...ox-cli/src/main/java/org/briarproject/mailbox/cli/Main.kt
with
98 additions
and
5 deletions
mailbox-cli/build.gradle
+
66
−
0
View file @
56406d27
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'
}
}
This diff is collapsed.
Click to expand it.
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/Main.kt
+
32
−
5
View file @
56406d27
...
@@ -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
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment