From e015ffd5f0812b102fc4c6435a42229f4fe838c5 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Fri, 24 Apr 2020 17:39:58 +0430 Subject: [PATCH] LibCrypto: Ensure that EME padding does not contain zeros With this fix, we can now reliably open TLS connections! --- Libraries/LibCrypto/PK/RSA.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/LibCrypto/PK/RSA.cpp b/Libraries/LibCrypto/PK/RSA.cpp index 90e0d8098e..9fae5047bd 100644 --- a/Libraries/LibCrypto/PK/RSA.cpp +++ b/Libraries/LibCrypto/PK/RSA.cpp @@ -233,6 +233,12 @@ void RSA_PKCS1_EME::encrypt(const ByteBuffer& in, ByteBuffer& out) u8 ps[ps_length]; arc4random_buf(ps, ps_length); + // since arc4random can create zeros (shocking!) + // we have to go through and un-zero the zeros + for (size_t i = 0; i < ps_length; ++i) + if (!ps[i]) + ps[i] = 0xfe; + u8 paddings[] { 0x00, 0x02 }; out.overwrite(0, paddings, 2);