mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-12 02:10:00 +00:00
@@ -78,8 +78,8 @@ static SpcIndirectDataContent* get_content(PKCS7* content)
|
||||
if (!spcContent)
|
||||
return NULL;
|
||||
|
||||
int len = content->d.other->value.sequence->length;
|
||||
const uint8_t* data = content->d.other->value.sequence->data;
|
||||
int len = ASN1_STRING_length(content->d.other->value.sequence);
|
||||
const uint8_t* data = ASN1_STRING_get0_data(content->d.other->value.sequence);
|
||||
|
||||
d2i_SpcIndirectDataContent(&spcContent, &data, len);
|
||||
|
||||
@@ -88,8 +88,8 @@ static SpcIndirectDataContent* get_content(PKCS7* content)
|
||||
|
||||
static char* parse_program_name(ASN1_TYPE* spcAttr)
|
||||
{
|
||||
const uint8_t* spcData = spcAttr->value.sequence->data;
|
||||
int spcLen = spcAttr->value.sequence->length;
|
||||
const uint8_t* spcData = ASN1_STRING_get0_data(spcAttr->value.sequence);
|
||||
int spcLen = ASN1_STRING_length(spcAttr->value.sequence);
|
||||
SpcSpOpusInfo* spcInfo = d2i_SpcSpOpusInfo(NULL, &spcData, spcLen);
|
||||
if (!spcInfo)
|
||||
return NULL;
|
||||
@@ -131,8 +131,8 @@ static void parse_nested_authenticode(PKCS7_SIGNER_INFO* si, AuthenticodeArray*
|
||||
ASN1_TYPE* nested = X509_ATTRIBUTE_get0_type(attr, i);
|
||||
if (nested == NULL)
|
||||
break;
|
||||
int len = nested->value.sequence->length;
|
||||
const uint8_t* data = nested->value.sequence->data;
|
||||
int len = ASN1_STRING_length(nested->value.sequence);
|
||||
const uint8_t* data = ASN1_STRING_get0_data(nested->value.sequence);
|
||||
AuthenticodeArray* auth = authenticode_new(data, len);
|
||||
if (!auth)
|
||||
continue;
|
||||
@@ -162,8 +162,8 @@ static void parse_pkcs9_countersig(PKCS7* p7, Authenticode* auth)
|
||||
ASN1_TYPE* nested = X509_ATTRIBUTE_get0_type(attr, i);
|
||||
if (nested == NULL)
|
||||
break;
|
||||
int len = nested->value.sequence->length;
|
||||
const uint8_t* data = nested->value.sequence->data;
|
||||
int len = ASN1_STRING_length(nested->value.sequence);
|
||||
const uint8_t* data = ASN1_STRING_get0_data(nested->value.sequence);
|
||||
|
||||
Countersignature* sig = pkcs9_countersig_new(data, len, p7->d.sign->cert, si->enc_digest);
|
||||
if (!sig)
|
||||
@@ -193,8 +193,8 @@ static void parse_ms_countersig(PKCS7* p7, Authenticode* auth)
|
||||
ASN1_TYPE* nested = X509_ATTRIBUTE_get0_type(attr, i);
|
||||
if (nested == NULL)
|
||||
break;
|
||||
int len = nested->value.sequence->length;
|
||||
const uint8_t* data = nested->value.sequence->data;
|
||||
int len = ASN1_STRING_length(nested->value.sequence);
|
||||
const uint8_t* data = ASN1_STRING_get0_data(nested->value.sequence);
|
||||
|
||||
Countersignature* csig = ms_countersig_new(data, len, si->enc_digest);
|
||||
if (!csig)
|
||||
@@ -209,8 +209,8 @@ static void parse_ms_countersig(PKCS7* p7, Authenticode* auth)
|
||||
|
||||
static bool authenticode_verify(PKCS7* p7, PKCS7_SIGNER_INFO* si, X509* signCert)
|
||||
{
|
||||
const uint8_t* contentData = p7->d.sign->contents->d.other->value.sequence->data;
|
||||
long contentLen = p7->d.sign->contents->d.other->value.sequence->length;
|
||||
const uint8_t* contentData = ASN1_STRING_get0_data(p7->d.sign->contents->d.other->value.sequence);
|
||||
long contentLen = ASN1_STRING_length(p7->d.sign->contents->d.other->value.sequence);
|
||||
|
||||
uint64_t version = 0;
|
||||
ASN1_INTEGER_get_uint64(&version, p7->d.sign->version);
|
||||
@@ -315,8 +315,8 @@ AuthenticodeArray* authenticode_new(const uint8_t* data, int32_t len)
|
||||
int digestnid = OBJ_obj2nid(messageDigest->digestAlgorithm->algorithm);
|
||||
auth->digest_alg = strdup(OBJ_nid2ln(digestnid));
|
||||
|
||||
int digestLen = messageDigest->digest->length;
|
||||
const uint8_t* digestData = messageDigest->digest->data;
|
||||
int digestLen = ASN1_STRING_length(messageDigest->digest);
|
||||
const uint8_t* digestData = ASN1_STRING_get0_data(messageDigest->digest);
|
||||
byte_array_init(&auth->digest, digestData, digestLen);
|
||||
|
||||
SpcIndirectDataContent_free(dataContent);
|
||||
@@ -372,8 +372,8 @@ AuthenticodeArray* authenticode_new(const uint8_t* data, int32_t len)
|
||||
digestnid = OBJ_obj2nid(si->digest_alg->algorithm);
|
||||
signer->digest_alg = strdup(OBJ_nid2ln(digestnid));
|
||||
|
||||
digestLen = digest->value.asn1_string->length;
|
||||
digestData = digest->value.asn1_string->data;
|
||||
digestLen = ASN1_STRING_length(digest->value.asn1_string);
|
||||
digestData = ASN1_STRING_get0_data(digest->value.asn1_string);
|
||||
byte_array_init(&signer->digest, digestData, digestLen);
|
||||
|
||||
/* Authenticode stores optional programName in non-optional SpcSpOpusInfo attribute */
|
||||
@@ -551,7 +551,7 @@ AuthenticodeArray* parse_authenticode(const uint8_t* pe_data, uint64_t pe_len)
|
||||
continue;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
int mdlen = EVP_MD_get_size(md);
|
||||
#else
|
||||
int mdlen = EVP_MD_size(md);
|
||||
|
||||
@@ -31,7 +31,7 @@ SOFTWARE.
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
/* Removes any escaping \/ -> / that is happening with oneline() functions
|
||||
from OpenSSL 3.0 */
|
||||
static void parse_oneline_string(char* string)
|
||||
@@ -65,7 +65,7 @@ static void parse_name_attributes(X509_NAME* raw, Attributes* attr)
|
||||
const char* key = OBJ_nid2sn(OBJ_obj2nid(X509_NAME_ENTRY_get_object(entryName)));
|
||||
|
||||
ByteArray array = {0};
|
||||
if (byte_array_init(&array, asn1String->data, asn1String->length) == -1)
|
||||
if (byte_array_init(&array, ASN1_STRING_get0_data(asn1String), ASN1_STRING_length(asn1String)) == -1)
|
||||
break;
|
||||
|
||||
if (strcmp(key, "C") == 0 && !attr->country.data)
|
||||
@@ -293,14 +293,14 @@ Certificate* certificate_new(X509* x509)
|
||||
|
||||
result->issuer = strdup(buffer);
|
||||
/* This is a little ugly hack for 3.0 compatibility */
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
parse_oneline_string(result->issuer);
|
||||
#endif
|
||||
|
||||
X509_NAME* subjectName = X509_get_subject_name(x509);
|
||||
X509_NAME_oneline(subjectName, buffer, sizeof(buffer));
|
||||
result->subject = strdup(buffer);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
parse_oneline_string(result->subject);
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@ Certificate* certificate_new(X509* x509)
|
||||
EVP_PKEY* pkey = X509_get0_pubkey(x509);
|
||||
if (pkey) {
|
||||
result->key = pubkey_to_pem(pkey);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
result->key_alg = strdup(OBJ_nid2sn(EVP_PKEY_get_base_id(pkey)));
|
||||
#else
|
||||
result->key_alg = strdup(OBJ_nid2sn(EVP_PKEY_base_id(pkey)));
|
||||
|
||||
@@ -147,7 +147,7 @@ Countersignature* pkcs9_countersig_new(
|
||||
goto end;
|
||||
}
|
||||
|
||||
size_t digestLen = messageDigest->value.octet_string->length;
|
||||
size_t digestLen = ASN1_STRING_length(messageDigest->value.octet_string);
|
||||
|
||||
if (!digestLen) {
|
||||
result->verify_flags = COUNTERSIGNATURE_VFY_DIGEST_MISSING;
|
||||
@@ -160,7 +160,7 @@ Countersignature* pkcs9_countersig_new(
|
||||
goto end;
|
||||
}
|
||||
|
||||
const uint8_t* digestData = messageDigest->value.octet_string->data;
|
||||
const uint8_t* digestData = ASN1_STRING_get0_data(messageDigest->value.octet_string);
|
||||
byte_array_init(&result->digest, digestData, digestLen);
|
||||
|
||||
/* By this point we all necessary things for verification
|
||||
@@ -187,8 +187,8 @@ Countersignature* pkcs9_countersig_new(
|
||||
goto end;
|
||||
}
|
||||
|
||||
uint8_t* encData = si->enc_digest->data;
|
||||
size_t encLen = si->enc_digest->length;
|
||||
uint8_t* encData = (uint8_t*) ASN1_STRING_get0_data(si->enc_digest);
|
||||
size_t encLen = ASN1_STRING_length(si->enc_digest);
|
||||
|
||||
/* Decrypt the encrypted digest */
|
||||
EVP_PKEY_verify_recover_init(ctx);
|
||||
@@ -204,7 +204,7 @@ Countersignature* pkcs9_countersig_new(
|
||||
/* compare the encrypted digest and calculated digest */
|
||||
bool isValid = false;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
size_t mdLen = EVP_MD_get_size(md);
|
||||
#else
|
||||
size_t mdLen = EVP_MD_size(md);
|
||||
@@ -220,7 +220,7 @@ Countersignature* pkcs9_countersig_new(
|
||||
const uint8_t* data_ptr = decData;
|
||||
DigestInfo* digest_info = d2i_DigestInfo(NULL, &data_ptr, decLen);
|
||||
if (digest_info) {
|
||||
isValid = !memcmp(digest_info->digest->data, calc_digest, mdLen);
|
||||
isValid = !memcmp(ASN1_STRING_get0_data(digest_info->digest), calc_digest, mdLen);
|
||||
DigestInfo_free(digest_info);
|
||||
} else {
|
||||
isValid = false;
|
||||
@@ -235,7 +235,7 @@ Countersignature* pkcs9_countersig_new(
|
||||
|
||||
/* Now check the countersignature message-digest that should correspond
|
||||
* to Signatures encrypted digest it countersigns */
|
||||
calculate_digest(md, enc_digest->data, enc_digest->length, calc_digest);
|
||||
calculate_digest(md, ASN1_STRING_get0_data(enc_digest), ASN1_STRING_length(enc_digest), calc_digest);
|
||||
|
||||
/* Check if calculated one matches the stored one */
|
||||
if (digestLen != mdLen || memcmp(calc_digest, digestData, mdLen) != 0) {
|
||||
@@ -269,8 +269,8 @@ TS_TST_INFO* IMPL_FUNC_NAME(get_ts_tst_info, cms)(CountersignatureImpl* impl)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint8_t* data = (*content)->data;
|
||||
TS_TST_INFO* ts_tst_info = d2i_TS_TST_INFO(NULL, &data, (*content)->length);
|
||||
const uint8_t* data = ASN1_STRING_get0_data(*content);
|
||||
TS_TST_INFO* ts_tst_info = d2i_TS_TST_INFO(NULL, &data, ASN1_STRING_length(*content));
|
||||
if (!ts_tst_info) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ int IMPL_FUNC_NAME(verify_digest, pkcs7)(
|
||||
|
||||
TS_VERIFY_CTX_set_flags(ctx, TS_VFY_VERSION | TS_VFY_IMPRINT);
|
||||
TS_VERIFY_CTX_set_store(ctx, store);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
TS_VERIFY_CTX_set_certs(ctx, impl->funcs->get_certs(impl));
|
||||
#else
|
||||
TS_VERIFY_CTS_set_certs(ctx, impl->funcs->get_certs(impl));
|
||||
@@ -400,8 +400,8 @@ int IMPL_FUNC_NAME(verify_digest, cms)(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ts_imprint_digest->length != (int)digest_size ||
|
||||
memcmp(ts_imprint_digest->data, digest, digest_size) != 0) {
|
||||
if (ASN1_STRING_length(ts_imprint_digest) != (int)digest_size ||
|
||||
memcmp(ASN1_STRING_get0_data(ts_imprint_digest), digest, digest_size) != 0) {
|
||||
TS_TST_INFO_free(ts_tst_info);
|
||||
return 0;
|
||||
}
|
||||
@@ -554,8 +554,8 @@ Countersignature* ms_countersig_new(const uint8_t* data, long size, ASN1_STRING*
|
||||
|
||||
ASN1_STRING* rawDigest = TS_MSG_IMPRINT_get_msg(imprint);
|
||||
|
||||
int digestLen = rawDigest->length;
|
||||
uint8_t* digestData = rawDigest->data;
|
||||
int digestLen = ASN1_STRING_length(rawDigest);
|
||||
uint8_t* digestData = (uint8_t*) ASN1_STRING_get0_data(rawDigest);
|
||||
|
||||
byte_array_init(&result->digest, digestData, digestLen);
|
||||
|
||||
@@ -571,9 +571,9 @@ Countersignature* ms_countersig_new(const uint8_t* data, long size, ASN1_STRING*
|
||||
}
|
||||
|
||||
uint8_t calc_digest[EVP_MAX_MD_SIZE];
|
||||
calculate_digest(md, enc_digest->data, enc_digest->length, calc_digest);
|
||||
calculate_digest(md, ASN1_STRING_get0_data(enc_digest), ASN1_STRING_length(enc_digest), calc_digest);
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x3000000fL
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
int mdLen = EVP_MD_get_size(md);
|
||||
#else
|
||||
int mdLen = EVP_MD_size(md);
|
||||
|
||||
Reference in New Issue
Block a user