mirror of
https://github.com/mtrojnar/osslsigncode.git
synced 2025-04-05 01:00:11 -05:00
Use bio_hash_data() to compute a message digest value of a CAB file
This commit is contained in:
parent
b0391244a6
commit
11eb76d4f3
2
msi.c
2
msi.c
@ -745,7 +745,7 @@ int msi_calc_digest(char *indata, int mdtype, u_char *mdbuf, uint32_t fileend)
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
BIO_push(bhash, BIO_new(BIO_s_null()));
|
BIO_push(bhash, BIO_new(BIO_s_null()));
|
||||||
if (!bio_hash_data(indata, bhash, 0, fileend)) {
|
if (!bio_hash_data(indata, bhash, 0, 0, fileend)) {
|
||||||
printf("Unable to calculate digest\n");
|
printf("Unable to calculate digest\n");
|
||||||
BIO_free_all(bhash);
|
BIO_free_all(bhash);
|
||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
|
@ -796,13 +796,14 @@ static int is_content_type(PKCS7 *p7, const char *objid)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bio_hash_data(char *indata, BIO *hash, uint32_t idx, uint32_t fileend)
|
int bio_hash_data(char *indata, BIO *hash, uint32_t idx, uint32_t offset, uint32_t fileend)
|
||||||
{
|
{
|
||||||
size_t written;
|
size_t written;
|
||||||
uint32_t want;
|
uint32_t want;
|
||||||
|
uint32_t start = offset ? offset : idx;
|
||||||
|
|
||||||
while (idx < fileend) {
|
while (start < fileend) {
|
||||||
want = fileend - idx;
|
want = fileend - start;
|
||||||
if (want > SIZE_64K)
|
if (want > SIZE_64K)
|
||||||
want = SIZE_64K;
|
want = SIZE_64K;
|
||||||
if (!BIO_write_ex(hash, indata + idx, want, &written)) {
|
if (!BIO_write_ex(hash, indata + idx, want, &written)) {
|
||||||
@ -810,6 +811,7 @@ int bio_hash_data(char *indata, BIO *hash, uint32_t idx, uint32_t fileend)
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
idx += (uint32_t)written;
|
idx += (uint32_t)written;
|
||||||
|
start += (uint32_t)written;
|
||||||
}
|
}
|
||||||
return 1; /* OK */
|
return 1; /* OK */
|
||||||
}
|
}
|
||||||
@ -3491,7 +3493,7 @@ static int pe_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER *
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
idx += (uint32_t)written + 8;
|
idx += (uint32_t)written + 8;
|
||||||
if (!bio_hash_data(indata, bhash, idx, fileend)) {
|
if (!bio_hash_data(indata, bhash, idx, 0, fileend)) {
|
||||||
printf("Unable to calculate digest\n");
|
printf("Unable to calculate digest\n");
|
||||||
BIO_free_all(bhash);
|
BIO_free_all(bhash);
|
||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
@ -3912,8 +3914,7 @@ static int cab_verify_header(char *indata, char *infile, uint32_t filesize, FILE
|
|||||||
/* Compute a message digest value of the signed or unsigned CAB file */
|
/* Compute a message digest value of the signed or unsigned CAB file */
|
||||||
static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER *header)
|
static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER *header)
|
||||||
{
|
{
|
||||||
size_t written;
|
uint32_t idx = 0, fileend, coffFiles;
|
||||||
uint32_t idx = 0, offset, coffFiles;
|
|
||||||
const EVP_MD *md = EVP_get_digestbynid(mdtype);
|
const EVP_MD *md = EVP_get_digestbynid(mdtype);
|
||||||
BIO *bhash = BIO_new(BIO_f_md());
|
BIO *bhash = BIO_new(BIO_f_md());
|
||||||
|
|
||||||
@ -3925,9 +3926,9 @@ static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER
|
|||||||
BIO_push(bhash, BIO_new(BIO_s_null()));
|
BIO_push(bhash, BIO_new(BIO_s_null()));
|
||||||
|
|
||||||
if (header->sigpos)
|
if (header->sigpos)
|
||||||
offset = header->sigpos;
|
fileend = header->sigpos;
|
||||||
else
|
else
|
||||||
offset = header->fileend;
|
fileend = header->fileend;
|
||||||
|
|
||||||
/* u1 signature[4] 4643534D MSCF: 0-3 */
|
/* u1 signature[4] 4643534D MSCF: 0-3 */
|
||||||
BIO_write(bhash, indata, 4);
|
BIO_write(bhash, indata, 4);
|
||||||
@ -3980,14 +3981,14 @@ static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER
|
|||||||
BIO_write(bhash, indata + idx, 1);
|
BIO_write(bhash, indata + idx, 1);
|
||||||
pos++;
|
pos++;
|
||||||
idx++;
|
idx++;
|
||||||
} while (byte && pos < offset);
|
} while (byte && pos < fileend);
|
||||||
/* szDiskPrev */
|
/* szDiskPrev */
|
||||||
do {
|
do {
|
||||||
byte = GET_UINT8_LE(indata + idx);
|
byte = GET_UINT8_LE(indata + idx);
|
||||||
BIO_write(bhash, indata + idx, 1);
|
BIO_write(bhash, indata + idx, 1);
|
||||||
pos++;
|
pos++;
|
||||||
idx++;
|
idx++;
|
||||||
} while (byte && pos < offset);
|
} while (byte && pos < fileend);
|
||||||
}
|
}
|
||||||
if (flags & FLAG_NEXT_CABINET) {
|
if (flags & FLAG_NEXT_CABINET) {
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
@ -3997,14 +3998,14 @@ static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER
|
|||||||
BIO_write(bhash, indata + idx, 1);
|
BIO_write(bhash, indata + idx, 1);
|
||||||
pos++;
|
pos++;
|
||||||
idx++;
|
idx++;
|
||||||
} while (byte && pos < offset);
|
} while (byte && pos < fileend);
|
||||||
/* szDiskNext */
|
/* szDiskNext */
|
||||||
do {
|
do {
|
||||||
byte = GET_UINT8_LE(indata + idx);
|
byte = GET_UINT8_LE(indata + idx);
|
||||||
BIO_write(bhash, indata + idx, 1);
|
BIO_write(bhash, indata + idx, 1);
|
||||||
pos++;
|
pos++;
|
||||||
idx++;
|
idx++;
|
||||||
} while (byte && pos < offset);
|
} while (byte && pos < fileend);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* (u8 * cFolders) CFFOLDER - structure contains information about
|
* (u8 * cFolders) CFFOLDER - structure contains information about
|
||||||
@ -4020,17 +4021,11 @@ static int cab_calc_digest(char *indata, int mdtype, u_char *mdbuf, FILE_HEADER
|
|||||||
coffFiles = 8;
|
coffFiles = 8;
|
||||||
}
|
}
|
||||||
/* (variable) ab - the compressed data bytes */
|
/* (variable) ab - the compressed data bytes */
|
||||||
while (coffFiles < offset) {
|
if (!bio_hash_data(indata, bhash, idx, coffFiles, fileend)) {
|
||||||
uint32_t want = offset - coffFiles;
|
printf("Unable to calculate digest\n");
|
||||||
if (want > SIZE_64K)
|
|
||||||
want = SIZE_64K;
|
|
||||||
if (!BIO_write_ex(bhash, indata + idx, want, &written)) {
|
|
||||||
BIO_free_all(bhash);
|
BIO_free_all(bhash);
|
||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
idx += (uint32_t)written;
|
|
||||||
coffFiles += (uint32_t)written;
|
|
||||||
}
|
|
||||||
BIO_gets(bhash, (char*)mdbuf, EVP_MD_size(md));
|
BIO_gets(bhash, (char*)mdbuf, EVP_MD_size(md));
|
||||||
return 1; /* OK */
|
return 1; /* OK */
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int bio_hash_data(char *indata, BIO *hash, uint32_t idx, uint32_t fileend);
|
int bio_hash_data(char *indata, BIO *hash, uint32_t idx, uint32_t offset, uint32_t fileend);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user