2012-01-19 08:11:36 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Electrum - lightweight Bitcoin client
|
|
|
|
# Copyright (C) 2011 thomasv@gitorious
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2015-05-06 16:16:42 -07:00
|
|
|
import copy, re, errno, os
|
2015-05-04 22:02:51 -07:00
|
|
|
import threading, traceback, sys, time, Queue
|
2013-10-01 02:24:55 -07:00
|
|
|
import socket
|
|
|
|
import ssl
|
2012-02-03 06:45:41 -08:00
|
|
|
|
2014-09-28 14:19:52 -07:00
|
|
|
import requests
|
|
|
|
ca_path = requests.certs.where()
|
|
|
|
|
2015-05-06 16:16:42 -07:00
|
|
|
import util
|
|
|
|
import x509
|
2012-11-06 13:20:54 -08:00
|
|
|
from version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
2013-10-02 01:21:25 -07:00
|
|
|
from simple_config import SimpleConfig
|
2012-10-11 11:10:12 -07:00
|
|
|
|
2013-10-02 00:22:13 -07:00
|
|
|
|
2015-05-05 01:24:03 -07:00
|
|
|
def Interface(server, response_queue, config = None):
|
2015-05-04 22:02:51 -07:00
|
|
|
"""Interface factory function. The returned interface class handles the connection
|
|
|
|
to a single remote electrum server. The object handles all necessary locking. It's
|
|
|
|
exposed API is:
|
|
|
|
|
|
|
|
- Inherits everything from threading.Thread.
|
2015-05-05 01:24:03 -07:00
|
|
|
- Member functions send_request(), stop(), is_connected()
|
2015-05-04 22:53:07 -07:00
|
|
|
- Member variable server.
|
2015-05-04 22:02:51 -07:00
|
|
|
|
2015-05-06 16:16:42 -07:00
|
|
|
"server" is constant for the object's lifetime and hence synchronization is unnecessary.
|
2015-05-04 22:02:51 -07:00
|
|
|
"""
|
2014-07-29 00:28:27 -07:00
|
|
|
host, port, protocol = server.split(':')
|
|
|
|
if protocol in 'st':
|
2015-05-05 01:24:03 -07:00
|
|
|
return TcpInterface(server, response_queue, config)
|
2014-07-29 00:28:27 -07:00
|
|
|
else:
|
|
|
|
raise Exception('Unknown protocol: %s'%protocol)
|
|
|
|
|
2015-05-23 06:59:29 -07:00
|
|
|
# Connection status
|
|
|
|
CS_OPENING, CS_CONNECTED, CS_FAILED = range(3)
|
|
|
|
|
2014-07-29 00:28:27 -07:00
|
|
|
class TcpInterface(threading.Thread):
|
2012-10-11 11:10:12 -07:00
|
|
|
|
2015-05-05 01:24:03 -07:00
|
|
|
def __init__(self, server, response_queue, config = None):
|
2013-10-01 00:01:46 -07:00
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.daemon = True
|
2013-10-06 03:28:45 -07:00
|
|
|
self.config = config if config is not None else SimpleConfig()
|
2015-05-06 16:16:42 -07:00
|
|
|
# Set by stop(); no more data is exchanged and the thread exits after gracefully
|
|
|
|
# closing the socket
|
|
|
|
self.disconnect = False
|
2015-05-23 06:59:29 -07:00
|
|
|
self._status = CS_OPENING
|
2013-10-04 07:00:20 -07:00
|
|
|
self.debug = False # dump network messages. can be changed at runtime using the console
|
2012-03-18 00:07:40 -07:00
|
|
|
self.message_id = 0
|
2015-05-05 01:24:03 -07:00
|
|
|
self.response_queue = response_queue
|
2015-05-06 07:42:18 -07:00
|
|
|
self.request_queue = Queue.Queue()
|
2012-05-04 00:28:44 -07:00
|
|
|
self.unanswered_requests = {}
|
2015-05-05 08:16:44 -07:00
|
|
|
# request timeouts
|
2015-05-06 08:25:29 -07:00
|
|
|
self.request_time = time.time()
|
2015-05-19 02:28:30 -07:00
|
|
|
self.ping_time = 0
|
2013-10-01 00:01:46 -07:00
|
|
|
# parse server
|
2013-10-06 03:28:45 -07:00
|
|
|
self.server = server
|
2014-07-29 00:28:27 -07:00
|
|
|
self.host, self.port, self.protocol = self.server.split(':')
|
2015-07-01 00:09:00 -07:00
|
|
|
self.host = str(self.host)
|
2014-07-29 00:28:27 -07:00
|
|
|
self.port = int(self.port)
|
|
|
|
self.use_ssl = (self.protocol == 's')
|
2013-10-01 00:01:46 -07:00
|
|
|
|
2015-03-12 13:39:05 -07:00
|
|
|
def print_error(self, *msg):
|
|
|
|
util.print_error("[%s]"%self.host, *msg)
|
|
|
|
|
2014-07-29 00:28:27 -07:00
|
|
|
def process_response(self, response):
|
2013-10-04 07:00:20 -07:00
|
|
|
if self.debug:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("<--", response)
|
2012-07-06 13:36:13 -07:00
|
|
|
|
2014-07-29 00:28:27 -07:00
|
|
|
msg_id = response.get('id')
|
|
|
|
error = response.get('error')
|
|
|
|
result = response.get('result')
|
2014-07-27 15:13:40 -07:00
|
|
|
|
2012-04-29 09:33:01 -07:00
|
|
|
if msg_id is not None:
|
2015-05-06 07:42:18 -07:00
|
|
|
method, params, _id, queue = self.unanswered_requests.pop(msg_id)
|
2014-07-27 15:13:40 -07:00
|
|
|
if queue is None:
|
|
|
|
queue = self.response_queue
|
2012-03-17 15:32:36 -07:00
|
|
|
else:
|
2013-09-11 23:41:27 -07:00
|
|
|
# notification
|
2014-07-29 00:28:27 -07:00
|
|
|
method = response.get('method')
|
|
|
|
params = response.get('params')
|
2014-07-27 15:13:40 -07:00
|
|
|
_id = None
|
2014-07-29 00:28:27 -07:00
|
|
|
queue = self.response_queue
|
|
|
|
# restore parameters
|
2012-04-29 09:33:01 -07:00
|
|
|
if method == 'blockchain.numblocks.subscribe':
|
|
|
|
result = params[0]
|
|
|
|
params = []
|
2012-10-25 06:40:30 -07:00
|
|
|
elif method == 'blockchain.headers.subscribe':
|
|
|
|
result = params[0]
|
|
|
|
params = []
|
2012-04-29 09:33:01 -07:00
|
|
|
elif method == 'blockchain.address.subscribe':
|
|
|
|
addr = params[0]
|
|
|
|
result = params[1]
|
|
|
|
params = [addr]
|
|
|
|
|
2014-07-29 00:28:27 -07:00
|
|
|
if method == 'server.version':
|
|
|
|
self.server_version = result
|
|
|
|
return
|
|
|
|
|
2014-09-05 05:51:37 -07:00
|
|
|
if error:
|
|
|
|
queue.put((self, {'method':method, 'params':params, 'error':error, 'id':_id}))
|
|
|
|
else:
|
|
|
|
queue.put((self, {'method':method, 'params':params, 'result':result, 'id':_id}))
|
2012-03-19 07:57:47 -07:00
|
|
|
|
|
|
|
|
2014-09-19 00:25:44 -07:00
|
|
|
def get_simple_socket(self):
|
|
|
|
try:
|
|
|
|
l = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM)
|
|
|
|
except socket.gaierror:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("cannot resolve hostname")
|
2014-09-19 00:25:44 -07:00
|
|
|
return
|
|
|
|
for res in l:
|
|
|
|
try:
|
|
|
|
s = socket.socket(res[0], socket.SOCK_STREAM)
|
|
|
|
s.connect(res[4])
|
2015-06-02 02:13:36 -07:00
|
|
|
s.settimeout(2)
|
|
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
2014-09-19 00:25:44 -07:00
|
|
|
return s
|
2015-02-28 10:45:10 -08:00
|
|
|
except BaseException as e:
|
2014-09-19 00:25:44 -07:00
|
|
|
continue
|
|
|
|
else:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("failed to connect", str(e))
|
2013-09-30 05:01:49 -07:00
|
|
|
|
2013-10-01 02:24:55 -07:00
|
|
|
|
2014-09-19 00:25:44 -07:00
|
|
|
def get_socket(self):
|
2013-09-30 05:01:49 -07:00
|
|
|
if self.use_ssl:
|
2013-10-06 03:28:45 -07:00
|
|
|
cert_path = os.path.join( self.config.path, 'certs', self.host)
|
2013-09-30 05:01:49 -07:00
|
|
|
if not os.path.exists(cert_path):
|
2013-10-01 18:24:14 -07:00
|
|
|
is_new = True
|
2014-09-19 00:25:44 -07:00
|
|
|
s = self.get_simple_socket()
|
|
|
|
if s is None:
|
2013-12-13 00:22:39 -08:00
|
|
|
return
|
2014-09-19 00:25:44 -07:00
|
|
|
# try with CA first
|
|
|
|
try:
|
2015-07-30 11:40:05 -07:00
|
|
|
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1, cert_reqs=ssl.CERT_REQUIRED, ca_certs=ca_path, do_handshake_on_connect=True)
|
2014-09-19 00:25:44 -07:00
|
|
|
except ssl.SSLError, e:
|
2014-09-19 01:18:33 -07:00
|
|
|
s = None
|
2015-07-26 08:11:00 -07:00
|
|
|
if s and check_host_name(s.getpeercert(), self.host):
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("SSL certificate signed by CA")
|
2014-09-19 01:18:33 -07:00
|
|
|
return s
|
2013-11-13 11:35:35 -08:00
|
|
|
|
2014-09-19 00:25:44 -07:00
|
|
|
# get server certificate.
|
|
|
|
# Do not use ssl.get_server_certificate because it does not work with proxy
|
|
|
|
s = self.get_simple_socket()
|
2015-06-02 02:13:36 -07:00
|
|
|
if s is None:
|
|
|
|
return
|
2014-09-19 00:25:44 -07:00
|
|
|
try:
|
2015-07-30 11:40:05 -07:00
|
|
|
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1, cert_reqs=ssl.CERT_NONE, ca_certs=None)
|
2014-09-19 00:25:44 -07:00
|
|
|
except ssl.SSLError, e:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("SSL error retrieving SSL certificate:", e)
|
2013-09-30 05:01:49 -07:00
|
|
|
return
|
2013-10-01 02:24:55 -07:00
|
|
|
|
|
|
|
dercert = s.getpeercert(True)
|
|
|
|
s.close()
|
|
|
|
cert = ssl.DER_cert_to_PEM_cert(dercert)
|
2013-10-08 04:08:13 -07:00
|
|
|
# workaround android bug
|
2013-10-08 04:24:54 -07:00
|
|
|
cert = re.sub("([^\n])-----END CERTIFICATE-----","\\1\n-----END CERTIFICATE-----",cert)
|
2013-10-02 00:22:13 -07:00
|
|
|
temporary_path = cert_path + '.temp'
|
|
|
|
with open(temporary_path,"w") as f:
|
2013-09-30 05:01:49 -07:00
|
|
|
f.write(cert)
|
2013-10-01 18:24:14 -07:00
|
|
|
else:
|
|
|
|
is_new = False
|
2013-09-30 05:01:49 -07:00
|
|
|
|
2014-09-19 00:25:44 -07:00
|
|
|
s = self.get_simple_socket()
|
2013-11-14 00:23:38 -08:00
|
|
|
if s is None:
|
2013-10-01 00:01:46 -07:00
|
|
|
return
|
2013-09-30 05:01:49 -07:00
|
|
|
|
2012-10-17 02:35:24 -07:00
|
|
|
if self.use_ssl:
|
2013-09-30 05:01:49 -07:00
|
|
|
try:
|
|
|
|
s = ssl.wrap_socket(s,
|
2015-07-30 11:40:05 -07:00
|
|
|
ssl_version=ssl.PROTOCOL_TLSv1,
|
2013-09-30 05:01:49 -07:00
|
|
|
cert_reqs=ssl.CERT_REQUIRED,
|
2013-10-02 00:22:13 -07:00
|
|
|
ca_certs= (temporary_path if is_new else cert_path),
|
2013-09-30 05:01:49 -07:00
|
|
|
do_handshake_on_connect=True)
|
2013-10-01 00:01:46 -07:00
|
|
|
except ssl.SSLError, e:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("SSL error:", e)
|
2013-10-02 01:43:02 -07:00
|
|
|
if e.errno != 1:
|
|
|
|
return
|
2013-10-01 18:33:45 -07:00
|
|
|
if is_new:
|
2013-11-11 07:59:36 -08:00
|
|
|
rej = cert_path + '.rej'
|
|
|
|
if os.path.exists(rej):
|
|
|
|
os.unlink(rej)
|
|
|
|
os.rename(temporary_path, rej)
|
2013-10-02 01:36:29 -07:00
|
|
|
else:
|
2014-06-27 02:36:51 -07:00
|
|
|
with open(cert_path) as f:
|
|
|
|
cert = f.read()
|
|
|
|
try:
|
|
|
|
x = x509.X509()
|
|
|
|
x.parse(cert)
|
|
|
|
except:
|
2014-07-29 00:28:27 -07:00
|
|
|
traceback.print_exc(file=sys.stderr)
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("wrong certificate")
|
2014-06-27 02:36:51 -07:00
|
|
|
return
|
|
|
|
try:
|
|
|
|
x.check_date()
|
|
|
|
except:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("certificate has expired:", cert_path)
|
2013-10-02 01:36:29 -07:00
|
|
|
os.unlink(cert_path)
|
2014-06-27 02:36:51 -07:00
|
|
|
return
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("wrong certificate")
|
2013-10-01 00:01:46 -07:00
|
|
|
return
|
2015-02-21 05:45:09 -08:00
|
|
|
except BaseException, e:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error(e)
|
2015-02-21 05:45:09 -08:00
|
|
|
if e.errno == 104:
|
|
|
|
return
|
2014-07-29 00:28:27 -07:00
|
|
|
traceback.print_exc(file=sys.stderr)
|
2013-09-30 05:01:49 -07:00
|
|
|
return
|
|
|
|
|
2013-10-02 00:22:13 -07:00
|
|
|
if is_new:
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("saving certificate")
|
2013-10-02 00:22:13 -07:00
|
|
|
os.rename(temporary_path, cert_path)
|
|
|
|
|
2014-08-22 01:33:13 -07:00
|
|
|
return s
|
2014-10-21 10:05:51 -07:00
|
|
|
|
2015-05-05 02:40:22 -07:00
|
|
|
def send_request(self, request, response_queue = None):
|
2015-05-06 07:42:18 -07:00
|
|
|
'''Queue a request. Blocking only if called from other threads.'''
|
2015-05-06 08:25:29 -07:00
|
|
|
self.request_time = time.time()
|
2015-05-06 16:16:42 -07:00
|
|
|
self.request_queue.put((copy.deepcopy(request), response_queue), threading.current_thread() != self)
|
2015-05-06 07:42:18 -07:00
|
|
|
|
|
|
|
def send_requests(self):
|
|
|
|
'''Sends all queued requests'''
|
|
|
|
while self.is_connected() and not self.request_queue.empty():
|
|
|
|
request, response_queue = self.request_queue.get()
|
2015-05-05 02:40:22 -07:00
|
|
|
method = request.get('method')
|
|
|
|
params = request.get('params')
|
|
|
|
r = {'id': self.message_id, 'method': method, 'params': params}
|
2014-07-29 05:19:23 -07:00
|
|
|
try:
|
2014-08-13 12:58:01 -07:00
|
|
|
self.pipe.send(r)
|
2014-07-29 08:57:03 -07:00
|
|
|
except socket.error, e:
|
2015-05-05 02:40:22 -07:00
|
|
|
self.print_error("socket error:", e)
|
2015-05-05 08:16:44 -07:00
|
|
|
self.stop()
|
2014-07-29 05:19:23 -07:00
|
|
|
return
|
2015-05-05 02:40:22 -07:00
|
|
|
if self.debug:
|
|
|
|
self.print_error("-->", r)
|
|
|
|
self.unanswered_requests[self.message_id] = method, params, request.get('id'), response_queue
|
2012-03-17 08:02:28 -07:00
|
|
|
self.message_id += 1
|
2012-10-20 17:57:31 -07:00
|
|
|
|
2015-05-04 22:53:07 -07:00
|
|
|
def is_connected(self):
|
2015-05-23 06:59:29 -07:00
|
|
|
'''True if status is connected'''
|
|
|
|
return self._status == CS_CONNECTED and not self.disconnect
|
2015-05-04 22:53:07 -07:00
|
|
|
|
2012-11-24 11:31:07 -08:00
|
|
|
def stop(self):
|
2015-05-23 06:59:29 -07:00
|
|
|
if not self.disconnect:
|
|
|
|
self.disconnect = True
|
|
|
|
self.print_error("disconnecting")
|
2013-12-17 09:20:54 -08:00
|
|
|
|
2015-05-05 01:50:10 -07:00
|
|
|
def maybe_ping(self):
|
2015-05-06 07:42:18 -07:00
|
|
|
# ping the server with server.version
|
2015-05-05 01:50:10 -07:00
|
|
|
if time.time() - self.ping_time > 60:
|
2015-05-06 07:42:18 -07:00
|
|
|
self.send_request({'method':'server.version', 'params':[ELECTRUM_VERSION, PROTOCOL_VERSION]})
|
|
|
|
self.ping_time = time.time()
|
|
|
|
# stop interface if we have been waiting for more than 10 seconds
|
2015-05-08 08:47:04 -07:00
|
|
|
if self.unanswered_requests and time.time() - self.request_time > 10 and self.pipe.idle_time() > 10:
|
2015-05-06 07:42:18 -07:00
|
|
|
self.print_error("interface timeout", len(self.unanswered_requests))
|
|
|
|
self.stop()
|
|
|
|
|
2015-05-06 16:16:42 -07:00
|
|
|
def get_and_process_response(self):
|
2015-05-05 08:16:44 -07:00
|
|
|
if self.is_connected():
|
|
|
|
try:
|
|
|
|
response = self.pipe.get()
|
|
|
|
except util.timeout:
|
|
|
|
return
|
|
|
|
# If remote side closed the socket, SocketPipe closes our socket and returns None
|
|
|
|
if response is None:
|
2015-05-23 06:59:29 -07:00
|
|
|
self.disconnect = True
|
2015-05-06 16:16:42 -07:00
|
|
|
self.print_error("connection closed remotely")
|
|
|
|
else:
|
|
|
|
self.process_response(response)
|
2015-05-05 08:16:44 -07:00
|
|
|
|
2012-10-20 17:57:31 -07:00
|
|
|
def run(self):
|
2015-05-06 16:16:42 -07:00
|
|
|
s = self.get_socket()
|
|
|
|
if s:
|
|
|
|
self.pipe = util.SocketPipe(s)
|
|
|
|
s.settimeout(0.1)
|
2015-03-12 13:39:05 -07:00
|
|
|
self.print_error("connected")
|
2015-05-23 06:59:29 -07:00
|
|
|
self._status = CS_CONNECTED
|
2015-05-06 16:16:42 -07:00
|
|
|
# Indicate to parent that we've connected
|
2015-05-23 06:59:29 -07:00
|
|
|
self.notify_status()
|
2015-05-06 16:16:42 -07:00
|
|
|
while self.is_connected():
|
|
|
|
self.maybe_ping()
|
|
|
|
self.send_requests()
|
|
|
|
self.get_and_process_response()
|
2015-06-04 00:30:59 -07:00
|
|
|
s.shutdown(socket.SHUT_RDWR)
|
|
|
|
s.close()
|
2014-08-22 01:33:13 -07:00
|
|
|
|
2015-05-06 16:16:42 -07:00
|
|
|
# Also for the s is None case
|
2015-05-23 06:59:29 -07:00
|
|
|
self._status = CS_FAILED
|
2015-05-06 16:16:42 -07:00
|
|
|
# Indicate to parent that the connection is now down
|
2015-05-23 06:59:29 -07:00
|
|
|
self.notify_status()
|
2015-03-12 13:39:05 -07:00
|
|
|
|
2015-05-23 06:59:29 -07:00
|
|
|
def notify_status(self):
|
|
|
|
'''Notify owner that we have just connected or just failed the connection.
|
|
|
|
Owner determines which through e.g. testing is_connected()'''
|
2014-07-27 15:13:40 -07:00
|
|
|
self.response_queue.put((self, None))
|
2013-09-30 05:01:49 -07:00
|
|
|
|
2014-01-29 07:48:00 -08:00
|
|
|
|
2015-07-26 08:11:00 -07:00
|
|
|
def _match_hostname(name, val):
|
|
|
|
if val == name:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return val.startswith('*.') and name.endswith(val[1:])
|
|
|
|
|
|
|
|
|
|
|
|
def check_host_name(peercert, name):
|
|
|
|
"""Simple certificate/host name checker. Returns True if the
|
|
|
|
certificate matches, False otherwise."""
|
|
|
|
# Check that the peer has supplied a certificate.
|
|
|
|
# None/{} is not acceptable.
|
|
|
|
if not peercert:
|
|
|
|
return False
|
|
|
|
if peercert.has_key("subjectAltName"):
|
|
|
|
for typ, val in peercert["subjectAltName"]:
|
|
|
|
if typ == "DNS" and _match_hostname(name, val):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# Only check the subject DN if there is no subject alternative
|
|
|
|
# name.
|
|
|
|
cn = None
|
|
|
|
for attr, val in peercert["subject"]:
|
|
|
|
# Use most-specific (last) commonName attribute.
|
|
|
|
if attr == "commonName":
|
|
|
|
cn = val
|
|
|
|
if cn is not None:
|
|
|
|
return _match_hostname(name, cn)
|
|
|
|
return False
|
2013-09-30 05:01:49 -07:00
|
|
|
|
2014-07-27 15:13:40 -07:00
|
|
|
|
2014-06-27 02:36:51 -07:00
|
|
|
def check_cert(host, cert):
|
|
|
|
try:
|
|
|
|
x = x509.X509()
|
|
|
|
x.parse(cert)
|
|
|
|
except:
|
|
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
x.check_date()
|
|
|
|
expired = False
|
|
|
|
except:
|
|
|
|
expired = True
|
|
|
|
|
|
|
|
m = "host: %s\n"%host
|
|
|
|
m += "has_expired: %s\n"% expired
|
2015-03-12 13:39:05 -07:00
|
|
|
util.print_msg(m)
|
2014-06-27 02:36:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_certificates():
|
|
|
|
config = SimpleConfig()
|
|
|
|
mydir = os.path.join(config.path, "certs")
|
|
|
|
certs = os.listdir(mydir)
|
|
|
|
for c in certs:
|
|
|
|
print c
|
|
|
|
p = os.path.join(mydir,c)
|
|
|
|
with open(p) as f:
|
|
|
|
cert = f.read()
|
|
|
|
check_cert(c, cert)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_certificates()
|