CryptoDataHub 0.11.1__py3-none-any.whl → 0.12.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of CryptoDataHub might be problematic. Click here for more details.

@@ -1,8 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  import binascii
4
+ import hashlib
4
5
 
6
+ import attr
5
7
  import six
8
+ import urllib3
9
+
10
+ from cryptodatahub.common.algorithm import Hash
6
11
 
7
12
 
8
13
  def bytes_to_hex_string(byte_array, separator='', lowercase=False):
@@ -35,3 +40,71 @@ def name_to_enum_item_name(name):
35
40
  converted_name += '_'
36
41
 
37
42
  return converted_name.rstrip('_').upper()
43
+
44
+
45
+ _HASHLIB_FUNCS = {
46
+ Hash.MD5: hashlib.md5,
47
+ Hash.SHA1: hashlib.sha1,
48
+ Hash.SHA2_224: hashlib.sha224,
49
+ Hash.SHA2_256: hashlib.sha256,
50
+ Hash.SHA2_384: hashlib.sha384,
51
+ Hash.SHA2_512: hashlib.sha512,
52
+ }
53
+
54
+
55
+ def hash_bytes(hash_algorithm, hashable_value):
56
+ try:
57
+ hashlib_funcs = _HASHLIB_FUNCS[hash_algorithm]
58
+ except KeyError as e:
59
+ six.raise_from(NotImplementedError(hash_algorithm), e)
60
+
61
+ return hashlib_funcs(hashable_value).digest()
62
+
63
+
64
+ @attr.s
65
+ class HttpFetcher(object):
66
+ connect_timeout = attr.ib(default=2, validator=attr.validators.instance_of((int, float)))
67
+ read_timeout = attr.ib(default=1, validator=attr.validators.instance_of((int, float)))
68
+ retry = attr.ib(default=1, validator=attr.validators.instance_of(int))
69
+ _request_params = attr.ib(default=None, init=False)
70
+ _response = attr.ib(default=None, init=False)
71
+
72
+ def __attrs_post_init__(self):
73
+ request_params = {
74
+ 'preload_content': False,
75
+ 'timeout': urllib3.Timeout(connect=self.connect_timeout, read=self.read_timeout),
76
+ 'retries': urllib3.Retry(
77
+ self.retry, status_forcelist=urllib3.Retry.RETRY_AFTER_STATUS_CODES | frozenset([502])
78
+ ),
79
+ }
80
+
81
+ object.__setattr__(self, '_request_params', request_params)
82
+
83
+ def get_response_header(self, header_name):
84
+ if self._response is None:
85
+ raise AttributeError()
86
+
87
+ return self._response.headers.get(header_name, None)
88
+
89
+ @property
90
+ def response_data(self):
91
+ if self._response is None:
92
+ raise AttributeError()
93
+
94
+ return self._response.data
95
+
96
+ def fetch(self, url):
97
+ pool_manager = urllib3.PoolManager()
98
+
99
+ try:
100
+ self._response = pool_manager.request('GET', str(url), **self._request_params)
101
+ except BaseException as e: # pylint: disable=broad-except
102
+ if e.__class__.__name__ != 'TimeoutError' and not isinstance(e, urllib3.exceptions.HTTPError):
103
+ raise e
104
+
105
+ pool_manager.clear()
106
+
107
+ def __call__(self, url):
108
+ self.fetch(url)
109
+
110
+ return self.response_data
@@ -27,7 +27,7 @@ from cryptodatahub.common.types import (
27
27
  )
28
28
 
29
29
 
30
- @attr.s
30
+ @attr.s(frozen=True)
31
31
  class SshAlgorithmParams(CryptoDataParamsEnumString, GradeableComplex):
32
32
  @property
33
33
  @abc.abstractmethod
@@ -52,15 +52,15 @@ class SshAlgorithmParams(CryptoDataParamsEnumString, GradeableComplex):
52
52
  attr.validate(self)
