Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
re6stnet
Commits
3687dd51
Commit
3687dd51
authored
Apr 12, 2022
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not fallback on old expired certificate when it can't be renewed
parent
4fe44ea3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
27 deletions
+30
-27
re6st/x509.py
re6st/x509.py
+30
-27
No files found.
re6st/x509.py
View file @
3687dd51
...
@@ -44,37 +44,40 @@ def fingerprint(cert, alg='sha1'):
...
@@ -44,37 +44,40 @@ def fingerprint(cert, alg='sha1'):
def
maybe_renew
(
path
,
cert
,
info
,
renew
,
force
=
False
):
def
maybe_renew
(
path
,
cert
,
info
,
renew
,
force
=
False
):
from
.registry
import
RENEW_PERIOD
from
.registry
import
RENEW_PERIOD
retry_period
=
86400
not_after
=
0
if
force
else
notAfter
(
cert
)
while
True
:
while
True
:
if
force
:
while
True
:
force
=
False
next_renew
=
not_after
-
RENEW_PERIOD
else
:
next_renew
=
notAfter
(
cert
)
-
RENEW_PERIOD
if
time
.
time
()
<
next_renew
:
if
time
.
time
()
<
next_renew
:
return
cert
,
next_renew
return
cert
,
next_renew
try
:
try
:
pem
=
renew
()
pem
=
renew
()
if
not
pem
or
pem
==
crypto
.
dump_certificate
(
if
not
pem
or
pem
==
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
):
crypto
.
FILETYPE_PEM
,
cert
):
exc_info
=
0
exc_info
=
0
break
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
pem
)
except
Exception
:
exc_info
=
1
break
break
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
pem
)
new_path
=
path
+
'.new'
except
Exception
:
with
open
(
new_path
,
'w'
)
as
f
:
exc_info
=
1
f
.
write
(
pem
)
break
try
:
new_path
=
path
+
'.new'
s
=
os
.
stat
(
path
)
with
open
(
new_path
,
'w'
)
as
f
:
os
.
chown
(
new_path
,
s
.
st_uid
,
s
.
st_gid
)
f
.
write
(
pem
)
except
OSError
:
try
:
pass
s
=
os
.
stat
(
path
)
os
.
rename
(
new_path
,
path
)
os
.
chown
(
new_path
,
s
.
st_uid
,
s
.
st_gid
)
not_after
=
notAfter
(
cert
)
except
OSError
:
logging
.
info
(
"%s renewed until %s UTC"
,
pass
info
,
time
.
asctime
(
time
.
gmtime
(
not_after
)))
os
.
rename
(
new_path
,
path
)
logging
.
error
(
"%s not renewed. Will retry tomorrow."
,
logging
.
info
(
"%s renewed until %s UTC"
,
info
,
exc_info
=
exc_info
)
info
,
time
.
asctime
(
time
.
gmtime
(
notAfter
(
cert
))))
if
time
.
time
()
<
not_after
:
logging
.
error
(
"%s not renewed. Will retry tomorrow."
,
return
cert
,
time
.
time
()
+
retry_period
info
,
exc_info
=
exc_info
)
time
.
sleep
(
retry_period
)
return
cert
,
time
.
time
()
+
86400
class
VerifyError
(
Exception
):
class
VerifyError
(
Exception
):
...
...
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