-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
2,902 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: lint | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
uses: lnbits/lnbits/.github/workflows/lint.yml@dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
__pycache__ | ||
node_modules | ||
.mypy_cache | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"semi": false, | ||
"arrowParens": "avoid", | ||
"insertPragma": false, | ||
"printWidth": 80, | ||
"proseWrap": "preserve", | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"useTabs": false, | ||
"bracketSameLine": false, | ||
"bracketSpacing": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
all: format check | ||
|
||
format: prettier black ruff | ||
|
||
check: mypy pyright checkblack checkruff checkprettier | ||
|
||
prettier: | ||
poetry run ./node_modules/.bin/prettier --write . | ||
pyright: | ||
poetry run ./node_modules/.bin/pyright | ||
|
||
mypy: | ||
poetry run mypy . | ||
|
||
black: | ||
poetry run black . | ||
|
||
ruff: | ||
poetry run ruff check . --fix | ||
|
||
checkruff: | ||
poetry run ruff check . | ||
|
||
checkprettier: | ||
poetry run ./node_modules/.bin/prettier --check . | ||
|
||
checkblack: | ||
poetry run black --check . | ||
|
||
checkeditorconfig: | ||
editorconfig-checker | ||
|
||
test: | ||
PYTHONUNBUFFERED=1 \ | ||
DEBUG=true \ | ||
poetry run pytest | ||
install-pre-commit-hook: | ||
@echo "Installing pre-commit hook to git" | ||
@echo "Uninstall the hook with poetry run pre-commit uninstall" | ||
poetry run pre-commit install | ||
|
||
pre-commit: | ||
poetry run pre-commit run --all-files | ||
|
||
|
||
checkbundle: | ||
@echo "skipping checkbundle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
# https://www.nxp.com/docs/en/application-note/AN12196.pdf | ||
from typing import Tuple | ||
|
||
from Cryptodome.Cipher import AES | ||
from Cryptodome.Hash import CMAC | ||
|
||
SV2 = "3CC300010080" | ||
|
||
|
||
def myCMAC(key: bytes, msg: bytes = b"") -> bytes: | ||
def my_cmac(key: bytes, msg: bytes = b"") -> bytes: | ||
cobj = CMAC.new(key, ciphermod=AES) | ||
if msg != b"": | ||
cobj.update(msg) | ||
return cobj.digest() | ||
|
||
|
||
def decryptSUN(sun: bytes, key: bytes) -> Tuple[bytes, bytes]: | ||
IVbytes = b"\x00" * 16 | ||
def decrypt_sun(sun: bytes, key: bytes) -> tuple[bytes, bytes]: | ||
ivbytes = b"\x00" * 16 | ||
|
||
cipher = AES.new(key, AES.MODE_CBC, IVbytes) | ||
cipher = AES.new(key, AES.MODE_CBC, ivbytes) | ||
sun_plain = cipher.decrypt(sun) | ||
|
||
UID = sun_plain[1:8] | ||
uid = sun_plain[1:8] | ||
counter = sun_plain[8:11] | ||
|
||
return UID, counter | ||
return uid, counter | ||
|
||
|
||
def getSunMAC(UID: bytes, counter: bytes, key: bytes) -> bytes: | ||
def get_sun_mac(uid: bytes, counter: bytes, key: bytes) -> bytes: | ||
sv2prefix = bytes.fromhex(SV2) | ||
sv2bytes = sv2prefix + UID + counter | ||
sv2bytes = sv2prefix + uid + counter | ||
|
||
mac1 = myCMAC(key, sv2bytes) | ||
mac2 = myCMAC(mac1) | ||
mac1 = my_cmac(key, sv2bytes) | ||
mac2 = my_cmac(mac1) | ||
|
||
return mac2[1::2] |
Oops, something went wrong.