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
677
Issues
677
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
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
43787dea
Verified
Commit
43787dea
authored
May 14, 2019
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review comments.
parent
e5fc91b6
Pipeline
#3303
passed with stage
in 7 minutes and 15 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
14 deletions
+30
-14
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
...rg/briarproject/bramble/identity/IdentityManagerImpl.java
+30
-14
No files found.
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
View file @
43787dea
...
...
@@ -92,12 +92,18 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
public
void
onDatabaseOpened
(
Transaction
txn
)
throws
DbException
{
Identity
cached
=
getCachedIdentity
(
txn
);
if
(
shouldStoreIdentity
)
{
// The identity was registered at startup - store it
db
.
addIdentity
(
txn
,
cached
);
LOG
.
info
(
"Identity stored"
);
}
else
if
(
shouldStoreKeys
)
{
byte
[]
publicKey
=
requireNonNull
(
cached
.
getHandshakePublicKey
());
byte
[]
privateKey
=
requireNonNull
(
cached
.
getHandshakePrivateKey
());
db
.
setHandshakeKeyPair
(
txn
,
cached
.
getId
(),
publicKey
,
privateKey
);
// Handshake keys were generated when loading the identity -
// store them
byte
[]
handshakePub
=
requireNonNull
(
cached
.
getHandshakePublicKey
());
byte
[]
handshakePriv
=
requireNonNull
(
cached
.
getHandshakePrivateKey
());
db
.
setHandshakeKeyPair
(
txn
,
cached
.
getId
(),
handshakePub
,
handshakePriv
);
LOG
.
info
(
"Handshake key pair stored"
);
}
}
...
...
@@ -124,6 +130,15 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
};
}
/**
* Loads the identity if necessary and returns it. If
* {@code cachedIdentity} was not already set by calling
* {@link #registerIdentity(Identity)}, this method sets it. If
* {@code cachedIdentity} was already set, either by calling
* {@link #registerIdentity(Identity)} or by a previous call to this
* method, then this method returns the cached identity without hitting
* the database.
*/
private
Identity
getCachedIdentity
(
Transaction
txn
)
throws
DbException
{
Identity
cached
=
cachedIdentity
;
if
(
cached
==
null
)
...
...
@@ -131,23 +146,24 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
return
cached
;
}
/**
* Loads and returns the identity, generating a handshake key pair if
* necessary and setting {@code shouldStoreKeys} if a handshake key pair
* was generated.
*/
private
Identity
loadIdentityWithKeyPair
(
Transaction
txn
)
throws
DbException
{
Identity
i
=
loadIdentity
(
txn
);
Collection
<
Identity
>
identities
=
db
.
getIdentities
(
txn
);
if
(
identities
.
size
()
!=
1
)
throw
new
DbException
();
Identity
i
=
identities
.
iterator
().
next
();
LOG
.
info
(
"Identity loaded"
);
if
(
i
.
hasHandshakeKeyPair
())
return
i
;
KeyPair
k
eyPair
=
crypto
.
generateAgreementKeyPair
();
byte
[]
publicKey
=
k
eyPair
.
getPublic
().
getEncoded
();
byte
[]
privateKey
=
k
eyPair
.
getPrivate
().
getEncoded
();
KeyPair
handshakeK
eyPair
=
crypto
.
generateAgreementKeyPair
();
byte
[]
handshakePub
=
handshakeK
eyPair
.
getPublic
().
getEncoded
();
byte
[]
handshakePriv
=
handshakeK
eyPair
.
getPrivate
().
getEncoded
();
LOG
.
info
(
"Handshake key pair generated"
);
shouldStoreKeys
=
true
;
return
new
Identity
(
i
.
getLocalAuthor
(),
publicKey
,
privateKey
,
return
new
Identity
(
i
.
getLocalAuthor
(),
handshakePub
,
handshakePriv
,
i
.
getTimeCreated
());
}
private
Identity
loadIdentity
(
Transaction
txn
)
throws
DbException
{
Collection
<
Identity
>
identities
=
db
.
getIdentities
(
txn
);
if
(
identities
.
size
()
!=
1
)
throw
new
DbException
();
return
identities
.
iterator
().
next
();
}
}
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