cryptoparser 0.11.2__tar.gz → 0.12.0__tar.gz

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.
Files changed (49) hide show
  1. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CHANGELOG.rst +17 -0
  2. {CryptoParser-0.11.2 → CryptoParser-0.12.0/CryptoParser.egg-info}/PKG-INFO +1 -1
  3. {CryptoParser-0.11.2/CryptoParser.egg-info → CryptoParser-0.12.0}/PKG-INFO +1 -1
  4. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/__setup__.py +1 -1
  5. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/base.py +34 -4
  6. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/field.py +85 -0
  7. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/parse.py +13 -10
  8. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/httpx/header.py +930 -51
  9. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CONTRIBUTING.rst +0 -0
  10. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CryptoParser.egg-info/SOURCES.txt +0 -0
  11. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CryptoParser.egg-info/dependency_links.txt +0 -0
  12. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CryptoParser.egg-info/requires.txt +0 -0
  13. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/CryptoParser.egg-info/top_level.txt +0 -0
  14. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/LICENSE.txt +0 -0
  15. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/MANIFEST.in +0 -0
  16. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/README.rst +0 -0
  17. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/__init__.py +0 -0
  18. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/__init__.py +0 -0
  19. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/classes.py +0 -0
  20. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/exception.py +0 -0
  21. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/utils.py +0 -0
  22. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/common/x509.py +0 -0
  23. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/dnsrec/__init__.py +0 -0
  24. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/dnsrec/record.py +0 -0
  25. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/dnsrec/txt.py +0 -0
  26. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/httpx/__init__.py +0 -0
  27. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/httpx/parse.py +0 -0
  28. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/httpx/version.py +0 -0
  29. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/ssh/__init__.py +0 -0
  30. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/ssh/key.py +0 -0
  31. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/ssh/record.py +0 -0
  32. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/ssh/subprotocol.py +0 -0
  33. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/ssh/version.py +0 -0
  34. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/__init__.py +0 -0
  35. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/algorithm.py +0 -0
  36. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/ciphersuite.py +0 -0
  37. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/extension.py +0 -0
  38. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/grease.py +0 -0
  39. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/ldap.py +0 -0
  40. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/mysql.py +0 -0
  41. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/openvpn.py +0 -0
  42. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/postgresql.py +0 -0
  43. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/rdp.py +0 -0
  44. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/record.py +0 -0
  45. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/subprotocol.py +0 -0
  46. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/cryptoparser/tls/version.py +0 -0
  47. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/requirements.txt +0 -0
  48. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/setup.cfg +0 -0
  49. {CryptoParser-0.11.2 → CryptoParser-0.12.0}/setup.py +0 -0
