[androidtv] fix new shield tv key not read and stored correctly#20354
[androidtv] fix new shield tv key not read and stored correctly#20354mythbai wants to merge 1 commit intoopenhab:mainfrom
Conversation
|
Here is another analysis about necessity of the changes: Root Cause: The original String st = "" + charArray[i+2] + charArray[i+3] + charArray[i] + charArray[i+1]; // byte-swap LE→BE
int privLen = 2246 + ((Integer.parseInt(st, 16) - 2400) * 2);This formula computed Three fixes applied in the current commit:
|
Signed-off-by: Victor Bai <mythbai@gmail.com>
519a434 to
788940e
Compare
Claude Analysis:
ShieldTVMessageParser: TheprivLenwas being calculated incorrectly — it used a raw byte count from the protobuf message instead of reading the actual DER structure length of the private key. Similarly, the certificate bytes needed to skip the protobuf field tag bytes before reading the DER length. Both were fixed to properly parse the DERSEQUENCEtag and length bytes.AndroidTVPKI.decodePrivateKey(): The private key bytes from the ShieldTV are in PKCS#1 (RSA) format, but the code was passing them directly toKeyFactory.generatePrivate()which expects PKCS#8 format. The fix wraps the PKCS#1 bytes in a PKCS#8PrivateKeyInfostructure using BouncyCastle before decoding.AndroidTVPKI.initialize(): WhenloadFromKeyStore()failed (e.g., due to a corrupt or empty keystore file from a previous failed PIN attempt), the code would throw an exception instead of regenerating a fresh keystore. The fix catches the exception and falls back to generating a new self-signed certificate and key pair.fixes #20340
@morph166955 Please review the comments