MSI: add support for remove-signature.

This commit is contained in:
Mikkel Krautz 2013-04-30 23:08:39 +02:00 committed by Per Allansson
parent 31facc400d
commit 9904aea27f

View File

@ -1195,6 +1195,7 @@ static gboolean msi_handle_dir(GsfInfile *infile, GsfOutfile *outole, BIO *hash)
GSList *sorted = NULL; GSList *sorted = NULL;
gsf_infile_msole_get_class_id(GSF_INFILE_MSOLE(infile), classid); gsf_infile_msole_get_class_id(GSF_INFILE_MSOLE(infile), classid);
if (outole != NULL)
gsf_outfile_msole_set_class_id(GSF_OUTFILE_MSOLE(outole), classid); gsf_outfile_msole_set_class_id(GSF_OUTFILE_MSOLE(outole), classid);
sorted = msi_sorted_infile_children(infile); sorted = msi_sorted_infile_children(infile);
@ -1206,7 +1207,9 @@ static gboolean msi_handle_dir(GsfInfile *infile, GsfOutfile *outole, BIO *hash)
continue; continue;
gboolean is_dir = GSF_IS_INFILE(child) && gsf_infile_num_children(GSF_INFILE(child)) > 0; gboolean is_dir = GSF_IS_INFILE(child) && gsf_infile_num_children(GSF_INFILE(child)) > 0;
GsfOutput *outchild = gsf_outfile_new_child(outole, name, is_dir); GsfOutput *outchild = NULL;
if (outole != NULL)
outchild = gsf_outfile_new_child(outole, name, is_dir);
if (is_dir) { if (is_dir) {
if (!msi_handle_dir(GSF_INFILE(child), GSF_OUTFILE(outchild), hash)) { if (!msi_handle_dir(GSF_INFILE(child), GSF_OUTFILE(outchild), hash)) {
return FALSE; return FALSE;
@ -1216,15 +1219,17 @@ static gboolean msi_handle_dir(GsfInfile *infile, GsfOutfile *outole, BIO *hash)
gsf_off_t size = MIN(gsf_input_remaining(child), 4096); gsf_off_t size = MIN(gsf_input_remaining(child), 4096);
guint8 const *data = gsf_input_read(child, size, NULL); guint8 const *data = gsf_input_read(child, size, NULL);
BIO_write(hash, data, size); BIO_write(hash, data, size);
if (!gsf_output_write(outchild, size, data)) { if (outchild != NULL && !gsf_output_write(outchild, size, data)) {
return FALSE; return FALSE;
} }
} }
} }
if (outchild != NULL) {
gsf_output_close(outchild); gsf_output_close(outchild);
g_object_unref(outchild); g_object_unref(outchild);
} }
}
BIO_write(hash, classid, sizeof(classid)); BIO_write(hash, classid, sizeof(classid));
@ -1852,8 +1857,8 @@ int main(int argc, char **argv)
DO_EXIT_1("Unrecognized file type: %s\n", infile); DO_EXIT_1("Unrecognized file type: %s\n", infile);
} }
if (cmd != CMD_SIGN && type != FILE_TYPE_PE) if (cmd != CMD_SIGN && !(type == FILE_TYPE_PE || type == FILE_TYPE_MSI))
DO_EXIT_1("Command is not supported for non-PE files: %s\n", infile); DO_EXIT_1("Command is not supported for non-PE/non-MSI files: %s\n", infile);
hash = BIO_new(BIO_f_md()); hash = BIO_new(BIO_f_md());
BIO_set_md(hash, md); BIO_set_md(hash, md);
@ -1882,12 +1887,14 @@ int main(int argc, char **argv)
if (!src) if (!src)
DO_EXIT_1("Error opening file %s", infile); DO_EXIT_1("Error opening file %s", infile);
if (cmd == CMD_SIGN || cmd == CMD_REMOVE) {
sink = gsf_output_stdio_new(outfile, NULL); sink = gsf_output_stdio_new(outfile, NULL);
if (!sink) if (!sink)
DO_EXIT_1("Error opening output file %s", outfile); DO_EXIT_1("Error opening output file %s", outfile);
ole = gsf_infile_msole_new(src, NULL); ole = gsf_infile_msole_new(src, NULL);
outole = gsf_outfile_msole_new(sink); outole = gsf_outfile_msole_new(sink);
}
#ifndef NO_MSI_DIGITALSIGNATUREEX #ifndef NO_MSI_DIGITALSIGNATUREEX
/* /*
@ -1948,6 +1955,11 @@ int main(int argc, char **argv)
if (!msi_handle_dir(ole, outole, hash)) { if (!msi_handle_dir(ole, outole, hash)) {
DO_EXIT_0("unable to msi_handle_dir()\n"); DO_EXIT_0("unable to msi_handle_dir()\n");
} }
if (cmd == CMD_REMOVE) {
gsf_output_close(GSF_OUTPUT(outole));
g_object_unref(sink);
}
#else #else
DO_EXIT_1("libgsf is not available, msi support is disabled: %s\n", infile); DO_EXIT_1("libgsf is not available, msi support is disabled: %s\n", infile);
#endif #endif
@ -2260,6 +2272,8 @@ int main(int argc, char **argv)
} }
#ifdef WITH_GSF #ifdef WITH_GSF
} else if (type == FILE_TYPE_MSI) { } else if (type == FILE_TYPE_MSI) {
/* Only output signatures if we're signing. */
if (cmd == CMD_SIGN) {
GsfOutput *child = gsf_outfile_new_child(outole, "\05DigitalSignature", FALSE); GsfOutput *child = gsf_outfile_new_child(outole, "\05DigitalSignature", FALSE);
if (!gsf_output_write(child, len, p)) if (!gsf_output_write(child, len, p))
DO_EXIT_1("Failed to write MSI 'DigitalSignature' signature to %s", infile); DO_EXIT_1("Failed to write MSI 'DigitalSignature' signature to %s", infile);
@ -2275,6 +2289,7 @@ int main(int argc, char **argv)
gsf_output_close(GSF_OUTPUT(outole)); gsf_output_close(GSF_OUTPUT(outole));
g_object_unref(sink); g_object_unref(sink);
}
#endif #endif
} }