Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
c05cfa11
Commit
c05cfa11
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Implement /keys/query
parent
31632908
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/client.cpp
+9
-0
9 additions, 0 deletions
src/client.cpp
src/client.hpp
+5
-0
5 additions, 0 deletions
src/client.hpp
tests/e2ee.cpp
+107
-0
107 additions, 0 deletions
tests/e2ee.cpp
with
121 additions
and
0 deletions
src/client.cpp
+
9
−
0
View file @
c05cfa11
...
...
@@ -568,3 +568,12 @@ Client::upload_keys(
post
<
mtx
::
requests
::
UploadKeys
,
mtx
::
responses
::
UploadKeys
>
(
"/client/r0/keys/upload"
,
req
,
callback
);
}
void
Client
::
query_keys
(
const
mtx
::
requests
::
QueryKeys
&
req
,
std
::
function
<
void
(
const
mtx
::
responses
::
QueryKeys
&
res
,
RequestErr
err
)
>
callback
)
{
post
<
mtx
::
requests
::
QueryKeys
,
mtx
::
responses
::
QueryKeys
>
(
"/client/r0/keys/query"
,
req
,
callback
);
}
This diff is collapsed.
Click to expand it.
src/client.hpp
+
5
−
0
View file @
c05cfa11
...
...
@@ -206,6 +206,11 @@ public:
const
mtx
::
requests
::
UploadKeys
&
req
,
std
::
function
<
void
(
const
mtx
::
responses
::
UploadKeys
&
res
,
RequestErr
err
)
>
cb
);
//! Returns the current devices and identity keys for the given users.
void
query_keys
(
const
mtx
::
requests
::
QueryKeys
&
req
,
std
::
function
<
void
(
const
mtx
::
responses
::
QueryKeys
&
res
,
RequestErr
err
)
>
cb
);
private
:
template
<
class
Request
,
class
Response
>
void
post
(
const
std
::
string
&
endpoint
,
...
...
This diff is collapsed.
Click to expand it.
tests/e2ee.cpp
+
107
−
0
View file @
c05cfa11
...
...
@@ -162,3 +162,110 @@ TEST(Encryption, UploadKeys)
alice
->
close
();
}
TEST
(
Encryption
,
QueryKeys
)
{
auto
alice
=
std
::
make_shared
<
Client
>
(
"localhost"
);
auto
alice_olm
=
mtx
::
client
::
crypto
::
olm_new_account
();
auto
bob
=
std
::
make_shared
<
Client
>
(
"localhost"
);
auto
bob_olm
=
mtx
::
client
::
crypto
::
olm_new_account
();
alice
->
login
(
"alice"
,
"secret"
,
[](
const
mtx
::
responses
::
Login
&
,
ErrType
err
)
{
check_error
(
err
);
});
bob
->
login
(
"bob"
,
"secret"
,
[](
const
mtx
::
responses
::
Login
&
,
ErrType
err
)
{
check_error
(
err
);
});
while
(
alice
->
access_token
().
empty
()
||
bob
->
access_token
().
empty
())
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
// Create and upload keys for both users.
auto
alice_idks
=
mtx
::
client
::
crypto
::
identity_keys
(
alice_olm
);
auto
bob_idks
=
mtx
::
client
::
crypto
::
identity_keys
(
bob_olm
);
mtx
::
client
::
crypto
::
generate_one_time_keys
(
alice_olm
,
1
);
mtx
::
client
::
crypto
::
generate_one_time_keys
(
bob_olm
,
1
);
auto
alice_otks
=
mtx
::
client
::
crypto
::
one_time_keys
(
alice_olm
);
auto
bob_otks
=
mtx
::
client
::
crypto
::
one_time_keys
(
bob_olm
);
auto
alice_req
=
mtx
::
client
::
crypto
::
create_upload_keys_request
(
alice_olm
,
alice_idks
,
alice_otks
,
alice
->
user_id
(),
alice
->
device_id
());
auto
bob_req
=
mtx
::
client
::
crypto
::
create_upload_keys_request
(
bob_olm
,
bob_idks
,
bob_otks
,
bob
->
user_id
(),
bob
->
device_id
());
// Validates that both upload requests are finished.
atomic_int
uploads
(
0
);
alice
->
upload_keys
(
alice_req
,
[
&
uploads
](
const
mtx
::
responses
::
UploadKeys
&
res
,
ErrType
err
)
{
check_error
(
err
);
EXPECT_EQ
(
res
.
one_time_key_counts
.
size
(),
1
);
EXPECT_EQ
(
res
.
one_time_key_counts
.
at
(
"signed_curve25519"
),
1
);
uploads
+=
1
;
});
bob
->
upload_keys
(
bob_req
,
[
&
uploads
](
const
mtx
::
responses
::
UploadKeys
&
res
,
ErrType
err
)
{
check_error
(
err
);
EXPECT_EQ
(
res
.
one_time_key_counts
.
size
(),
1
);
EXPECT_EQ
(
res
.
one_time_key_counts
.
at
(
"signed_curve25519"
),
1
);
uploads
+=
1
;
});
while
(
uploads
!=
2
)
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
atomic_int
responses
(
0
);
// Each user is requests each other's keys.
mtx
::
requests
::
QueryKeys
alice_rk
;
alice_rk
.
device_keys
[
bob
->
user_id
().
to_string
()]
=
{};
alice
->
query_keys
(
alice_rk
,
[
&
responses
,
bob
,
bob_req
](
const
mtx
::
responses
::
QueryKeys
&
res
,
ErrType
err
)
{
check_error
(
err
);
ASSERT_TRUE
(
res
.
failures
.
size
()
==
0
);
auto
bob_devices
=
res
.
device_keys
.
at
(
bob
->
user_id
().
to_string
());
ASSERT_TRUE
(
bob_devices
.
size
()
>
0
);
auto
dev_keys
=
bob_devices
.
at
(
bob
->
device_id
());
EXPECT_EQ
(
dev_keys
.
user_id
,
bob
->
user_id
().
to_string
());
EXPECT_EQ
(
dev_keys
.
device_id
,
bob
->
device_id
());
EXPECT_EQ
(
dev_keys
.
keys
,
bob_req
.
device_keys
.
keys
);
EXPECT_EQ
(
dev_keys
.
signatures
,
bob_req
.
device_keys
.
signatures
);
responses
+=
1
;
});
mtx
::
requests
::
QueryKeys
bob_rk
;
bob_rk
.
device_keys
[
alice
->
user_id
().
to_string
()]
=
{};
bob
->
query_keys
(
bob_rk
,
[
&
responses
,
alice
,
alice_req
](
const
mtx
::
responses
::
QueryKeys
&
res
,
ErrType
err
)
{
check_error
(
err
);
ASSERT_TRUE
(
res
.
failures
.
size
()
==
0
);
auto
bob_devices
=
res
.
device_keys
.
at
(
alice
->
user_id
().
to_string
());
ASSERT_TRUE
(
bob_devices
.
size
()
>
0
);
auto
dev_keys
=
bob_devices
.
at
(
alice
->
device_id
());
EXPECT_EQ
(
dev_keys
.
user_id
,
alice
->
user_id
().
to_string
());
EXPECT_EQ
(
dev_keys
.
device_id
,
alice
->
device_id
());
EXPECT_EQ
(
dev_keys
.
keys
,
alice_req
.
device_keys
.
keys
);
EXPECT_EQ
(
dev_keys
.
signatures
,
alice_req
.
device_keys
.
signatures
);
responses
+=
1
;
});
while
(
responses
!=
2
)
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
alice
->
close
();
bob
->
close
();
}
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