python-ecdsa: initial integration (#9637)

Signed-off-by: David Korczynski <david@adalogics.com>

Signed-off-by: David Korczynski <david@adalogics.com>
This commit is contained in:
DavidKorczynski 2023-02-08 10:54:44 +00:00 committed by GitHub
parent 0325500290
commit 093e04a650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 272 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#!/usr/bin/python3
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM gcr.io/oss-fuzz-base/base-builder-python
RUN pip3 install --upgrade pip
RUN git clone https://github.com/tlsfuzzer/python-ecdsa python-ecdsa
COPY *.sh *py $SRC/
WORKDIR $SRC/python-ecdsa

View File

@ -0,0 +1,21 @@
#!/bin/bash -eu
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
pip3 install .
# Build fuzzers in $OUT.
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
compile_python_fuzzer $fuzzer
done

View File

@ -0,0 +1,63 @@
#!/usr/bin/python3
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import atheris
import hashlib
import binascii
import ecdsa
def target1(fdp):
d = fdp.ConsumeIntInRange(
1, 9999999999999999999999999999999999999999999999999999999999)
k = fdp.ConsumeIntInRange(
1, 9999999999999999999999999999999999999999999999999999999999)
msg = fdp.ConsumeIntInRange(
1, 9999999999999999999999999999999999999999999999999999999999)
Q = d * ecdsa.ecdsa.generator_192
R = k * ecdsa.ecdsa.generator_192
pubk = ecdsa.ecdsa.Public_key(ecdsa.ecdsa.generator_192,
ecdsa.ecdsa.generator_192 * d)
privk = ecdsa.ecdsa.Private_key(pubk, d)
sig = privk.sign(msg, k)
pubk.verifies(msg, sig)
pubk.verifies(msg - 1, sig)
def target2(fdp):
ecdsa._sha3.shake_256(fdp.ConsumeBytes(sys.maxsize),
fdp.ConsumeIntInRange(1, 64))
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
targets = [
target1,
target2,
]
target = fdp.PickValueInList(targets)
target(fdp)
def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,60 @@
#!/usr/bin/python3
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import atheris
import hashlib
import binascii
import ecdsa
def target1(fdp):
a = ecdsa.ellipticcurve.PointEdwards(ecdsa.eddsa.curve_ed25519,
fdp.ConsumeIntInRange(0, 10),
fdp.ConsumeIntInRange(0, 10),
fdp.ConsumeIntInRange(0, 10),
fdp.ConsumeIntInRange(0, 10))
z = a.double()
def target2(fdp):
try:
key = ecdsa.eddsa.PublicKey(ecdsa.eddsa.generator_ed25519,
fdp.ConsumeBytes(sys.maxsize))
key.verify(fdp.ConsumeBytes(sys.maxsize), fdp.ConsumeBytes(sys.maxsize))
except ValueError:
pass
except ecdsa.errors.MalformedPointError:
pass
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
targets = [
target1,
target2,
]
target = fdp.PickValueInList(targets)
target(fdp)
def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,99 @@
#!/usr/bin/python3
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import atheris
import hashlib
import binascii
import ecdsa
from ecdsa.keys import VerifyingKey
def target1(fdp):
try:
VerifyingKey.from_der(fdp.ConsumeBytes(sys.maxsize))
except ecdsa.der.UnexpectedDER:
pass
def target2(fdp):
try:
VerifyingKey.from_pem(fdp.ConsumeBytes(sys.maxsize), hashlib.sha256)
except ecdsa.der.UnexpectedDER:
pass
except binascii.Error:
pass
def target3(fdp):
try:
VerifyingKey.from_public_key_recovery_with_digest(
fdp.ConsumeBytes(sys.maxsize), fdp.ConsumeBytes(sys.maxsize),
ecdsa.curves.Ed25519)
except ecdsa.der.UnexpectedDER:
pass
except ValueError:
pass
def target4(fdp):
try:
VerifyingKey.from_string(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize),
ecdsa.curves.Ed25519)
except ecdsa.keys.MalformedPointError:
pass
except ecdsa.der.UnexpectedDER:
pass
except ValueError:
pass
def target5(fdp):
vk_str = fdp.ConsumeUnicodeNoSurrogates(sys.maxsize)
sig = fdp.ConsumeBytes(sys.maxsize)
data = fdp.ConsumeBytes(sys.maxsize)
try:
vk = VerifyingKey.from_pem(vk_str)
vk.verify(sig, data)
except ecdsa.keys.MalformedPointError:
pass
except ecdsa.der.UnexpectedDER:
pass
except ValueError:
pass
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
targets = [
target1,
target2,
target3,
target4,
target5,
]
target = fdp.PickValueInList(targets)
target(fdp)
def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,10 @@
homepage: https://github.com/tlsfuzzer/python-ecdsa
main_repo: https://github.com/tlsfuzzer/python-ecdsa
language: python
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefined
vendor_ccs:
- david@adalogics.com