This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Panasonic Viera TV IP control
#15
Here's Python code converted to Lua:
Code:
require('encdec')
aes = require('user.aes')

iv = encdec.base64dec('mUQdS7/RyJTMsiojPz9i1Q==')
iv_vals = { iv:byte(1, -1) }
key_vals = {}

for i = 1, 16, 4 do
  key_vals[ i ] = bit.band(bit.bnot(iv_vals[ i + 3 ]), 0xFF)
  key_vals[ i + 1 ] = bit.band(bit.bnot(iv_vals[ i + 2 ]), 0xFF)
  key_vals[ i + 2 ] = bit.band(bit.bnot(iv_vals[ i + 1 ]), 0xFF)
  key_vals[ i + 3 ] = bit.band(bit.bnot(iv_vals[ i ]), 0xFF)
end

key = string.char(unpack(key_vals))
hmac_key_mask = lmcore.hextostr('15C95AC2B08AA7EB4E228F811E34D04FA54BA7DCAC9879FA8ACDA3FC244F3854', true)
hmac_key_mask_vals = { hmac_key_mask:byte(1, -1) }
hmac_vals = {}

for i = 1, 32, 4 do
  hmac_vals[ i ] = bit.bxor(hmac_key_mask_vals[ i ], iv_vals[ bit.band(i + 1, 0xF) + 1 ])
  hmac_vals[ i + 1 ] = bit.bxor(hmac_key_mask_vals[ i + 1 ], iv_vals[ bit.band(i + 2, 0xF) + 1 ])
  hmac_vals[ i + 2 ] = bit.bxor(hmac_key_mask_vals[ i + 2 ], iv_vals[ bit.band(i - 1, 0xF) + 1 ])
  hmac_vals[ i + 3 ] = bit.bxor(hmac_key_mask_vals[ i + 3 ], iv_vals[ bit.band(i, 0xF) + 1 ])
end

hmac_key = string.char(unpack(hmac_vals))

authinfo = '<X_PinCode>4410</X_PinCode>'
payload = '000000000000'
n = #authinfo

payload = payload .. string.char(bit.band(bit.rshift(n, 24), 0xFF))
payload = payload .. string.char(bit.band(bit.rshift(n, 16), 0xFF))
payload = payload .. string.char(bit.band(bit.rshift(n, 8), 0xFF))
payload = payload .. string.char(bit.band(n, 0xFF))

payload = payload .. authinfo

aes_cbc, err = aes:new(key, nil, aes.cipher(128, 'cbc'), { iv = iv }, nil, 1)
ciphertext = aes_cbc:encrypt(payload)

sig = encdec.hmacsha256(ciphertext, hmac_key, true)
encrypted_payload = encdec.base64enc(ciphertext .. sig)
Reply


Messages In This Thread
Panasonic Viera TV IP control - by jetsetter - 29.02.2016, 11:54
RE: Panasonic Viera TV IP control - by admin - 10.03.2016, 14:32
RE: Panasonic Viera TV IP control - by admin - 16.03.2016, 08:25
RE: Panasonic Viera TV IP control - by andeug - 10.10.2016, 14:41
RE: Panasonic Viera TV IP control - by Habib - 08.04.2018, 11:32
RE: Panasonic Viera TV IP control - by admin - 08.04.2018, 11:58
RE: Panasonic Viera TV IP control - by Habib - 08.04.2018, 13:37
RE: Panasonic Viera TV IP control - by admin - 20.01.2020, 08:32
RE: Panasonic Viera TV IP control - by admin - 14.04.2020, 07:57
RE: Panasonic Viera TV IP control - by admin - 25.12.2020, 13:49
RE: Panasonic Viera TV IP control - by admin - 28.12.2020, 07:46
RE: Panasonic Viera TV IP control - by admin - 06.04.2021, 05:43
RE: Panasonic Viera TV IP control - by admin - 06.04.2021, 09:39

Forum Jump: