]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add binary_form argument to get_ssl_certificate.
authorBen Darnell <ben@bendarnell.com>
Sun, 19 Aug 2012 02:39:57 +0000 (19:39 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 19 Aug 2012 02:39:57 +0000 (19:39 -0700)
The default form contains only basic information; the binary form is more
complete.

tornado/httpserver.py

index 952a6a26815485fb0539d16f1548668d775ec08a..1596a88675f03ecf3aebc227e1bcb31eea56a17e 100644 (file)
@@ -427,7 +427,7 @@ class HTTPRequest(object):
         else:
             return self._finish_time - self._start_time
 
-    def get_ssl_certificate(self):
+    def get_ssl_certificate(self, binary_form=False):
         """Returns the client's SSL certificate, if any.
 
         To use client certificates, the HTTPServer must have been constructed
@@ -440,12 +440,16 @@ class HTTPRequest(object):
                     cert_reqs=ssl.CERT_REQUIRED,
                     ca_certs="cacert.crt"))
 
-        The return value is a dictionary, see SSLSocket.getpeercert() in
-        the standard library for more details.
+        By default, the return value is a dictionary (or None, if no
+        client certificate is present).  If ``binary_form`` is true, a
+        DER-encoded form of the certificate is returned instead.  See
+        SSLSocket.getpeercert() in the standard library for more
+        details.
         http://docs.python.org/library/ssl.html#sslsocket-objects
         """
         try:
-            return self.connection.stream.socket.getpeercert()
+            return self.connection.stream.socket.getpeercert(
+                binary_form=binary_form)
         except ssl.SSLError:
             return None