Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
579
Issues
579
List
Boards
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
briar
briar
Commits
c062c16d
Commit
c062c16d
authored
May 15, 2019
by
Torsten Grote
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'merge-handshake-and-transport-keys' into 'master'
Add support for handshake keys to KeyManager See merge request
!1088
parents
6f31a3c2
84e24024
Pipeline
#3317
passed with stage
in 7 minutes and 11 seconds
Changes
37
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
1036 additions
and
1415 deletions
+1036
-1415
TransportCrypto.java
.../org/briarproject/bramble/api/crypto/TransportCrypto.java
+9
-16
DatabaseComponent.java
...va/org/briarproject/bramble/api/db/DatabaseComponent.java
+18
-63
AbstractTransportKeys.java
...rproject/bramble/api/transport/AbstractTransportKeys.java
+0
-57
HandshakeKeys.java
...org/briarproject/bramble/api/transport/HandshakeKeys.java
+0
-36
IncomingKeys.java
.../org/briarproject/bramble/api/transport/IncomingKeys.java
+2
-2
KeyManager.java
...va/org/briarproject/bramble/api/transport/KeyManager.java
+2
-2
KeySetId.java
...java/org/briarproject/bramble/api/transport/KeySetId.java
+5
-7
OutgoingKeys.java
.../org/briarproject/bramble/api/transport/OutgoingKeys.java
+2
-2
StreamContext.java
...org/briarproject/bramble/api/transport/StreamContext.java
+24
-2
TransportKeySet.java
...g/briarproject/bramble/api/transport/TransportKeySet.java
+20
-6
TransportKeySetId.java
...briarproject/bramble/api/transport/TransportKeySetId.java
+0
-38
TransportKeys.java
...org/briarproject/bramble/api/transport/TransportKeys.java
+92
-4
TransportCryptoImpl.java
.../org/briarproject/bramble/crypto/TransportCryptoImpl.java
+36
-32
Database.java
...e/src/main/java/org/briarproject/bramble/db/Database.java
+16
-59
DatabaseComponentImpl.java
...va/org/briarproject/bramble/db/DatabaseComponentImpl.java
+25
-92
JdbcDatabase.java
...c/main/java/org/briarproject/bramble/db/JdbcDatabase.java
+85
-399
Migration43_44.java
...main/java/org/briarproject/bramble/db/Migration43_44.java
+58
-0
ConnectionManagerImpl.java
...rg/briarproject/bramble/plugin/ConnectionManagerImpl.java
+5
-1
KeyManagerImpl.java
...va/org/briarproject/bramble/transport/KeyManagerImpl.java
+6
-6
MutableKeySet.java
...ava/org/briarproject/bramble/transport/MutableKeySet.java
+0
-30
MutableTransportKeySet.java
...riarproject/bramble/transport/MutableTransportKeySet.java
+50
-0
MutableTransportKeys.java
.../briarproject/bramble/transport/MutableTransportKeys.java
+34
-2
TransportKeyManager.java
...g/briarproject/bramble/transport/TransportKeyManager.java
+4
-5
TransportKeyManagerImpl.java
...iarproject/bramble/transport/TransportKeyManagerImpl.java
+114
-89
HandshakeKeyDerivationTest.java
...iarproject/bramble/crypto/HandshakeKeyDerivationTest.java
+0
-167
KeyDerivationTestUtils.java
...g/briarproject/bramble/crypto/KeyDerivationTestUtils.java
+0
-45
TransportKeyDerivationTest.java
...iarproject/bramble/crypto/TransportKeyDerivationTest.java
+214
-43
DatabaseComponentImplTest.java
...rg/briarproject/bramble/db/DatabaseComponentImplTest.java
+51
-29
JdbcDatabaseTest.java
...st/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
+82
-99
SyncIntegrationTest.java
...va/org/briarproject/bramble/sync/SyncIntegrationTest.java
+4
-4
KeyManagerImplTest.java
...rg/briarproject/bramble/transport/KeyManagerImplTest.java
+5
-5
TransportKeyManagerImplTest.java
...roject/bramble/transport/TransportKeyManagerImplTest.java
+52
-51
IntroduceeProtocolEngine.java
...rproject/briar/introduction/IntroduceeProtocolEngine.java
+2
-2
IntroduceeSession.java
...rg/briarproject/briar/introduction/IntroduceeSession.java
+5
-6
SessionEncoderImpl.java
...g/briarproject/briar/introduction/SessionEncoderImpl.java
+4
-3
SessionParserImpl.java
...rg/briarproject/briar/introduction/SessionParserImpl.java
+5
-5
SessionEncoderParserIntegrationTest.java
...iar/introduction/SessionEncoderParserIntegrationTest.java
+5
-6
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/crypto/TransportCrypto.java
View file @
c062c16d
package
org
.
briarproject
.
bramble
.
api
.
crypto
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.transport.HandshakeKeys
;
import
org.briarproject.bramble.api.transport.TransportKeys
;
/**
...
...
@@ -11,35 +10,29 @@ import org.briarproject.bramble.api.transport.TransportKeys;
public
interface
TransportCrypto
{
/**
* Derives initial
transport keys for the given transport in the give
n
* time period from the given root key.
* Derives initial
rotation mode transport keys for the given transport i
n
* t
he given t
ime period from the given root key.
*
* @param alice
whether the keys are for use by Alice or Bob.
* @param active
whether the keys are usable for outgoing streams.
* @param alice
Whether the keys are for use by Alice or Bob
* @param active
Whether the keys are usable for outgoing streams
*/
TransportKeys
derive
Transport
Keys
(
TransportId
t
,
SecretKey
rootKey
,
TransportKeys
derive
Rotation
Keys
(
TransportId
t
,
SecretKey
rootKey
,
long
timePeriod
,
boolean
alice
,
boolean
active
);
/**
* Rotates the given transport keys to the given time period. If the keys
* are for the given period or any later period they are not rotated.
*/
TransportKeys
rotateTransportKeys
(
TransportKeys
k
,
long
timePeriod
);
/**
* Derives handshake keys for the given transport in the given time period
* from the given root key.
*
* @param alice
whether the keys are for use by Alice or Bob.
* @param alice
Whether the keys are for use by Alice or Bob
*/
Handshake
Keys
deriveHandshakeKeys
(
TransportId
t
,
SecretKey
rootKey
,
Transport
Keys
deriveHandshakeKeys
(
TransportId
t
,
SecretKey
rootKey
,
long
timePeriod
,
boolean
alice
);
/**
* Updates the given
handshake
keys to the given time period. If the keys
* Updates the given
transport
keys to the given time period. If the keys
* are for the given period or any later period they are not updated.
*/
HandshakeKeys
updateHandshakeKeys
(
Handshake
Keys
k
,
long
timePeriod
);
TransportKeys
updateTransportKeys
(
Transport
Keys
k
,
long
timePeriod
);
/**
* Encodes the pseudo-random tag that is used to recognise a stream.
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java
View file @
c062c16d
...
...
@@ -24,11 +24,8 @@ import org.briarproject.bramble.api.sync.MessageStatus;
import
org.briarproject.bramble.api.sync.Offer
;
import
org.briarproject.bramble.api.sync.Request
;
import
org.briarproject.bramble.api.sync.validation.MessageState
;
import
org.briarproject.bramble.api.transport.HandshakeKeySet
;
import
org.briarproject.bramble.api.transport.HandshakeKeySetId
;
import
org.briarproject.bramble.api.transport.HandshakeKeys
;
import
org.briarproject.bramble.api.transport.KeySetId
;
import
org.briarproject.bramble.api.transport.TransportKeySet
;
import
org.briarproject.bramble.api.transport.TransportKeySetId
;
import
org.briarproject.bramble.api.transport.TransportKeys
;
import
java.util.Collection
;
...
...
@@ -115,20 +112,6 @@ public interface DatabaseComponent {
*/
void
addGroup
(
Transaction
txn
,
Group
g
)
throws
DbException
;
/**
* Stores the given handshake keys for the given contact and returns a
* key set ID.
*/
HandshakeKeySetId
addHandshakeKeys
(
Transaction
txn
,
ContactId
c
,
HandshakeKeys
k
)
throws
DbException
;
/**
* Stores the given handshake keys for the given pending contact and
* returns a key set ID.
*/
HandshakeKeySetId
addHandshakeKeys
(
Transaction
txn
,
PendingContactId
p
,
HandshakeKeys
k
)
throws
DbException
;
/**
* Stores an identity.
*/
...
...
@@ -156,7 +139,14 @@ public interface DatabaseComponent {
* Stores the given transport keys for the given contact and returns a
* key set ID.
*/
TransportKeySetId
addTransportKeys
(
Transaction
txn
,
ContactId
c
,
KeySetId
addTransportKeys
(
Transaction
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
* Stores the given transport keys for the given pending contact and
* returns a key set ID.
*/
KeySetId
addTransportKeys
(
Transaction
txn
,
PendingContactId
p
,
TransportKeys
k
)
throws
DbException
;
/**
...
...
@@ -276,7 +266,7 @@ public interface DatabaseComponent {
* <p/>
* Read-only.
*/
Collection
<
ContactId
>
getContacts
(
Transaction
txn
,
AuthorId
a
)
Collection
<
ContactId
>
getContacts
(
Transaction
txn
,
AuthorId
local
)
throws
DbException
;
/**
...
...
@@ -310,14 +300,6 @@ public interface DatabaseComponent {
Visibility
getGroupVisibility
(
Transaction
txn
,
ContactId
c
,
GroupId
g
)
throws
DbException
;
/**
* Returns all handshake keys for the given transport.
* <p/>
* Read-only.
*/
Collection
<
HandshakeKeySet
>
getHandshakeKeys
(
Transaction
txn
,
TransportId
t
)
throws
DbException
;
/**
* Returns the identity for the local pseudonym with the given ID.
* <p/>
...
...
@@ -489,17 +471,11 @@ public interface DatabaseComponent {
Collection
<
TransportKeySet
>
getTransportKeys
(
Transaction
txn
,
TransportId
t
)
throws
DbException
;
/**
* Increments the outgoing stream counter for the given handshake keys.
*/
void
incrementStreamCounter
(
Transaction
txn
,
TransportId
t
,
HandshakeKeySetId
k
)
throws
DbException
;
/**
* Increments the outgoing stream counter for the given transport keys.
*/
void
incrementStreamCounter
(
Transaction
txn
,
TransportId
t
,
TransportKeySetId
k
)
throws
DbException
;
void
incrementStreamCounter
(
Transaction
txn
,
TransportId
t
,
KeySetId
k
)
throws
DbException
;
/**
* Merges the given metadata with the existing metadata for the given
...
...
@@ -554,12 +530,6 @@ public interface DatabaseComponent {
*/
void
removeGroup
(
Transaction
txn
,
Group
g
)
throws
DbException
;
/**
* Removes the given handshake keys from the database.
*/
void
removeHandshakeKeys
(
Transaction
txn
,
TransportId
t
,
HandshakeKeySetId
k
)
throws
DbException
;
/**
* Removes an identity (and all associated state) from the database.
*/
...
...
@@ -584,8 +554,8 @@ public interface DatabaseComponent {
/**
* Removes the given transport keys from the database.
*/
void
removeTransportKeys
(
Transaction
txn
,
TransportId
t
,
TransportKeySetId
k
)
throws
DbException
;
void
removeTransportKeys
(
Transaction
txn
,
TransportId
t
,
KeySetId
k
)
throws
DbException
;
/**
* Marks the given contact as verified.
...
...
@@ -628,31 +598,16 @@ public interface DatabaseComponent {
PublicKey
publicKey
,
PrivateKey
privateKey
)
throws
DbException
;
/**
* Sets the reordering window for the given transport key
set
in the given
* Sets the reordering window for the given transport key
s
in the given
* time period.
*/
void
setReorderingWindow
(
Transaction
txn
,
TransportKeySetId
k
,
TransportId
t
,
long
timePeriod
,
long
base
,
byte
[]
bitmap
)
throws
DbException
;
/**
* Sets the reordering window for the given handshake key set in the given
* time period.
*/
void
setReorderingWindow
(
Transaction
txn
,
HandshakeKeySetId
k
,
TransportId
t
,
long
timePeriod
,
long
base
,
byte
[]
bitmap
)
throws
DbException
;
void
setReorderingWindow
(
Transaction
txn
,
KeySetId
k
,
TransportId
t
,
long
timePeriod
,
long
base
,
byte
[]
bitmap
)
throws
DbException
;
/**
* Marks the given transport keys as usable for outgoing streams.
*/
void
setTransportKeysActive
(
Transaction
txn
,
TransportId
t
,
TransportKeySetId
k
)
throws
DbException
;
/**
* Stores the given handshake keys, deleting any keys they have replaced.
*/
void
updateHandshakeKeys
(
Transaction
txn
,
Collection
<
HandshakeKeySet
>
keys
)
void
setTransportKeysActive
(
Transaction
txn
,
TransportId
t
,
KeySetId
k
)
throws
DbException
;
/**
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/AbstractTransportKeys.java
deleted
100644 → 0
View file @
6f31a3c2
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
javax.annotation.concurrent.Immutable
;
/**
* Abstract superclass for {@link TransportKeys} and {@link HandshakeKeys}.
*/
@Immutable
@NotNullByDefault
public
abstract
class
AbstractTransportKeys
{
private
final
TransportId
transportId
;
private
final
IncomingKeys
inPrev
,
inCurr
,
inNext
;
private
final
OutgoingKeys
outCurr
;
AbstractTransportKeys
(
TransportId
transportId
,
IncomingKeys
inPrev
,
IncomingKeys
inCurr
,
IncomingKeys
inNext
,
OutgoingKeys
outCurr
)
{
if
(
inPrev
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
()
-
1
)
throw
new
IllegalArgumentException
();
if
(
inCurr
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
())
throw
new
IllegalArgumentException
();
if
(
inNext
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
()
+
1
)
throw
new
IllegalArgumentException
();
this
.
transportId
=
transportId
;
this
.
inPrev
=
inPrev
;
this
.
inCurr
=
inCurr
;
this
.
inNext
=
inNext
;
this
.
outCurr
=
outCurr
;
}
public
TransportId
getTransportId
()
{
return
transportId
;
}
public
IncomingKeys
getPreviousIncomingKeys
()
{
return
inPrev
;
}
public
IncomingKeys
getCurrentIncomingKeys
()
{
return
inCurr
;
}
public
IncomingKeys
getNextIncomingKeys
()
{
return
inNext
;
}
public
OutgoingKeys
getCurrentOutgoingKeys
()
{
return
outCurr
;
}
public
long
getTimePeriod
()
{
return
outCurr
.
getTimePeriod
();
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/transport/HandshakeKeys.java
deleted
100644 → 0
View file @
6f31a3c2
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
javax.annotation.concurrent.Immutable
;
/**
* Keys for handshaking with a given contact or pending contact over a given
* transport. Unlike {@link TransportKeys} these keys do not provide forward
* secrecy.
*/
@Immutable
@NotNullByDefault
public
class
HandshakeKeys
extends
AbstractTransportKeys
{
private
final
SecretKey
rootKey
;
private
final
boolean
alice
;
public
HandshakeKeys
(
TransportId
transportId
,
IncomingKeys
inPrev
,
IncomingKeys
inCurr
,
IncomingKeys
inNext
,
OutgoingKeys
outCurr
,
SecretKey
rootKey
,
boolean
alice
)
{
super
(
transportId
,
inPrev
,
inCurr
,
inNext
,
outCurr
);
this
.
rootKey
=
rootKey
;
this
.
alice
=
alice
;
}
public
SecretKey
getRootKey
()
{
return
rootKey
;
}
public
boolean
isAlice
()
{
return
alice
;
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/transport/IncomingKeys.java
View file @
c062c16d
...
...
@@ -8,8 +8,8 @@ import javax.annotation.concurrent.Immutable;
import
static
org
.
briarproject
.
bramble
.
api
.
transport
.
TransportConstants
.
REORDERING_WINDOW_SIZE
;
/**
* Contains transport keys for receiving streams from a given contact o
ver a
* given transport in a given time period.
* Contains transport keys for receiving streams from a given contact o
r
*
pending contact over a
given transport in a given time period.
*/
@Immutable
@NotNullByDefault
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java
View file @
c062c16d
...
...
@@ -27,14 +27,14 @@ public interface KeyManager {
* @param alice true if the local party is Alice
* @param active whether the derived keys can be used for outgoing streams
*/
Map
<
TransportId
,
Transport
KeySetId
>
addContact
(
Transaction
txn
,
ContactId
c
,
Map
<
TransportId
,
KeySetId
>
addContact
(
Transaction
txn
,
ContactId
c
,
SecretKey
rootKey
,
long
timestamp
,
boolean
alice
,
boolean
active
)
throws
DbException
;
/**
* Marks the given transport keys as usable for outgoing streams.
*/
void
activateKeys
(
Transaction
txn
,
Map
<
TransportId
,
Transport
KeySetId
>
keys
)
void
activateKeys
(
Transaction
txn
,
Map
<
TransportId
,
KeySetId
>
keys
)
throws
DbException
;
/**
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/
Handshake
KeySetId.java
→
bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeySetId.java
View file @
c062c16d
...
...
@@ -5,17 +5,16 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import
javax.annotation.concurrent.Immutable
;
/**
* Type-safe wrapper for an integer that uniquely identifies a
* {@link HandshakeKeySet set of handshake keys} within the scope of the local
* device.
* Type-safe wrapper for an integer that uniquely identifies a set of
* {@link TransportKeySet transport keys} within the scope of the local device.
*/
@Immutable
@NotNullByDefault
public
class
Handshake
KeySetId
{
public
class
KeySetId
{
private
final
int
id
;
public
Handshake
KeySetId
(
int
id
)
{
public
KeySetId
(
int
id
)
{
this
.
id
=
id
;
}
...
...
@@ -30,7 +29,6 @@ public class HandshakeKeySetId {
@Override
public
boolean
equals
(
Object
o
)
{
return
o
instanceof
HandshakeKeySetId
&&
id
==
((
HandshakeKeySetId
)
o
).
id
;
return
o
instanceof
KeySetId
&&
id
==
((
KeySetId
)
o
).
id
;
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/transport/OutgoingKeys.java
View file @
c062c16d
...
...
@@ -6,8 +6,8 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import
javax.annotation.concurrent.Immutable
;
/**
* Contains transport keys for sending streams to a given contact o
ver a given
* transport in a given time period.
* Contains transport keys for sending streams to a given contact o
r pending
*
contact over a given
transport in a given time period.
*/
@Immutable
@NotNullByDefault
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/StreamContext.java
View file @
c062c16d
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.contact.PendingContactId
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.Immutable
;
@Immutable
@NotNullByDefault
public
class
StreamContext
{
@Nullable
private
final
ContactId
contactId
;
@Nullable
private
final
PendingContactId
pendingContactId
;
private
final
TransportId
transportId
;
private
final
SecretKey
tagKey
,
headerKey
;
private
final
long
streamNumber
;
private
final
boolean
handshakeMode
;
public
StreamContext
(
ContactId
contactId
,
TransportId
transportId
,
SecretKey
tagKey
,
SecretKey
headerKey
,
long
streamNumber
)
{
public
StreamContext
(
@Nullable
ContactId
contactId
,
@Nullable
PendingContactId
pendingContactId
,
TransportId
transportId
,
SecretKey
tagKey
,
SecretKey
headerKey
,
long
streamNumber
,
boolean
handshakeMode
)
{
if
((
contactId
==
null
)
==
(
pendingContactId
==
null
))
throw
new
IllegalArgumentException
();
this
.
contactId
=
contactId
;
this
.
pendingContactId
=
pendingContactId
;
this
.
transportId
=
transportId
;
this
.
tagKey
=
tagKey
;
this
.
headerKey
=
headerKey
;
this
.
streamNumber
=
streamNumber
;
this
.
handshakeMode
=
handshakeMode
;
}
@Nullable
public
ContactId
getContactId
()
{
return
contactId
;
}
@Nullable
public
PendingContactId
getPendingContactId
()
{
return
pendingContactId
;
}
public
TransportId
getTransportId
()
{
return
transportId
;
}
...
...
@@ -44,4 +62,8 @@ public class StreamContext {
public
long
getStreamNumber
()
{
return
streamNumber
;
}
public
boolean
isHandshakeMode
()
{
return
handshakeMode
;
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/transport/TransportKeySet.java
View file @
c062c16d
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.contact.PendingContactId
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.Immutable
;
/**
* A set of keys for communicating with a given contact o
ver a given transport.
*
Unlike a {@link HandshakeKeySet} these keys provide forward secrecy
.
* A set of keys for communicating with a given contact o
r pending contact
*
over a given transport
.
*/
@Immutable
@NotNullByDefault
public
class
TransportKeySet
{
private
final
TransportKeySetId
keySetId
;
private
final
KeySetId
keySetId
;
@Nullable
private
final
ContactId
contactId
;
@Nullable
private
final
PendingContactId
pendingContactId
;
private
final
TransportKeys
keys
;
public
TransportKeySet
(
TransportKeySetId
keySetId
,
ContactId
contactId
,
TransportKeys
keys
)
{
public
TransportKeySet
(
KeySetId
keySetId
,
@Nullable
ContactId
contactId
,
@Nullable
PendingContactId
pendingContactId
,
TransportKeys
keys
)
{
if
((
contactId
==
null
)
==
(
pendingContactId
==
null
))
throw
new
IllegalArgumentException
();
this
.
keySetId
=
keySetId
;
this
.
contactId
=
contactId
;
this
.
pendingContactId
=
pendingContactId
;
this
.
keys
=
keys
;
}
public
Transport
KeySetId
getKeySetId
()
{
public
KeySetId
getKeySetId
()
{
return
keySetId
;
}
@Nullable
public
ContactId
getContactId
()
{
return
contactId
;
}
@Nullable
public
PendingContactId
getPendingContactId
()
{
return
pendingContactId
;
}
public
TransportKeys
getKeys
()
{
return
keys
;
}
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/transport/TransportKeySetId.java
deleted
100644 → 0
View file @
6f31a3c2
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
javax.annotation.concurrent.Immutable
;
/**
* Type-safe wrapper for an integer that uniquely identifies a
* {@link TransportKeySet set of transport keys} within the scope of the local
* device.
* <p/>
* Key sets created on a given device must have increasing identifiers.
*/
@Immutable
@NotNullByDefault
public
class
TransportKeySetId
{
private
final
int
id
;
public
TransportKeySetId
(
int
id
)
{
this
.
id
=
id
;
}
public
int
getInt
()
{
return
id
;
}
@Override
public
int
hashCode
()
{
return
id
;
}
@Override
public
boolean
equals
(
Object
o
)
{
return
o
instanceof
TransportKeySetId
&&
id
==
((
TransportKeySetId
)
o
).
id
;
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/transport/TransportKeys.java
View file @
c062c16d
package
org
.
briarproject
.
bramble
.
api
.
transport
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.Immutable
;
/**
* Keys for communicating with a given contact o
ver a given transport. Unlike
*
{@link HandshakeKeys} these keys provide forward secrecy
.
* Keys for communicating with a given contact o
r pending contact over a given
*
transport
.
*/
@Immutable
@NotNullByDefault
public
class
TransportKeys
extends
AbstractTransportKeys
{
public
class
TransportKeys
{
private
final
TransportId
transportId
;
private
final
IncomingKeys
inPrev
,
inCurr
,
inNext
;
private
final
OutgoingKeys
outCurr
;
@Nullable
private
final
SecretKey
rootKey
;
private
final
boolean
alice
;
/**
* Constructor for rotation mode.
*/
public
TransportKeys
(
TransportId
transportId
,
IncomingKeys
inPrev
,
IncomingKeys
inCurr
,
IncomingKeys
inNext
,
OutgoingKeys
outCurr
)
{
super
(
transportId
,
inPrev
,
inCurr
,
inNext
,
outCurr
);
this
(
transportId
,
inPrev
,
inCurr
,
inNext
,
outCurr
,
null
,
false
);
}
/**
* Constructor for handshake mode.
*/
public
TransportKeys
(
TransportId
transportId
,
IncomingKeys
inPrev
,
IncomingKeys
inCurr
,
IncomingKeys
inNext
,
OutgoingKeys
outCurr
,
@Nullable
SecretKey
rootKey
,
boolean
alice
)
{
if
(
inPrev
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
()
-
1
)
throw
new
IllegalArgumentException
();
if
(
inCurr
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
())
throw
new
IllegalArgumentException
();
if
(
inNext
.
getTimePeriod
()
!=
outCurr
.
getTimePeriod
()
+
1
)
throw
new
IllegalArgumentException
();
this
.
transportId
=
transportId
;
this
.
inPrev
=
inPrev
;
this
.
inCurr
=
inCurr
;
this
.
inNext
=
inNext
;
this
.
outCurr
=
outCurr
;
this
.
rootKey
=
rootKey
;
this
.
alice
=
alice
;
}
public
TransportId
getTransportId
()
{
return
transportId
;
}
public
IncomingKeys
getPreviousIncomingKeys
()
{
return
inPrev
;
}
public
IncomingKeys
getCurrentIncomingKeys
()
{
return
inCurr
;
}
public
IncomingKeys
getNextIncomingKeys
()
{
return
inNext
;
}
public
OutgoingKeys
getCurrentOutgoingKeys
()
{
return
outCurr
;
}
public
long
getTimePeriod
()
{
return
outCurr
.
getTimePeriod
();
}
/**
* Returns true if these keys are for use in handshake mode or false if
* they're for use in rotation mode.
*/
public
boolean
isHandshakeMode
()
{
return
rootKey
!=
null
;
}
/**
* If these keys are for use in handshake mode, returns the root key.
*
* @throws UnsupportedOperationException If these keys are for use in
* rotation mode
*/
public
SecretKey
getRootKey
()
{
if
(
rootKey
==
null
)
throw
new
UnsupportedOperationException
();
return
rootKey
;
}
/**
* If these keys are for use in handshake mode, returns true if the local
* party is Alice.
*
* @throws UnsupportedOperationException If these keys are for use in
* rotation mode
*/
public
boolean
isAlice
()
{
if
(
rootKey
==
null
)
throw
new
UnsupportedOperationException
();
return
alice
;
}
}
bramble-core/src/main/java/org/briarproject/bramble/crypto/TransportCryptoImpl.java
View file @
c062c16d
...
...
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.crypto.CryptoComponent;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.crypto.TransportCrypto
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.transport.HandshakeKeys
;
import
org.briarproject.bramble.api.transport.IncomingKeys
;
import
org.briarproject.bramble.api.transport.OutgoingKeys
;
import
org.briarproject.bramble.api.transport.TransportKeys
;
...
...
@@ -42,7 +41,7 @@ class TransportCryptoImpl implements TransportCrypto {
}
@Override
public
TransportKeys
derive
Transport
Keys
(
TransportId
t
,
public
TransportKeys
derive
Rotation
Keys
(
TransportId
t
,
SecretKey
rootKey
,
long
timePeriod
,
boolean
weAreAlice
,
boolean
active
)
{
// Keys for the previous period are derived from the root key
...
...
@@ -70,31 +69,6 @@ class TransportCryptoImpl implements TransportCrypto {
return
new
TransportKeys
(
t
,
inPrev
,
inCurr
,
inNext
,
outCurr
);
}
@Override
public
TransportKeys
rotateTransportKeys
(
TransportKeys
k
,
long
timePeriod
)
{
if
(
k
.
getTimePeriod
()
>=
timePeriod
)
return
k
;
IncomingKeys
inPrev
=
k
.
getPreviousIncomingKeys
();
IncomingKeys
inCurr
=
k
.
getCurrentIncomingKeys
();
IncomingKeys
inNext
=
k
.
getNextIncomingKeys
();
OutgoingKeys
outCurr
=
k
.
getCurrentOutgoingKeys
();
long
startPeriod
=
outCurr
.
getTimePeriod
();
boolean
active
=
outCurr
.
isActive
();