Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
b2542a57
Commit
b2542a57
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
securedht: cache value signature check/decryption results
parent
00c1be9c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/value.h
+10
-0
10 additions, 0 deletions
include/opendht/value.h
src/securedht.cpp
+12
-2
12 additions, 2 deletions
src/securedht.cpp
with
22 additions
and
2 deletions
include/opendht/value.h
+
10
−
0
View file @
b2542a57
...
...
@@ -122,6 +122,8 @@ private:
std
::
map
<
ValueType
::
Id
,
ValueType
>
types
{};
};
struct
CryptoValueCache
;
/**
* A "value" is data potentially stored on the Dht, with some metadata.
*
...
...
@@ -588,6 +590,14 @@ struct OPENDHT_PUBLIC Value
* Hold encrypted version of the data.
*/
Blob
cypher
{};
private
:
friend
class
SecureDht
;
/* Cache for crypto ops */
bool
signatureChecked
{
false
};
bool
signatureValid
{
false
};
bool
decrypted
{
false
};
Sp
<
Value
>
decryptedValue
{};
};
using
ValuesExport
=
std
::
pair
<
InfoHash
,
Blob
>
;
...
...
This diff is collapsed.
Click to expand it.
src/securedht.cpp
+
12
−
2
View file @
b2542a57
...
...
@@ -235,12 +235,17 @@ SecureDht::checkValue(const Sp<Value>& v)
#endif
return
{};
}
if
(
v
->
decrypted
)
{
return
v
->
decryptedValue
;
}
v
->
decrypted
=
true
;
try
{
Value
decrypted_val
(
decrypt
(
*
v
));
if
(
decrypted_val
.
recipient
==
getId
())
{
if
(
decrypted_val
.
owner
)
nodesPubKeys_
[
decrypted_val
.
owner
->
getId
()]
=
decrypted_val
.
owner
;
return
std
::
make_shared
<
Value
>
(
std
::
move
(
decrypted_val
));
v
->
decryptedValue
=
std
::
make_shared
<
Value
>
(
std
::
move
(
decrypted_val
));
return
v
->
decryptedValue
;
}
// Ignore values belonging to other people
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -249,7 +254,12 @@ SecureDht::checkValue(const Sp<Value>& v)
}
// Check signed values
else
if
(
v
->
isSigned
())
{
if
(
v
->
signatureChecked
)
{
return
v
->
signatureValid
?
v
:
Sp
<
Value
>
{};
}
v
->
signatureChecked
=
true
;
if
(
v
->
owner
and
v
->
owner
->
checkSignature
(
v
->
getToSign
(),
v
->
signature
))
{
v
->
signatureValid
=
true
;
nodesPubKeys_
[
v
->
owner
->
getId
()]
=
v
->
owner
;
return
v
;
}
...
...
@@ -355,7 +365,7 @@ SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback,
void
SecureDht
::
putEncrypted
(
const
InfoHash
&
hash
,
const
InfoHash
&
to
,
Sp
<
Value
>
val
,
DoneCallback
callback
,
bool
permanent
)
{
findPublicKey
(
to
,
[
=
](
const
Sp
<
const
crypto
::
PublicKey
>
pk
)
{
findPublicKey
(
to
,
[
=
](
const
Sp
<
const
crypto
::
PublicKey
>
&
pk
)
{
if
(
!
pk
||
!*
pk
)
{
if
(
callback
)
callback
(
false
,
{});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment