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
13902b0f
Commit
13902b0f
authored
Feb 24, 2015
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
run filter after decryption & security verifications
parent
51a4c176
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/securedht.h
+3
-3
3 additions, 3 deletions
include/opendht/securedht.h
src/dhtrunner.cpp
+4
-4
4 additions, 4 deletions
src/dhtrunner.cpp
src/securedht.cpp
+15
-10
15 additions, 10 deletions
src/securedht.cpp
with
22 additions
and
17 deletions
include/opendht/securedht.h
+
3
−
3
View file @
13902b0f
...
...
@@ -86,9 +86,9 @@ public:
* If the signature can't be checked, or if the data can't be decrypted, it is not returned.
* Public, non-signed & non-encrypted data is retransmitted as-is.
*/
void
get
(
const
InfoHash
&
id
,
GetCallback
cb
,
DoneCallback
donecb
,
Value
::
Filter
=
Value
::
AllFilter
()
);
void
get
(
const
InfoHash
&
id
,
GetCallback
cb
,
DoneCallback
donecb
,
Value
::
Filter
&&
=
{}
);
size_t
listen
(
const
InfoHash
&
id
,
GetCallback
cb
,
Value
::
Filter
=
Value
::
AllFilter
()
);
size_t
listen
(
const
InfoHash
&
id
,
GetCallback
cb
,
Value
::
Filter
&&
=
{}
);
/**
* Will take ownership of the value, sign it using our private key and put it in the DHT.
...
...
@@ -127,7 +127,7 @@ private:
SecureDht
(
const
SecureDht
&
)
=
delete
;
SecureDht
&
operator
=
(
const
SecureDht
&
)
=
delete
;
GetCallback
getCallbackFilter
(
GetCallback
);
GetCallback
getCallbackFilter
(
GetCallback
,
Value
::
Filter
&&
);
std
::
shared_ptr
<
crypto
::
PrivateKey
>
key_
{};
std
::
shared_ptr
<
crypto
::
Certificate
>
certificate_
{};
...
...
This diff is collapsed.
Click to expand it.
src/dhtrunner.cpp
+
4
−
4
View file @
13902b0f
...
...
@@ -221,8 +221,8 @@ void
DhtRunner
::
get
(
InfoHash
hash
,
Dht
::
GetCallback
vcb
,
Dht
::
DoneCallback
dcb
,
Value
::
Filter
f
)
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
storage_mtx
);
pending_ops
.
emplace
([
=
](
SecureDht
&
dht
)
{
dht
.
get
(
hash
,
vcb
,
dcb
,
f
);
pending_ops
.
emplace
([
=
](
SecureDht
&
dht
)
mutable
{
dht
.
get
(
hash
,
vcb
,
dcb
,
std
::
move
(
f
)
);
});
cv
.
notify_all
();
}
...
...
@@ -238,8 +238,8 @@ DhtRunner::listen(InfoHash hash, Dht::GetCallback vcb, Value::Filter f)
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
storage_mtx
);
auto
ret_token
=
std
::
make_shared
<
std
::
promise
<
size_t
>>
();
pending_ops
.
emplace
([
=
](
SecureDht
&
dht
)
{
ret_token
->
set_value
(
dht
.
listen
(
hash
,
vcb
,
f
));
pending_ops
.
emplace
([
=
](
SecureDht
&
dht
)
mutable
{
ret_token
->
set_value
(
dht
.
listen
(
hash
,
vcb
,
std
::
move
(
f
)
));
});
cv
.
notify_all
();
return
ret_token
->
get_future
();
...
...
This diff is collapsed.
Click to expand it.
src/securedht.cpp
+
15
−
10
View file @
13902b0f
...
...
@@ -183,7 +183,7 @@ SecureDht::findCertificate(const InfoHash& node, std::function<void(const std::s
Dht
::
GetCallback
SecureDht
::
getCallbackFilter
(
GetCallback
cb
)
SecureDht
::
getCallbackFilter
(
GetCallback
cb
,
Value
::
Filter
&&
filter
)
{
return
[
=
](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
)
{
std
::
vector
<
std
::
shared_ptr
<
Value
>>
tmpvals
{};
...
...
@@ -193,8 +193,10 @@ SecureDht::getCallbackFilter(GetCallback cb)
try
{
Value
decrypted_val
(
decrypt
(
*
v
));
if
(
decrypted_val
.
recipient
==
getId
())
{
if
(
decrypted_val
.
owner
.
checkSignature
(
decrypted_val
.
getToSign
(),
decrypted_val
.
signature
))
if
(
decrypted_val
.
owner
.
checkSignature
(
decrypted_val
.
getToSign
(),
decrypted_val
.
signature
))
{
if
(
not
filter
or
filter
(
decrypted_val
))
tmpvals
.
push_back
(
std
::
make_shared
<
Value
>
(
std
::
move
(
decrypted_val
)));
}
else
DHT_WARN
(
"Signature verification failed for %s"
,
v
->
toString
().
c_str
());
}
...
...
@@ -205,13 +207,16 @@ SecureDht::getCallbackFilter(GetCallback cb)
}
// Check signed values
else
if
(
v
->
isSigned
())
{
if
(
v
->
owner
.
checkSignature
(
v
->
getToSign
(),
v
->
signature
))
if
(
v
->
owner
.
checkSignature
(
v
->
getToSign
(),
v
->
signature
))
{
if
(
not
filter
or
filter
(
*
v
))
tmpvals
.
push_back
(
v
);
}
else
DHT_WARN
(
"Signature verification failed for %s"
,
v
->
toString
().
c_str
());
}
// Forward normal values
else
{
if
(
not
filter
or
filter
(
*
v
))
tmpvals
.
push_back
(
v
);
}
}
...
...
@@ -222,15 +227,15 @@ SecureDht::getCallbackFilter(GetCallback cb)
}
void
SecureDht
::
get
(
const
InfoHash
&
id
,
GetCallback
cb
,
DoneCallback
donecb
,
Value
::
Filter
f
ilter
)
SecureDht
::
get
(
const
InfoHash
&
id
,
GetCallback
cb
,
DoneCallback
donecb
,
Value
::
Filter
&&
f
)
{
Dht
::
get
(
id
,
getCallbackFilter
(
cb
)
,
donecb
,
filter
);
Dht
::
get
(
id
,
getCallbackFilter
(
cb
,
std
::
forward
<
Value
::
Filter
>
(
f
)),
donecb
);
}
size_t
SecureDht
::
listen
(
const
InfoHash
&
id
,
GetCallback
cb
,
Value
::
Filter
f
ilter
)
SecureDht
::
listen
(
const
InfoHash
&
id
,
GetCallback
cb
,
Value
::
Filter
&&
f
)
{
return
Dht
::
listen
(
id
,
getCallbackFilter
(
cb
)
,
filter
);
return
Dht
::
listen
(
id
,
getCallbackFilter
(
cb
,
std
::
forward
<
Value
::
Filter
>
(
f
))
);
}
void
...
...
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