aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-12 14:59:37 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-12 15:20:15 -0500
commite28d6c47eb73ab3d3297745873a25e0f6c0eae8e (patch)
tree0faab703ed6dac2c109dbf88868098cabebf9ac4 /src
parent699616f4ed6ee7f2e92d87b038842864c517feaa (diff)
downloadcryptography-e28d6c47eb73ab3d3297745873a25e0f6c0eae8e.tar.gz
cryptography-e28d6c47eb73ab3d3297745873a25e0f6c0eae8e.tar.bz2
cryptography-e28d6c47eb73ab3d3297745873a25e0f6c0eae8e.zip
expand UniformResourceIdentiier to parse and internally IDNA encode
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/x509.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 8bed79e2..58e1a37c 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -13,6 +13,8 @@ import idna
import six
+from six.moves import urllib_parse
+
from cryptography import utils
from cryptography.hazmat.primitives import hashes
@@ -966,7 +968,31 @@ class UniformResourceIdentifier(object):
if not isinstance(value, six.text_type):
raise TypeError("value must be a unicode string")
+ parsed = urllib_parse.urlparse(value)
+ if not parsed.hostname:
+ netloc = ""
+ elif parsed.port:
+ netloc = (
+ idna.encode(parsed.hostname) +
+ ":{0}".format(parsed.port).encode("ascii")
+ ).decode("ascii")
+ else:
+ netloc = idna.encode(parsed.hostname).decode("ascii")
+
+ # Note that building a URL in this fashion means it should be
+ # semantically indistinguishable from the original but is not
+ # guaranteed to be exactly the same.
+ uri = urllib_parse.urlunparse((
+ parsed.scheme,
+ netloc,
+ parsed.path,
+ parsed.params,
+ parsed.query,
+ parsed.fragment
+ )).encode("ascii")
+
self._value = value
+ self._encoded = uri
value = utils.read_only_property("_value")