remove old fiatjaf's checksum thing (replaced with stepan's).
This commit is contained in:
parent
207961307a
commit
703e6107fa
1 changed files with 14 additions and 12 deletions
|
|
@ -56,7 +56,7 @@ async def handle_lnurl_firstrequest(
|
||||||
if not pos:
|
if not pos:
|
||||||
return {
|
return {
|
||||||
"status": "ERROR",
|
"status": "ERROR",
|
||||||
"reason": f"lnurlpos {pos_id} not found on this server.",
|
"reason": f"lnurlpos {pos_id} not found on this server",
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -83,22 +83,24 @@ async def handle_lnurl_firstrequest(
|
||||||
"reason": f"Invalid hex or base64 payload: {payload}",
|
"reason": f"Invalid hex or base64 payload: {payload}",
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(payloadb)!=8:
|
# check payload and nonce sizes
|
||||||
raise RuntimeError("Expected 8 bytes")
|
if len(payloadb) != 8 or len(nonceb) != 8:
|
||||||
expected = hmac.new(pos.key.encode(), payloadb[:-2], digestmod="sha256").digest()
|
return {"status": "ERROR", "reason": "Expected 8 bytes"}
|
||||||
if expected[:2] != payloadb[-2:]:
|
|
||||||
raise RuntimeError("Invalid HMAC")
|
|
||||||
s = hmac.new(pos.key.encode(), nonceb, digestmod="sha256").digest()
|
|
||||||
|
|
||||||
|
# verify hmac
|
||||||
|
if verify_checksum:
|
||||||
|
expected = hmac.new(
|
||||||
|
pos.key.encode(), payloadb[:-2], digestmod="sha256"
|
||||||
|
).digest()
|
||||||
|
if expected[:2] != payloadb[-2:]:
|
||||||
|
return {"status": "ERROR", "reason": "Invalid HMAC"}
|
||||||
|
|
||||||
|
# decrypt
|
||||||
|
s = hmac.new(pos.key.encode(), nonceb, digestmod="sha256").digest()
|
||||||
res = bytearray(payloadb)
|
res = bytearray(payloadb)
|
||||||
for i in range(len(res)):
|
for i in range(len(res)):
|
||||||
res[i] = res[i] ^ s[i]
|
res[i] = res[i] ^ s[i]
|
||||||
|
|
||||||
if verify_checksum:
|
|
||||||
checksum = res[6:8]
|
|
||||||
if hashlib.sha256(res[0:6]).digest()[0:2] != checksum:
|
|
||||||
return {"status": "ERROR", "reason": "Invalid checksum!"}
|
|
||||||
|
|
||||||
pin = int.from_bytes(res[0:2], "little")
|
pin = int.from_bytes(res[0:2], "little")
|
||||||
amount = int.from_bytes(res[2:6], "little")
|
amount = int.from_bytes(res[2:6], "little")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue