mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 00:24:00 +02:00
Few fixes in signature generation and verification
This commit is contained in:
parent
d0121aaed9
commit
db0e5721ff
4 changed files with 15 additions and 10 deletions
|
@ -72,7 +72,8 @@ All dependencies except for wiring can be installed via:
|
|||
|
||||
- you need to program the Desfire card to have the signature
|
||||
|
||||
|
||||
./write_signed_ndef_on_desfire.py private_key_in_hex
|
||||
|
||||
Finally, run the daemon:
|
||||
|
||||
sudo python brmdoor_nfc_daemon.py brmdoor_nfc.config
|
||||
|
|
|
@ -161,6 +161,7 @@ class DesfireEd25519Authenthicator(object):
|
|||
"""
|
||||
Returns true iff uid (as binary) is the message signed by signature (binary string)
|
||||
"""
|
||||
print "Signature len:", len(signature)
|
||||
verified = curve.verifySignature(self.pubKey, uid, signature) == 0
|
||||
return verified
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ class NFCScanner(object):
|
|||
)
|
||||
self.desfireAuthenticator = DesfireEd25519Authenthicator(
|
||||
config.authDbFilename, self.nfc,
|
||||
config.desfirePubkey
|
||||
config.desfirePubkey.decode("hex")
|
||||
)
|
||||
#self.nfc.pollNr = 0xFF #poll indefinitely
|
||||
while True:
|
||||
|
|
|
@ -13,7 +13,7 @@ if len(sys.argv) < 2:
|
|||
print "Usage: write_signed_ndef_on_desfire.py private_key_in_hex"
|
||||
sys.exit(3)
|
||||
|
||||
tempFile = None
|
||||
tempFd = None
|
||||
tempFname = None
|
||||
|
||||
try:
|
||||
|
@ -24,23 +24,26 @@ try:
|
|||
uid_hex = hexlify(nfc.scanUID())
|
||||
key = sys.argv[1].decode("hex")
|
||||
|
||||
print("Got UID %s", uid_hex)
|
||||
print "Got UID %s" % uid_hex
|
||||
signature = signUid(key, uid_hex.decode("hex"))
|
||||
(tempFile, tempFname) = tempfile.mkstemp(dir="/tmp")
|
||||
with tempFile:
|
||||
tempFile.write(signature)
|
||||
(tempFd, tempFname) = tempfile.mkstemp(dir="/tmp")
|
||||
os.write(tempFd, signature)
|
||||
os.close(tempFd)
|
||||
print "Wrote signature into %s" % tempFname
|
||||
except NFCError, e:
|
||||
#this exception happens also when scanUID times out
|
||||
print("Failed to wait for Desfire card: %s" % e)
|
||||
if tempFname:
|
||||
os.unlink(tempFname)
|
||||
sys.exit(1)
|
||||
except Exception, e:
|
||||
print("Something went wrong when writing the signature to file:", e)
|
||||
if tempFname:
|
||||
os.unlink(tempFname)
|
||||
sys.exit(2)
|
||||
finally:
|
||||
nfc.close()
|
||||
nfc.unload()
|
||||
if tempFname:
|
||||
os.unlink(tempFname)
|
||||
|
||||
# We'll just call the command line tools so that we don't need to copy&paste the NDEF writing code to nfc_smartcard.cpp
|
||||
print "Formatting card"
|
||||
|
@ -54,7 +57,7 @@ if res != 0:
|
|||
print "Creating NDEF failed"
|
||||
sys.exit(4)
|
||||
print "Writing NDEF with signature onto Desfire"
|
||||
res = os.system("mifare-desfire-create-ndef -y -i '%'" % tempFname)
|
||||
res = os.system("mifare-desfire-write-ndef -y -i %s" % tempFname)
|
||||
if res != 0:
|
||||
print "Writing NDEF failed"
|
||||
sys.exit(4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue