Mint a rune with no restriction but its unique_id from a master secret. The authcode is the SHA256 state after the secret and each restriction, each padded exactly like the SHA256 end marker, so knowing the secret it is plain SHA256 over the whole padded stream.
(secret, unique_id)
| 921 | |
| 922 | |
| 923 | def forge_rune(secret, unique_id): |
| 924 | """Mint a rune with no restriction but its unique_id from a master secret. |
| 925 | |
| 926 | The authcode is the SHA256 state after the secret and each restriction, |
| 927 | each padded exactly like the SHA256 end marker, so knowing the secret it |
| 928 | is plain SHA256 over the whole padded stream.""" |
| 929 | padded = (secret + b'\x80' + bytes(64 - len(secret) - 1 - 8) |
| 930 | + (len(secret) * 8).to_bytes(8, 'big')) |
| 931 | restr = ('=' + unique_id).encode() |
| 932 | authcode = hashlib.sha256(padded + restr).digest() |
| 933 | return base64.urlsafe_b64encode(authcode + restr).decode() |
| 934 | |
| 935 | |
| 936 | def test_makesecret_rune_master_secret(node_factory): |
no test coverage detected