53
53
 
54
54
 
55
- @attr.s
55
+ @attr.s(frozen=True)
56
56
  class EncryptionAlgorithmParams(SshAlgorithmParams):
57
57
  cipher = attr.ib(
58
58
  converter=convert_enum(BlockCipher),
59
- validator=attr.validators.optional(attr.validators.instance_of((BlockCipher, six.string_types)))
59
+ validator=attr.validators.optional(attr.validators.instance_of(BlockCipher))
60
60
  )
61
61
  mode = attr.ib(
62
62
  converter=convert_enum(BlockCipherMode),
63
- validator=attr.validators.optional(attr.validators.instance_of((BlockCipherMode, six.string_types)))
63
+ validator=attr.validators.optional(attr.validators.instance_of(BlockCipherMode))
64
64
  )
65
65
 
66
66
  @property
@@ -68,16 +68,16 @@ class EncryptionAlgorithmParams(SshAlgorithmParams):
68
68
  return ('cipher', 'mode')
69
69
 
70
70
 
71
- @attr.s
71
+ @attr.s(frozen=True)
72
72
  class MacAlgorithmParams(SshAlgorithmParams):
73
73
  truncated_size = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int)))
74
74
  mac = attr.ib(
75
75
  converter=convert_enum(MAC),
76
- validator=attr.validators.optional(attr.validators.instance_of((MAC, six.string_types)))
76
+ validator=attr.validators.optional(attr.validators.instance_of(MAC))
77
77
  )
78
78
  mode = attr.ib(
79
79
  converter=convert_enum(MACMode),
80
- validator=attr.validators.optional(attr.validators.instance_of((MACMode, six.string_types)))
80
+ validator=attr.validators.optional(attr.validators.instance_of(MACMode))
81
81
  )
82
82
 
83
83
  @property
@@ -92,11 +92,11 @@ class MacAlgorithmParams(SshAlgorithmParams):
92
92
  return ('mac', 'mode')
93
93
 
94
94
 
95
- @attr.s
95
+ @attr.s(frozen=True)
96
96
  class KexAlgorithmParams(SshAlgorithmParams):
97
97
  kex = attr.ib(
98
98
  converter=convert_enum(KeyExchange),
99
- validator=attr.validators.optional(attr.validators.instance_of((KeyExchange, six.string_types)))
99
+ validator=attr.validators.optional(attr.validators.instance_of(KeyExchange))
100
100
  )
101
101
  key_parameter = attr.ib(
102
102
  converter=convert_variadic((convert_enum(NamedGroup), convert_enum(DHParamWellKnown))),
@@ -106,7 +106,7 @@ class KexAlgorithmParams(SshAlgorithmParams):
106
106
  )
107
107
  exchange_hash = attr.ib(
108
108
  converter=convert_enum(Hash),
109
- validator=attr.validators.optional(attr.validators.instance_of((Hash, six.string_types)))
109
+ validator=attr.validators.optional(attr.validators.instance_of(Hash))
110
110
  )
111
111
  key_size = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int)))
112
112
 
@@ -136,20 +136,22 @@ class SshHostKeyType(enum.Enum):
136
136
  HOST_KEY = 'host key'
137
137
  HOST_CERTIFICATE = 'host certificate'
138
138
  PGP_KEY = 'PGP key'
139
+ SECURE_KEY = 'secure key'
140
+ SECURE_CERTIFICATE = 'secure certificate'
139
141
  SPKI_KEY = 'SPKI key'
140
142
  X509_CERTIFICATE = 'X.509 certificate'
141
143
  X509_CERTIFICATE_CHAIN = 'X.509 certificate chain'
142
144
 
143
145
 
144
- @attr.s
146
+ @attr.s(frozen=True)
145
147
  class HostKeyAlgorithmParams(SshAlgorithmParams):
