py-euvd 0.2.0__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.
- py_euvd-0.2.0.dist-info/METADATA +102 -0
- py_euvd-0.2.0.dist-info/RECORD +33 -0
- py_euvd-0.2.0.dist-info/WHEEL +4 -0
- py_euvd-0.2.0.dist-info/licenses/LICENSE +202 -0
- py_euvd-0.2.0.dist-info/licenses/NOTICE +2 -0
- pyeuvd/__init__.py +52 -0
- pyeuvd/_version.py +1 -0
- pyeuvd/async_client.py +169 -0
- pyeuvd/base_client.py +70 -0
- pyeuvd/client.py +155 -0
- pyeuvd/constants.py +9 -0
- pyeuvd/errors.py +38 -0
- pyeuvd/filters.py +67 -0
- pyeuvd/models/__init__.py +25 -0
- pyeuvd/models/advisory.py +39 -0
- pyeuvd/models/advisory_detail.py +29 -0
- pyeuvd/models/kev_entry.py +34 -0
- pyeuvd/models/model.py +74 -0
- pyeuvd/models/page.py +62 -0
- pyeuvd/models/product.py +34 -0
- pyeuvd/models/record.py +54 -0
- pyeuvd/models/source_record.py +54 -0
- pyeuvd/models/vulnerability.py +67 -0
- pyeuvd/models/vulnerability_detail.py +29 -0
- pyeuvd/parsing.py +139 -0
- pyeuvd/py.typed +0 -0
- pyeuvd/response.py +47 -0
- pyeuvd/transports/__init__.py +8 -0
- pyeuvd/transports/async_transport.py +44 -0
- pyeuvd/transports/threaded_transport.py +46 -0
- pyeuvd/transports/transport.py +44 -0
- pyeuvd/transports/urllib_transport.py +136 -0
- pyeuvd/utils.py +91 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: py-euvd
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Dependency-free Python client for the EU Vulnerability Database (EUVD) API
|
|
5
|
+
Project-URL: Documentation, https://py-euvd.spoons.fyi
|
|
6
|
+
Project-URL: Repository, https://github.com/dmuhs/py-euvd
|
|
7
|
+
Project-URL: Issues, https://github.com/dmuhs/py-euvd/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/dmuhs/py-euvd/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Dominik Muhs
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: cve,enisa,euvd,security,vulnerability
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
24
|
+
Classifier: Topic :: Security
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# py-euvd
|
|
31
|
+
|
|
32
|
+
[](https://github.com/dmuhs/py-euvd/actions/workflows/ci.yml)
|
|
33
|
+
|
|
34
|
+
A Python client for the [EU Vulnerability Database](https://euvd.enisa.europa.eu) (EUVD), run by ENISA.
|
|
35
|
+
|
|
36
|
+
**Documentation: [py-euvd.spoons.fyi](https://py-euvd.spoons.fyi)**
|
|
37
|
+
|
|
38
|
+
- **No dependencies.** Uses only the Python standard library.
|
|
39
|
+
- **Complete.** Covers every endpoint of the [public API](https://euvd.enisa.europa.eu/apidoc).
|
|
40
|
+
- **Sync and async** clients with the same methods.
|
|
41
|
+
- **Typed results.** Dates and lists are parsed, not left as strings.
|
|
42
|
+
- **Extensible.** Swap the HTTP layer to add retries, caching or another HTTP library.
|
|
43
|
+
- **Tested.** 100% test coverage, and a weekly check against the real API.
|
|
44
|
+
- **Open source.** Apache 2.0 licensed.
|
|
45
|
+
|
|
46
|
+
The API is public. You do not need a key.
|
|
47
|
+
|
|
48
|
+
This project is unofficial and not affiliated with ENISA.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
pip install py-euvd
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Requires Python 3.11 or newer.
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from pyeuvd import EUVD
|
|
62
|
+
|
|
63
|
+
euvd = EUVD()
|
|
64
|
+
|
|
65
|
+
# One entry, by EUVD ID or CVE ID
|
|
66
|
+
vuln = euvd.get_vulnerability("CVE-2024-3400")
|
|
67
|
+
print(vuln.id, vuln.severity, vuln.exploited) # EUVD-2024-31989 critical True
|
|
68
|
+
|
|
69
|
+
# Search
|
|
70
|
+
for vuln in euvd.iter_search(vendor="Cisco", from_score=9, limit=20):
|
|
71
|
+
print(vuln.id, vuln.cve_id, vuln.base_score)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The [documentation](https://py-euvd.spoons.fyi) covers searching, results, async use, errors and customizing.
|
|
75
|
+
|
|
76
|
+
## Contributing
|
|
77
|
+
|
|
78
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/dmuhs/py-euvd).
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
uv sync
|
|
82
|
+
uv run pytest --cov # tests; coverage must stay at 100%
|
|
83
|
+
uv run pytest -m live # checks against the real API
|
|
84
|
+
uv run ruff check .
|
|
85
|
+
uv run mypy
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To work on the documentation in `docs/`:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
uv run --only-group docs zensical serve # preview at http://localhost:8000
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To release, add an entry to `CHANGELOG.md`, push, then create a GitHub release. The version comes from the tag, and the release is uploaded to PyPI automatically:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
gh release create v1.2.3 --notes "See CHANGELOG.md"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
[Apache License 2.0](https://github.com/dmuhs/py-euvd/blob/main/LICENSE)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
pyeuvd/__init__.py,sha256=g8eE1Woc5XiYcAJExxxfeZ4c6Ub-LquBR8P2tXtPkEo,1128
|
|
2
|
+
pyeuvd/_version.py,sha256=Zn1KFblwuFHiDRdRAiRnDBRkbPttWh44jKa5zG2ov0E,22
|
|
3
|
+
pyeuvd/async_client.py,sha256=Slv2iomUxOHp8smIfno5iJkHHbis43j6vYjWBVJIt6k,6730
|
|
4
|
+
pyeuvd/base_client.py,sha256=82QaRDcNPKlDag1orRzOl1y8dGojSXI9OorewUpt66c,2498
|
|
5
|
+
pyeuvd/client.py,sha256=WizW6JbtKvGajEhYui5Y-Q5Q5CKL2-DBtHoWNSU95dY,5978
|
|
6
|
+
pyeuvd/constants.py,sha256=6gx3Q3UWZ_st_slZT_r-aKsTKuqiNZWisKGeccbXaA4,248
|
|
7
|
+
pyeuvd/errors.py,sha256=SnsRwrhAzehRyoTgkMc2mM9CdhfTUhPThFaoTSgBa60,1228
|
|
8
|
+
pyeuvd/filters.py,sha256=0Zrh3qxsq6KhqyDgo_Oh0h_QCbdUfDsM6FxU9usQgD4,2266
|
|
9
|
+
pyeuvd/parsing.py,sha256=To4hacSe3u9enMedN9k9ZcuH24BdyRgRuX07vCfH2AE,4647
|
|
10
|
+
pyeuvd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
pyeuvd/response.py,sha256=9uxEUyFjmdN-ZSAzMblZsySR0Kgu20eH_C1dAVA6eF4,1386
|
|
12
|
+
pyeuvd/utils.py,sha256=4qxkyyL_WB7utLbFF3KXL8clNvXLBpoek5jzL-ASbDA,3121
|
|
13
|
+
pyeuvd/models/__init__.py,sha256=l-vDfjtOzzHoSP9MZo3N5EXlWIOhpoctNoljhgtqFR8,584
|
|
14
|
+
pyeuvd/models/advisory.py,sha256=nBUWb_f0yYaJAMSgldn2UzbKVxUOulHhhW7pt6JyAqQ,1287
|
|
15
|
+
pyeuvd/models/advisory_detail.py,sha256=UlZ6glvO62JpObueskjxLcs_HLmHowh6JVe1F1adK-k,1073
|
|
16
|
+
pyeuvd/models/kev_entry.py,sha256=wM3LRy6O5XuA7tw4hLEU-f2pdiY7tS-c2dr0Ure3Sxw,1103
|
|
17
|
+
pyeuvd/models/model.py,sha256=pCrgvg-mx7K99KJuZgAyVNiN1kMjrcZ2iy3ct4yIH6I,2676
|
|
18
|
+
pyeuvd/models/page.py,sha256=P16opYR59SGeDolPJWQ2nCnb5SgVeHWppZkk9BIg08o,1910
|
|
19
|
+
pyeuvd/models/product.py,sha256=69JR8EJChUoJqOmyIR8rvGJ3JzDaKWHRMxrhp6An5s0,1051
|
|
20
|
+
pyeuvd/models/record.py,sha256=rMNAxXP0MI-qrQMofxcfs70lZGF0mT61WPF7pJ9uDEQ,2043
|
|
21
|
+
pyeuvd/models/source_record.py,sha256=CH6ybPtE6N8k04me6Rakv8ZXPwSsvs258OSf2gl8Iu0,2166
|
|
22
|
+
pyeuvd/models/vulnerability.py,sha256=LKrBJ67w-TCHVephRRTTwSBjFth4HAHTD1sZzqb6O34,2495
|
|
23
|
+
pyeuvd/models/vulnerability_detail.py,sha256=sHmcoEprHwM3NFI5NzP6qYNMnDTbBBmG5Wthaiw6hL8,1049
|
|
24
|
+
pyeuvd/transports/__init__.py,sha256=Pq7pxgrs3TbpUoCcYS8F7fq0UcbpIzOsra16pC7ZUyA,331
|
|
25
|
+
pyeuvd/transports/async_transport.py,sha256=JEzISIqdgNC7rfJCwfWRQOr10X_Zmb6pqkjEaAksMvM,1428
|
|
26
|
+
pyeuvd/transports/threaded_transport.py,sha256=62EfkiQumkZPPTpqc1N3JaL3s62PfhW0u4TUBLYiWt4,1630
|
|
27
|
+
pyeuvd/transports/transport.py,sha256=KA11tZpkhCdj5Gkva80CcdEKVnlekATEuRNrBkJWH1o,1389
|
|
28
|
+
pyeuvd/transports/urllib_transport.py,sha256=zcQzRYXvHaHDqnto4XPFBRrCluukEwcBkmjFu0HnbYY,5124
|
|
29
|
+
py_euvd-0.2.0.dist-info/METADATA,sha256=g1PEAu7mD92cyQxct7vIXZYFY9BLPlJRV2SWncKnALo,3366
|
|
30
|
+
py_euvd-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
31
|
+
py_euvd-0.2.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
32
|
+
py_euvd-0.2.0.dist-info/licenses/NOTICE,sha256=dmrdWBW71V9seJ7S_zyDgTj-tIz59zyptDSINB25PrQ,36
|
|
33
|
+
py_euvd-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
pyeuvd/__init__.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Python client for the EU Vulnerability Database (EUVD)."""
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
from .async_client import AsyncEUVD
|
|
5
|
+
from .client import EUVD
|
|
6
|
+
from .constants import BASE_URL, MAX_PAGE_SIZE
|
|
7
|
+
from .errors import APIError, EUVDError, NotFoundError, TransportError
|
|
8
|
+
from .filters import SearchFilters
|
|
9
|
+
from .models import (
|
|
10
|
+
Advisory,
|
|
11
|
+
AdvisoryDetail,
|
|
12
|
+
KevEntry,
|
|
13
|
+
Model,
|
|
14
|
+
Page,
|
|
15
|
+
Product,
|
|
16
|
+
Record,
|
|
17
|
+
SourceRecord,
|
|
18
|
+
Vulnerability,
|
|
19
|
+
VulnerabilityDetail,
|
|
20
|
+
)
|
|
21
|
+
from .response import Response
|
|
22
|
+
from .transports import AsyncTransport, ThreadedTransport, Transport, UrllibTransport
|
|
23
|
+
from .utils import Severity
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"BASE_URL",
|
|
27
|
+
"EUVD",
|
|
28
|
+
"MAX_PAGE_SIZE",
|
|
29
|
+
"APIError",
|
|
30
|
+
"Advisory",
|
|
31
|
+
"AdvisoryDetail",
|
|
32
|
+
"AsyncEUVD",
|
|
33
|
+
"AsyncTransport",
|
|
34
|
+
"EUVDError",
|
|
35
|
+
"KevEntry",
|
|
36
|
+
"Model",
|
|
37
|
+
"NotFoundError",
|
|
38
|
+
"Page",
|
|
39
|
+
"Product",
|
|
40
|
+
"Record",
|
|
41
|
+
"Response",
|
|
42
|
+
"SearchFilters",
|
|
43
|
+
"Severity",
|
|
44
|
+
"SourceRecord",
|
|
45
|
+
"ThreadedTransport",
|
|
46
|
+
"Transport",
|
|
47
|
+
"TransportError",
|
|
48
|
+
"UrllibTransport",
|
|
49
|
+
"Vulnerability",
|
|
50
|
+
"VulnerabilityDetail",
|
|
51
|
+
"__version__",
|
|
52
|
+
]
|
pyeuvd/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
pyeuvd/async_client.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
import time
|
|
5
|
+
from collections.abc import AsyncGenerator, AsyncIterator, Callable, Mapping
|
|
6
|
+
from typing import Any, Self, Unpack
|
|
7
|
+
|
|
8
|
+
from .base_client import BaseClient, logger
|
|
9
|
+
from .constants import BASE_URL, MAX_PAGE_SIZE
|
|
10
|
+
from .filters import SearchFilters
|
|
11
|
+
from .models import AdvisoryDetail, KevEntry, Page, Vulnerability, VulnerabilityDetail
|
|
12
|
+
from .parsing import expect_dict, expect_list, parse_mapping_line
|
|
13
|
+
from .transports import AsyncTransport, ThreadedTransport, Transport, UrllibTransport
|
|
14
|
+
from .utils import build_search_params
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AsyncEUVD(BaseClient):
|
|
18
|
+
"""Async client for the EU Vulnerability Database.
|
|
19
|
+
|
|
20
|
+
It has the same methods as ``EUVD``:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
euvd = AsyncEUVD()
|
|
24
|
+
vuln = await euvd.get_vulnerability("CVE-2024-3400")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
``timeout`` is in seconds, 30 by default. The built-in transport runs each
|
|
28
|
+
request in a worker thread. Pass an ``AsyncTransport`` to use an async HTTP
|
|
29
|
+
library. A blocking ``Transport`` also works and runs in threads. A
|
|
30
|
+
transport sets its own timeout, so passing both raises ``ValueError``.
|
|
31
|
+
|
|
32
|
+
The client can be used in an ``async with`` block, which closes the
|
|
33
|
+
transport at the end. The built-in transport holds nothing open, so this
|
|
34
|
+
is optional.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
base_url: str = BASE_URL,
|
|
41
|
+
timeout: float | None = None,
|
|
42
|
+
transport: AsyncTransport | Transport | None = None,
|
|
43
|
+
) -> None:
|
|
44
|
+
super().__init__(base_url)
|
|
45
|
+
timeout = self._timeout(timeout, transport)
|
|
46
|
+
if transport is None:
|
|
47
|
+
transport = UrllibTransport(timeout=timeout)
|
|
48
|
+
if isinstance(transport, Transport):
|
|
49
|
+
transport = ThreadedTransport(transport)
|
|
50
|
+
self.transport: AsyncTransport = transport
|
|
51
|
+
|
|
52
|
+
async def aclose(self) -> None:
|
|
53
|
+
"""Close the transport."""
|
|
54
|
+
await self.transport.aclose()
|
|
55
|
+
|
|
56
|
+
async def __aenter__(self) -> Self:
|
|
57
|
+
return self
|
|
58
|
+
|
|
59
|
+
async def __aexit__(self, *exc_info: object) -> None:
|
|
60
|
+
await self.aclose()
|
|
61
|
+
|
|
62
|
+
async def get_json(self, path: str, params: Mapping[str, str] | None = None) -> Any:
|
|
63
|
+
"""Call any API path and return the decoded JSON.
|
|
64
|
+
|
|
65
|
+
Use it for endpoints this library does not cover.
|
|
66
|
+
"""
|
|
67
|
+
return await self._get(path, params)
|
|
68
|
+
|
|
69
|
+
async def _get(
|
|
70
|
+
self,
|
|
71
|
+
path: str,
|
|
72
|
+
params: Mapping[str, str] | None = None,
|
|
73
|
+
check: Callable[[Any], Any] | None = None,
|
|
74
|
+
) -> Any:
|
|
75
|
+
url = self._url(path, params)
|
|
76
|
+
with self._errors_at(url):
|
|
77
|
+
started = time.perf_counter()
|
|
78
|
+
return self._decode(url, await self.transport.get(url), started, check)
|
|
79
|
+
|
|
80
|
+
async def latest(self) -> list[Vulnerability]:
|
|
81
|
+
"""The API's list of latest entries. It holds at most 8."""
|
|
82
|
+
data = await self._get("/lastvulnerabilities", check=expect_list)
|
|
83
|
+
return Vulnerability.from_list(data)
|
|
84
|
+
|
|
85
|
+
async def latest_exploited(self) -> list[Vulnerability]:
|
|
86
|
+
"""The API's list of latest exploited entries. It holds at most 8."""
|
|
87
|
+
data = await self._get("/exploitedvulnerabilities", check=expect_list)
|
|
88
|
+
return Vulnerability.from_list(data)
|
|
89
|
+
|
|
90
|
+
async def latest_critical(self) -> list[Vulnerability]:
|
|
91
|
+
"""The API's list of latest critical entries. It holds at most 8."""
|
|
92
|
+
data = await self._get("/criticalvulnerabilities", check=expect_list)
|
|
93
|
+
return Vulnerability.from_list(data)
|
|
94
|
+
|
|
95
|
+
async def search(
|
|
96
|
+
self, *, page: int = 0, size: int = 10, **filters: Unpack[SearchFilters]
|
|
97
|
+
) -> Page:
|
|
98
|
+
"""Fetch one page of search results. Pages start at 0, ``size`` is at most 100.
|
|
99
|
+
|
|
100
|
+
Filters, all optional: ``text``, ``product``, ``vendor``, ``advisory``,
|
|
101
|
+
``assigner``, ``exploited``, and the ranges ``from_score``/``to_score``,
|
|
102
|
+
``from_epss``/``to_epss``, ``from_date``/``to_date``,
|
|
103
|
+
``from_updated_date``/``to_updated_date`` and
|
|
104
|
+
``from_kev_date``/``to_kev_date``. See ``SearchFilters`` for details.
|
|
105
|
+
"""
|
|
106
|
+
params = build_search_params(page, size, filters)
|
|
107
|
+
data = await self._get("/search", params, expect_dict)
|
|
108
|
+
return Page.from_dict(data, page=page, size=size)
|
|
109
|
+
|
|
110
|
+
async def count(self, **filters: Unpack[SearchFilters]) -> int:
|
|
111
|
+
"""Return how many entries match the filters. Takes the same filters as ``search``."""
|
|
112
|
+
return (await self.search(size=1, **filters)).total
|
|
113
|
+
|
|
114
|
+
async def iter_search(
|
|
115
|
+
self,
|
|
116
|
+
*,
|
|
117
|
+
size: int = MAX_PAGE_SIZE,
|
|
118
|
+
limit: int | None = None,
|
|
119
|
+
**filters: Unpack[SearchFilters],
|
|
120
|
+
) -> AsyncIterator[Vulnerability]:
|
|
121
|
+
"""Yield every search result, fetching pages as needed.
|
|
122
|
+
|
|
123
|
+
Takes the same filters as ``search``. ``limit`` stops after that many
|
|
124
|
+
results. Without it, a broad search can return hundreds of thousands of
|
|
125
|
+
entries.
|
|
126
|
+
"""
|
|
127
|
+
size = self._page_size(size, limit)
|
|
128
|
+
seen = 0
|
|
129
|
+
page = 0
|
|
130
|
+
while limit is None or seen < limit:
|
|
131
|
+
result = await self.search(page=page, size=size, **filters)
|
|
132
|
+
for item in result.items[: None if limit is None else limit - seen]:
|
|
133
|
+
yield item
|
|
134
|
+
seen += 1
|
|
135
|
+
if not result.has_next:
|
|
136
|
+
return
|
|
137
|
+
page += 1
|
|
138
|
+
|
|
139
|
+
async def get_vulnerability(self, id: str) -> VulnerabilityDetail:
|
|
140
|
+
"""Fetch one entry by EUVD ID, or by another ID such as a CVE ID.
|
|
141
|
+
|
|
142
|
+
Raises ``NotFoundError`` if nothing matches.
|
|
143
|
+
"""
|
|
144
|
+
data = await self._get("/enisaid", {"id": id.strip()}, expect_dict)
|
|
145
|
+
return VulnerabilityDetail.from_dict(data)
|
|
146
|
+
|
|
147
|
+
async def get_advisory(self, id: str) -> AdvisoryDetail:
|
|
148
|
+
"""Fetch one advisory by ID. Raises ``NotFoundError`` if nothing matches."""
|
|
149
|
+
data = await self._get("/advisory", {"id": id.strip()}, expect_dict)
|
|
150
|
+
return AdvisoryDetail.from_dict(data)
|
|
151
|
+
|
|
152
|
+
async def kev(self) -> list[KevEntry]:
|
|
153
|
+
"""Download the full Known Exploited Vulnerabilities list."""
|
|
154
|
+
return KevEntry.from_list(await self._get("/kev/dump", check=expect_list))
|
|
155
|
+
|
|
156
|
+
async def cve_mapping(self) -> AsyncGenerator[tuple[str, str], None]:
|
|
157
|
+
"""Yield ``(euvd_id, cve_id)`` pairs for every entry linked to a CVE.
|
|
158
|
+
|
|
159
|
+
The download is large: several hundred thousand rows.
|
|
160
|
+
"""
|
|
161
|
+
url = self._url("/dump/cve-euvd-mapping")
|
|
162
|
+
logger.debug("GET %s (streaming)", url)
|
|
163
|
+
lines = self.transport.stream_lines(url)
|
|
164
|
+
with self._errors_at(url):
|
|
165
|
+
async with contextlib.aclosing(lines):
|
|
166
|
+
async for line in lines:
|
|
167
|
+
row = parse_mapping_line(line)
|
|
168
|
+
if row:
|
|
169
|
+
yield row
|
pyeuvd/base_client.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import time
|
|
5
|
+
import urllib.parse
|
|
6
|
+
from collections.abc import Callable, Iterator, Mapping
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .constants import BASE_URL, DEFAULT_TIMEOUT
|
|
11
|
+
from .errors import EUVDError
|
|
12
|
+
from .response import Response
|
|
13
|
+
from .utils import build_url
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BaseClient:
|
|
19
|
+
"""Shared by the sync and async clients: URL building and response decoding."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, base_url: str = BASE_URL) -> None:
|
|
22
|
+
if urllib.parse.urlsplit(base_url).scheme not in ("http", "https"):
|
|
23
|
+
raise ValueError("base_url must start with http:// or https://")
|
|
24
|
+
self.base_url = base_url.rstrip("/")
|
|
25
|
+
|
|
26
|
+
def _url(self, path: str, params: Mapping[str, str] | None = None) -> str:
|
|
27
|
+
return build_url(self.base_url, path, params)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def _timeout(timeout: float | None, transport: object) -> float:
|
|
31
|
+
"""The timeout for the built-in transport. A custom transport sets its own."""
|
|
32
|
+
if timeout is not None and transport is not None:
|
|
33
|
+
raise ValueError(
|
|
34
|
+
"timeout only applies to the built-in transport; set it on your transport"
|
|
35
|
+
)
|
|
36
|
+
return DEFAULT_TIMEOUT if timeout is None else timeout
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
@contextmanager
|
|
40
|
+
def _errors_at(url: str) -> Iterator[None]:
|
|
41
|
+
"""Add the URL to any pyeuvd error raised inside the block."""
|
|
42
|
+
try:
|
|
43
|
+
yield
|
|
44
|
+
except EUVDError as exc:
|
|
45
|
+
if exc.url is None:
|
|
46
|
+
exc.url = url
|
|
47
|
+
raise
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def _decode(
|
|
51
|
+
url: str,
|
|
52
|
+
response: Response,
|
|
53
|
+
started: float,
|
|
54
|
+
check: Callable[[Any], Any] | None = None,
|
|
55
|
+
) -> Any:
|
|
56
|
+
"""Log the response, then return its JSON or raise for an error status.
|
|
57
|
+
|
|
58
|
+
``started`` is the ``time.perf_counter()`` reading from before the request.
|
|
59
|
+
``check`` is applied to the JSON, to reject data of the wrong shape.
|
|
60
|
+
"""
|
|
61
|
+
elapsed = (time.perf_counter() - started) * 1000
|
|
62
|
+
logger.debug("GET %s -> %d in %.0f ms", url, response.status, elapsed)
|
|
63
|
+
response.raise_for_status()
|
|
64
|
+
data = response.json()
|
|
65
|
+
return data if check is None else check(data)
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def _page_size(size: int, limit: int | None) -> int:
|
|
69
|
+
"""The page size to request: never more than ``limit``."""
|
|
70
|
+
return size if limit is None else min(size, max(limit, 1))
|