mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 16:36:25 +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,6 +72,7 @@ All dependencies except for wiring can be installed via:
|
||||||
|
|
||||||
- you need to program the Desfire card to have the signature
|
- 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:
|
Finally, run the daemon:
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,7 @@ class DesfireEd25519Authenthicator(object):
|
||||||
"""
|
"""
|
||||||
Returns true iff uid (as binary) is the message signed by signature (binary string)
|
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
|
verified = curve.verifySignature(self.pubKey, uid, signature) == 0
|
||||||
return verified
|
return verified
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ class NFCScanner(object):
|
||||||
)
|
)
|
||||||
self.desfireAuthenticator = DesfireEd25519Authenthicator(
|
self.desfireAuthenticator = DesfireEd25519Authenthicator(
|
||||||
config.authDbFilename, self.nfc,
|
config.authDbFilename, self.nfc,
|
||||||
config.desfirePubkey
|
config.desfirePubkey.decode("hex")
|
||||||
)
|
)
|
||||||
#self.nfc.pollNr = 0xFF #poll indefinitely
|
#self.nfc.pollNr = 0xFF #poll indefinitely
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -13,7 +13,7 @@ if len(sys.argv) < 2:
|
||||||
print "Usage: write_signed_ndef_on_desfire.py private_key_in_hex"
|
print "Usage: write_signed_ndef_on_desfire.py private_key_in_hex"
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
tempFile = None
|
tempFd = None
|
||||||
tempFname = None
|
tempFname = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -24,23 +24,26 @@ try:
|
||||||
uid_hex = hexlify(nfc.scanUID())
|
uid_hex = hexlify(nfc.scanUID())
|
||||||
key = sys.argv[1].decode("hex")
|
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"))
|
signature = signUid(key, uid_hex.decode("hex"))
|
||||||
(tempFile, tempFname) = tempfile.mkstemp(dir="/tmp")
|
(tempFd, tempFname) = tempfile.mkstemp(dir="/tmp")
|
||||||
with tempFile:
|
os.write(tempFd, signature)
|
||||||
tempFile.write(signature)
|
os.close(tempFd)
|
||||||
|
print "Wrote signature into %s" % tempFname
|
||||||
except NFCError, e:
|
except NFCError, e:
|
||||||
#this exception happens also when scanUID times out
|
#this exception happens also when scanUID times out
|
||||||
print("Failed to wait for Desfire card: %s" % e)
|
print("Failed to wait for Desfire card: %s" % e)
|
||||||
|
if tempFname:
|
||||||
|
os.unlink(tempFname)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print("Something went wrong when writing the signature to file:", e)
|
print("Something went wrong when writing the signature to file:", e)
|
||||||
|
if tempFname:
|
||||||
|
os.unlink(tempFname)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
finally:
|
finally:
|
||||||
nfc.close()
|
nfc.close()
|
||||||
nfc.unload()
|
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
|
# 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"
|
print "Formatting card"
|
||||||
|
@ -54,7 +57,7 @@ if res != 0:
|
||||||
print "Creating NDEF failed"
|
print "Creating NDEF failed"
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
print "Writing NDEF with signature onto Desfire"
|
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:
|
if res != 0:
|
||||||
print "Writing NDEF failed"
|
print "Writing NDEF failed"
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue