akaaafk commited on
Commit
bf67702
·
verified ·
1 Parent(s): 8a49e59

Add files using upload-large-folder tool

Browse files
Files changed (50) hide show
  1. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Bujumbura +0 -0
  2. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Cairo +0 -0
  3. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Casablanca +0 -0
  4. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Ceuta +0 -0
  5. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Conakry +0 -0
  6. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Godthab +0 -0
  7. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Goose_Bay +0 -0
  8. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Grand_Turk +0 -0
  9. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Grenada +0 -0
  10. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guadeloupe +0 -0
  11. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guatemala +0 -0
  12. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guayaquil +0 -0
  13. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guyana +0 -0
  14. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Manaus +0 -0
  15. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Marigot +0 -0
  16. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Martinique +0 -0
  17. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Matamoros +0 -0
  18. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mazatlan +0 -0
  19. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mendoza +0 -0
  20. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Menominee +0 -0
  21. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Merida +0 -0
  22. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Metlakatla +0 -0
  23. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mexico_City +0 -0
  24. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Harbin +0 -0
  25. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Hebron +0 -0
  26. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ulaanbaatar +0 -0
  27. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ulan_Bator +0 -0
  28. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Urumqi +0 -0
  29. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ust-Nera +0 -0
  30. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Vientiane +0 -0
  31. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Vladivostok +0 -0
  32. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yakutsk +0 -0
  33. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yangon +0 -0
  34. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yekaterinburg +0 -0
  35. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yerevan +0 -0
  36. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Atlantic/Madeira +0 -0
  37. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-0 +0 -0
  38. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-1 +0 -0
  39. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-10 +0 -0
  40. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-11 +0 -0
  41. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-12 +0 -0
  42. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-13 +0 -0
  43. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Jamaica +0 -0
  44. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Japan +0 -0
  45. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Kwajalein +0 -0
  46. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/contrib/_securetransport/bindings.py +593 -0
  47. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/rfc3986/__init__.py +56 -0
  48. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/rfc3986/_mixin.py +353 -0
  49. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname/__init__.py +19 -0
  50. benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname/_implementation.py +156 -0
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Bujumbura ADDED
Binary file (149 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Cairo ADDED
Binary file (1.96 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Casablanca ADDED
Binary file (2.43 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Ceuta ADDED
Binary file (2.04 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Africa/Conakry ADDED
Binary file (148 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Godthab ADDED
Binary file (1.88 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Goose_Bay ADDED
Binary file (3.21 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Grand_Turk ADDED
Binary file (1.85 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Grenada ADDED
Binary file (148 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guadeloupe ADDED
Binary file (148 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guatemala ADDED
Binary file (280 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guayaquil ADDED
Binary file (246 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Guyana ADDED
Binary file (236 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Manaus ADDED
Binary file (604 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Marigot ADDED
Binary file (148 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Martinique ADDED
Binary file (232 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Matamoros ADDED
Binary file (1.39 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mazatlan ADDED
Binary file (1.53 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mendoza ADDED
Binary file (1.08 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Menominee ADDED
Binary file (2.27 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Merida ADDED
Binary file (1.42 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Metlakatla ADDED
Binary file (1.42 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/America/Mexico_City ADDED
Binary file (1.58 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Harbin ADDED
Binary file (533 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Hebron ADDED
Binary file (2.34 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ulaanbaatar ADDED
Binary file (891 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ulan_Bator ADDED
Binary file (891 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Urumqi ADDED
Binary file (165 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Ust-Nera ADDED
Binary file (1.25 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Vientiane ADDED
Binary file (199 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Vladivostok ADDED
Binary file (1.21 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yakutsk ADDED
Binary file (1.21 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yangon ADDED
Binary file (268 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yekaterinburg ADDED
Binary file (1.24 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Asia/Yerevan ADDED
Binary file (1.15 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Atlantic/Madeira ADDED
Binary file (3.48 kB). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-0 ADDED
Binary file (114 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-1 ADDED
Binary file (117 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-10 ADDED
Binary file (118 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-11 ADDED
Binary file (118 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-12 ADDED
Binary file (118 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Etc/GMT-13 ADDED
Binary file (118 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Jamaica ADDED
Binary file (482 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Japan ADDED
Binary file (309 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/pytz/zoneinfo/Kwajalein ADDED
Binary file (316 Bytes). View file
 
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/contrib/_securetransport/bindings.py ADDED
@@ -0,0 +1,593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This module uses ctypes to bind a whole bunch of functions and constants from
3
+ SecureTransport. The goal here is to provide the low-level API to
4
+ SecureTransport. These are essentially the C-level functions and constants, and
5
+ they're pretty gross to work with.
6
+
7
+ This code is a bastardised version of the code found in Will Bond's oscrypto
8
+ library. An enormous debt is owed to him for blazing this trail for us. For
9
+ that reason, this code should be considered to be covered both by urllib3's
10
+ license and by oscrypto's:
11
+
12
+ Copyright (c) 2015-2016 Will Bond <will@wbond.net>
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a
15
+ copy of this software and associated documentation files (the "Software"),
16
+ to deal in the Software without restriction, including without limitation
17
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
18
+ and/or sell copies of the Software, and to permit persons to whom the
19
+ Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in
22
+ all copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30
+ DEALINGS IN THE SOFTWARE.
31
+ """
32
+ from __future__ import absolute_import
33
+
34
+ import platform
35
+ from ctypes.util import find_library
36
+ from ctypes import (
37
+ c_void_p, c_int32, c_char_p, c_size_t, c_byte, c_uint32, c_ulong, c_long,
38
+ c_bool
39
+ )
40
+ from ctypes import CDLL, POINTER, CFUNCTYPE
41
+
42
+
43
+ security_path = find_library('Security')
44
+ if not security_path:
45
+ raise ImportError('The library Security could not be found')
46
+
47
+
48
+ core_foundation_path = find_library('CoreFoundation')
49
+ if not core_foundation_path:
50
+ raise ImportError('The library CoreFoundation could not be found')
51
+
52
+
53
+ version = platform.mac_ver()[0]
54
+ version_info = tuple(map(int, version.split('.')))
55
+ if version_info < (10, 8):
56
+ raise OSError(
57
+ 'Only OS X 10.8 and newer are supported, not %s.%s' % (
58
+ version_info[0], version_info[1]
59
+ )
60
+ )
61
+
62
+ Security = CDLL(security_path, use_errno=True)
63
+ CoreFoundation = CDLL(core_foundation_path, use_errno=True)
64
+
65
+ Boolean = c_bool
66
+ CFIndex = c_long
67
+ CFStringEncoding = c_uint32
68
+ CFData = c_void_p
69
+ CFString = c_void_p
70
+ CFArray = c_void_p
71
+ CFMutableArray = c_void_p
72
+ CFDictionary = c_void_p
73
+ CFError = c_void_p
74
+ CFType = c_void_p
75
+ CFTypeID = c_ulong
76
+
77
+ CFTypeRef = POINTER(CFType)
78
+ CFAllocatorRef = c_void_p
79
+
80
+ OSStatus = c_int32
81
+
82
+ CFDataRef = POINTER(CFData)
83
+ CFStringRef = POINTER(CFString)
84
+ CFArrayRef = POINTER(CFArray)
85
+ CFMutableArrayRef = POINTER(CFMutableArray)
86
+ CFDictionaryRef = POINTER(CFDictionary)
87
+ CFArrayCallBacks = c_void_p
88
+ CFDictionaryKeyCallBacks = c_void_p
89
+ CFDictionaryValueCallBacks = c_void_p
90
+
91
+ SecCertificateRef = POINTER(c_void_p)
92
+ SecExternalFormat = c_uint32
93
+ SecExternalItemType = c_uint32
94
+ SecIdentityRef = POINTER(c_void_p)
95
+ SecItemImportExportFlags = c_uint32
96
+ SecItemImportExportKeyParameters = c_void_p
97
+ SecKeychainRef = POINTER(c_void_p)
98
+ SSLProtocol = c_uint32
99
+ SSLCipherSuite = c_uint32
100
+ SSLContextRef = POINTER(c_void_p)
101
+ SecTrustRef = POINTER(c_void_p)
102
+ SSLConnectionRef = c_uint32
103
+ SecTrustResultType = c_uint32
104
+ SecTrustOptionFlags = c_uint32
105
+ SSLProtocolSide = c_uint32
106
+ SSLConnectionType = c_uint32
107
+ SSLSessionOption = c_uint32
108
+
109
+
110
+ try:
111
+ Security.SecItemImport.argtypes = [
112
+ CFDataRef,
113
+ CFStringRef,
114
+ POINTER(SecExternalFormat),
115
+ POINTER(SecExternalItemType),
116
+ SecItemImportExportFlags,
117
+ POINTER(SecItemImportExportKeyParameters),
118
+ SecKeychainRef,
119
+ POINTER(CFArrayRef),
120
+ ]
121
+ Security.SecItemImport.restype = OSStatus
122
+
123
+ Security.SecCertificateGetTypeID.argtypes = []
124
+ Security.SecCertificateGetTypeID.restype = CFTypeID
125
+
126
+ Security.SecIdentityGetTypeID.argtypes = []
127
+ Security.SecIdentityGetTypeID.restype = CFTypeID
128
+
129
+ Security.SecKeyGetTypeID.argtypes = []
130
+ Security.SecKeyGetTypeID.restype = CFTypeID
131
+
132
+ Security.SecCertificateCreateWithData.argtypes = [
133
+ CFAllocatorRef,
134
+ CFDataRef
135
+ ]
136
+ Security.SecCertificateCreateWithData.restype = SecCertificateRef
137
+
138
+ Security.SecCertificateCopyData.argtypes = [
139
+ SecCertificateRef
140
+ ]
141
+ Security.SecCertificateCopyData.restype = CFDataRef
142
+
143
+ Security.SecCopyErrorMessageString.argtypes = [
144
+ OSStatus,
145
+ c_void_p
146
+ ]
147
+ Security.SecCopyErrorMessageString.restype = CFStringRef
148
+
149
+ Security.SecIdentityCreateWithCertificate.argtypes = [
150
+ CFTypeRef,
151
+ SecCertificateRef,
152
+ POINTER(SecIdentityRef)
153
+ ]
154
+ Security.SecIdentityCreateWithCertificate.restype = OSStatus
155
+
156
+ Security.SecKeychainCreate.argtypes = [
157
+ c_char_p,
158
+ c_uint32,
159
+ c_void_p,
160
+ Boolean,
161
+ c_void_p,
162
+ POINTER(SecKeychainRef)
163
+ ]
164
+ Security.SecKeychainCreate.restype = OSStatus
165
+
166
+ Security.SecKeychainDelete.argtypes = [
167
+ SecKeychainRef
168
+ ]
169
+ Security.SecKeychainDelete.restype = OSStatus
170
+
171
+ Security.SecPKCS12Import.argtypes = [
172
+ CFDataRef,
173
+ CFDictionaryRef,
174
+ POINTER(CFArrayRef)
175
+ ]
176
+ Security.SecPKCS12Import.restype = OSStatus
177
+
178
+ SSLReadFunc = CFUNCTYPE(OSStatus, SSLConnectionRef, c_void_p, POINTER(c_size_t))
179
+ SSLWriteFunc = CFUNCTYPE(OSStatus, SSLConnectionRef, POINTER(c_byte), POINTER(c_size_t))
180
+
181
+ Security.SSLSetIOFuncs.argtypes = [
182
+ SSLContextRef,
183
+ SSLReadFunc,
184
+ SSLWriteFunc
185
+ ]
186
+ Security.SSLSetIOFuncs.restype = OSStatus
187
+
188
+ Security.SSLSetPeerID.argtypes = [
189
+ SSLContextRef,
190
+ c_char_p,
191
+ c_size_t
192
+ ]
193
+ Security.SSLSetPeerID.restype = OSStatus
194
+
195
+ Security.SSLSetCertificate.argtypes = [
196
+ SSLContextRef,
197
+ CFArrayRef
198
+ ]
199
+ Security.SSLSetCertificate.restype = OSStatus
200
+
201
+ Security.SSLSetCertificateAuthorities.argtypes = [
202
+ SSLContextRef,
203
+ CFTypeRef,
204
+ Boolean
205
+ ]
206
+ Security.SSLSetCertificateAuthorities.restype = OSStatus
207
+
208
+ Security.SSLSetConnection.argtypes = [
209
+ SSLContextRef,
210
+ SSLConnectionRef
211
+ ]
212
+ Security.SSLSetConnection.restype = OSStatus
213
+
214
+ Security.SSLSetPeerDomainName.argtypes = [
215
+ SSLContextRef,
216
+ c_char_p,
217
+ c_size_t
218
+ ]
219
+ Security.SSLSetPeerDomainName.restype = OSStatus
220
+
221
+ Security.SSLHandshake.argtypes = [
222
+ SSLContextRef
223
+ ]
224
+ Security.SSLHandshake.restype = OSStatus
225
+
226
+ Security.SSLRead.argtypes = [
227
+ SSLContextRef,
228
+ c_char_p,
229
+ c_size_t,
230
+ POINTER(c_size_t)
231
+ ]
232
+ Security.SSLRead.restype = OSStatus
233
+
234
+ Security.SSLWrite.argtypes = [
235
+ SSLContextRef,
236
+ c_char_p,
237
+ c_size_t,
238
+ POINTER(c_size_t)
239
+ ]
240
+ Security.SSLWrite.restype = OSStatus
241
+
242
+ Security.SSLClose.argtypes = [
243
+ SSLContextRef
244
+ ]
245
+ Security.SSLClose.restype = OSStatus
246
+
247
+ Security.SSLGetNumberSupportedCiphers.argtypes = [
248
+ SSLContextRef,
249
+ POINTER(c_size_t)
250
+ ]
251
+ Security.SSLGetNumberSupportedCiphers.restype = OSStatus
252
+
253
+ Security.SSLGetSupportedCiphers.argtypes = [
254
+ SSLContextRef,
255
+ POINTER(SSLCipherSuite),
256
+ POINTER(c_size_t)
257
+ ]
258
+ Security.SSLGetSupportedCiphers.restype = OSStatus
259
+
260
+ Security.SSLSetEnabledCiphers.argtypes = [
261
+ SSLContextRef,
262
+ POINTER(SSLCipherSuite),
263
+ c_size_t
264
+ ]
265
+ Security.SSLSetEnabledCiphers.restype = OSStatus
266
+
267
+ Security.SSLGetNumberEnabledCiphers.argtype = [
268
+ SSLContextRef,
269
+ POINTER(c_size_t)
270
+ ]
271
+ Security.SSLGetNumberEnabledCiphers.restype = OSStatus
272
+
273
+ Security.SSLGetEnabledCiphers.argtypes = [
274
+ SSLContextRef,
275
+ POINTER(SSLCipherSuite),
276
+ POINTER(c_size_t)
277
+ ]
278
+ Security.SSLGetEnabledCiphers.restype = OSStatus
279
+
280
+ Security.SSLGetNegotiatedCipher.argtypes = [
281
+ SSLContextRef,
282
+ POINTER(SSLCipherSuite)
283
+ ]
284
+ Security.SSLGetNegotiatedCipher.restype = OSStatus
285
+
286
+ Security.SSLGetNegotiatedProtocolVersion.argtypes = [
287
+ SSLContextRef,
288
+ POINTER(SSLProtocol)
289
+ ]
290
+ Security.SSLGetNegotiatedProtocolVersion.restype = OSStatus
291
+
292
+ Security.SSLCopyPeerTrust.argtypes = [
293
+ SSLContextRef,
294
+ POINTER(SecTrustRef)
295
+ ]
296
+ Security.SSLCopyPeerTrust.restype = OSStatus
297
+
298
+ Security.SecTrustSetAnchorCertificates.argtypes = [
299
+ SecTrustRef,
300
+ CFArrayRef
301
+ ]
302
+ Security.SecTrustSetAnchorCertificates.restype = OSStatus
303
+
304
+ Security.SecTrustSetAnchorCertificatesOnly.argstypes = [
305
+ SecTrustRef,
306
+ Boolean
307
+ ]
308
+ Security.SecTrustSetAnchorCertificatesOnly.restype = OSStatus
309
+
310
+ Security.SecTrustEvaluate.argtypes = [
311
+ SecTrustRef,
312
+ POINTER(SecTrustResultType)
313
+ ]
314
+ Security.SecTrustEvaluate.restype = OSStatus
315
+
316
+ Security.SecTrustGetCertificateCount.argtypes = [
317
+ SecTrustRef
318
+ ]
319
+ Security.SecTrustGetCertificateCount.restype = CFIndex
320
+
321
+ Security.SecTrustGetCertificateAtIndex.argtypes = [
322
+ SecTrustRef,
323
+ CFIndex
324
+ ]
325
+ Security.SecTrustGetCertificateAtIndex.restype = SecCertificateRef
326
+
327
+ Security.SSLCreateContext.argtypes = [
328
+ CFAllocatorRef,
329
+ SSLProtocolSide,
330
+ SSLConnectionType
331
+ ]
332
+ Security.SSLCreateContext.restype = SSLContextRef
333
+
334
+ Security.SSLSetSessionOption.argtypes = [
335
+ SSLContextRef,
336
+ SSLSessionOption,
337
+ Boolean
338
+ ]
339
+ Security.SSLSetSessionOption.restype = OSStatus
340
+
341
+ Security.SSLSetProtocolVersionMin.argtypes = [
342
+ SSLContextRef,
343
+ SSLProtocol
344
+ ]
345
+ Security.SSLSetProtocolVersionMin.restype = OSStatus
346
+
347
+ Security.SSLSetProtocolVersionMax.argtypes = [
348
+ SSLContextRef,
349
+ SSLProtocol
350
+ ]
351
+ Security.SSLSetProtocolVersionMax.restype = OSStatus
352
+
353
+ Security.SecCopyErrorMessageString.argtypes = [
354
+ OSStatus,
355
+ c_void_p
356
+ ]
357
+ Security.SecCopyErrorMessageString.restype = CFStringRef
358
+
359
+ Security.SSLReadFunc = SSLReadFunc
360
+ Security.SSLWriteFunc = SSLWriteFunc
361
+ Security.SSLContextRef = SSLContextRef
362
+ Security.SSLProtocol = SSLProtocol
363
+ Security.SSLCipherSuite = SSLCipherSuite
364
+ Security.SecIdentityRef = SecIdentityRef
365
+ Security.SecKeychainRef = SecKeychainRef
366
+ Security.SecTrustRef = SecTrustRef
367
+ Security.SecTrustResultType = SecTrustResultType
368
+ Security.SecExternalFormat = SecExternalFormat
369
+ Security.OSStatus = OSStatus
370
+
371
+ Security.kSecImportExportPassphrase = CFStringRef.in_dll(
372
+ Security, 'kSecImportExportPassphrase'
373
+ )
374
+ Security.kSecImportItemIdentity = CFStringRef.in_dll(
375
+ Security, 'kSecImportItemIdentity'
376
+ )
377
+
378
+ # CoreFoundation time!
379
+ CoreFoundation.CFRetain.argtypes = [
380
+ CFTypeRef
381
+ ]
382
+ CoreFoundation.CFRetain.restype = CFTypeRef
383
+
384
+ CoreFoundation.CFRelease.argtypes = [
385
+ CFTypeRef
386
+ ]
387
+ CoreFoundation.CFRelease.restype = None
388
+
389
+ CoreFoundation.CFGetTypeID.argtypes = [
390
+ CFTypeRef
391
+ ]
392
+ CoreFoundation.CFGetTypeID.restype = CFTypeID
393
+
394
+ CoreFoundation.CFStringCreateWithCString.argtypes = [
395
+ CFAllocatorRef,
396
+ c_char_p,
397
+ CFStringEncoding
398
+ ]
399
+ CoreFoundation.CFStringCreateWithCString.restype = CFStringRef
400
+
401
+ CoreFoundation.CFStringGetCStringPtr.argtypes = [
402
+ CFStringRef,
403
+ CFStringEncoding
404
+ ]
405
+ CoreFoundation.CFStringGetCStringPtr.restype = c_char_p
406
+
407
+ CoreFoundation.CFStringGetCString.argtypes = [
408
+ CFStringRef,
409
+ c_char_p,
410
+ CFIndex,
411
+ CFStringEncoding
412
+ ]
413
+ CoreFoundation.CFStringGetCString.restype = c_bool
414
+
415
+ CoreFoundation.CFDataCreate.argtypes = [
416
+ CFAllocatorRef,
417
+ c_char_p,
418
+ CFIndex
419
+ ]
420
+ CoreFoundation.CFDataCreate.restype = CFDataRef
421
+
422
+ CoreFoundation.CFDataGetLength.argtypes = [
423
+ CFDataRef
424
+ ]
425
+ CoreFoundation.CFDataGetLength.restype = CFIndex
426
+
427
+ CoreFoundation.CFDataGetBytePtr.argtypes = [
428
+ CFDataRef
429
+ ]
430
+ CoreFoundation.CFDataGetBytePtr.restype = c_void_p
431
+
432
+ CoreFoundation.CFDictionaryCreate.argtypes = [
433
+ CFAllocatorRef,
434
+ POINTER(CFTypeRef),
435
+ POINTER(CFTypeRef),
436
+ CFIndex,
437
+ CFDictionaryKeyCallBacks,
438
+ CFDictionaryValueCallBacks
439
+ ]
440
+ CoreFoundation.CFDictionaryCreate.restype = CFDictionaryRef
441
+
442
+ CoreFoundation.CFDictionaryGetValue.argtypes = [
443
+ CFDictionaryRef,
444
+ CFTypeRef
445
+ ]
446
+ CoreFoundation.CFDictionaryGetValue.restype = CFTypeRef
447
+
448
+ CoreFoundation.CFArrayCreate.argtypes = [
449
+ CFAllocatorRef,
450
+ POINTER(CFTypeRef),
451
+ CFIndex,
452
+ CFArrayCallBacks,
453
+ ]
454
+ CoreFoundation.CFArrayCreate.restype = CFArrayRef
455
+
456
+ CoreFoundation.CFArrayCreateMutable.argtypes = [
457
+ CFAllocatorRef,
458
+ CFIndex,
459
+ CFArrayCallBacks
460
+ ]
461
+ CoreFoundation.CFArrayCreateMutable.restype = CFMutableArrayRef
462
+
463
+ CoreFoundation.CFArrayAppendValue.argtypes = [
464
+ CFMutableArrayRef,
465
+ c_void_p
466
+ ]
467
+ CoreFoundation.CFArrayAppendValue.restype = None
468
+
469
+ CoreFoundation.CFArrayGetCount.argtypes = [
470
+ CFArrayRef
471
+ ]
472
+ CoreFoundation.CFArrayGetCount.restype = CFIndex
473
+
474
+ CoreFoundation.CFArrayGetValueAtIndex.argtypes = [
475
+ CFArrayRef,
476
+ CFIndex
477
+ ]
478
+ CoreFoundation.CFArrayGetValueAtIndex.restype = c_void_p
479
+
480
+ CoreFoundation.kCFAllocatorDefault = CFAllocatorRef.in_dll(
481
+ CoreFoundation, 'kCFAllocatorDefault'
482
+ )
483
+ CoreFoundation.kCFTypeArrayCallBacks = c_void_p.in_dll(CoreFoundation, 'kCFTypeArrayCallBacks')
484
+ CoreFoundation.kCFTypeDictionaryKeyCallBacks = c_void_p.in_dll(
485
+ CoreFoundation, 'kCFTypeDictionaryKeyCallBacks'
486
+ )
487
+ CoreFoundation.kCFTypeDictionaryValueCallBacks = c_void_p.in_dll(
488
+ CoreFoundation, 'kCFTypeDictionaryValueCallBacks'
489
+ )
490
+
491
+ CoreFoundation.CFTypeRef = CFTypeRef
492
+ CoreFoundation.CFArrayRef = CFArrayRef
493
+ CoreFoundation.CFStringRef = CFStringRef
494
+ CoreFoundation.CFDictionaryRef = CFDictionaryRef
495
+
496
+ except (AttributeError):
497
+ raise ImportError('Error initializing ctypes')
498
+
499
+
500
+ class CFConst(object):
501
+ """
502
+ A class object that acts as essentially a namespace for CoreFoundation
503
+ constants.
504
+ """
505
+ kCFStringEncodingUTF8 = CFStringEncoding(0x08000100)
506
+
507
+
508
+ class SecurityConst(object):
509
+ """
510
+ A class object that acts as essentially a namespace for Security constants.
511
+ """
512
+ kSSLSessionOptionBreakOnServerAuth = 0
513
+
514
+ kSSLProtocol2 = 1
515
+ kSSLProtocol3 = 2
516
+ kTLSProtocol1 = 4
517
+ kTLSProtocol11 = 7
518
+ kTLSProtocol12 = 8
519
+ kTLSProtocol13 = 10
520
+ kTLSProtocolMaxSupported = 999
521
+
522
+ kSSLClientSide = 1
523
+ kSSLStreamType = 0
524
+
525
+ kSecFormatPEMSequence = 10
526
+
527
+ kSecTrustResultInvalid = 0
528
+ kSecTrustResultProceed = 1
529
+ # This gap is present on purpose: this was kSecTrustResultConfirm, which
530
+ # is deprecated.
531
+ kSecTrustResultDeny = 3
532
+ kSecTrustResultUnspecified = 4
533
+ kSecTrustResultRecoverableTrustFailure = 5
534
+ kSecTrustResultFatalTrustFailure = 6
535
+ kSecTrustResultOtherError = 7
536
+
537
+ errSSLProtocol = -9800
538
+ errSSLWouldBlock = -9803
539
+ errSSLClosedGraceful = -9805
540
+ errSSLClosedNoNotify = -9816
541
+ errSSLClosedAbort = -9806
542
+
543
+ errSSLXCertChainInvalid = -9807
544
+ errSSLCrypto = -9809
545
+ errSSLInternal = -9810
546
+ errSSLCertExpired = -9814
547
+ errSSLCertNotYetValid = -9815
548
+ errSSLUnknownRootCert = -9812
549
+ errSSLNoRootCert = -9813
550
+ errSSLHostNameMismatch = -9843
551
+ errSSLPeerHandshakeFail = -9824
552
+ errSSLPeerUserCancelled = -9839
553
+ errSSLWeakPeerEphemeralDHKey = -9850
554
+ errSSLServerAuthCompleted = -9841
555
+ errSSLRecordOverflow = -9847
556
+
557
+ errSecVerifyFailed = -67808
558
+ errSecNoTrustSettings = -25263
559
+ errSecItemNotFound = -25300
560
+ errSecInvalidTrustSettings = -25262
561
+
562
+ # Cipher suites. We only pick the ones our default cipher string allows.
563
+ # Source: https://developer.apple.com/documentation/security/1550981-ssl_cipher_suite_values
564
+ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C
565
+ TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030
566
+ TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B
567
+ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F
568
+ TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA9
569
+ TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA8
570
+ TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F
571
+ TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E
572
+ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC024
573
+ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0xC028
574
+ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A
575
+ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014
576
+ TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x006B
577
+ TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039
578
+ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC023
579
+ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0xC027
580
+ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009
581
+ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013
582
+ TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x0067
583
+ TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033
584
+ TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D
585
+ TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C
586
+ TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x003D
587
+ TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x003C
588
+ TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035
589
+ TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F
590
+ TLS_AES_128_GCM_SHA256 = 0x1301
591
+ TLS_AES_256_GCM_SHA384 = 0x1302
592
+ TLS_AES_128_CCM_8_SHA256 = 0x1305
593
+ TLS_AES_128_CCM_SHA256 = 0x1304
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/rfc3986/__init__.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2014 Rackspace
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
+ # implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """
17
+ An implementation of semantics and validations described in RFC 3986.
18
+
19
+ See http://rfc3986.readthedocs.io/ for detailed documentation.
20
+
21
+ :copyright: (c) 2014 Rackspace
22
+ :license: Apache v2.0, see LICENSE for details
23
+ """
24
+
25
+ from .api import iri_reference
26
+ from .api import IRIReference
27
+ from .api import is_valid_uri
28
+ from .api import normalize_uri
29
+ from .api import uri_reference
30
+ from .api import URIReference
31
+ from .api import urlparse
32
+ from .parseresult import ParseResult
33
+
34
+ __title__ = 'rfc3986'
35
+ __author__ = 'Ian Stapleton Cordasco'
36
+ __author_email__ = 'graffatcolmingov@gmail.com'
37
+ __license__ = 'Apache v2.0'
38
+ __copyright__ = 'Copyright 2014 Rackspace'
39
+ __version__ = '1.3.2'
40
+
41
+ __all__ = (
42
+ 'ParseResult',
43
+ 'URIReference',
44
+ 'IRIReference',
45
+ 'is_valid_uri',
46
+ 'normalize_uri',
47
+ 'uri_reference',
48
+ 'iri_reference',
49
+ 'urlparse',
50
+ '__title__',
51
+ '__author__',
52
+ '__author_email__',
53
+ '__license__',
54
+ '__copyright__',
55
+ '__version__',
56
+ )
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/rfc3986/_mixin.py ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Module containing the implementation of the URIMixin class."""
2
+ import warnings
3
+
4
+ from . import exceptions as exc
5
+ from . import misc
6
+ from . import normalizers
7
+ from . import validators
8
+
9
+
10
+ class URIMixin(object):
11
+ """Mixin with all shared methods for URIs and IRIs."""
12
+
13
+ __hash__ = tuple.__hash__
14
+
15
+ def authority_info(self):
16
+ """Return a dictionary with the ``userinfo``, ``host``, and ``port``.
17
+
18
+ If the authority is not valid, it will raise a
19
+ :class:`~rfc3986.exceptions.InvalidAuthority` Exception.
20
+
21
+ :returns:
22
+ ``{'userinfo': 'username:password', 'host': 'www.example.com',
23
+ 'port': '80'}``
24
+ :rtype: dict
25
+ :raises rfc3986.exceptions.InvalidAuthority:
26
+ If the authority is not ``None`` and can not be parsed.
27
+ """
28
+ if not self.authority:
29
+ return {'userinfo': None, 'host': None, 'port': None}
30
+
31
+ match = self._match_subauthority()
32
+
33
+ if match is None:
34
+ # In this case, we have an authority that was parsed from the URI
35
+ # Reference, but it cannot be further parsed by our
36
+ # misc.SUBAUTHORITY_MATCHER. In this case it must not be a valid
37
+ # authority.
38
+ raise exc.InvalidAuthority(self.authority.encode(self.encoding))
39
+
40
+ # We had a match, now let's ensure that it is actually a valid host
41
+ # address if it is IPv4
42
+ matches = match.groupdict()
43
+ host = matches.get('host')
44
+
45
+ if (host and misc.IPv4_MATCHER.match(host) and not
46
+ validators.valid_ipv4_host_address(host)):
47
+ # If we have a host, it appears to be IPv4 and it does not have
48
+ # valid bytes, it is an InvalidAuthority.
49
+ raise exc.InvalidAuthority(self.authority.encode(self.encoding))
50
+
51
+ return matches
52
+
53
+ def _match_subauthority(self):
54
+ return misc.SUBAUTHORITY_MATCHER.match(self.authority)
55
+
56
+ @property
57
+ def host(self):
58
+ """If present, a string representing the host."""
59
+ try:
60
+ authority = self.authority_info()
61
+ except exc.InvalidAuthority:
62
+ return None
63
+ return authority['host']
64
+
65
+ @property
66
+ def port(self):
67
+ """If present, the port extracted from the authority."""
68
+ try:
69
+ authority = self.authority_info()
70
+ except exc.InvalidAuthority:
71
+ return None
72
+ return authority['port']
73
+
74
+ @property
75
+ def userinfo(self):
76
+ """If present, the userinfo extracted from the authority."""
77
+ try:
78
+ authority = self.authority_info()
79
+ except exc.InvalidAuthority:
80
+ return None
81
+ return authority['userinfo']
82
+
83
+ def is_absolute(self):
84
+ """Determine if this URI Reference is an absolute URI.
85
+
86
+ See http://tools.ietf.org/html/rfc3986#section-4.3 for explanation.
87
+
88
+ :returns: ``True`` if it is an absolute URI, ``False`` otherwise.
89
+ :rtype: bool
90
+ """
91
+ return bool(misc.ABSOLUTE_URI_MATCHER.match(self.unsplit()))
92
+
93
+ def is_valid(self, **kwargs):
94
+ """Determine if the URI is valid.
95
+
96
+ .. deprecated:: 1.1.0
97
+
98
+ Use the :class:`~rfc3986.validators.Validator` object instead.
99
+
100
+ :param bool require_scheme: Set to ``True`` if you wish to require the
101
+ presence of the scheme component.
102
+ :param bool require_authority: Set to ``True`` if you wish to require
103
+ the presence of the authority component.
104
+ :param bool require_path: Set to ``True`` if you wish to require the
105
+ presence of the path component.
106
+ :param bool require_query: Set to ``True`` if you wish to require the
107
+ presence of the query component.
108
+ :param bool require_fragment: Set to ``True`` if you wish to require
109
+ the presence of the fragment component.
110
+ :returns: ``True`` if the URI is valid. ``False`` otherwise.
111
+ :rtype: bool
112
+ """
113
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
114
+ "This method will be eventually removed.",
115
+ DeprecationWarning)
116
+ validators = [
117
+ (self.scheme_is_valid, kwargs.get('require_scheme', False)),
118
+ (self.authority_is_valid, kwargs.get('require_authority', False)),
119
+ (self.path_is_valid, kwargs.get('require_path', False)),
120
+ (self.query_is_valid, kwargs.get('require_query', False)),
121
+ (self.fragment_is_valid, kwargs.get('require_fragment', False)),
122
+ ]
123
+ return all(v(r) for v, r in validators)
124
+
125
+ def authority_is_valid(self, require=False):
126
+ """Determine if the authority component is valid.
127
+
128
+ .. deprecated:: 1.1.0
129
+
130
+ Use the :class:`~rfc3986.validators.Validator` object instead.
131
+
132
+ :param bool require:
133
+ Set to ``True`` to require the presence of this component.
134
+ :returns:
135
+ ``True`` if the authority is valid. ``False`` otherwise.
136
+ :rtype:
137
+ bool
138
+ """
139
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
140
+ "This method will be eventually removed.",
141
+ DeprecationWarning)
142
+ try:
143
+ self.authority_info()
144
+ except exc.InvalidAuthority:
145
+ return False
146
+
147
+ return validators.authority_is_valid(
148
+ self.authority,
149
+ host=self.host,
150
+ require=require,
151
+ )
152
+
153
+ def scheme_is_valid(self, require=False):
154
+ """Determine if the scheme component is valid.
155
+
156
+ .. deprecated:: 1.1.0
157
+
158
+ Use the :class:`~rfc3986.validators.Validator` object instead.
159
+
160
+ :param str require: Set to ``True`` to require the presence of this
161
+ component.
162
+ :returns: ``True`` if the scheme is valid. ``False`` otherwise.
163
+ :rtype: bool
164
+ """
165
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
166
+ "This method will be eventually removed.",
167
+ DeprecationWarning)
168
+ return validators.scheme_is_valid(self.scheme, require)
169
+
170
+ def path_is_valid(self, require=False):
171
+ """Determine if the path component is valid.
172
+
173
+ .. deprecated:: 1.1.0
174
+
175
+ Use the :class:`~rfc3986.validators.Validator` object instead.
176
+
177
+ :param str require: Set to ``True`` to require the presence of this
178
+ component.
179
+ :returns: ``True`` if the path is valid. ``False`` otherwise.
180
+ :rtype: bool
181
+ """
182
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
183
+ "This method will be eventually removed.",
184
+ DeprecationWarning)
185
+ return validators.path_is_valid(self.path, require)
186
+
187
+ def query_is_valid(self, require=False):
188
+ """Determine if the query component is valid.
189
+
190
+ .. deprecated:: 1.1.0
191
+
192
+ Use the :class:`~rfc3986.validators.Validator` object instead.
193
+
194
+ :param str require: Set to ``True`` to require the presence of this
195
+ component.
196
+ :returns: ``True`` if the query is valid. ``False`` otherwise.
197
+ :rtype: bool
198
+ """
199
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
200
+ "This method will be eventually removed.",
201
+ DeprecationWarning)
202
+ return validators.query_is_valid(self.query, require)
203
+
204
+ def fragment_is_valid(self, require=False):
205
+ """Determine if the fragment component is valid.
206
+
207
+ .. deprecated:: 1.1.0
208
+
209
+ Use the Validator object instead.
210
+
211
+ :param str require: Set to ``True`` to require the presence of this
212
+ component.
213
+ :returns: ``True`` if the fragment is valid. ``False`` otherwise.
214
+ :rtype: bool
215
+ """
216
+ warnings.warn("Please use rfc3986.validators.Validator instead. "
217
+ "This method will be eventually removed.",
218
+ DeprecationWarning)
219
+ return validators.fragment_is_valid(self.fragment, require)
220
+
221
+ def normalized_equality(self, other_ref):
222
+ """Compare this URIReference to another URIReference.
223
+
224
+ :param URIReference other_ref: (required), The reference with which
225
+ we're comparing.
226
+ :returns: ``True`` if the references are equal, ``False`` otherwise.
227
+ :rtype: bool
228
+ """
229
+ return tuple(self.normalize()) == tuple(other_ref.normalize())
230
+
231
+ def resolve_with(self, base_uri, strict=False):
232
+ """Use an absolute URI Reference to resolve this relative reference.
233
+
234
+ Assuming this is a relative reference that you would like to resolve,
235
+ use the provided base URI to resolve it.
236
+
237
+ See http://tools.ietf.org/html/rfc3986#section-5 for more information.
238
+
239
+ :param base_uri: Either a string or URIReference. It must be an
240
+ absolute URI or it will raise an exception.
241
+ :returns: A new URIReference which is the result of resolving this
242
+ reference using ``base_uri``.
243
+ :rtype: :class:`URIReference`
244
+ :raises rfc3986.exceptions.ResolutionError:
245
+ If the ``base_uri`` is not an absolute URI.
246
+ """
247
+ if not isinstance(base_uri, URIMixin):
248
+ base_uri = type(self).from_string(base_uri)
249
+
250
+ if not base_uri.is_absolute():
251
+ raise exc.ResolutionError(base_uri)
252
+
253
+ # This is optional per
254
+ # http://tools.ietf.org/html/rfc3986#section-5.2.1
255
+ base_uri = base_uri.normalize()
256
+
257
+ # The reference we're resolving
258
+ resolving = self
259
+
260
+ if not strict and resolving.scheme == base_uri.scheme:
261
+ resolving = resolving.copy_with(scheme=None)
262
+
263
+ # http://tools.ietf.org/html/rfc3986#page-32
264
+ if resolving.scheme is not None:
265
+ target = resolving.copy_with(
266
+ path=normalizers.normalize_path(resolving.path)
267
+ )
268
+ else:
269
+ if resolving.authority is not None:
270
+ target = resolving.copy_with(
271
+ scheme=base_uri.scheme,
272
+ path=normalizers.normalize_path(resolving.path)
273
+ )
274
+ else:
275
+ if resolving.path is None:
276
+ if resolving.query is not None:
277
+ query = resolving.query
278
+ else:
279
+ query = base_uri.query
280
+ target = resolving.copy_with(
281
+ scheme=base_uri.scheme,
282
+ authority=base_uri.authority,
283
+ path=base_uri.path,
284
+ query=query
285
+ )
286
+ else:
287
+ if resolving.path.startswith('/'):
288
+ path = normalizers.normalize_path(resolving.path)
289
+ else:
290
+ path = normalizers.normalize_path(
291
+ misc.merge_paths(base_uri, resolving.path)
292
+ )
293
+ target = resolving.copy_with(
294
+ scheme=base_uri.scheme,
295
+ authority=base_uri.authority,
296
+ path=path,
297
+ query=resolving.query
298
+ )
299
+ return target
300
+
301
+ def unsplit(self):
302
+ """Create a URI string from the components.
303
+
304
+ :returns: The URI Reference reconstituted as a string.
305
+ :rtype: str
306
+ """
307
+ # See http://tools.ietf.org/html/rfc3986#section-5.3
308
+ result_list = []
309
+ if self.scheme:
310
+ result_list.extend([self.scheme, ':'])
311
+ if self.authority:
312
+ result_list.extend(['//', self.authority])
313
+ if self.path:
314
+ result_list.append(self.path)
315
+ if self.query is not None:
316
+ result_list.extend(['?', self.query])
317
+ if self.fragment is not None:
318
+ result_list.extend(['#', self.fragment])
319
+ return ''.join(result_list)
320
+
321
+ def copy_with(self, scheme=misc.UseExisting, authority=misc.UseExisting,
322
+ path=misc.UseExisting, query=misc.UseExisting,
323
+ fragment=misc.UseExisting):
324
+ """Create a copy of this reference with the new components.
325
+
326
+ :param str scheme:
327
+ (optional) The scheme to use for the new reference.
328
+ :param str authority:
329
+ (optional) The authority to use for the new reference.
330
+ :param str path:
331
+ (optional) The path to use for the new reference.
332
+ :param str query:
333
+ (optional) The query to use for the new reference.
334
+ :param str fragment:
335
+ (optional) The fragment to use for the new reference.
336
+ :returns:
337
+ New URIReference with provided components.
338
+ :rtype:
339
+ URIReference
340
+ """
341
+ attributes = {
342
+ 'scheme': scheme,
343
+ 'authority': authority,
344
+ 'path': path,
345
+ 'query': query,
346
+ 'fragment': fragment,
347
+ }
348
+ for key, value in list(attributes.items()):
349
+ if value is misc.UseExisting:
350
+ del attributes[key]
351
+ uri = self._replace(**attributes)
352
+ uri.encoding = self.encoding
353
+ return uri
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname/__init__.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ try:
4
+ # Our match_hostname function is the same as 3.5's, so we only want to
5
+ # import the match_hostname function if it's at least that good.
6
+ if sys.version_info < (3, 5):
7
+ raise ImportError("Fallback to vendored code")
8
+
9
+ from ssl import CertificateError, match_hostname
10
+ except ImportError:
11
+ try:
12
+ # Backport of the function from a pypi module
13
+ from backports.ssl_match_hostname import CertificateError, match_hostname
14
+ except ImportError:
15
+ # Our vendored copy
16
+ from ._implementation import CertificateError, match_hostname
17
+
18
+ # Not needed, but documenting what we provide.
19
+ __all__ = ('CertificateError', 'match_hostname')
benchmark/NYU_CTF_Bench/test/2019/CSAW-Quals/crypto/brillouin/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname/_implementation.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The match_hostname() function from Python 3.3.3, essential when using SSL."""
2
+
3
+ # Note: This file is under the PSF license as the code comes from the python
4
+ # stdlib. http://docs.python.org/3/license.html
5
+
6
+ import re
7
+ import sys
8
+
9
+ # ipaddress has been backported to 2.6+ in pypi. If it is installed on the
10
+ # system, use it to handle IPAddress ServerAltnames (this was added in
11
+ # python-3.5) otherwise only do DNS matching. This allows
12
+ # backports.ssl_match_hostname to continue to be used in Python 2.7.
13
+ try:
14
+ import ipaddress
15
+ except ImportError:
16
+ ipaddress = None
17
+
18
+ __version__ = '3.5.0.1'
19
+
20
+
21
+ class CertificateError(ValueError):
22
+ pass
23
+
24
+
25
+ def _dnsname_match(dn, hostname, max_wildcards=1):
26
+ """Matching according to RFC 6125, section 6.4.3
27
+
28
+ http://tools.ietf.org/html/rfc6125#section-6.4.3
29
+ """
30
+ pats = []
31
+ if not dn:
32
+ return False
33
+
34
+ # Ported from python3-syntax:
35
+ # leftmost, *remainder = dn.split(r'.')
36
+ parts = dn.split(r'.')
37
+ leftmost = parts[0]
38
+ remainder = parts[1:]
39
+
40
+ wildcards = leftmost.count('*')
41
+ if wildcards > max_wildcards:
42
+ # Issue #17980: avoid denials of service by refusing more
43
+ # than one wildcard per fragment. A survey of established
44
+ # policy among SSL implementations showed it to be a
45
+ # reasonable choice.
46
+ raise CertificateError(
47
+ "too many wildcards in certificate DNS name: " + repr(dn))
48
+
49
+ # speed up common case w/o wildcards
50
+ if not wildcards:
51
+ return dn.lower() == hostname.lower()
52
+
53
+ # RFC 6125, section 6.4.3, subitem 1.
54
+ # The client SHOULD NOT attempt to match a presented identifier in which
55
+ # the wildcard character comprises a label other than the left-most label.
56
+ if leftmost == '*':
57
+ # When '*' is a fragment by itself, it matches a non-empty dotless
58
+ # fragment.
59
+ pats.append('[^.]+')
60
+ elif leftmost.startswith('xn--') or hostname.startswith('xn--'):
61
+ # RFC 6125, section 6.4.3, subitem 3.
62
+ # The client SHOULD NOT attempt to match a presented identifier
63
+ # where the wildcard character is embedded within an A-label or
64
+ # U-label of an internationalized domain name.
65
+ pats.append(re.escape(leftmost))
66
+ else:
67
+ # Otherwise, '*' matches any dotless string, e.g. www*
68
+ pats.append(re.escape(leftmost).replace(r'\*', '[^.]*'))
69
+
70
+ # add the remaining fragments, ignore any wildcards
71
+ for frag in remainder:
72
+ pats.append(re.escape(frag))
73
+
74
+ pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
75
+ return pat.match(hostname)
76
+
77
+
78
+ def _to_unicode(obj):
79
+ if isinstance(obj, str) and sys.version_info < (3,):
80
+ obj = unicode(obj, encoding='ascii', errors='strict')
81
+ return obj
82
+
83
+ def _ipaddress_match(ipname, host_ip):
84
+ """Exact matching of IP addresses.
85
+
86
+ RFC 6125 explicitly doesn't define an algorithm for this
87
+ (section 1.7.2 - "Out of Scope").
88
+ """
89
+ # OpenSSL may add a trailing newline to a subjectAltName's IP address
90
+ # Divergence from upstream: ipaddress can't handle byte str
91
+ ip = ipaddress.ip_address(_to_unicode(ipname).rstrip())
92
+ return ip == host_ip
93
+
94
+
95
+ def match_hostname(cert, hostname):
96
+ """Verify that *cert* (in decoded format as returned by
97
+ SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
98
+ rules are followed, but IP addresses are not accepted for *hostname*.
99
+
100
+ CertificateError is raised on failure. On success, the function
101
+ returns nothing.
102
+ """
103
+ if not cert:
104
+ raise ValueError("empty or no certificate, match_hostname needs a "
105
+ "SSL socket or SSL context with either "
106
+ "CERT_OPTIONAL or CERT_REQUIRED")
107
+ try:
108
+ # Divergence from upstream: ipaddress can't handle byte str
109
+ host_ip = ipaddress.ip_address(_to_unicode(hostname))
110
+ except ValueError:
111
+ # Not an IP address (common case)
112
+ host_ip = None
113
+ except UnicodeError:
114
+ # Divergence from upstream: Have to deal with ipaddress not taking
115
+ # byte strings. addresses should be all ascii, so we consider it not
116
+ # an ipaddress in this case
117
+ host_ip = None
118
+ except AttributeError:
119
+ # Divergence from upstream: Make ipaddress library optional
120
+ if ipaddress is None:
121
+ host_ip = None
122
+ else:
123
+ raise
124
+ dnsnames = []
125
+ san = cert.get('subjectAltName', ())
126
+ for key, value in san:
127
+ if key == 'DNS':
128
+ if host_ip is None and _dnsname_match(value, hostname):
129
+ return
130
+ dnsnames.append(value)
131
+ elif key == 'IP Address':
132
+ if host_ip is not None and _ipaddress_match(value, host_ip):
133
+ return
134
+ dnsnames.append(value)
135
+ if not dnsnames:
136
+ # The subject is only checked when there is no dNSName entry
137
+ # in subjectAltName
138
+ for sub in cert.get('subject', ()):
139
+ for key, value in sub:
140
+ # XXX according to RFC 2818, the most specific Common Name
141
+ # must be used.
142
+ if key == 'commonName':
143
+ if _dnsname_match(value, hostname):
144
+ return
145
+ dnsnames.append(value)
146
+ if len(dnsnames) > 1:
147
+ raise CertificateError("hostname %r "
148
+ "doesn't match either of %s"
149
+ % (hostname, ', '.join(map(repr, dnsnames))))
150
+ elif len(dnsnames) == 1:
151
+ raise CertificateError("hostname %r "
152
+ "doesn't match %r"
153
+ % (hostname, dnsnames[0]))
154
+ else:
155
+ raise CertificateError("no appropriate commonName or "
156
+ "subjectAltName fields were found")