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
31632908
Commit
31632908
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Move helper functions from the tests into the lib
parent
e17ecf77
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.travis.yml
+3
-3
3 additions, 3 deletions
.travis.yml
src/crypto.cpp
+29
-0
29 additions, 0 deletions
src/crypto.cpp
src/crypto.hpp
+9
-0
9 additions, 0 deletions
src/crypto.hpp
tests/e2ee.cpp
+4
-50
4 additions, 50 deletions
tests/e2ee.cpp
with
45 additions
and
53 deletions
.travis.yml
+
3
−
3
View file @
31632908
...
...
@@ -39,10 +39,10 @@ matrix:
apt
:
sources
:
-
"
ubuntu-toolchain-r-test"
-
"
llvm-toolchain-trusty-
5
.0"
-
"
llvm-toolchain-trusty-
6
.0"
packages
:
-
"
clang++-
5
.0"
-
"
clang-
5
.0"
-
"
clang++-
6
.0"
-
"
clang-
6
.0"
-
"
g++-7"
install
:
...
...
This diff is collapsed.
Click to expand it.
src/crypto.cpp
+
29
−
0
View file @
31632908
...
...
@@ -125,6 +125,35 @@ mtx::client::crypto::sign_one_time_keys(std::shared_ptr<olm::Account> account,
return
signed_one_time_keys
;
}
mtx
::
requests
::
UploadKeys
mtx
::
client
::
crypto
::
create_upload_keys_request
(
std
::
shared_ptr
<
olm
::
Account
>
account
,
const
mtx
::
client
::
crypto
::
IdentityKeys
&
identity_keys
,
const
mtx
::
client
::
crypto
::
OneTimeKeys
&
one_time_keys
,
const
mtx
::
identifiers
::
User
&
user_id
,
const
std
::
string
&
device_id
)
{
mtx
::
requests
::
UploadKeys
req
;
req
.
device_keys
.
user_id
=
user_id
.
to_string
();
req
.
device_keys
.
device_id
=
device_id
;
req
.
device_keys
.
keys
[
"curve25519:"
+
device_id
]
=
identity_keys
.
curve25519
;
req
.
device_keys
.
keys
[
"ed25519:"
+
device_id
]
=
identity_keys
.
ed25519
;
// Generate and add the signature to the request.
auto
sig
=
sign_identity_keys
(
account
,
identity_keys
,
user_id
,
device_id
);
req
.
device_keys
.
signatures
[
user_id
.
to_string
()][
"ed25519:"
+
device_id
]
=
sig
;
if
(
one_time_keys
.
curve25519
.
empty
())
return
req
;
// Sign & append the one time keys.
req
.
one_time_keys
=
mtx
::
client
::
crypto
::
sign_one_time_keys
(
account
,
one_time_keys
,
user_id
,
device_id
);
return
req
;
}
std
::
unique_ptr
<
BinaryBuf
>
mtx
::
client
::
crypto
::
sign_message
(
std
::
shared_ptr
<
olm
::
Account
>
account
,
const
std
::
string
&
msg
)
{
...
...
This diff is collapsed.
Click to expand it.
src/crypto.hpp
+
9
−
0
View file @
31632908
...
...
@@ -5,6 +5,7 @@
#include
<json.hpp>
#include
<mtx/identifiers.hpp>
#include
<mtx/requests.hpp>
#include
<olm/account.hh>
#include
<olm/error.h>
...
...
@@ -125,6 +126,14 @@ sign_one_time_keys(std::shared_ptr<olm::Account> account,
const
mtx
::
identifiers
::
User
&
user_id
,
const
std
::
string
&
device_id
);
//! Prepare request for the /keys/upload endpoint by signing identity & one time keys.
mtx
::
requests
::
UploadKeys
create_upload_keys_request
(
std
::
shared_ptr
<
olm
::
Account
>
account
,
const
mtx
::
client
::
crypto
::
IdentityKeys
&
identity_keys
,
const
mtx
::
client
::
crypto
::
OneTimeKeys
&
one_time_keys
,
const
mtx
::
identifiers
::
User
&
user_id
,
const
std
::
string
&
device_id
);
std
::
string
encode_base64
(
const
uint8_t
*
data
,
std
::
size_t
len
);
...
...
This diff is collapsed.
Click to expand it.
tests/e2ee.cpp
+
4
−
50
View file @
31632908
...
...
@@ -24,52 +24,6 @@ using namespace std;
using
ErrType
=
std
::
experimental
::
optional
<
errors
::
ClientError
>
;
std
::
map
<
std
::
string
,
json
>
sign_one_time_keys
(
std
::
shared_ptr
<
olm
::
Account
>
account
,
const
mtx
::
client
::
crypto
::
OneTimeKeys
&
keys
,
const
mtx
::
identifiers
::
User
&
user_id
,
const
std
::
string
&
device_id
)
{
// Sign & append the one time keys.
std
::
map
<
std
::
string
,
json
>
signed_one_time_keys
;
for
(
const
auto
&
elem
:
keys
.
curve25519
)
{
auto
sig
=
mtx
::
client
::
crypto
::
sign_one_time_key
(
account
,
elem
.
second
);
signed_one_time_keys
[
"signed_curve25519:"
+
elem
.
first
]
=
mtx
::
client
::
crypto
::
signed_one_time_key_json
(
user_id
,
device_id
,
elem
.
second
,
sig
);
}
return
signed_one_time_keys
;
}
mtx
::
requests
::
UploadKeys
create_upload_keys_request
(
std
::
shared_ptr
<
olm
::
Account
>
account
,
const
mtx
::
client
::
crypto
::
IdentityKeys
&
identity_keys
,
const
mtx
::
client
::
crypto
::
OneTimeKeys
&
one_time_keys
,
const
mtx
::
identifiers
::
User
&
user_id
,
const
string
&
device_id
)
{
mtx
::
requests
::
UploadKeys
req
;
req
.
device_keys
.
user_id
=
user_id
.
to_string
();
req
.
device_keys
.
device_id
=
device_id
;
req
.
device_keys
.
keys
[
"curve25519:"
+
device_id
]
=
identity_keys
.
curve25519
;
req
.
device_keys
.
keys
[
"ed25519:"
+
device_id
]
=
identity_keys
.
ed25519
;
// Generate and add the signature to the request.
auto
sig
=
sign_identity_keys
(
account
,
identity_keys
,
user_id
,
device_id
);
req
.
device_keys
.
signatures
[
user_id
.
to_string
()][
"ed25519:"
+
device_id
]
=
sig
;
if
(
one_time_keys
.
curve25519
.
empty
())
return
req
;
// Sign & append the one time keys.
req
.
one_time_keys
=
::
sign_one_time_keys
(
account
,
one_time_keys
,
user_id
,
device_id
);
return
req
;
}
void
check_error
(
ErrType
err
)
{
...
...
@@ -104,7 +58,7 @@ TEST(Encryption, UploadIdentityKeys)
ASSERT_TRUE
(
identity_keys
.
curve25519
.
size
()
>
10
);
mtx
::
client
::
crypto
::
OneTimeKeys
unused
;
auto
request
=
::
create_upload_keys_request
(
auto
request
=
mtx
::
client
::
crypto
::
create_upload_keys_request
(
olm_account
,
identity_keys
,
unused
,
alice
->
user_id
(),
alice
->
device_id
());
// Make the request with the signed identity keys.
...
...
@@ -169,8 +123,8 @@ TEST(Encryption, UploadSignedOneTimeKeys)
auto
one_time_keys
=
mtx
::
client
::
crypto
::
one_time_keys
(
olm_account
);
mtx
::
requests
::
UploadKeys
req
;
req
.
one_time_keys
=
::
sign_one_time_keys
(
olm_account
,
one_time_keys
,
alice
->
user_id
(),
alice
->
device_id
());
req
.
one_time_keys
=
mtx
::
client
::
crypto
::
sign_one_time_keys
(
olm_account
,
one_time_keys
,
alice
->
user_id
(),
alice
->
device_id
());
alice
->
upload_keys
(
req
,
[
nkeys
](
const
mtx
::
responses
::
UploadKeys
&
res
,
ErrType
err
)
{
check_error
(
err
);
...
...
@@ -197,7 +151,7 @@ TEST(Encryption, UploadKeys)
mtx
::
client
::
crypto
::
generate_one_time_keys
(
olm_account
,
1
);
auto
one_time_keys
=
mtx
::
client
::
crypto
::
one_time_keys
(
olm_account
);
auto
req
=
::
create_upload_keys_request
(
auto
req
=
mtx
::
client
::
crypto
::
create_upload_keys_request
(
olm_account
,
identity_keys
,
one_time_keys
,
alice
->
user_id
(),
alice
->
device_id
());
alice
->
upload_keys
(
req
,
[](
const
mtx
::
responses
::
UploadKeys
&
res
,
ErrType
err
)
{
...
...
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