Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
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
Maunium
synapse
Commits
c6a8e7d9
You need to sign in or sign up before continuing.
Commit
c6a8e7d9
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Read signing keys using methods from syutil. convert keys that are in the wrong format
parent
6876b1a2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/config/server.py
+30
-9
30 additions, 9 deletions
synapse/config/server.py
with
30 additions
and
9 deletions
synapse/config/server.py
+
30
−
9
View file @
c6a8e7d9
...
...
@@ -13,10 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
nacl.signing
import
os
from
._base
import
Config
from
syutil.
base64util
import
encode_base64
,
decode_base64
from
._base
import
Config
,
ConfigError
import
syutil.
crypto.signing_key
class
ServerConfig
(
Config
):
...
...
@@ -70,9 +69,16 @@ class ServerConfig(Config):
"
content repository
"
)
def
read_signing_key
(
self
,
signing_key_path
):
signing_key_base64
=
self
.
read_file
(
signing_key_path
,
"
signing_key
"
)
signing_key_bytes
=
decode_base64
(
signing_key_base64
)
return
nacl
.
signing
.
SigningKey
(
signing_key_bytes
)
signing_keys
=
self
.
read_file
(
signing_key_path
,
"
signing_key
"
)
try
:
return
syutil
.
crypto
.
signing_key
.
read_signing_keys
(
signing_keys
.
splitlines
(
True
)
)
except
Exception
as
e
:
raise
ConfigError
(
"
Error reading signing_key.
"
"
Try running again with --generate-config
"
)
@classmethod
def
generate_config
(
cls
,
args
,
config_dir_path
):
...
...
@@ -86,6 +92,21 @@ class ServerConfig(Config):
if
not
os
.
path
.
exists
(
args
.
signing_key_path
):
with
open
(
args
.
signing_key_path
,
"
w
"
)
as
signing_key_file
:
key
=
nacl
.
signing
.
SigningKey
.
generate
()
signing_key_file
.
write
(
encode_base64
(
key
.
encode
()))
syutil
.
crypto
.
signing_key
.
write_signing_keys
(
signing_key_file
,
(
syutil
.
crypto
.
SigningKey
.
generate
(
"
auto
"
),),
)
else
:
signing_keys
=
cls
.
read_file
(
args
.
signing_key_path
,
"
signing_key
"
)
if
len
(
signing_keys
.
split
(
"
\n
"
)[
0
].
split
())
==
1
:
# handle keys in the old format.
key
=
syutil
.
crypto
.
signing_key
.
decode_signing_key_base64
(
syutil
.
crypto
.
signing_key
.
NACL_ED25519
,
"
auto
"
,
signing_keys
.
split
(
"
\n
"
)[
0
]
)
with
open
(
args
.
signing_key_path
,
"
w
"
)
as
signing_key_file
:
syutil
.
crypto
.
signing_key
.
write_signing_keys
(
signing_key_file
,
(
key
,),
)
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