Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cbb94213
Commit
cbb94213
authored
Oct 28, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bytes/str issues in get-remote-certificate.py.
parent
4d540885
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
7 deletions
+11
-7
Tools/ssl/get-remote-certificate.py
Tools/ssl/get-remote-certificate.py
+11
-7
No files found.
Tools/ssl/get-remote-certificate.py
View file @
cbb94213
...
...
@@ -6,11 +6,14 @@
#
# By Bill Janssen.
import
re
import
os
import
ssl
import
sys
import
tempfile
def
fetch_server_certificate
(
host
,
port
):
import
re
,
tempfile
,
os
,
ssl
def
fetch_server_certificate
(
host
,
port
):
def
subproc
(
cmd
):
from
subprocess
import
Popen
,
PIPE
,
STDOUT
...
...
@@ -20,15 +23,15 @@ def fetch_server_certificate (host, port):
return
status
,
output
def
strip_to_x509_cert
(
certfile_contents
,
outfile
=
None
):
m
=
re
.
search
(
r"^([-]+BEGIN CERTIFICATE[-]+[\r]*\n"
r".*[\r]*^[-]+END CERTIFICATE[-]+)$"
,
m
=
re
.
search
(
b
r"^([-]+BEGIN CERTIFICATE[-]+[\r]*\n"
b
r".*[\r]*^[-]+END CERTIFICATE[-]+)$"
,
certfile_contents
,
re
.
MULTILINE
|
re
.
DOTALL
)
if
not
m
:
return
None
else
:
tn
=
tempfile
.
mktemp
()
fp
=
open
(
tn
,
"w"
)
fp
.
write
(
m
.
group
(
1
)
+
"
\
n
"
)
fp
=
open
(
tn
,
"w
b
"
)
fp
.
write
(
m
.
group
(
1
)
+
b
"
\
n
"
)
fp
.
close
()
try
:
tn2
=
(
outfile
or
tempfile
.
mktemp
())
...
...
@@ -67,6 +70,7 @@ def fetch_server_certificate (host, port):
(
host
,
port
))
return
certtext
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
<
2
:
sys
.
stderr
.
write
(
...
...
@@ -75,5 +79,5 @@ if __name__ == "__main__":
sys
.
exit
(
1
)
for
arg
in
sys
.
argv
[
1
:]:
host
,
port
=
arg
.
split
(
":"
)
sys
.
stdout
.
write
(
fetch_server_certificate
(
host
,
int
(
port
)))
sys
.
stdout
.
buffer
.
write
(
fetch_server_certificate
(
host
,
int
(
port
)))
sys
.
exit
(
0
)
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