Show More
@@ -7,7 +7,7 | |||||
7 | # This software may be used and distributed according to the terms of the |
|
7 | # This software may be used and distributed according to the terms of the | |
8 | # GNU General Public License version 2 or any later version. |
|
8 | # GNU General Public License version 2 or any later version. | |
9 |
|
9 | |||
10 |
import urllib, urllib2, urlparse, httplib, os, re, socket, cStringIO |
|
10 | import urllib, urllib2, urlparse, httplib, os, re, socket, cStringIO | |
11 | import __builtin__ |
|
11 | import __builtin__ | |
12 | from i18n import _ |
|
12 | from i18n import _ | |
13 | import keepalive, util |
|
13 | import keepalive, util | |
@@ -487,19 +487,13 class httphandler(keepalive.HTTPHandler) | |||||
487 | return keepalive.HTTPHandler._start_transaction(self, h, req) |
|
487 | return keepalive.HTTPHandler._start_transaction(self, h, req) | |
488 |
|
488 | |||
489 | def _verifycert(cert, hostname): |
|
489 | def _verifycert(cert, hostname): | |
490 |
'''Verify that cert (in socket.getpeercert() format) matches hostname |
|
490 | '''Verify that cert (in socket.getpeercert() format) matches hostname. | |
491 |
|
|
491 | CRLs and subjectAltName are not handled. | |
492 |
|
492 | |||
493 | Returns error message if any problems are found and None on success. |
|
493 | Returns error message if any problems are found and None on success. | |
494 | ''' |
|
494 | ''' | |
495 | if not cert: |
|
495 | if not cert: | |
496 | return _('no certificate received') |
|
496 | return _('no certificate received') | |
497 | notafter = cert.get('notAfter') |
|
|||
498 | if notafter and time.time() > ssl.cert_time_to_seconds(notafter): |
|
|||
499 | return _('certificate expired %s') % notafter |
|
|||
500 | notbefore = cert.get('notBefore') |
|
|||
501 | if notbefore and time.time() < ssl.cert_time_to_seconds(notbefore): |
|
|||
502 | return _('certificate not valid before %s') % notbefore |
|
|||
503 | dnsname = hostname.lower() |
|
497 | dnsname = hostname.lower() | |
504 | for s in cert.get('subject', []): |
|
498 | for s in cert.get('subject', []): | |
505 | key, value = s[0] |
|
499 | key, value = s[0] |
@@ -1,9 +1,5 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | import sys |
|
2 | import sys | |
3 | try: |
|
|||
4 | import ssl |
|
|||
5 | except ImportError: |
|
|||
6 | sys.exit(80) |
|
|||
7 |
|
3 | |||
8 | def check(a, b): |
|
4 | def check(a, b): | |
9 | if a != b: |
|
5 | if a != b: | |
@@ -36,17 +32,7 check(_verifycert(cert('*.foo'), 'foo'), | |||||
36 | check(_verifycert(cert('*o'), 'foo'), |
|
32 | check(_verifycert(cert('*o'), 'foo'), | |
37 | 'certificate is for *o') |
|
33 | 'certificate is for *o') | |
38 |
|
34 | |||
39 | import time |
|
35 | check(_verifycert({'subject': ()}, | |
40 | lastyear = time.gmtime().tm_year - 1 |
|
|||
41 | nextyear = time.gmtime().tm_year + 1 |
|
|||
42 | check(_verifycert({'notAfter': 'May 9 00:00:00 %s GMT' % lastyear}, |
|
|||
43 | 'example.com'), |
|
|||
44 | 'certificate expired May 9 00:00:00 %s GMT' % lastyear) |
|
|||
45 | check(_verifycert({'notBefore': 'May 9 00:00:00 %s GMT' % nextyear}, |
|
|||
46 | 'example.com'), |
|
|||
47 | 'certificate not valid before May 9 00:00:00 %s GMT' % nextyear) |
|
|||
48 | check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear, |
|
|||
49 | 'subject': ()}, |
|
|||
50 | 'example.com'), |
|
36 | 'example.com'), | |
51 | 'no commonName found in certificate') |
|
37 | 'no commonName found in certificate') | |
52 | check(_verifycert(None, 'example.com'), |
|
38 | check(_verifycert(None, 'example.com'), |
General Comments 0
You need to be logged in to leave comments.
Login now