146
148
  key_type = attr.ib(
147
149
  converter=convert_enum(SshHostKeyType),
148
- validator=attr.validators.instance_of((SshHostKeyType, six.string_types))
150
+ validator=attr.validators.instance_of(SshHostKeyType)
149
151
  )
150
152
  signature = attr.ib(
151
153
  converter=convert_enum(Signature),
152
- validator=attr.validators.optional(attr.validators.instance_of((Signature, six.string_types)))
154
+ validator=attr.validators.optional(attr.validators.instance_of(Signature))
153
155
  )
154
156
 
155
157
  @property
@@ -157,14 +159,14 @@ class HostKeyAlgorithmParams(SshAlgorithmParams):
157
159
  return ('signature',)
158
160
 
159
161
 
160
- @attr.s
162
+ @attr.s(frozen=True)
161
163
  class CompressionAlgorithmParams(CryptoDataParamsEnumString, GradeableVulnerabilities):
162
164
  @classmethod
163
165
  def get_gradeable_name(cls):
164
166
  return 'compression'
165
167
 
166
168
 
167
- @attr.s
169
+ @attr.s(frozen=True)
168
170
  class EllipticCurveIdentifierParams(CryptoDataParamsEnumString):
169
171
  named_group = attr.ib(
170
172
  converter=convert_enum(NamedGroup),
@@ -13,6 +13,10 @@
13
13
  }
14
14
  ]
15
15
  },
16
+ "LZ4_SENSORSDATA_CN": {
17
+ "code": "lz4@sensorsdata.cn",
18
+ "vulnerabilities": []
19
+ },
16
20
  "NONE": {
17
21
  "code": "none",
18
22
  "vulnerabilities": []
@@ -14,6 +14,11 @@
14
14
  "cipher": "AES_128",
15
15
  "mode": "CBC"
16
16
  },
17
+ "AES128_CFB": {
18
+ "code": "aes128-cfb",
19
+ "cipher": "AES_128",
20
+ "mode": "CFB"
21
+ },
17
22
  "AES128_CTR": {
18
23
  "code": "aes128-ctr",
19
24
  "cipher": "AES_128",
@@ -39,16 +44,36 @@
39
44
  "cipher": "AES_192",
40
45
  "mode": "CTR"
41
46
  },
47
+ "AES192_GCM": {
48
+ "code": "aes192-gcm",
49
+ "cipher": "AES_192",
50
+ "mode": "GCM"
51
+ },
52
+ "AES192_GCM_OPENSSH_COM": {
53
+ "code": "aes192-gcm@openssh.com",
54
+ "cipher": "AES_192",
55
+ "mode": "GCM"
56
+ },
42
57
  "AES256_CBC": {
43
58
  "code": "aes256-cbc",
44
59
  "cipher": "AES_256",
45
60
  "mode": "CBC"
46
61
  },
62
+ "AES256_CFB": {
63
+ "code": "aes256-cfb",
64
+ "cipher": "AES_256",
65
+ "mode": "CFB"
66
+ },
47
67
  "AES256_CTR": {
48
68
  "code": "aes256-ctr",
49
69
  "cipher": "AES_256",
50
70
  "mode": "CTR"
51
71
  },
72
+ "AES256_GCM": {
73
+ "code": "aes256-gcm",
74
+ "cipher": "AES_256",
75
+ "mode": "GCM"
76
+ },
52
77
  "AES256_GCM_OPENSSH_COM": {
53
78
  "code": "aes256-gcm@openssh.com",
54
79
  "cipher": "AES_256",
@@ -69,6 +94,11 @@
69
94
  "cipher": "RC4_256",
70
95
  "mode": null
71
96
  },
97
+ "BLOWFISH": {
98
+ "code": "blowfish",
99
+ "cipher": "BLOWFISH",
100
+ "mode": "CBC"
101
+ },
72
102
  "BLOWFISH_CBC": {
73
103
  "code": "blowfish-cbc",
74
104
  "cipher": "BLOWFISH",
@@ -94,6 +124,66 @@
94
124
  "cipher": "BLOWFISH",
95
125
  "mode": "OFB"
96
126
  },
