Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with authenticator token #104

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

epenet
Copy link
Collaborator

@epenet epenet commented Mar 22, 2022

No description provided.

@epenet
Copy link
Collaborator Author

epenet commented Mar 22, 2022

I wrongly assumed that the py3rijndael public library matched the folder in PySmartCrypto, but that is not the case!

Public library has: https://github.com/meyt/py3rijndael/blob/3c2a6a3776b38b1f988b3c9148b3bca3c89f3112/py3rijndael/constants.py#L7-L11

num_rounds = {
    16: {16: 10, 24: 12, 32: 14},
    24: {16: 12, 24: 12, 32: 14},
    32: {16: 14, 24: 14, 32: 14}
}

PySmartCrypto has: https://github.com/sermayoral/ha-samsungtv-encrypted/blob/da0f13fe3bcffc834e84fb0d46b8d9066bb2681e/custom_components/samsungtv_encrypted/PySmartCrypto/py3rijndael/constants.py#L7-L9

num_rounds = {
    16: {16: 3}
}

@epenet
Copy link
Collaborator Author

epenet commented Mar 22, 2022

We need to adjust

def _apply_samy_go_key_transform(data: bytes) -> bytes:
cipher = Cipher(algorithms.AES(bytes.fromhex(TRANS_KEY)), modes.ECB())
encryptor: CipherContext = cipher.encryptor()
return encryptor.update(data) + encryptor.finalize() # type:ignore[no-any-return]
but I am not sure how yet.

@epenet epenet force-pushed the fix-authenticator branch from 89e8433 to f97725b Compare March 22, 2022 14:41
@epenet epenet force-pushed the fix-authenticator branch from f97725b to 5143669 Compare March 22, 2022 14:46
@epenet epenet marked this pull request as ready for review March 22, 2022 14:48
@epenet
Copy link
Collaborator Author

epenet commented Mar 22, 2022

I couldn't find a way to use cryptography for the _apply_samy_go_key_transform routine.
I decided instead to add a dependency to py3rijndael, and override the __init__ method accordingly.

If there is a better way to do this I'm all ears...

@epenet epenet added the bug Something isn't working label Mar 22, 2022
@xchwarze xchwarze merged commit 8914a90 into xchwarze:master Mar 22, 2022
@epenet epenet deleted the fix-authenticator branch March 22, 2022 16:03
@epenet
Copy link
Collaborator Author

epenet commented Mar 22, 2022

It was difficult, but @sermayoral confirmed it was working.

@xchwarze could you publish a release when you get a chance please?

@xchwarze
Copy link
Owner

@epenet ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants