From 8232d6a259a7045e9b5de192f199776cb7ee17b2 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 21 Sep 2014 22:08:07 +0000 Subject: Add CMS goo to simple CMS client, remove need for async HTTP in Zookeeper. svn path=/branches/tk705/; revision=5966 --- rpki/http_simple.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'rpki/http_simple.py') diff --git a/rpki/http_simple.py b/rpki/http_simple.py index 4a05d607..2a00ff9c 100644 --- a/rpki/http_simple.py +++ b/rpki/http_simple.py @@ -1,5 +1,5 @@ # $Id$ - +# # Copyright (C) 2014 Dragon Research Labs ("DRL") # # Permission to use, copy, modify, and distribute this software for any @@ -97,11 +97,10 @@ class BadContentType(Exception): "Wrong HTTP Content-Type" -def client(url, query): +def client(proto_cms_msg, client_key, client_cert, server_ta, server_cert, url, q_msg, + debug = False, replay_track = None, client_crl = None): """ - Issue single a query and return the response. - - Might want to add CMS processing here, not sure yet. + Issue single a query and return the response, handling all the CMS and XML goo. """ u = urlparse.urlparse(url) @@ -109,10 +108,14 @@ def client(url, query): if u.scheme not in ("", "http") or u.username or u.password or u.params or u.query or u.fragment: raise BadURL("Unusable URL %s", url) - http = httplib.HTTPConnection(u.hostname, u.port or httplib.HTTP_PORT) + q_cms = proto_cms_msg() + q_der = q_cms.wrap(q_msg, client_key, client_cert, client_crl) - http.request("POST", u.path, query, {"Content-Type" : rpki_content_type}) + if debug: + debug.write("\n" + q_cms.pretty_print_content() + "\n") + http = httplib.HTTPConnection(u.hostname, u.port or httplib.HTTP_PORT) + http.request("POST", u.path, q_der, {"Content-Type" : rpki_content_type}) r = http.getresponse() if r.status != 200: @@ -121,4 +124,14 @@ def client(url, query): if r.getheader("Content-Type") != rpki_content_type: raise BadContentType("HTTP Content-Type %r, expected %r" % (r.getheader("Content-Type"), rpki_content_type)) - return r.read() + r_der = r.read() + r_cms = proto_cms_msg(DER = r_der) + r_msg = r_cms.unwrap((server_ta, server_cert)) + + if replay_track is not None: + replay_track.cms_timestamp = r_cms.check_replay(replay_track.cms_timestamp, url) + + if debug: + debug.write("\n" + r_cms.pretty_print_content() + "\n") + + return r_msg -- cgit v1.2.3