Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_keys.py: 56%
66 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-13 07:46 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-13 07:46 +0000
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
13# Copyright 2023 Google LLC
14#
15# Licensed under the Apache License, Version 2.0 (the "License");
16# you may not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS,
23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
26import sys
27import atheris
28import hashlib
29import binascii
31import ecdsa
32from ecdsa.keys import VerifyingKey
35def target1(fdp):
36 try:
37 VerifyingKey.from_der(fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024)))
38 except ecdsa.der.UnexpectedDER:
39 pass
42def target2(fdp):
43 try:
44 VerifyingKey.from_pem(fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024)), hashlib.sha256)
45 except ecdsa.der.UnexpectedDER:
46 pass
47 except binascii.Error:
48 pass
51def target3(fdp):
52 try:
53 VerifyingKey.from_public_key_recovery_with_digest(
54 fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024)), fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024)),
55 ecdsa.curves.Ed25519)
56 except ecdsa.der.UnexpectedDER:
57 pass
58 except ValueError:
59 pass
62def target4(fdp):
63 try:
64 VerifyingKey.from_string(fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(0, 1024)),
65 ecdsa.curves.Ed25519)
66 except ecdsa.keys.MalformedPointError:
67 pass
68 except ecdsa.der.UnexpectedDER:
69 pass
70 except ValueError:
71 pass
74def target5(fdp):
75 vk_str = fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(0, 1024))
76 sig = fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024))
77 data = fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, 1024))
78 try:
79 vk = VerifyingKey.from_pem(vk_str)
80 vk.verify(sig, data)
81 except ecdsa.keys.MalformedPointError:
82 pass
83 except ecdsa.der.UnexpectedDER:
84 pass
85 except ValueError:
86 pass
89def TestOneInput(data):
90 fdp = atheris.FuzzedDataProvider(data)
91 targets = [
92 target1,
93 target2,
94 target3,
95 target4,
96 target5,
97 ]
99 target = fdp.PickValueInList(targets)
100 target(fdp)
103def main():
104 atheris.instrument_all()
105 atheris.Setup(sys.argv, TestOneInput)
106 atheris.Fuzz()
109if __name__ == "__main__":
110 main()