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
681
Issues
681
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
briar
briar
Commits
9c8125d7
Verified
Commit
9c8125d7
authored
Apr 19, 2019
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename 'alice' flags to clarify usage, add comments.
parent
1a1a010e
Pipeline
#3213
passed with stage
in 10 minutes and 24 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
40 deletions
+46
-40
bramble-core/src/main/java/org/briarproject/bramble/crypto/TransportCryptoImpl.java
.../org/briarproject/bramble/crypto/TransportCryptoImpl.java
+46
-40
No files found.
bramble-core/src/main/java/org/briarproject/bramble/crypto/TransportCryptoImpl.java
View file @
9c8125d7
...
...
@@ -43,12 +43,13 @@ class TransportCryptoImpl implements TransportCrypto {
@Override
public
TransportKeys
deriveTransportKeys
(
TransportId
t
,
SecretKey
rootKey
,
long
timePeriod
,
boolean
alice
,
boolean
active
)
{
SecretKey
rootKey
,
long
timePeriod
,
boolean
weAreAlice
,
boolean
active
)
{
// Keys for the previous period are derived from the root key
SecretKey
inTagPrev
=
deriveTagKey
(
rootKey
,
t
,
!
a
lice
);
SecretKey
inHeaderPrev
=
deriveHeaderKey
(
rootKey
,
t
,
!
a
lice
);
SecretKey
outTagPrev
=
deriveTagKey
(
rootKey
,
t
,
a
lice
);
SecretKey
outHeaderPrev
=
deriveHeaderKey
(
rootKey
,
t
,
a
lice
);
SecretKey
inTagPrev
=
deriveTagKey
(
rootKey
,
t
,
!
weAreA
lice
);
SecretKey
inHeaderPrev
=
deriveHeaderKey
(
rootKey
,
t
,
!
weAreA
lice
);
SecretKey
outTagPrev
=
deriveTagKey
(
rootKey
,
t
,
weAreA
lice
);
SecretKey
outHeaderPrev
=
deriveHeaderKey
(
rootKey
,
t
,
weAreA
lice
);
// Derive the keys for the current and next periods
SecretKey
inTagCurr
=
rotateKey
(
inTagPrev
,
timePeriod
);
SecretKey
inHeaderCurr
=
rotateKey
(
inHeaderPrev
,
timePeriod
);
...
...
@@ -101,54 +102,57 @@ class TransportCryptoImpl implements TransportCrypto {
}
private
SecretKey
deriveTagKey
(
SecretKey
rootKey
,
TransportId
t
,
boolean
a
lice
)
{
String
label
=
a
lice
?
ALICE_TAG_LABEL
:
BOB_TAG_LABEL
;
boolean
keyBelongsToA
lice
)
{
String
label
=
keyBelongsToA
lice
?
ALICE_TAG_LABEL
:
BOB_TAG_LABEL
;
byte
[]
id
=
toUtf8
(
t
.
getString
());
return
crypto
.
deriveKey
(
label
,
rootKey
,
id
);
}
private
SecretKey
deriveHeaderKey
(
SecretKey
rootKey
,
TransportId
t
,
boolean
alice
)
{
String
label
=
alice
?
ALICE_HEADER_LABEL
:
BOB_HEADER_LABEL
;
boolean
keyBelongsToAlice
)
{
String
label
=
keyBelongsToAlice
?
ALICE_HEADER_LABEL
:
BOB_HEADER_LABEL
;
byte
[]
id
=
toUtf8
(
t
.
getString
());
return
crypto
.
deriveKey
(
label
,
rootKey
,
id
);
}
@Override
public
HandshakeKeys
deriveHandshakeKeys
(
TransportId
t
,
SecretKey
rootKey
,
long
timePeriod
,
boolean
a
lice
)
{
long
timePeriod
,
boolean
weAreA
lice
)
{
if
(
timePeriod
<
1
)
throw
new
IllegalArgumentException
();
IncomingKeys
inPrev
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
alice
,
timePeriod
-
1
);
IncomingKeys
inCurr
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
alice
,
timePeriod
);
IncomingKeys
inNext
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
alice
,
timePeriod
+
1
);
OutgoingKeys
outCurr
=
deriveOutgoingHandshakeKeys
(
t
,
rootKey
,
alice
,
timePeriod
);
IncomingKeys
inPrev
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
weAreAlice
,
timePeriod
-
1
);
IncomingKeys
inCurr
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
weAreAlice
,
timePeriod
);
IncomingKeys
inNext
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
weAreAlice
,
timePeriod
+
1
);
OutgoingKeys
outCurr
=
deriveOutgoingHandshakeKeys
(
t
,
rootKey
,
weAreAlice
,
timePeriod
);
return
new
HandshakeKeys
(
t
,
inPrev
,
inCurr
,
inNext
,
outCurr
,
rootKey
,
a
lice
);
weAreA
lice
);
}
private
IncomingKeys
deriveIncomingHandshakeKeys
(
TransportId
t
,
SecretKey
rootKey
,
boolean
alice
,
long
timePeriod
)
{
SecretKey
tag
=
deriveHandshakeTagKey
(
t
,
rootKey
,
!
alice
,
timePeriod
);
SecretKey
header
=
deriveHandshakeHeaderKey
(
t
,
rootKey
,
!
alice
,
SecretKey
rootKey
,
boolean
weAreAlice
,
long
timePeriod
)
{
SecretKey
tag
=
deriveHandshakeTagKey
(
t
,
rootKey
,
!
weAreAlice
,
timePeriod
);
SecretKey
header
=
deriveHandshakeHeaderKey
(
t
,
rootKey
,
!
weAreAlice
,
timePeriod
);
return
new
IncomingKeys
(
tag
,
header
,
timePeriod
);
}
private
OutgoingKeys
deriveOutgoingHandshakeKeys
(
TransportId
t
,
SecretKey
rootKey
,
boolean
alice
,
long
timePeriod
)
{
SecretKey
tag
=
deriveHandshakeTagKey
(
t
,
rootKey
,
alice
,
timePeriod
);
SecretKey
header
=
deriveHandshakeHeaderKey
(
t
,
rootKey
,
alice
,
SecretKey
rootKey
,
boolean
weAreAlice
,
long
timePeriod
)
{
SecretKey
tag
=
deriveHandshakeTagKey
(
t
,
rootKey
,
weAreAlice
,
timePeriod
);
SecretKey
header
=
deriveHandshakeHeaderKey
(
t
,
rootKey
,
weAreAlice
,
timePeriod
);
return
new
OutgoingKeys
(
tag
,
header
,
timePeriod
,
true
);
}
private
SecretKey
deriveHandshakeTagKey
(
TransportId
t
,
SecretKey
rootKey
,
boolean
a
lice
,
long
timePeriod
)
{
String
label
=
a
lice
?
ALICE_HANDSHAKE_TAG_LABEL
:
boolean
keyBelongsToA
lice
,
long
timePeriod
)
{
String
label
=
keyBelongsToA
lice
?
ALICE_HANDSHAKE_TAG_LABEL
:
BOB_HANDSHAKE_TAG_LABEL
;
byte
[]
id
=
toUtf8
(
t
.
getString
());
byte
[]
period
=
new
byte
[
INT_64_BYTES
];
...
...
@@ -157,8 +161,8 @@ class TransportCryptoImpl implements TransportCrypto {
}
private
SecretKey
deriveHandshakeHeaderKey
(
TransportId
t
,
SecretKey
rootKey
,
boolean
a
lice
,
long
timePeriod
)
{
String
label
=
a
lice
?
ALICE_HANDSHAKE_HEADER_LABEL
:
boolean
keyBelongsToA
lice
,
long
timePeriod
)
{
String
label
=
keyBelongsToA
lice
?
ALICE_HANDSHAKE_HEADER_LABEL
:
BOB_HANDSHAKE_HEADER_LABEL
;
byte
[]
id
=
toUtf8
(
t
.
getString
());
byte
[]
period
=
new
byte
[
INT_64_BYTES
];
...
...
@@ -171,34 +175,36 @@ class TransportCryptoImpl implements TransportCrypto {
long
elapsed
=
timePeriod
-
k
.
getTimePeriod
();
TransportId
t
=
k
.
getTransportId
();
SecretKey
rootKey
=
k
.
getRootKey
();
boolean
a
lice
=
k
.
isAlice
();
boolean
weAreA
lice
=
k
.
isAlice
();
if
(
elapsed
<=
0
)
{
// The keys are for the given period or later - don't update them
return
k
;
}
else
if
(
elapsed
==
1
)
{
// The keys are one period old - shift by one period
// The keys are one period old - shift by one period, keeping the
// reordering windows for keys we retain
IncomingKeys
inPrev
=
k
.
getCurrentIncomingKeys
();
IncomingKeys
inCurr
=
k
.
getNextIncomingKeys
();
IncomingKeys
inNext
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
a
lice
,
timePeriod
+
1
);
weAreA
lice
,
timePeriod
+
1
);
OutgoingKeys
outCurr
=
deriveOutgoingHandshakeKeys
(
t
,
rootKey
,
a
lice
,
timePeriod
);
weAreA
lice
,
timePeriod
);
return
new
HandshakeKeys
(
t
,
inPrev
,
inCurr
,
inNext
,
outCurr
,
rootKey
,
a
lice
);
rootKey
,
weAreA
lice
);
}
else
if
(
elapsed
==
2
)
{
// The keys are two periods old - shift by two periods
// The keys are two periods old - shift by two periods, keeping
// the reordering windows for keys we retain
IncomingKeys
inPrev
=
k
.
getNextIncomingKeys
();
IncomingKeys
inCurr
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
a
lice
,
timePeriod
);
weAreA
lice
,
timePeriod
);
IncomingKeys
inNext
=
deriveIncomingHandshakeKeys
(
t
,
rootKey
,
a
lice
,
timePeriod
+
1
);
weAreA
lice
,
timePeriod
+
1
);
OutgoingKeys
outCurr
=
deriveOutgoingHandshakeKeys
(
t
,
rootKey
,
a
lice
,
timePeriod
);
weAreA
lice
,
timePeriod
);
return
new
HandshakeKeys
(
t
,
inPrev
,
inCurr
,
inNext
,
outCurr
,
rootKey
,
a
lice
);
rootKey
,
weAreA
lice
);
}
else
{
// The keys are more than two periods old - derive fresh keys
return
deriveHandshakeKeys
(
t
,
rootKey
,
timePeriod
,
a
lice
);
return
deriveHandshakeKeys
(
t
,
rootKey
,
timePeriod
,
weAreA
lice
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment