Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
ab972785
Commit
ab972785
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
test_ssl: add expiration verification
parent
c1ef9240
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_ssl.py
+33
-12
33 additions, 12 deletions
tests/test_ssl.py
with
33 additions
and
12 deletions
tests/test_ssl.py
+
33
−
12
View file @
ab972785
...
@@ -3,12 +3,15 @@
...
@@ -3,12 +3,15 @@
# Copyright 2017, Florent Thiery
# Copyright 2017, Florent Thiery
'''
'''
Criticality: Normal
Criticality: Normal
Checks that
SSL
certificates are valid; if invalid, the user will have to add an exception in his browser
Checks that
TLS
certificates are valid; if invalid, the user will have to add an exception in his browser
'''
'''
import
datetime
import
imp
import
OpenSSL
import
os
import
os
import
sys
import
requests
import
requests
import
imp
import
sys
import
ssl
YELLOW
=
'
\033
[93m
'
YELLOW
=
'
\033
[93m
'
GREEN
=
'
\033
[92m
'
GREEN
=
'
\033
[92m
'
...
@@ -27,8 +30,6 @@ if not os.path.isfile('../utils.py'):
...
@@ -27,8 +30,6 @@ if not os.path.isfile('../utils.py'):
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
conf
=
es_utils
.
load_conf
()
all_ok
=
True
conf_servers
=
(
conf_servers
=
(
(
'
MS_SERVER_NAME
'
,
'
mediaserver
'
),
(
'
MS_SERVER_NAME
'
,
'
mediaserver
'
),
(
'
MONITOR_SERVER_NAME
'
,
'
monitor
'
),
(
'
MONITOR_SERVER_NAME
'
,
'
monitor
'
),
...
@@ -47,13 +48,33 @@ for s, d in conf_servers:
...
@@ -47,13 +48,33 @@ for s, d in conf_servers:
# the domain is not in the hosts file, the service is surely not installed
# the domain is not in the hosts file, the service is surely not installed
continue
continue
try
:
try
:
# further tests
conn
=
ssl
.
create_connection
((
v
,
443
))
context
=
ssl
.
SSLContext
()
sock
=
context
.
wrap_socket
(
conn
,
server_hostname
=
v
)
cert
=
ssl
.
DER_cert_to_PEM_cert
(
sock
.
getpeercert
(
True
))
x509
=
OpenSSL
.
crypto
.
load_certificate
(
OpenSSL
.
crypto
.
FILETYPE_PEM
,
cert
)
not_after
=
x509
.
get_notAfter
().
decode
(
'
ascii
'
)
expires
=
datetime
.
datetime
.
strptime
(
not_after
,
'
%Y%m%d%H%M%SZ
'
)
print
(
'
TLS cert for {} expires at {}
'
.
format
(
v
,
expires
.
isoformat
()))
remaining
=
expires
-
datetime
.
datetime
.
utcnow
()
if
remaining
<
datetime
.
timedelta
(
days
=
0
):
print
(
'
Error, already expired…
'
)
sys
.
exit
(
1
)
elif
remaining
<
datetime
.
timedelta
(
days
=
14
):
print
(
'
Warning, will expire soon!
'
)
sys
.
exit
(
3
)
else
:
print
(
'
Good, enough time before expiration.
'
)
url
=
'
https://%s
'
%
v
url
=
'
https://%s
'
%
v
print
(
'
Checking
SSL
certificate of %s
'
%
url
)
print
(
'
Checking
TLS
certificate of %s
'
%
url
)
requests
.
get
(
url
)
requests
.
get
(
url
)
except
requests
.
exceptions
.
SSLError
:
except
requests
.
exceptions
.
SSLError
:
print
(
'
%sSSL certificate for %s is not valid%s
'
%
(
YELLOW
,
url
,
DEF
))
print
(
'
%sTLS certificate for %s is not valid%s
'
%
(
YELLOW
,
url
,
DEF
))
all_ok
=
False
sys
.
exit
(
3
)
if
not
all_ok
:
sys
.
exit
(
3
)
sys
.
exit
(
0
)
else
:
sys
.
exit
(
0
)
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