Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
ff4780d5
Commit
ff4780d5
authored
Jul 03, 2015
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better error handling of invalid PEM files
parent
0924f8ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
status_checks.py
management/status_checks.py
+9
-2
No files found.
management/status_checks.py
View file @
ff4780d5
...
...
@@ -665,7 +665,11 @@ def check_certificate(domain, ssl_certificate, ssl_private_key, warn_if_expiring
# Second, check that the certificate matches the private key.
if
ssl_private_key
is
not
None
:
priv_key
=
load_pem
(
open
(
ssl_private_key
,
'rb'
)
.
read
())
try
:
priv_key
=
load_pem
(
open
(
ssl_private_key
,
'rb'
)
.
read
())
except
ValueError
as
e
:
return
(
"The private key file
%
s is not a private key file:
%
s"
%
(
ssl_private_key
,
str
(
e
)),
None
)
if
not
isinstance
(
priv_key
,
RSAPrivateKey
):
return
(
"The private key file
%
s is not a private key file."
%
ssl_private_key
,
None
)
...
...
@@ -759,7 +763,10 @@ def load_pem(pem):
from
cryptography.x509
import
load_pem_x509_certificate
from
cryptography.hazmat.primitives
import
serialization
from
cryptography.hazmat.backends
import
default_backend
pem_type
=
re
.
match
(
b
"-+BEGIN (.*?)-+
\n
"
,
pem
)
.
group
(
1
)
pem_type
=
re
.
match
(
b
"-+BEGIN (.*?)-+
\n
"
,
pem
)
if
pem_type
is
None
:
raise
ValueError
(
"File is not a valid PEM-formatted file."
)
pem_type
=
pem_type
.
group
(
1
)
if
pem_type
in
(
b
"RSA PRIVATE KEY"
,
b
"PRIVATE KEY"
):
return
serialization
.
load_pem_private_key
(
pem
,
password
=
None
,
backend
=
default_backend
())
if
pem_type
==
b
"CERTIFICATE"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment