diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/http-client.py | 19 | ||||
-rw-r--r-- | scripts/http-server.py | 51 | ||||
-rwxr-xr-x | scripts/irbe-cli.py | 25 |
3 files changed, 85 insertions, 10 deletions
diff --git a/scripts/http-client.py b/scripts/http-client.py new file mode 100644 index 00000000..815270ad --- /dev/null +++ b/scripts/http-client.py @@ -0,0 +1,19 @@ +# $Id$ + +import httplib + +http = httplib.HTTPSConnection("localhost", 8080) + +http.connect() +http.request("POST", "/", "This is a test. This is only a test. Had this been real you would now be really confused.\n", {"Content-Type":"application/wombat"}) +response = http.getresponse() + +for h in response.getheaders(): + print "%s: %s" % h +print +if response.status == httplib.OK: + print "OK" +else: + print "Ouch" +print +print response.read() diff --git a/scripts/http-server.py b/scripts/http-server.py new file mode 100644 index 00000000..913cacd2 --- /dev/null +++ b/scripts/http-server.py @@ -0,0 +1,51 @@ +# $Id$ + +import BaseHTTPServer, tlslite.api + +class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + + def do_POST(self): + echo = "" + for h in self.headers: + echo += "%s: %s\n" % (h, self.headers[h]) + self.query_string = self.rfile.read(int(self.headers["Content-Length"])) + echo += self.query_string + + f = open("http-server.log", "a") + f.write(echo) + f.close() + + self.send_response(200) + self.send_header("Content-Type", "application/x-wombat") + self.end_headers() + + self.wfile.write(echo) + +class httpServer(tlslite.api.TLSSocketServerMixIn, BaseHTTPServer.HTTPServer): + + def handshake(self, tlsConnection): + try: + tlsConnection.handshakeServer(certChain=certChain, + privateKey=privateKey, + sessionCache=sessionCache) + tlsConnection.ignoreAbruptClose = True + return True + except tlslite.api.TLSError, error: + print "TLS handshake failure:", str(error) + return False + +f = open("biz-certs/Carol-EE.cer", "r") +x509 = tlslite.api.X509() +x509.parse(f.read()) +f.close() + +certChain = tlslite.api.X509CertChain([x509]) + +f = open("biz-certs/Carol-EE.key", "r") +privateKey = tlslite.api.parsePEMKey(f.read(), private=True) +f.close() + +sessionCache = tlslite.api.SessionCache() + +httpd = httpServer(("", 8080), requestHandler) +httpd.serve_forever() diff --git a/scripts/irbe-cli.py b/scripts/irbe-cli.py index 86763887..83664521 100755 --- a/scripts/irbe-cli.py +++ b/scripts/irbe-cli.py @@ -4,7 +4,7 @@ Command line program to simulate behavior of the IR back-end. """ -import glob, rpki.left_right, rpki.relaxng, getopt, sys, lxml.etree, POW, POW.pkix +import glob, rpki.left_right, rpki.relaxng, getopt, sys, lxml.etree, POW, POW.pkix, rpki.cms # Kludge around current test setup all being PEM rather than DER format convert_from_pem = True @@ -109,13 +109,18 @@ else: usage() argv = cmd.process(msg, argv[1:]) -if msg: - elt = msg.toXML() - xml = lxml.etree.tostring(elt, pretty_print=True, encoding="us-ascii", xml_declaration=True) - try: - rng.assertValid(elt) - except lxml.etree.DocumentInvalid: - print "Generated request document doesn't pass schema check:" - print xml - sys.exit(1) +assert msg + +elt = msg.toXML() +xml = lxml.etree.tostring(elt, pretty_print=True, encoding="us-ascii", xml_declaration=True) +try: + rng.assertValid(elt) +except lxml.etree.DocumentInvalid: + print "Generated request document doesn't pass schema check:" print xml + sys.exit(1) + +print xml +cms = rpki.cms.encode(xml, "biz-certs/Alice-EE.key", ("biz-certs/Alice-EE.cer", "biz-certs/Alice-CA.cer")) + +# now send an https request... |