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
59a9d02f
Commit
59a9d02f
authored
Jul 07, 2014
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check that installed certificates are for the domains we are using the certificates for
parent
3d4eadd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
buy_certificate.py
management/buy_certificate.py
+1
-1
whats_next.py
management/whats_next.py
+37
-2
No files found.
management/buy_certificate.py
View file @
59a9d02f
...
...
@@ -108,7 +108,7 @@ def buy_ssl_certificate(api_key, domain, command, env):
# Check before we overwrite something we shouldn't.
if
os
.
path
.
exists
(
ssl_certificate
):
cert_status
=
check_certificate
(
ssl_certificate
)
cert_status
=
check_certificate
(
None
,
ssl_certificate
)
if
cert_status
!=
"SELF-SIGNED"
:
print
(
"Please back up and delete the file
%
s so I can save your new certificate."
%
ssl_certificate
)
sys
.
exit
(
1
)
...
...
management/whats_next.py
View file @
59a9d02f
...
...
@@ -223,7 +223,7 @@ def check_ssl_cert(domain, env):
# Check that the certificate is good.
cert_status
=
check_certificate
(
ssl_certificate
)
cert_status
=
check_certificate
(
domain
,
ssl_certificate
)
if
cert_status
==
"SELF-SIGNED"
:
fingerprint
=
shell
(
'check_output'
,
[
...
...
@@ -265,9 +265,44 @@ def check_ssl_cert(domain, env):
print
(
cert_status
)
print
(
""
)
def
check_certificate
(
ssl_certificate
):
def
check_certificate
(
domain
,
ssl_certificate
):
# Use openssl verify to check the status of a certificate.
# First check that the certificate is for the right domain. The domain
# must be found in the Subject Common Name (CN) or be one of the
# Subject Alternative Names.
cert_dump
=
shell
(
'check_output'
,
[
"openssl"
,
"x509"
,
"-in"
,
ssl_certificate
,
"-noout"
,
"-text"
,
"-nameopt"
,
"rfc2253"
,
])
cert_dump
=
cert_dump
.
split
(
"
\n
"
)
certificate_names
=
set
()
while
len
(
cert_dump
)
>
0
:
line
=
cert_dump
.
pop
(
0
)
# Grab from the Subject Common Name. We include the indentation
# at the start of the line in case maybe the cert includes the
# common name of some other referenced entity (which would be
# indented, I hope).
m
=
re
.
match
(
" Subject: CN=([^,]+)"
,
line
)
if
m
:
certificate_names
.
add
(
m
.
group
(
1
))
# Grab from the Subject Alternative Name, which is a comma-delim
# list of names, like DNS:mydomain.com, DNS:otherdomain.com.
m
=
re
.
match
(
" X509v3 Subject Alternative Name:"
,
line
)
if
m
:
names
=
re
.
split
(
",
\
s*"
,
cert_dump
.
pop
(
0
)
.
strip
())
for
n
in
names
:
m
=
re
.
match
(
"DNS:(.*)"
,
n
)
if
m
:
certificate_names
.
add
(
m
.
group
(
1
))
if
domain
is
not
None
and
domain
not
in
certificate_names
:
return
"This certificate is for the wrong domain names. It is for
%
s."
%
\
", "
.
join
(
sorted
(
certificate_names
))
# In order to verify with openssl, we need to split out any
# intermediary certificates in the chain (if any) from our
# certificate (at the top). They need to be passed separately.
...
...
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