Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies = [
"argcomplete >= 1.8.2",
"colorama >= 0.3.7",
"crcmod >= 1.7",
"ecdsa >= 0.19.1",
"pycryptodome >= 3.15.0",
"pynrfjprog == 10.19.0",
"pyserial >= 3.0.1",
Expand Down
18 changes: 9 additions & 9 deletions tockloader/tbfh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import traceback

import Crypto
from Crypto.Signature import pkcs1_15
from Crypto.PublicKey import RSA
from Crypto.Signature import pkcs1_15, DSS
from Crypto.PublicKey import RSA, ECC
from Crypto.Hash import SHA512, SHA256, HMAC
import ecdsa

from .exceptions import TockLoaderException

Expand Down Expand Up @@ -1712,9 +1711,9 @@ def verify(self, keys, integrity_blob):
# verify this credential one way or another.
for i, key in enumerate(keys):
try:
signature = key.verify(
signature, integrity_blob, hashfunc=hashlib.sha256
)
hash = Crypto.Hash.SHA256.new(integrity_blob)
Crypto.Signature.DSS.new(key, "fips-186-3").verify(hash, signature)
# Signature verified!
self.verified = "yes"
except Exception as e:
print(e)
Expand Down Expand Up @@ -1911,9 +1910,10 @@ def compute(self, public_key, private_key, integrity_blob, cleartext_id):
self.verified = "yes"
elif self.credentials_type == self.CREDENTIALS_TYPE_ECDSAP256:
# Load the private key from the .pem file.
pri_key = ecdsa.SigningKey.from_pem(private_key)
pri_key = Crypto.PublicKey.ECC.import_key(private_key, curve_name="p256")
# Compute the signature.
signature = pri_key.sign(integrity_blob, hashfunc=hashlib.sha256)
hash = Crypto.Hash.SHA256.new(integrity_blob)
signature = Crypto.Signature.DSS.new(pri_key, "fips-186-3").sign(hash)
# Store the signature.
self.buffer = signature
elif self.credentials_type == self.CREDENTIALS_TYPE_HMACSHA256:
Expand Down Expand Up @@ -2134,7 +2134,7 @@ def verify_credentials(self, public_keys, integrity_blob):
except:
pass
try:
key = ecdsa.VerifyingKey.from_pem(public_key)
key = Crypto.PublicKey.ECC.import_key(public_key)
keys.append(key)
except:
pass
Expand Down