@@ -2,6 +2,23 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ -------------------
6
+ 0.12.0 - 2023-11-23
7
+ -------------------
8
+
9
+ Features
10
+ ========
11
+
12
+ - HTTP(S) (``http``)
13
+
14
+ - Headers (``headers``)
15
+
16
+ - add parsers for security related headers
17
+ (`Content Security Policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>`__ (CSP),
18
+ `Content-Security-Policy-Report-Only <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only>`__)
19
+ (#59)
20
+
21
+
5
22
  -------------------
6
23
  0.11.2 - 2023-11-13
7
24
  -------------------
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CryptoParser
3
- Version: 0.11.2
3
+ Version: 0.12.0
4
4
  Summary: Fast and flexible security protocol parser and generator
5
5
  Author: Szilárd Pfeiffer
6
6
  Author-email: coroner@pfeifferszilard.hu
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CryptoParser
3
- Version: 0.11.2
3
+ Version: 0.12.0
4
4
  Summary: Fast and flexible security protocol parser and generator
5
5
  Author: Szilárd Pfeiffer
6
6
  Author-email: coroner@pfeifferszilard.hu
@@ -2,7 +2,7 @@
2
2
 
3
3
  __title__ = 'CryptoParser'
4
4
  __technical_name__ = __title__.lower()
5
- __version__ = '0.11.2'
5
+ __version__ = '0.12.0'
6
6
  __description__ = 'Fast and flexible security protocol parser and generator'
7
7
  __author__ = 'Szilárd Pfeiffer'
8
8
  __author_email__ = 'coroner@pfeifferszilard.hu'
@@ -279,7 +279,7 @@ class Serializable(object): # pylint: disable=too-few-public-methods
279
279
 
280
280
 
281
281
  @attr.s
282
- class VariantParsable(ParsableBase):
282
+ class VariantParsableBase(ParsableBase):
283
283
  variant = attr.ib()
284
284
 
285
285
  _REGISTERED_VARIANTS = OrderedDict()
@@ -324,6 +324,21 @@ class VariantParsable(ParsableBase):
324
324
 
325
325
  registered_variants[variant_tag].append(parsable_class)
326
326
 
327
+ @classmethod
328
+ @abc.abstractmethod
329
+ def _parse(cls, parsable):
330
+ raise NotImplementedError()
331
+
332
+ def compose(self):
333
+ return self.variant.compose()
334
+
335
+
336
+ class VariantParsable(VariantParsableBase):
337
+ @classmethod
338
+ @abc.abstractmethod
339
+ def _get_variants(cls):
340
+ raise NotImplementedError()
341
+
327
342
  @classmethod
328
343
  def _parse(cls, parsable):
329
344
  for variant_parser in cls._get_variant_types():
@@ -335,8 +350,23 @@ class VariantParsable(ParsableBase):
335
350
 
336
351
  raise InvalidValue(parsable, cls)
337
352
 
338
- def compose(self):
339
- return self.variant.compose()
353
+
354
+ class VariantParsableExact(VariantParsableBase):
355
+ @classmethod
356
+ @abc.abstractmethod
357
+ def _get_variants(cls):
358
+ raise NotImplementedError()
359
+
360
+ @classmethod
361
+ def _parse(cls, parsable):
362
+ for variant_parser in cls._get_variant_types():
363
+ try:
364
+ parsed_object = variant_parser.parse_exact_size(parsable)
365
+ return parsed_object, len(parsable)
366
+ except (InvalidType, InvalidValue, TooMuchData):
367
+ pass
368
+
369
+ raise InvalidValue(parsable, cls)
340
370
 
341
371
 
342
372
  @attr.s
@@ -825,7 +855,7 @@ class StringEnumParsableBase(ParsableBaseNoABC):
825
855
  enum_items.sort(key=lambda color: len(color.value.code), reverse=True)
826
856
 
827
857
  try:
828
- code = six.ensure_text(parsable, 'ascii')
858
+ code = six.ensure_text(bytes(parsable), 'ascii')
829
859
  except UnicodeDecodeError as e:
830
860
  six.raise_from(InvalidValue(parsable, cls), e)
831
861
 
@@ -1,8 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # pylint: disable=too-many-lines
2
3
 
3
4
  import abc
4
5
  import collections
5
6
  import datetime
7
+ import enum
6
8
  import json
7
9
 
8
10
  import attr
@@ -791,6 +793,63 @@ class FieldsSemicolonSeparated(FieldValueMultiple):
791
793
  return NameValuePairListSemicolonSeparated
792
794
 
793
795
 
796
+ class MimeTypeRegistry(enum.Enum):
797
+ APPLICATION = 'application'
798
+ AUDIO = 'audio'
799
+ FONT = 'font'
800
+ EXAMPLE = 'example'
801
+ IMAGE = 'image'
802
+ MESSAGE = 'message'
803
+ MODEL = 'model'
804
+ MULTIPART = 'multipart'
805
+ TEXT = 'text'
806
+ VIDEO = 'video'
807
+
808
+
809
+ @attr.s
810
+ class FieldValueMimeType(FieldValueComponentBase):
811
+ type = attr.ib(
812
+ validator=attr.validators.instance_of(six.string_types),
813
+ default=None,
814
+ )
815
+ registry = attr.ib(
816
+ validator=attr.validators.optional(attr.validators.instance_of(MimeTypeRegistry)),
817
+ default=None,
818
+ )
819
+
820
+ def __str__(self):
821
+ return '{}/{}'.format(self.registry.value, self.type)
822
+
823
+ @property
824
+ def value(self):
825
+ return self
826
+
827
+ @classmethod
828
+ def get_canonical_name(cls):
829
+ return ''
830
+
831
+ @classmethod
832
+ def _parse(cls, parsable):
833
+ parser = ParserText(parsable)
834
+
835
+ parser.parse_string_until_separator('registry', '/', item_class=MimeTypeRegistry)
836
+ parser.parse_separator('/')
837
+ parser.parse_string_by_length('type', parser.unparsed_length)
838
+
839
+ return FieldValueMimeType(**parser), parser.parsed_length
840
+
841
+ def compose(self):
842
+ composer = ComposerText()
843
+
844
+ composer.compose_string(str(self))
845
+
846
+ return composer.composed
847
+
848
+ @classmethod
849
+ def _check_name(cls, name):
850
+ pass
851
+
852
+
794
853
  @attr.s
795
854
  class FieldValueSingleBase(FieldValueBase, Serializable):
796
855
  value = attr.ib()
@@ -916,6 +975,32 @@ class FieldValueDateTime(FieldValueSingleComplexBase):
916
975
  return self._markdown_result(self.value, level)
917
976
 
918
977
 
978
+ class FieldValueStringBySeparatorBase(FieldValueSingleComplexBase):
979
+ @classmethod
980
+ @abc.abstractmethod
981
+ def _get_separators(cls):
982
+ raise NotImplementedError()
983
+
984
+ @classmethod
985
+ def _get_value_type(cls):
986
+ return six.string_types
987
+
988
+ @classmethod
989
+ def _parse(cls, parsable):
990
+ parser = ParserText(parsable)
991
+
992
+ parser.parse_string_until_separator_or_end('value', cls._get_separators())
993
+
994
+ return cls(parser['value']), parser.parsed_length
995
+
996
+ def compose(self):
997
+ composer = ComposerText()
998
+
999
+ composer.compose_string(self.value)
1000
+
1001
+ return composer.composed
1002
+
1003
+
919
1004
  class FieldValueStringEnum(FieldValueSingleComplexBase):
920
1005
  @classmethod
921
1006
  @abc.abstractmethod
@@ -201,7 +201,7 @@ class ParserText(ParserBase):
201
201
 
202
202
  return actual_offset - count_offset
203
203
 
204
- def parse_separator(self, separator, min_length=1, max_length=1):
204
+ def parse_separator(self, separator, min_length=1, max_length=None):
205
205
  self._parsed_length += self._check_separators(
206
206
  'separator', self._parsed_length, separator, min_length, max_length
207
207
  )
@@ -405,15 +405,18 @@ class ParserText(ParserBase):
405
405
  name, item_offset, separator, str, None, True, separator_spaces
406
406
  )
407
407
  if parsed_length:
408
- parsed_value = self._apply_item_class(
409
- name,
410
- item_offset,
411
- item_offset + parsed_length,
412
- separator,
413
- item_class,
414
- fallback_class,
415
- True
416
- )
408
+ if isinstance(item_class, type) and issubclass(item_class, ParsableBase):
409
+ parsed_value = item_class.parse_exact_size(parsed_value.encode(self._encoding))
410
+ else:
411
+ parsed_value = self._apply_item_class(
412
+ name,
413
+ item_offset,
414
+ item_offset + parsed_length,
415
+ separator,
416
+ item_class,
417
+ fallback_class,
418
+ True
419
+ )
417
420
  value.append(parsed_value)
418
421
  item_offset += parsed_length
419
422
  elif not skip_empty: