mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-07 08:04:06 +02:00
Make the signature wrapped in JSON object to be able to extend structure later
This commit is contained in:
parent
d4a382ed2f
commit
cfe19b55a1
2 changed files with 16 additions and 3 deletions
|
@ -3,6 +3,7 @@ import sqlite3
|
||||||
import hmac
|
import hmac
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
|
||||||
import axolotl_curve25519 as curve
|
import axolotl_curve25519 as curve
|
||||||
|
|
||||||
|
@ -184,7 +185,8 @@ class DesfireEd25519Authenthicator(object):
|
||||||
nick = record[0]
|
nick = record[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ndefSignature = self.nfcReader.readDesfireNDEF()
|
ndefJson = json.loads(self.nfcReader.readDesfireNDEF())
|
||||||
|
ndefSignature = ndefJson["brmdoorSignature"].decode("hex")
|
||||||
if len(ndefSignature) != 64:
|
if len(ndefSignature) != 64:
|
||||||
logging.error("NDEF signature has wrong length")
|
logging.error("NDEF signature has wrong length")
|
||||||
return None
|
return None
|
||||||
|
@ -194,7 +196,16 @@ class DesfireEd25519Authenthicator(object):
|
||||||
logging.info("Signature check failed for Desfire NDEF for UID %s", uid_hex)
|
logging.info("Signature check failed for Desfire NDEF for UID %s", uid_hex)
|
||||||
return None
|
return None
|
||||||
except NFCError, e:
|
except NFCError, e:
|
||||||
logging.info("Desfire read NDEF failed: %s" % e.what())
|
logging.error("Desfire read NDEF failed: %s", e.what())
|
||||||
|
return None
|
||||||
|
except TypeError, e:
|
||||||
|
logging.error("Could not decode signature from JSON: %s", e)
|
||||||
|
return None
|
||||||
|
except ValueError, e:
|
||||||
|
logging.error("Could not decode JSON from NDEF: %s", e)
|
||||||
|
return None
|
||||||
|
except KeyError, e:
|
||||||
|
logging.error("Missing signature in JSON: %s", e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
|
|
@ -27,7 +27,9 @@ try:
|
||||||
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"))
|
||||||
(tempFd, tempFname) = tempfile.mkstemp(dir="/tmp")
|
(tempFd, tempFname) = tempfile.mkstemp(dir="/tmp")
|
||||||
os.write(tempFd, signature)
|
signatureJson = '{"brmdoorSignature": "%s"}' % signature.encode("hex")
|
||||||
|
print "Writing signature JSON:", signatureJson
|
||||||
|
os.write(tempFd, signatureJson)
|
||||||
os.close(tempFd)
|
os.close(tempFd)
|
||||||
print "Wrote signature into %s" % tempFname
|
print "Wrote signature into %s" % tempFname
|
||||||
except NFCError, e:
|
except NFCError, e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue