Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julian Dehm
briar
Commits
8283760e
Verified
Commit
8283760e
authored
Jul 20, 2018
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move local author creation into IdentityManager.
parent
81cbb7e8
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
178 additions
and
144 deletions
+178
-144
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
.../org/briarproject/bramble/api/contact/ContactManager.java
+1
-1
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseConfig.java
.../java/org/briarproject/bramble/api/db/DatabaseConfig.java
+0
-5
bramble-api/src/main/java/org/briarproject/bramble/api/identity/IdentityManager.java
...rg/briarproject/bramble/api/identity/IdentityManager.java
+20
-8
bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java
.../briarproject/bramble/api/lifecycle/LifecycleManager.java
+6
-9
bramble-api/src/main/java/org/briarproject/bramble/api/sync/ValidationManager.java
.../org/briarproject/bramble/api/sync/ValidationManager.java
+2
-3
bramble-api/src/main/java/org/briarproject/bramble/api/versioning/ClientVersioningManager.java
...oject/bramble/api/versioning/ClientVersioningManager.java
+1
-1
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
...rg/briarproject/bramble/identity/IdentityManagerImpl.java
+37
-6
bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java
.../briarproject/bramble/lifecycle/LifecycleManagerImpl.java
+2
-32
bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleModule.java
...a/org/briarproject/bramble/lifecycle/LifecycleModule.java
+3
-10
bramble-core/src/test/java/org/briarproject/bramble/identity/IdentityManagerImplTest.java
...riarproject/bramble/identity/IdentityManagerImplTest.java
+42
-9
bramble-core/src/test/java/org/briarproject/bramble/test/TestDatabaseConfig.java
...ava/org/briarproject/bramble/test/TestDatabaseConfig.java
+0
-10
bramble-core/src/test/java/org/briarproject/bramble/test/TestLifecycleModule.java
...va/org/briarproject/bramble/test/TestLifecycleModule.java
+4
-5
briar-android/src/main/java/org/briarproject/briar/android/AndroidDatabaseConfig.java
...org/briarproject/briar/android/AndroidDatabaseConfig.java
+0
-17
briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
...ain/java/org/briarproject/briar/android/BriarService.java
+1
-2
briar-android/src/main/java/org/briarproject/briar/android/login/SetupControllerImpl.java
...briarproject/briar/android/login/SetupControllerImpl.java
+11
-4
briar-android/src/test/java/org/briarproject/briar/android/login/SetupControllerImplTest.java
...rproject/briar/android/login/SetupControllerImplTest.java
+18
-6
briar-core/src/test/java/org/briarproject/briar/feed/FeedManagerIntegrationTest.java
...g/briarproject/briar/feed/FeedManagerIntegrationTest.java
+7
-1
briar-core/src/test/java/org/briarproject/briar/feed/FeedManagerIntegrationTestComponent.java
...oject/briar/feed/FeedManagerIntegrationTestComponent.java
+3
-0
briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java
...ject/briar/messaging/SimplexMessagingIntegrationTest.java
+9
-7
briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java
...ava/org/briarproject/briar/test/BriarIntegrationTest.java
+11
-8
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
View file @
8283760e
...
...
@@ -16,7 +16,7 @@ public interface ContactManager {
/**
* Registers a hook to be called whenever a contact is added or removed.
* This method should be called before
* {@link LifecycleManager#startServices(
String
)}.
* {@link LifecycleManager#startServices()}.
*/
void
registerContactHook
(
ContactHook
hook
);
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseConfig.java
View file @
8283760e
...
...
@@ -21,10 +21,5 @@ public interface DatabaseConfig {
@Nullable
SecretKey
getEncryptionKey
();
void
setLocalAuthorName
(
String
nickname
);
@Nullable
String
getLocalAuthorName
();
long
getMaxSize
();
}
bramble-api/src/main/java/org/briarproject/bramble/api/identity/IdentityManager.java
View file @
8283760e
package
org.briarproject.bramble.api.identity
;
import
org.briarproject.bramble.api.crypto.CryptoExecutor
;
import
org.briarproject.bramble.api.db.DbException
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.identity.Author.Status
;
...
...
@@ -9,29 +10,40 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
public
interface
IdentityManager
{
/**
*
Stores the local pseudonym
.
*
Creates a local identity with the given name
.
*/
void
registerLocalAuthor
(
LocalAuthor
a
)
throws
DbException
;
@CryptoExecutor
LocalAuthor
createLocalAuthor
(
String
name
);
/**
* Returns the cached main local identity, non-blocking, or loads it from
* the db, blocking
* Registers the given local identity with the manager. The identity is
* not stored until {@link #storeLocalAuthor()} is called.
*/
void
registerLocalAuthor
(
LocalAuthor
a
);
/**
* Stores the local identity registered with
* {@link #registerLocalAuthor(LocalAuthor)}, if any.
*/
void
storeLocalAuthor
()
throws
DbException
;
/**
* Returns the cached local identity or loads it from the database.
*/
LocalAuthor
getLocalAuthor
()
throws
DbException
;
/**
* Returns the cached main local identity, non-blocking, or loads it from
* the db, blocking, within the given Transaction.
* Returns the cached local identity or loads it from the database.
*/
LocalAuthor
getLocalAuthor
(
Transaction
txn
)
throws
DbException
;
/**
* Returns the
trust-level status of the author
* Returns the
{@link Status} of the given author.
*/
Status
getAuthorStatus
(
AuthorId
a
)
throws
DbException
;
/**
* Returns the
trust-level status of the author
* Returns the
{@link Status} of the given author.
*/
Status
getAuthorStatus
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java
View file @
8283760e
...
...
@@ -6,8 +6,6 @@ import org.briarproject.bramble.api.sync.Client;
import
java.util.concurrent.ExecutorService
;
import
javax.annotation.Nullable
;
/**
* Manages the lifecycle of the app, starting {@link Client Clients}, starting
* and stopping {@link Service Services}, shutting down
...
...
@@ -18,7 +16,7 @@ import javax.annotation.Nullable;
public
interface
LifecycleManager
{
/**
* The result of calling {@link #startServices(
String
)}.
* The result of calling {@link #startServices()}.
*/
enum
StartResult
{
ALREADY_RUNNING
,
...
...
@@ -44,28 +42,27 @@ public interface LifecycleManager {
/**
* Registers a {@link Service} to be started and stopped. This method
* should be called before {@link #startServices(
String
)}.
* should be called before {@link #startServices()}.
*/
void
registerService
(
Service
s
);
/**
* Registers a {@link Client} to be started. This method should be called
* before {@link #startServices(
String
)}.
* before {@link #startServices()}.
*/
void
registerClient
(
Client
c
);
/**
* Registers an {@link ExecutorService} to be shut down. This method
* should be called before {@link #startServices(
String
)}.
* should be called before {@link #startServices()}.
*/
void
registerForShutdown
(
ExecutorService
e
);
/**
* Opens the {@link DatabaseComponent}, optionally creates a local author
* with the provided nickname, and starts any registered
* Opens the {@link DatabaseComponent} and starts any registered
* {@link Client Clients} and {@link Service Services}.
*/
StartResult
startServices
(
@Nullable
String
nickname
);
StartResult
startServices
();
/**
* Stops any registered {@link Service Services}, shuts down any
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/sync/ValidationManager.java
View file @
8283760e
...
...
@@ -35,7 +35,7 @@ public interface ValidationManager {
/**
* Registers the message validator for the given client. This method
* should be called before {@link LifecycleManager#startServices(
String
)}.
* should be called before {@link LifecycleManager#startServices()}.
*/
void
registerMessageValidator
(
ClientId
c
,
int
majorVersion
,
MessageValidator
v
);
...
...
@@ -43,8 +43,7 @@ public interface ValidationManager {
/**
* Registers the incoming message hook for the given client. The hook will
* be called once for each incoming message that passes validation. This
* method should be called before
* {@link LifecycleManager#startServices(String)}.
* method should be called before {@link LifecycleManager#startServices()}.
*/
void
registerIncomingMessageHook
(
ClientId
c
,
int
majorVersion
,
IncomingMessageHook
hook
);
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/versioning/ClientVersioningManager.java
View file @
8283760e
...
...
@@ -25,7 +25,7 @@ public interface ClientVersioningManager {
/**
* Registers a client that will be advertised to contacts. The hook will
* be called when the visibility of the client changes. This method should
* be called before {@link LifecycleManager#startServices(
String
)}.
* be called before {@link LifecycleManager#startServices()}.
*/
void
registerClient
(
ClientId
clientId
,
int
majorVersion
,
int
minorVersion
,
ClientVersioningHook
hook
);
...
...
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
View file @
8283760e
package
org.briarproject.bramble.identity
;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.briarproject.bramble.api.crypto.KeyPair
;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
import
org.briarproject.bramble.api.db.DbException
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.identity.Author.Status
;
import
org.briarproject.bramble.api.identity.AuthorFactory
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
...
...
@@ -21,6 +24,8 @@ import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
UNKNOWN
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
UNVERIFIED
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
VERIFIED
;
import
static
org
.
briarproject
.
bramble
.
util
.
LogUtils
.
logDuration
;
import
static
org
.
briarproject
.
bramble
.
util
.
LogUtils
.
now
;
@ThreadSafe
@NotNullByDefault
...
...
@@ -30,25 +35,51 @@ class IdentityManagerImpl implements IdentityManager {
Logger
.
getLogger
(
IdentityManagerImpl
.
class
.
getName
());
private
final
DatabaseComponent
db
;
private
final
CryptoComponent
crypto
;
private
final
AuthorFactory
authorFactory
;
// The local author is immutable so we can cache it
@Nullable
private
volatile
LocalAuthor
cachedAuthor
;
@Inject
IdentityManagerImpl
(
DatabaseComponent
db
)
{
IdentityManagerImpl
(
DatabaseComponent
db
,
CryptoComponent
crypto
,
AuthorFactory
authorFactory
)
{
this
.
db
=
db
;
this
.
crypto
=
crypto
;
this
.
authorFactory
=
authorFactory
;
}
@Override
public
void
registerLocalAuthor
(
LocalAuthor
localAuthor
)
throws
DbException
{
public
LocalAuthor
createLocalAuthor
(
String
name
)
{
long
start
=
now
();
KeyPair
keyPair
=
crypto
.
generateSignatureKeyPair
();
byte
[]
publicKey
=
keyPair
.
getPublic
().
getEncoded
();
byte
[]
privateKey
=
keyPair
.
getPrivate
().
getEncoded
();
LocalAuthor
localAuthor
=
authorFactory
.
createLocalAuthor
(
name
,
publicKey
,
privateKey
);
logDuration
(
LOG
,
"Creating local author"
,
start
);
return
localAuthor
;
}
@Override
public
void
registerLocalAuthor
(
LocalAuthor
a
)
{
cachedAuthor
=
a
;
LOG
.
info
(
"Local author registered"
);
}
@Override
public
void
storeLocalAuthor
()
throws
DbException
{
LocalAuthor
cached
=
cachedAuthor
;
if
(
cached
==
null
)
{
LOG
.
info
(
"No local author to store"
);
return
;
}
Transaction
txn
=
db
.
startTransaction
(
false
);
try
{
db
.
addLocalAuthor
(
txn
,
localAuthor
);
db
.
addLocalAuthor
(
txn
,
cached
);
db
.
commitTransaction
(
txn
);
cachedAuthor
=
localAuthor
;
LOG
.
info
(
"Local author registered"
);
LOG
.
info
(
"Local author stored"
);
}
finally
{
db
.
endTransaction
(
txn
);
}
...
...
bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java
View file @
8283760e
package
org.briarproject.bramble.lifecycle
;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.briarproject.bramble.api.crypto.KeyPair
;
import
org.briarproject.bramble.api.db.DataTooNewException
;
import
org.briarproject.bramble.api.db.DataTooOldException
;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
...
...
@@ -9,9 +7,7 @@ import org.briarproject.bramble.api.db.DbException;
import
org.briarproject.bramble.api.db.MigrationListener
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.event.EventBus
;
import
org.briarproject.bramble.api.identity.AuthorFactory
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.api.lifecycle.LifecycleManager
;
import
org.briarproject.bramble.api.lifecycle.Service
;
import
org.briarproject.bramble.api.lifecycle.ServiceException
;
...
...
@@ -26,7 +22,6 @@ import java.util.concurrent.ExecutorService;
import
java.util.concurrent.Semaphore
;
import
java.util.logging.Logger
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.ThreadSafe
;
import
javax.inject.Inject
;
...
...
@@ -60,8 +55,6 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
private
final
List
<
Service
>
services
;
private
final
List
<
Client
>
clients
;
private
final
List
<
ExecutorService
>
executors
;
private
final
CryptoComponent
crypto
;
private
final
AuthorFactory
authorFactory
;
private
final
IdentityManager
identityManager
;
private
final
Semaphore
startStopSemaphore
=
new
Semaphore
(
1
);
private
final
CountDownLatch
dbLatch
=
new
CountDownLatch
(
1
);
...
...
@@ -72,12 +65,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
@Inject
LifecycleManagerImpl
(
DatabaseComponent
db
,
EventBus
eventBus
,
CryptoComponent
crypto
,
AuthorFactory
authorFactory
,
IdentityManager
identityManager
)
{
this
.
db
=
db
;
this
.
eventBus
=
eventBus
;
this
.
crypto
=
crypto
;
this
.
authorFactory
=
authorFactory
;
this
.
identityManager
=
identityManager
;
services
=
new
CopyOnWriteArrayList
<>();
clients
=
new
CopyOnWriteArrayList
<>();
...
...
@@ -104,25 +94,8 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
executors
.
add
(
e
);
}
private
LocalAuthor
createLocalAuthor
(
String
nickname
)
{
long
start
=
now
();
KeyPair
keyPair
=
crypto
.
generateSignatureKeyPair
();
byte
[]
publicKey
=
keyPair
.
getPublic
().
getEncoded
();
byte
[]
privateKey
=
keyPair
.
getPrivate
().
getEncoded
();
LocalAuthor
localAuthor
=
authorFactory
.
createLocalAuthor
(
nickname
,
publicKey
,
privateKey
);
logDuration
(
LOG
,
"Creating local author"
,
start
);
return
localAuthor
;
}
private
void
registerLocalAuthor
(
LocalAuthor
author
)
throws
DbException
{
long
start
=
now
();
identityManager
.
registerLocalAuthor
(
author
);
logDuration
(
LOG
,
"Registering local author"
,
start
);
}
@Override
public
StartResult
startServices
(
@Nullable
String
nickname
)
{
public
StartResult
startServices
()
{
if
(!
startStopSemaphore
.
tryAcquire
())
{
LOG
.
info
(
"Already starting or stopping"
);
return
ALREADY_RUNNING
;
...
...
@@ -134,10 +107,7 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
boolean
reopened
=
db
.
open
(
this
);
if
(
reopened
)
logDuration
(
LOG
,
"Reopening database"
,
start
);
else
logDuration
(
LOG
,
"Creating database"
,
start
);
if
(
nickname
!=
null
)
{
registerLocalAuthor
(
createLocalAuthor
(
nickname
));
}
identityManager
.
storeLocalAuthor
();
state
=
STARTING_SERVICES
;
dbLatch
.
countDown
();
...
...
bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleModule.java
View file @
8283760e
package
org.briarproject.bramble.lifecycle
;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
import
org.briarproject.bramble.api.event.EventBus
;
import
org.briarproject.bramble.api.identity.AuthorFactory
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.lifecycle.IoExecutor
;
import
org.briarproject.bramble.api.lifecycle.LifecycleManager
;
import
org.briarproject.bramble.api.lifecycle.ShutdownManager
;
...
...
@@ -54,11 +49,9 @@ public class LifecycleModule {
@Provides
@Singleton
LifecycleManager
provideLifecycleManager
(
DatabaseComponent
db
,
EventBus
eventBus
,
CryptoComponent
crypto
,
AuthorFactory
authorFactory
,
IdentityManager
identityManager
)
{
return
new
LifecycleManagerImpl
(
db
,
eventBus
,
crypto
,
authorFactory
,
identityManager
);
LifecycleManager
provideLifecycleManager
(
LifecycleManagerImpl
lifecycleManager
)
{
return
lifecycleManager
;
}
@Provides
...
...
bramble-core/src/test/java/org/briarproject/bramble/identity/IdentityManagerImplTest.java
View file @
8283760e
...
...
@@ -2,15 +2,21 @@ package org.briarproject.bramble.identity;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.briarproject.bramble.api.crypto.KeyPair
;
import
org.briarproject.bramble.api.crypto.PrivateKey
;
import
org.briarproject.bramble.api.crypto.PublicKey
;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
import
org.briarproject.bramble.api.db.DbException
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.identity.Author
;
import
org.briarproject.bramble.api.identity.AuthorFactory
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.test.BrambleMockTestCase
;
import
org.jmock.Expectations
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.util.ArrayList
;
...
...
@@ -27,24 +33,48 @@ import static org.junit.Assert.assertEquals;
public
class
IdentityManagerImplTest
extends
BrambleMockTestCase
{
private
final
IdentityManager
identityManager
;
private
final
DatabaseComponent
db
=
context
.
mock
(
DatabaseComponent
.
class
);
private
final
CryptoComponent
crypto
=
context
.
mock
(
CryptoComponent
.
class
);
private
final
AuthorFactory
authorFactory
=
context
.
mock
(
AuthorFactory
.
class
);
private
final
PublicKey
publicKey
=
context
.
mock
(
PublicKey
.
class
);
private
final
PrivateKey
privateKey
=
context
.
mock
(
PrivateKey
.
class
);
private
final
Transaction
txn
=
new
Transaction
(
null
,
false
);
private
final
LocalAuthor
localAuthor
=
getLocalAuthor
();
private
final
Collection
<
LocalAuthor
>
localAuthors
=
Collections
.
singletonList
(
localAuthor
);
public
IdentityManagerImplTest
()
{
identityManager
=
new
IdentityManagerImpl
(
db
);
private
final
String
authorName
=
localAuthor
.
getName
();
private
final
KeyPair
keyPair
=
new
KeyPair
(
publicKey
,
privateKey
);
private
final
byte
[]
publicKeyBytes
=
localAuthor
.
getPublicKey
();
private
final
byte
[]
privateKeyBytes
=
localAuthor
.
getPrivateKey
();
private
IdentityManager
identityManager
;
@Before
public
void
setUp
()
{
identityManager
=
new
IdentityManagerImpl
(
db
,
crypto
,
authorFactory
);
}
@Test
public
void
testRegisterLocalAuthor
()
throws
DbException
{
expectRegisterLocalAuthor
();
identityManager
.
registerLocalAuthor
(
localAuthor
);
public
void
testCreateLocalAuthor
()
{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
crypto
).
generateSignatureKeyPair
();
will
(
returnValue
(
keyPair
));
oneOf
(
publicKey
).
getEncoded
();
will
(
returnValue
(
publicKeyBytes
));
oneOf
(
privateKey
).
getEncoded
();
will
(
returnValue
(
privateKeyBytes
));
oneOf
(
authorFactory
).
createLocalAuthor
(
authorName
,
publicKeyBytes
,
privateKeyBytes
);
will
(
returnValue
(
localAuthor
));
}});
assertEquals
(
localAuthor
,
identityManager
.
createLocalAuthor
(
authorName
));
}
private
void
expectRegisterLocalAuthor
()
throws
DbException
{
@Test
public
void
testRegisterAndStoreLocalAuthor
()
throws
DbException
{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
db
).
startTransaction
(
false
);
will
(
returnValue
(
txn
));
...
...
@@ -52,6 +82,10 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
oneOf
(
db
).
commitTransaction
(
txn
);
oneOf
(
db
).
endTransaction
(
txn
);
}});
identityManager
.
registerLocalAuthor
(
localAuthor
);
assertEquals
(
localAuthor
,
identityManager
.
getLocalAuthor
());
identityManager
.
storeLocalAuthor
();
}
@Test
...
...
@@ -69,7 +103,6 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
@Test
public
void
testGetCachedLocalAuthor
()
throws
DbException
{
expectRegisterLocalAuthor
();
identityManager
.
registerLocalAuthor
(
localAuthor
);
assertEquals
(
localAuthor
,
identityManager
.
getLocalAuthor
());
}
...
...
bramble-core/src/test/java/org/briarproject/bramble/test/TestDatabaseConfig.java
View file @
8283760e
...
...
@@ -46,16 +46,6 @@ public class TestDatabaseConfig implements DatabaseConfig {
return
key
;
}
@Override
public
void
setLocalAuthorName
(
String
nickname
)
{
}
@Override
public
String
getLocalAuthorName
()
{
return
null
;
}
@Override
public
long
getMaxSize
()
{
return
maxSize
;
...
...
bramble-core/src/test/java/org/briarproject/bramble/test/TestLifecycleModule.java
View file @
8283760e
...
...
@@ -11,7 +11,6 @@ import java.util.concurrent.Executor;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
javax.annotation.Nullable
;
import
javax.inject.Singleton
;
import
dagger.Module
;
...
...
@@ -40,7 +39,7 @@ public class TestLifecycleModule {
}
@Override
public
StartResult
startServices
(
@Nullable
String
nickname
)
{
public
StartResult
startServices
()
{
return
StartResult
.
SUCCESS
;
}
...
...
@@ -49,15 +48,15 @@ public class TestLifecycleModule {
}
@Override
public
void
waitForDatabase
()
throws
InterruptedException
{
public
void
waitForDatabase
()
{
}
@Override
public
void
waitForStartup
()
throws
InterruptedException
{
public
void
waitForStartup
()
{
}
@Override
public
void
waitForShutdown
()
throws
InterruptedException
{
public
void
waitForShutdown
()
{
}
@Override
...
...
briar-android/src/main/java/org/briarproject/briar/android/AndroidDatabaseConfig.java
View file @
8283760e
...
...
@@ -21,8 +21,6 @@ class AndroidDatabaseConfig implements DatabaseConfig {
@Nullable
private
volatile
SecretKey
key
=
null
;
@Nullable
private
volatile
String
nickname
=
null
;
AndroidDatabaseConfig
(
File
dbDir
,
File
keyDir
)
{
this
.
dbDir
=
dbDir
;
...
...
@@ -70,21 +68,6 @@ class AndroidDatabaseConfig implements DatabaseConfig {
this
.
key
=
key
;
}
@Override
public
void
setLocalAuthorName
(
String
nickname
)
{
LOG
.
info
(
"Setting local author name"
);
this
.
nickname
=
nickname
;
}
@Override
@Nullable
public
String
getLocalAuthorName
()
{
String
nickname
=
this
.
nickname
;
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Local author name has been set: "
+
(
nickname
!=
null
));
return
nickname
;
}
@Override
@Nullable
public
SecretKey
getEncryptionKey
()
{
...
...
briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
View file @
8283760e
...
...
@@ -141,8 +141,7 @@ public class BriarService extends Service {
nm
.
cancel
(
REMINDER_NOTIFICATION_ID
);
// Start the services in a background thread
new
Thread
(()
->
{
String
nickname
=
databaseConfig
.
getLocalAuthorName
();
StartResult
result
=
lifecycleManager
.
startServices
(
nickname
);
StartResult
result
=
lifecycleManager
.
startServices
();
if
(
result
==
SUCCESS
)
{
started
=
true
;
}
else
if
(
result
==
ALREADY_RUNNING
)
{
...
...
briar-android/src/main/java/org/briarproject/briar/android/login/SetupControllerImpl.java
View file @
8283760e
...
...
@@ -8,6 +8,8 @@ import org.briarproject.bramble.api.crypto.CryptoExecutor;
import
org.briarproject.bramble.api.crypto.PasswordStrengthEstimator
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.db.DatabaseConfig
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.briar.android.controller.handler.ResultHandler
;
import
org.briarproject.briar.android.controller.handler.UiResultHandler
;
...
...
@@ -24,6 +26,8 @@ public class SetupControllerImpl extends PasswordControllerImpl
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
SetupControllerImpl
.
class
.
getName
());
private
final
IdentityManager
identityManager
;
@Nullable
private
volatile
SetupActivity
setupActivity
;
...
...
@@ -31,9 +35,11 @@ public class SetupControllerImpl extends PasswordControllerImpl
SetupControllerImpl
(
SharedPreferences
briarPrefs
,
DatabaseConfig
databaseConfig
,
@CryptoExecutor
Executor
cryptoExecutor
,
CryptoComponent
crypto
,
PasswordStrengthEstimator
strengthEstimator
)
{
PasswordStrengthEstimator
strengthEstimator
,
IdentityManager
identityManager
)
{
super
(
briarPrefs
,
databaseConfig
,
cryptoExecutor
,
crypto
,
strengthEstimator
);
this
.
identityManager
=
identityManager
;
}
@Override
...
...
@@ -102,13 +108,14 @@ public class SetupControllerImpl extends PasswordControllerImpl
if
(
password
==
null
)
throw
new
IllegalStateException
();
cryptoExecutor
.
execute
(()
->
{
LOG
.
info
(
"Creating account"
);
databaseConfig
.
setLocalAuthorName
(
authorName
);
LocalAuthor
localAuthor
=
identityManager
.
createLocalAuthor
(
authorName
);
identityManager
.
registerLocalAuthor
(
localAuthor
);
SecretKey
key
=
crypto
.
generateSecretKey
();
databaseConfig
.
setEncryptionKey
(
key
);
String
hex
=
encryptDatabaseKey
(
key
,
password
);
storeEncryptedDatabaseKey
(
hex
);
databaseConfig
.
setEncryptionKey
(
key
);
resultHandler
.
onResult
(
null
);
});
}
}
briar-android/src/test/java/org/briarproject/briar/android/login/SetupControllerImplTest.java
View file @
8283760e
...
...
@@ -7,6 +7,8 @@ import org.briarproject.bramble.api.crypto.CryptoComponent;
import
org.briarproject.bramble.api.crypto.PasswordStrengthEstimator
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.db.DatabaseConfig
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.test.BrambleMockTestCase
;
import
org.briarproject.bramble.test.ImmediateExecutor
;
import
org.jmock.Expectations
;
...
...
@@ -23,6 +25,7 @@ import static junit.framework.Assert.assertFalse;
import
static
junit
.
framework
.
Assert
.
assertTrue
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_AUTHOR_NAME_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
deleteTestDirectory
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getLocalAuthor
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomBytes
;