127
+ "CAMELLIA128_CBC_OPENSSH_ORG": {
128
+ "code": "camellia128-cbc@openssh.org",
129
+ "cipher": "CAMELLIA_128",
130
+ "mode": "CBC"
131
+ },
132
+ "CAMELLIA128_CBC": {
133
+ "code": "camellia128-cbc",
134
+ "cipher": "CAMELLIA_128",
135
+ "mode": "CBC"
136
+ },
137
+ "CAMELLIA128_CTR": {
138
+ "code": "camellia128-ctr",
139
+ "cipher": "CAMELLIA_128",
140
+ "mode": "CTR"
141
+ },
142
+ "CAMELLIA128_CTR_OPENSSH_ORG": {
143
+ "code": "camellia128-ctr@openssh.org",
144
+ "cipher": "CAMELLIA_128",
145
+ "mode": "CTR"
146
+ },
147
+ "CAMELLIA192_CBC_OPENSSH_ORG": {
148
+ "code": "camellia192-cbc@openssh.org",
149
+ "cipher": "CAMELLIA_192",
150
+ "mode": "CBC"
151
+ },
152
+ "CAMELLIA192_CBC": {
153
+ "code": "camellia192-cbc",
154
+ "cipher": "CAMELLIA_192",
155
+ "mode": "CBC"
156
+ },
157
+ "CAMELLIA192_CTR": {
158
+ "code": "camellia192-ctr",
159
+ "cipher": "CAMELLIA_192",
160
+ "mode": "CTR"
161
+ },
162
+ "CAMELLIA192_CTR_OPENSSH_ORG": {
163
+ "code": "camellia192-ctr@openssh.org",
164
+ "cipher": "CAMELLIA_192",
165
+ "mode": "CTR"
166
+ },
167
+ "CAMELLIA256_CBC_OPENSSH_ORG": {
168
+ "code": "camellia256-cbc@openssh.org",
169
+ "cipher": "CAMELLIA_256",
170
+ "mode": "CBC"
171
+ },
172
+ "CAMELLIA256_CBC": {
173
+ "code": "camellia256-cbc",
174
+ "cipher": "CAMELLIA_256",
175
+ "mode": "CBC"
176
+ },
177
+ "CAMELLIA256_CTR": {
178
+ "code": "camellia256-ctr",
179
+ "cipher": "CAMELLIA_256",
180
+ "mode": "CTR"
181
+ },
182
+ "CAMELLIA256_CTR_OPENSSH_ORG": {
183
+ "code": "camellia256-ctr@openssh.org",
184
+ "cipher": "CAMELLIA_256",
185
+ "mode": "CTR"
186
+ },
97
187
  "CAST128_CBC": {
98
188
  "code": "cast128-cbc",
99
189
  "cipher": "CAST_128",
@@ -119,21 +209,41 @@
119
209
  "cipher": "CAST_128",
120
210
  "mode": "OFB"
121
211
  },
212
+ "CAST128_12_CBC": {
213
+ "code": "cast128-12-cbc",
214
+ "cipher": "CAST_128",
215
+ "mode": "CBC"
216
+ },
122
217
  "CAST128_12_CBC_SSH_COM": {
123
218
  "code": "cast128-12-cbc@ssh.com",
124
219
  "cipher": "CAST_128",
125
220
  "mode": "CBC"
126
221
  },
222
+ "CAST128_12_CFB": {
223
+ "code": "cast128-12-cfb",
224
+ "cipher": "CAST_128",
225
+ "mode": "CFB"
226
+ },
127
227
  "CAST128_12_CFB_SSH_COM": {
128
228
  "code": "cast128-12-cfb@ssh.com",
129
229
  "cipher": "CAST_128",
130
230
  "mode": "CFB"
131
231
  },
