Fix various compiler warnings and update OpenSSL hash functions (#119)

* Update OpenSSL hash functions to OpenSSL 3.0
* Fix invalid sscanf format in DownloadManager
* Fix unset return value warning
* Fix erroneous check on otpMem in iosu_crypto
This commit is contained in:
bitscher 2022-08-30 00:27:25 -07:00 committed by GitHub
parent 86c0a8f698
commit 2d42c885da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 114 deletions

View file

@ -7,7 +7,8 @@
#include <algorithm>
#include <mutex>
#include "openssl/sha.h"
#include "openssl/evp.h" /* EVP_Digest */
#include "openssl/sha.h" /* SHA256_DIGEST_LENGTH */
#include "Cafe/Account/Account.h"
#include "config/ActiveSettings.h"
#include "util/helpers/helpers.h"
@ -557,24 +558,25 @@ int iosuAct_thread()
// 6 bytes from the end of UUID
// bytes 10-15 are used from the hash and replace the last 6 bytes of the UUID
SHA256_CTX ctx_sha256;
SHA256_Init(&ctx_sha256);
EVP_MD_CTX *ctx_sha256 = EVP_MD_CTX_new();
EVP_DigestInit(ctx_sha256, EVP_sha256());
uint8 tempArray[4];
uint32 name = (uint32)actCemuRequest->uuidName;
tempArray[0] = (name >> 24) & 0xFF;
tempArray[1] = (name >> 16) & 0xFF;
tempArray[2] = (name >> 8) & 0xFF;
tempArray[3] = (name >> 0) & 0xFF;
SHA256_Update(&ctx_sha256, tempArray, 4);
tempArray[0] = 0x3A;
tempArray[1] = 0x27;
tempArray[2] = 0x5E;
tempArray[3] = 0x09;
SHA256_Update(&ctx_sha256, tempArray, 4);
SHA256_Update(&ctx_sha256, actCemuRequest->resultBinary.binBuffer+10, 6);
uint8 h[32];
SHA256_Final(h, &ctx_sha256);
uint8 tempArray[] = {
(name >> 24) & 0xFF,
(name >> 16) & 0xFF,
(name >> 8) & 0xFF,
(name >> 0) & 0xFF,
0x3A,
0x27,
0x5E,
0x09,
};
EVP_DigestUpdate(ctx_sha256, tempArray, sizeof(tempArray));
EVP_DigestUpdate(ctx_sha256, actCemuRequest->resultBinary.binBuffer+10, 6);
uint8 h[SHA256_DIGEST_LENGTH];
EVP_DigestFinal_ex(ctx_sha256, h, NULL);
EVP_MD_CTX_free(ctx_sha256);
memcpy(actCemuRequest->resultBinary.binBuffer + 0xA, h + 0xA, 6);
}

View file

@ -6,7 +6,6 @@
#include "openssl/ec.h"
#include "openssl/x509.h"
#include "openssl/ssl.h"
#include "openssl/sha.h"
#include "openssl/ecdsa.h"
#include "util/crypto/aes128.h"
@ -54,7 +53,7 @@ bool iosuCrypto_getDeviceId(uint32* deviceId)
{
uint32be deviceIdBE;
*deviceId = 0;
if (otpMem == nullptr)
if (!hasOtpMem)
return false;
iosuCrypto_readOtpData(&deviceIdBE, 0x87, sizeof(uint32));
*deviceId = (uint32)deviceIdBE;
@ -228,7 +227,7 @@ void iosuCrypto_generateDeviceCertificate()
{
static_assert(sizeof(g_wiiuDeviceCert) == 0x180);
memset(&g_wiiuDeviceCert, 0, sizeof(g_wiiuDeviceCert));
if (otpMem == nullptr)
if (!hasOtpMem)
return; // cant generate certificate without OPT
// set header based on otp security mode
@ -293,14 +292,6 @@ void iosuCrypto_generateDeviceCertificate()
BN_CTX_free(context);
}
void CertECC_generateHashForSignature(CertECC_t& cert, CHash256& hashOut)
{
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, cert.certificateSubject, 0x100);
SHA256_Final(hashOut.b, &sha256);
}
bool iosuCrypto_hasAllDataForLogin()
{
if (hasOtpMem == false)