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
89a4d192
Verified
Commit
89a4d192
authored
Apr 26, 2018
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove support for unbound transport keys.
parent
e83d8bb7
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
121 additions
and
501 deletions
+121
-501
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
.../org/briarproject/bramble/api/contact/ContactManager.java
+3
-3
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java
...va/org/briarproject/bramble/api/db/DatabaseComponent.java
+3
-9
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java
...va/org/briarproject/bramble/api/transport/KeyManager.java
+5
-29
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeySet.java
...n/java/org/briarproject/bramble/api/transport/KeySet.java
+2
-6
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
.../org/briarproject/bramble/contact/ContactManagerImpl.java
+1
-1
bramble-core/src/main/java/org/briarproject/bramble/db/Database.java
...e/src/main/java/org/briarproject/bramble/db/Database.java
+3
-9
bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java
...va/org/briarproject/bramble/db/DatabaseComponentImpl.java
+3
-15
bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java
...c/main/java/org/briarproject/bramble/db/JdbcDatabase.java
+5
-35
bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java
...va/org/briarproject/bramble/transport/KeyManagerImpl.java
+4
-39
bramble-core/src/main/java/org/briarproject/bramble/transport/MutableKeySet.java
...ava/org/briarproject/bramble/transport/MutableKeySet.java
+5
-9
bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java
...g/briarproject/bramble/transport/TransportKeyManager.java
+2
-9
bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java
...iarproject/bramble/transport/TransportKeyManagerImpl.java
+9
-57
bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java
.../briarproject/bramble/contact/ContactManagerImplTest.java
+2
-2
bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java
...rg/briarproject/bramble/db/DatabaseComponentImplTest.java
+6
-28
bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
...st/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
+16
-100
bramble-core/src/test/java/org/briarproject/bramble/transport/KeyManagerImplTest.java
...rg/briarproject/bramble/transport/KeyManagerImplTest.java
+8
-18
bramble-core/src/test/java/org/briarproject/bramble/transport/TransportKeyManagerImplTest.java
...roject/bramble/transport/TransportKeyManagerImplTest.java
+41
-128
briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java
...rproject/briar/introduction/IntroduceeProtocolEngine.java
+3
-4
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
View file @
89a4d192
...
...
@@ -45,9 +45,9 @@ public interface ContactManager {
*
* @param alice true if the local party is Alice
*/
ContactId
addContact
(
Author
remote
,
AuthorId
local
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
verified
,
boolean
active
)
throws
DbException
;
ContactId
addContact
(
Author
remote
,
AuthorId
local
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
verified
,
boolean
active
)
throws
DbException
;
/**
* Returns the contact with the given ID.
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java
View file @
89a4d192
...
...
@@ -104,18 +104,12 @@ public interface DatabaseComponent {
throws
DbException
;
/**
* Stores the given transport keys
, optionally binding them to the given
*
contact, and returns a
key set ID.
* Stores the given transport keys
for the given contact and returns a
* key set ID.
*/
KeySetId
addTransportKeys
(
Transaction
txn
,
@Nullable
ContactId
c
,
KeySetId
addTransportKeys
(
Transaction
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
* Binds the given keys for the given transport to the given contact.
*/
void
bindTransportKeys
(
Transaction
txn
,
ContactId
c
,
TransportId
t
,
KeySetId
k
)
throws
DbException
;
/**
* Returns true if the database contains the given contact for the given
* local pseudonym.
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java
View file @
89a4d192
...
...
@@ -19,48 +19,24 @@ public interface KeyManager {
/**
* Informs the key manager that a new contact has been added. Derives and
* stores a set of transport keys for communicating with the contact over
* each transport.
* each transport
and returns the key set IDs
.
* <p/>
* {@link StreamContext StreamContexts} for the contact can be created
* after this method has returned.
*
* @param alice true if the local party is Alice
* @param active whether the derived keys can be used for outgoing streams
*/
void
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
;
/**
* Derives and stores a set of unbound transport keys for each transport
* and returns the key set IDs.
* <p/>
* The keys must be bound before they can be used for incoming streams,
* and also activated before they can be used for outgoing streams.
*
* @param alice true if the local party is Alice
*/
Map
<
TransportId
,
KeySetId
>
addUnboundKeys
(
Transaction
txn
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
;
/**
* Binds the given transport keys to the given contact.
*/
void
bindKeys
(
Transaction
txn
,
ContactId
c
,
Map
<
TransportId
,
KeySetId
>
keys
)
Map
<
TransportId
,
KeySetId
>
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
;
/**
* Marks the given transport keys as usable for outgoing streams. Keys must
* be bound before they are activated.
* Marks the given transport keys as usable for outgoing streams.
*/
void
activateKeys
(
Transaction
txn
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
;
/**
* Removes the given transport keys, which must not have been bound, from
* the manager and the database.
*/
void
removeKeys
(
Transaction
txn
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
;
/**
* Returns true if we have keys that can be used for outgoing streams to
* the given contact over the given transport.
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeySet.java
View file @
89a4d192
...
...
@@ -3,23 +3,20 @@ package org.briarproject.bramble.api.transport;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.Immutable
;
/**
* A set of transport keys for communicating with a contact. If the keys have
* not yet been bound to a contact, {@link #getContactId()}} returns null.
* A set of transport keys for communicating with a contact.
*/
@Immutable
@NotNullByDefault
public
class
KeySet
{
private
final
KeySetId
keySetId
;
@Nullable
private
final
ContactId
contactId
;
private
final
TransportKeys
transportKeys
;
public
KeySet
(
KeySetId
keySetId
,
@Nullable
ContactId
contactId
,
public
KeySet
(
KeySetId
keySetId
,
ContactId
contactId
,
TransportKeys
transportKeys
)
{
this
.
keySetId
=
keySetId
;
this
.
contactId
=
contactId
;
...
...
@@ -30,7 +27,6 @@ public class KeySet {
return
keySetId
;
}
@Nullable
public
ContactId
getContactId
()
{
return
contactId
;
}
...
...
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
View file @
89a4d192
...
...
@@ -46,7 +46,7 @@ class ContactManagerImpl implements ContactManager {
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
verified
,
boolean
active
)
throws
DbException
{
ContactId
c
=
db
.
addContact
(
txn
,
remote
,
local
,
verified
,
active
);
keyManager
.
addContact
(
txn
,
c
,
master
,
timestamp
,
alice
);
keyManager
.
addContact
(
txn
,
c
,
master
,
timestamp
,
alice
,
active
);
Contact
contact
=
db
.
getContact
(
txn
,
c
);
for
(
ContactHook
hook
:
hooks
)
hook
.
addingContact
(
txn
,
contact
);
return
c
;
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/Database.java
View file @
89a4d192
...
...
@@ -125,16 +125,10 @@ interface Database<T> {
throws
DbException
;
/**
* Stores the given transport keys
, optionally binding them to the given
*
contact, and returns a
key set ID.
* Stores the given transport keys
for the given contact and returns a
* key set ID.
*/
KeySetId
addTransportKeys
(
T
txn
,
@Nullable
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
* Binds the given keys for the given transport to the given contact.
*/
void
bindTransportKeys
(
T
txn
,
ContactId
c
,
TransportId
t
,
KeySetId
k
)
KeySetId
addTransportKeys
(
T
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java
View file @
89a4d192
...
...
@@ -234,29 +234,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
}
@Override
public
KeySetId
addTransportKeys
(
Transaction
transaction
,
@Nullable
ContactId
c
,
TransportKeys
k
)
throws
DbException
{
public
KeySetId
addTransportKeys
(
Transaction
transaction
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(
c
!=
null
&&
!
db
.
containsContact
(
txn
,
c
))
if
(!
db
.
containsContact
(
txn
,
c
))
throw
new
NoSuchContactException
();
if
(!
db
.
containsTransport
(
txn
,
k
.
getTransportId
()))
throw
new
NoSuchTransportException
();
return
db
.
addTransportKeys
(
txn
,
c
,
k
);
}
@Override
public
void
bindTransportKeys
(
Transaction
transaction
,
ContactId
c
,
TransportId
t
,
KeySetId
k
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsContact
(
txn
,
c
))
throw
new
NoSuchContactException
();
if
(!
db
.
containsTransport
(
txn
,
t
))
throw
new
NoSuchTransportException
();
db
.
bindTransportKeys
(
txn
,
c
,
t
,
k
);
}
@Override
public
boolean
containsContact
(
Transaction
transaction
,
AuthorId
remote
,
AuthorId
local
)
throws
DbException
{
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java
View file @
89a4d192
...
...
@@ -236,7 +236,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+
" (transportId _STRING NOT NULL,"
+
" keySetId _COUNTER,"
+
" rotationPeriod BIGINT NOT NULL,"
+
" contactId INT
,"
// Null if keys are not bound
+
" contactId INT
NOT NULL,"
+
" tagKey _SECRET NOT NULL,"
+
" headerKey _SECRET NOT NULL,"
+
" stream BIGINT NOT NULL,"
...
...
@@ -255,7 +255,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+
" (transportId _STRING NOT NULL,"
+
" keySetId INT NOT NULL,"
+
" rotationPeriod BIGINT NOT NULL,"
+
" contactId INT
,"
// Null if keys are not bound
+
" contactId INT
NOT NULL,"
+
" tagKey _SECRET NOT NULL,"
+
" headerKey _SECRET NOT NULL,"
+
" base BIGINT NOT NULL,"
...
...
@@ -883,7 +883,7 @@ abstract class JdbcDatabase implements Database<Connection> {
}
@Override
public
KeySetId
addTransportKeys
(
Connection
txn
,
@Nullable
ContactId
c
,
public
KeySetId
addTransportKeys
(
Connection
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
{
PreparedStatement
ps
=
null
;
ResultSet
rs
=
null
;
...
...
@@ -893,8 +893,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+
" rotationPeriod, tagKey, headerKey, stream, active)"
+
" VALUES (?, ?, ?, ?, ?, ?, ?)"
;
ps
=
txn
.
prepareStatement
(
sql
);
if
(
c
==
null
)
ps
.
setNull
(
1
,
INTEGER
);
else
ps
.
setInt
(
1
,
c
.
getInt
());
ps
.
setInt
(
1
,
c
.
getInt
());
ps
.
setString
(
2
,
k
.
getTransportId
().
getString
());
OutgoingKeys
outCurr
=
k
.
getCurrentOutgoingKeys
();
ps
.
setLong
(
3
,
outCurr
.
getRotationPeriod
());
...
...
@@ -922,8 +921,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
;
ps
=
txn
.
prepareStatement
(
sql
);
ps
.
setInt
(
1
,
keySetId
.
getInt
());
if
(
c
==
null
)
ps
.
setNull
(
2
,
INTEGER
);
else
ps
.
setInt
(
2
,
c
.
getInt
());
ps
.
setInt
(
2
,
c
.
getInt
());
ps
.
setString
(
3
,
k
.
getTransportId
().
getString
());
// Previous rotation period
IncomingKeys
inPrev
=
k
.
getPreviousIncomingKeys
();
...
...
@@ -965,33 +963,6 @@ abstract class JdbcDatabase implements Database<Connection> {
}
}
@Override
public
void
bindTransportKeys
(
Connection
txn
,
ContactId
c
,
TransportId
t
,
KeySetId
k
)
throws
DbException
{
PreparedStatement
ps
=
null
;
try
{
String
sql
=
"UPDATE outgoingKeys SET contactId = ?"
+
" WHERE keySetId = ?"
;
ps
=
txn
.
prepareStatement
(
sql
);
ps
.
setInt
(
1
,
c
.
getInt
());
ps
.
setInt
(
2
,
k
.
getInt
());
int
affected
=
ps
.
executeUpdate
();
if
(
affected
<
0
)
throw
new
DbStateException
();
ps
.
close
();
sql
=
"UPDATE incomingKeys SET contactId = ?"
+
" WHERE keySetId = ?"
;
ps
=
txn
.
prepareStatement
(
sql
);
ps
.
setInt
(
1
,
c
.
getInt
());
ps
.
setInt
(
2
,
k
.
getInt
());
affected
=
ps
.
executeUpdate
();
if
(
affected
<
0
)
throw
new
DbStateException
();
ps
.
close
();
}
catch
(
SQLException
e
)
{
tryToClose
(
ps
);
throw
new
DbException
(
e
);
}
}
@Override
public
boolean
containsContact
(
Connection
txn
,
AuthorId
remote
,
AuthorId
local
)
throws
DbException
{
...
...
@@ -2172,7 +2143,6 @@ abstract class JdbcDatabase implements Database<Connection> {
if
(
inKeys
.
size
()
<
(
i
+
1
)
*
3
)
throw
new
DbStateException
();
KeySetId
keySetId
=
new
KeySetId
(
rs
.
getInt
(
1
));
ContactId
contactId
=
new
ContactId
(
rs
.
getInt
(
2
));
if
(
rs
.
wasNull
())
contactId
=
null
;
long
rotationPeriod
=
rs
.
getLong
(
3
);
SecretKey
tagKey
=
new
SecretKey
(
rs
.
getBytes
(
4
));
SecretKey
headerKey
=
new
SecretKey
(
rs
.
getBytes
(
5
));
...
...
bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java
View file @
89a4d192
...
...
@@ -99,39 +99,18 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
}
@Override
public
void
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
{
for
(
TransportKeyManager
m
:
managers
.
values
())
m
.
addContact
(
txn
,
c
,
master
,
timestamp
,
alice
);
}
@Override
public
Map
<
TransportId
,
KeySetId
>
addUnboundKeys
(
Transaction
txn
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
public
Map
<
TransportId
,
KeySetId
>
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
{
Map
<
TransportId
,
KeySetId
>
ids
=
new
HashMap
<>();
for
(
Entry
<
TransportId
,
TransportKeyManager
>
e
:
managers
.
entrySet
())
{
TransportId
t
=
e
.
getKey
();
TransportKeyManager
m
=
e
.
getValue
();
ids
.
put
(
t
,
m
.
add
UnboundKeys
(
txn
,
master
,
timestamp
,
alic
e
));
ids
.
put
(
t
,
m
.
add
Contact
(
txn
,
c
,
master
,
timestamp
,
alice
,
activ
e
));
}
return
ids
;
}
@Override
public
void
bindKeys
(
Transaction
txn
,
ContactId
c
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
{
for
(
Entry
<
TransportId
,
KeySetId
>
e
:
keys
.
entrySet
())
{
TransportId
t
=
e
.
getKey
();
TransportKeyManager
m
=
managers
.
get
(
t
);
if
(
m
==
null
)
{
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"No key manager for "
+
t
);
}
else
{
m
.
bindKeys
(
txn
,
c
,
e
.
getValue
());
}
}
}
@Override
public
void
activateKeys
(
Transaction
txn
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
{
...
...
@@ -146,24 +125,10 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
}
}
@Override
public
void
removeKeys
(
Transaction
txn
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
{
for
(
Entry
<
TransportId
,
KeySetId
>
e
:
keys
.
entrySet
())
{
TransportId
t
=
e
.
getKey
();
TransportKeyManager
m
=
managers
.
get
(
t
);
if
(
m
==
null
)
{
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"No key manager for "
+
t
);
}
else
{
m
.
removeKeys
(
txn
,
e
.
getValue
());
}
}
}
@Override
public
boolean
canSendOutgoingStreams
(
ContactId
c
,
TransportId
t
)
{
TransportKeyManager
m
=
managers
.
get
(
t
);
return
m
==
null
?
false
:
m
.
canSendOutgoingStreams
(
c
);
return
m
!=
null
&&
m
.
canSendOutgoingStreams
(
c
);
}
@Override
...
...
bramble-core/src/main/java/org/briarproject/bramble/transport/MutableKeySet.java
View file @
89a4d192
...
...
@@ -3,32 +3,28 @@ package org.briarproject.bramble.transport;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.transport.KeySetId
;
import
javax.annotation.Nullable
;
public
class
MutableKeySet
{
class
MutableKeySet
{
private
final
KeySetId
keySetId
;
@Nullable
private
final
ContactId
contactId
;
private
final
MutableTransportKeys
transportKeys
;
public
MutableKeySet
(
KeySetId
keySetId
,
@Nullable
ContactId
contactId
,
MutableKeySet
(
KeySetId
keySetId
,
ContactId
contactId
,
MutableTransportKeys
transportKeys
)
{
this
.
keySetId
=
keySetId
;
this
.
contactId
=
contactId
;
this
.
transportKeys
=
transportKeys
;
}
public
KeySetId
getKeySetId
()
{
KeySetId
getKeySetId
()
{
return
keySetId
;
}
@Nullable
public
ContactId
getContactId
()
{
ContactId
getContactId
()
{
return
contactId
;
}
public
MutableTransportKeys
getTransportKeys
()
{
MutableTransportKeys
getTransportKeys
()
{
return
transportKeys
;
}
}
bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java
View file @
89a4d192
...
...
@@ -15,18 +15,11 @@ interface TransportKeyManager {
void
start
(
Transaction
txn
)
throws
DbException
;
void
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
;
KeySetId
addUnboundKeys
(
Transaction
txn
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
;
void
bindKeys
(
Transaction
txn
,
ContactId
c
,
KeySetId
k
)
throws
DbException
;
KeySetId
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
;
void
activateKeys
(
Transaction
txn
,
KeySetId
k
)
throws
DbException
;
void
removeKeys
(
Transaction
txn
,
KeySetId
k
)
throws
DbException
;
void
removeContact
(
ContactId
c
);
boolean
canSendOutgoingStreams
(
ContactId
c
);
...
...
bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java
View file @
89a4d192
...
...
@@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.logging.Logger
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.ThreadSafe
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
...
...
@@ -119,16 +118,14 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
// Locking: lock
private
void
addKeys
(
KeySetId
keySetId
,
@Nullable
ContactId
contactId
,
private
void
addKeys
(
KeySetId
keySetId
,
ContactId
contactId
,
MutableTransportKeys
m
)
{
MutableKeySet
ks
=
new
MutableKeySet
(
keySetId
,
contactId
,
m
);
keys
.
put
(
keySetId
,
ks
);
if
(
contactId
!=
null
)
{
encodeTags
(
keySetId
,
contactId
,
m
.
getPreviousIncomingKeys
());
encodeTags
(
keySetId
,
contactId
,
m
.
getCurrentIncomingKeys
());
encodeTags
(
keySetId
,
contactId
,
m
.
getNextIncomingKeys
());
considerReplacingOutgoingKeys
(
ks
);
}
encodeTags
(
keySetId
,
contactId
,
m
.
getPreviousIncomingKeys
());
encodeTags
(
keySetId
,
contactId
,
m
.
getCurrentIncomingKeys
());
encodeTags
(
keySetId
,
contactId
,
m
.
getNextIncomingKeys
());
considerReplacingOutgoingKeys
(
ks
);
}
// Locking: lock
...
...
@@ -150,8 +147,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
if
(
ks
.
getTransportKeys
().
getCurrentOutgoingKeys
().
isActive
())
{
MutableKeySet
old
=
outContexts
.
get
(
ks
.
getContactId
());
if
(
old
==
null
||
old
.
getKeySetId
().
getInt
()
<
ks
.
getKeySetId
().
getInt
())
old
.
getKeySetId
().
getInt
()
<
ks
.
getKeySetId
().
getInt
())
{
outContexts
.
put
(
ks
.
getContactId
(),
ks
);
}
}
}
...
...
@@ -177,20 +175,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
@Override
public
void
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
{
deriveAndAddKeys
(
txn
,
c
,
master
,
timestamp
,
alice
,
true
);
}
@Override
public
KeySetId
addUnboundKeys
(
Transaction
txn
,
SecretKey
master
,
long
timestamp
,
boolean
alice
)
throws
DbException
{
return
deriveAndAddKeys
(
txn
,
null
,
master
,
timestamp
,
alice
,
false
);
}
private
KeySetId
deriveAndAddKeys
(
Transaction
txn
,
@Nullable
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
{
public
KeySetId
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
master
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
{
lock
.
lock
();
try
{
// Work out what rotation period the timestamp belongs to
...
...
@@ -211,31 +197,12 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
@Override
public
void
bindKeys
(
Transaction
txn
,
ContactId
c
,
KeySetId
k
)
throws
DbException
{
lock
.
lock
();
try
{
MutableKeySet
ks
=
keys
.
get
(
k
);
if
(
ks
==
null
)
throw
new
IllegalArgumentException
();
// Check that the keys haven't already been bound
if
(
ks
.
getContactId
()
!=
null
)
throw
new
IllegalArgumentException
();
MutableTransportKeys
m
=
ks
.
getTransportKeys
();
addKeys
(
k
,
c
,
m
);
db
.
bindTransportKeys
(
txn
,
c
,
m
.
getTransportId
(),
k
);
}
finally
{
lock
.
unlock
();
}
}
@Override
public
void
activateKeys
(
Transaction
txn
,
KeySetId
k
)
throws
DbException
{
lock
.
lock
();
try
{
MutableKeySet
ks
=
keys
.
get
(
k
);
if
(
ks
==
null
)
throw
new
IllegalArgumentException
();
// Check that the keys have been bound
if
(
ks
.
getContactId
()
==
null
)
throw
new
IllegalArgumentException
();
MutableTransportKeys
m
=
ks
.
getTransportKeys
();
m
.
getCurrentOutgoingKeys
().
activate
();
considerReplacingOutgoingKeys
(
ks
);
...
...
@@ -245,21 +212,6 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
@Override
public
void
removeKeys
(
Transaction
txn
,
KeySetId
k
)
throws
DbException
{
lock
.
lock
();
try
{
MutableKeySet
ks
=
keys
.
remove
(
k
);
if
(
ks
==
null
)
throw
new
IllegalArgumentException
();
// Check that the keys haven't been bound
if
(
ks
.
getContactId
()
!=
null
)
throw
new
IllegalArgumentException
();
TransportId
t
=
ks
.
getTransportKeys
().
getTransportId
();
db
.
removeTransportKeys
(
txn
,
t
,
k
);
}
finally
{
lock
.
unlock
();
}
}
@Override
public
void
removeContact
(
ContactId
c
)
{
lock
.
lock
();
...
...
bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java
View file @
89a4d192
...
...
@@ -55,8 +55,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
will
(
returnValue
(
txn
));
oneOf
(
db
).
addContact
(
txn
,
remote
,
local
,
verified
,
active
);
will
(
returnValue
(
contactId
));
oneOf
(
keyManager
)
.
addContact
(
txn
,
contactId
,
master
,
timestamp
,
alic
e
);
oneOf
(
keyManager
)
.
addContact
(
txn
,
contactId
,
master
,
timestamp
,
alice
,
activ
e
);
oneOf
(
db
).
getContact
(
txn
,
contactId
);
will
(
returnValue
(
contact
));
oneOf
(
db
).
commitTransaction
(
txn
);
...
...
bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java
View file @
89a4d192
...
...
@@ -289,11 +289,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
throws
Exception
{
context
.
checking
(
new
Expectations
()
{{
// Check whether the contact is in the DB (which it's not)
exactly
(
1
7
).
of
(
database
).
startTransaction
();
exactly
(
1
6
).
of
(
database
).
startTransaction
();
will
(
returnValue
(
txn
));
exactly
(
1
7
).
of
(
database
).
containsContact
(
txn
,
contactId
);
exactly
(
1
6
).
of
(
database
).
containsContact
(
txn
,
contactId
);
will
(
returnValue
(
false
));
exactly
(
1
7
).
of
(
database
).
abortTransaction
(
txn
);
exactly
(
1
6
).
of
(
database
).
abortTransaction
(
txn
);
}});
DatabaseComponent
db
=
createDatabaseComponent
(
database
,
eventBus
,
shutdown
);
...
...
@@ -308,16 +308,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db
.
endTransaction
(
transaction
);
}
transaction
=
db
.
startTransaction
(
false
);
try
{
db
.
bindTransportKeys
(
transaction
,
contactId
,
transportId
,
keySetId
);
fail
();
}
catch
(
NoSuchContactException
expected
)
{
// Expected
}
finally
{
db
.
endTransaction
(
transaction
);
}
transaction
=
db
.
startTransaction
(
false
);
try
{
db
.
generateAck
(
transaction
,
contactId
,
123
);
...
...
@@ -773,13 +763,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
// endTransaction()
oneOf
(
database
).
commitTransaction
(
txn
);
// Check whether the transport is in the DB (which it's not)
exactly
(
6
).
of
(
database
).
startTransaction
();
exactly
(
5
).
of
(
database
).
startTransaction
();
will
(
returnValue
(
txn
));
oneOf
(
database
).
containsContact
(
txn
,
contactId
);
will
(
returnValue
(
true
));
exactly
(
6
).
of
(
database
).
containsTransport
(
txn
,
transportId
);
exactly
(
5
).
of
(
database
).
containsTransport
(
txn
,
transportId
);
will
(
returnValue
(
false
));
exactly
(
6
).
of
(
database
).
abortTransaction
(
txn
);
exactly
(
5
).
of
(
database
).
abortTransaction
(
txn
);
}});
DatabaseComponent
db
=
createDatabaseComponent
(
database
,
eventBus
,
shutdown
);
...
...
@@ -794,16 +782,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db
.
endTransaction
(
transaction
);
}
transaction
=
db
.
startTransaction
(
false
);
try
{
db
.
bin