Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
🥺
conduwuit
Commits
dd749b8a
Unverified
Commit
dd749b8a
authored
4 years ago
by
Timo Kösters
Browse files
Options
Downloads
Patches
Plain Diff
fix: server keys and destination resolution when server name contains port
parent
005e00e9
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/database/globals.rs
+35
-10
35 additions, 10 deletions
src/database/globals.rs
src/server_server.rs
+7
-2
7 additions, 2 deletions
src/server_server.rs
src/utils.rs
+7
-2
7 additions, 2 deletions
src/utils.rs
with
49 additions
and
14 deletions
src/database/globals.rs
+
35
−
10
View file @
dd749b8a
use
crate
::{
utils
,
Error
,
Result
};
use
log
::
error
;
use
ruma
::
ServerName
;
use
std
::{
convert
::
TryInto
,
sync
::
Arc
};
...
...
@@ -17,19 +18,43 @@ pub struct Globals {
impl
Globals
{
pub
fn
load
(
globals
:
sled
::
Tree
,
config
:
&
rocket
::
Config
)
->
Result
<
Self
>
{
let
keypair
=
Arc
::
new
(
ruma
::
signatures
::
Ed25519KeyPair
::
new
(
&*
globals
.update_and_fetch
(
"keypair"
,
utils
::
generate_keypair
)
?
.expect
(
"utils::generate_keypair always returns Some"
),
"key1"
.to_owned
(),
)
.map_err
(|
_
|
Error
::
bad_database
(
"Private or public keys are invalid."
))
?
,
);
let
bytes
=
&*
globals
.update_and_fetch
(
"keypair"
,
utils
::
generate_keypair
)
?
.expect
(
"utils::generate_keypair always returns Some"
);
let
mut
parts
=
bytes
.splitn
(
2
,
|
&
b
|
b
==
0xff
);
let
keypair
=
utils
::
string_from_bytes
(
// 1. version
parts
.next
()
.expect
(
"splitn always returns at least one element"
),
)
.map_err
(|
_
|
Error
::
bad_database
(
"Invalid version bytes in keypair."
))
.and_then
(|
version
|
{
// 2. key
parts
.next
()
.ok_or_else
(||
Error
::
bad_database
(
"Invalid keypair format in database."
))
.map
(|
key
|
(
version
,
key
))
})
.and_then
(|(
version
,
key
)|
{
ruma
::
signatures
::
Ed25519KeyPair
::
new
(
&
key
,
version
)
.map_err
(|
_
|
Error
::
bad_database
(
"Private or public keys are invalid."
))
});
let
keypair
=
match
keypair
{
Ok
(
k
)
=>
k
,
Err
(
e
)
=>
{
error!
(
"Keypair invalid. Deleting..."
);
globals
.remove
(
"keypair"
)
?
;
return
Err
(
e
);
}
};
Ok
(
Self
{
globals
,
keypair
,
keypair
:
Arc
::
new
(
keypair
)
,
reqwest_client
:
reqwest
::
Client
::
new
(),
server_name
:
config
.get_str
(
"server_name"
)
...
...
This diff is collapsed.
Click to expand it.
src/server_server.rs
+
7
−
2
View file @
dd749b8a
...
...
@@ -17,7 +17,6 @@
directory
::{
IncomingFilter
,
IncomingRoomNetwork
},
EventId
,
ServerName
,
};
use
serde_json
::
json
;
use
std
::{
collections
::
BTreeMap
,
convert
::
TryFrom
,
...
...
@@ -58,7 +57,13 @@ pub async fn send_request<T: OutgoingRequest>(
let
actual_destination
=
"https://"
.to_owned
()
+
&
request_well_known
(
globals
,
&
destination
.as_str
())
.await
.unwrap_or
(
destination
.as_str
()
.to_owned
()
+
":8448"
);
.unwrap_or_else
(||
{
let
mut
destination
=
destination
.as_str
()
.to_owned
();
if
destination
.find
(
':'
)
.is_none
()
{
destination
+=
":8448"
;
}
destination
});
let
mut
http_request
=
request
.try_into_http_request
(
&
actual_destination
,
Some
(
""
))
...
...
This diff is collapsed.
Click to expand it.
src/utils.rs
+
7
−
2
View file @
dd749b8a
...
...
@@ -29,8 +29,13 @@ pub fn increment(old: Option<&[u8]>) -> Option<Vec<u8>> {
pub
fn
generate_keypair
(
old
:
Option
<&
[
u8
]
>
)
->
Option
<
Vec
<
u8
>>
{
Some
(
old
.map
(|
s
|
s
.to_vec
())
.unwrap_or_else
(||
{
ruma
::
signatures
::
Ed25519KeyPair
::
generate
()
.expect
(
"Ed25519KeyPair generation always works (?)"
)
let
mut
value
=
random_string
(
8
)
.as_bytes
()
.to_vec
();
value
.push
(
0xff
);
value
.extend_from_slice
(
&
ruma
::
signatures
::
Ed25519KeyPair
::
generate
()
.expect
(
"Ed25519KeyPair generation always works (?)"
),
);
value
}))
}
...
...
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