diff --git a/README.md b/README.md index 14b9afd..b0757fb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/brmdoor_authenticator.py b/brmdoor_authenticator.py index 4478bc3..110a21f 100644 --- a/brmdoor_authenticator.py +++ b/brmdoor_authenticator.py @@ -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 diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index 6422fe3..ec697fe 100755 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -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: diff --git a/write_signed_ndef_on_desfire.py b/write_signed_ndef_on_desfire.py index d76be18..7e0a1be 100755 --- a/write_signed_ndef_on_desfire.py +++ b/write_signed_ndef_on_desfire.py @@ -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)