232
+ "CAST128_12_ECB": {
233
+ "code": "cast128-12-ecb",
234
+ "cipher": "CAST_128",
235
+ "mode": "ECB"
236
+ },
132
237
  "CAST128_12_ECB_SSH_COM": {
133
238
  "code": "cast128-12-ecb@ssh.com",
134
239
  "cipher": "CAST_128",
135
240
  "mode": "ECB"
136
241
  },
242
+ "CAST128_12_OFB": {
243
+ "code": "cast128-12-ofb",
244
+ "cipher": "CAST_128",
245
+ "mode": "OFB"
246
+ },
137
247
  "CAST128_12_OFB_SSH_COM": {
138
248
  "code": "cast128-12-ofb@ssh.com",
139
249
  "cipher": "CAST_128",
@@ -144,6 +254,11 @@
144
254
  "cipher": "CAST_256",
145
255
  "mode": "CBC"
146
256
  },
257
+ "CHACHA20_POLY1305": {
258
+ "code": "chacha20-poly1305",
259
+ "cipher": "CHACHA20",
260
+ "mode": null
261
+ },
147
262
  "CHACHA20_POLY1305_OPENSSH_COM": {
148
263
  "code": "chacha20-poly1305@openssh.com",
149
264
  "cipher": "CHACHA20",
@@ -154,6 +269,11 @@
154
269
  "cipher": "CRYPTICORE",
155
270
  "mode": null
156
271
  },
272
+ "DES": {
273
+ "code": "des",
274
+ "cipher": "DES",
275
+ "mode": "CBC"
276
+ },
157
277
  "DES_CBC": {
158
278
  "code": "des-cbc",
159
279
  "cipher": "DES",
@@ -194,6 +314,11 @@
194
314
  "cipher": "GOST_R3412_15_128",
195
315
  "mode": "CTR"
196
316
  },
317
+ "GRASSHOPPER_CTR128": {
318
+ "code": "grasshopper-ctr128",
319
+ "cipher": "GOST_R3412_15_128",
320
+ "mode": "CTR"
321
+ },
197
322
  "GOST89": {
198
323
  "code": "gost89",
199
324
  "cipher": "GOST2814789",
@@ -204,6 +329,11 @@
204
329
  "cipher": "GOST2814789",
205
330
  "mode": "CNT"
206
331
  },
332
+ "IDEA_CBC": {
333
+ "code": "idea-cbc",
334
+ "cipher": "IDEA",
335
+ "mode": "CBC"
336
+ },
207
337
  "IDEA_CFB": {
208
338
  "code": "idea-cfb",
209
339
  "cipher": "IDEA",
@@ -214,6 +344,21 @@
214
344
  "cipher": "IDEA",
215
345
  "mode": "CTR"
216
346
  },
347
+ "IDEA_ECB": {
348
+ "code": "idea-ecb",
349
+ "cipher": "IDEA",
350
+ "mode": "ECB"
351
+ },
352
+ "IDEA_OFB": {
353
+ "code": "idea-ofb",
354
+ "cipher": "IDEA",
355
+ "mode": "OFB"
356
+ },
357
+ "KUZNECHIK_OFB": {
358
+ "code": "kuznechik-ofb",
359
+ "cipher": "GOST_R3412_15_128",
360
+ "mode": "OFB"
361
+ },
217
362
  "RC2_CBC": {
218
363
  "code": "rc2-cbc",
219
364
  "cipher": "RC2",
@@ -229,6 +374,11 @@
229
374
  "cipher": "RC2",
230
375
  "mode": "CTR"
231
376
  },
377
+ "RIJNDAEL128": {
378
+ "code": "rijndael128",
379
+ "cipher": "RIJNDAEL_128",
380
+ "mode": "CBC"
381
+ },
232
382
  "RIJNDAEL128_CBC": {
233
383
  "code": "rijndael128-cbc",
234
384
  "cipher": "RIJNDAEL_128",
@@ -259,6 +409,11 @@
259
409
  "cipher": "SEED",
260
410
  "mode": "CBC"
261
411
  },
412
+ "SEED_CTR_SSH_COM": {
413
+ "code": "seed-ctr@ssh.com",
414
+ "cipher": "SEED",
415
+ "mode": "CTR"
416
+ },
262
417
  "SERPENT128_CBC": {
263
418
  "code": "serpent128-cbc",
264
419
  "cipher": "SERPENT_128",
@@ -269,6 +424,16 @@
269
424
  "cipher": "SERPENT_128",
270
425
  "mode": "CTR"
271
426
  },
427
+ "SERPENT128_GCM": {
428
+ "code": "serpent128-gcm",
429
+ "cipher": "SERPENT_128",
430
+ "mode": "GCM"
431
+ },
432
+ "SERPENT128_GCM_LIBASSH_ORG": {
433
+ "code": "serpent128-gcm@libassh.org",
434
+ "cipher": "SERPENT_128",
435
+ "mode": "GCM"
436
+ },
272
437
  "SERPENT192_CBC": {
273
438
  "code": "serpent192-cbc",
274
439
  "cipher": "SERPENT_192",
@@ -289,6 +454,36 @@
289
454
  "cipher": "SERPENT_256",
290
455
  "mode": "CTR"
291
456
  },
457
+ "SERPENT256_GCM": {
458
+ "code": "serpent256-gcm",
459
+ "cipher": "SERPENT_256",
460
+ "mode": "GCM"
461
+ },
462
+ "SERPENT256_GCM_LIBASSH_ORG": {
463
+ "code": "serpent256-gcm@libassh.org",
464
+ "cipher": "SERPENT_256",
465
+ "mode": "GCM"
466
+ },
467
+ "SM4": {
468
+ "code": "sm4",
469
+ "cipher": "SM4",
470
+ "mode": "CBC"
471
+ },
472
+ "SM4_CBC": {
473
+ "code": "sm4-cbc",
474
+ "cipher": "SM4",
475
+ "mode": "CBC"
476
+ },
477
+ "SM4_CTR": {
478
+ "code": "sm4-ctr",
479
+ "cipher": "SM4",
480
+ "mode": "CTR"
481
+ },
482
+ "SM4_CBC_HUAWEI": {
483
+ "code": "sm4-cbc@huawei",
484
+ "cipher": "SM4",
485
+ "mode": "CBC"
486
+ },
292
487
  "TRIPLE_DES_CBC": {
293
488
  "code": "3des-cbc",
294
489
  "cipher": "TRIPLE_DES",
@@ -349,6 +544,16 @@
349
544
  "cipher": "TWOFISH128",
350
545
  "mode": "CTR"
351
546
  },
547
+ "TWOFISH128_GCM": {
548
+ "code": "twofish128-gcm",
549
+ "cipher": "TWOFISH128",
550
+ "mode": "GCM"
551
+ },
552
+ "TWOFISH128_GCM_LIBASSH_ORG": {
553
+ "code": "twofish128-gcm@libassh.org",
554
+ "cipher": "TWOFISH128",
555
+ "mode": "GCM"
556
+ },
352
557
  "TWOFISH192_CBC": {
353
558
  "code": "twofish192-cbc",
354
559
  "cipher": "TWOFISH192",
@@ -368,5 +573,15 @@
368
573
  "code": "twofish256-ctr",
369
574
  "cipher": "TWOFISH256",
370
575
  "mode": "CTR"
576
+ },
577
+ "TWOFISH256_GCM": {
578
+ "code": "twofish256-gcm",
579
+ "cipher": "TWOFISH256",
580
+ "mode": "GCM"
581
+ },
582
+ "TWOFISH256_GCM_LIBASSH_ORG": {
583
+ "code": "twofish256-gcm@libassh.org",
584
+ "cipher": "TWOFISH256",
585
+ "mode": "GCM"
371
586
  }
372
587
  }