- packager: add signature specific files/contents if workbook->vba_project_signature is set

- vba_project is always set if vba_project_signature is set due to new function workbook_add_signed_vba_project
- rename functional test_macro_signed to test_macro04
- remove dev/vba_code_signing, will be part of Python lib
- remove trailing spaces
This commit is contained in:
Holger Hoffmann 2023-09-20 18:09:17 +02:00
parent a744934058
commit a733212990
9 changed files with 12 additions and 31 deletions

Binary file not shown.

View File

@ -1,11 +0,0 @@
# Generate new self-signed certificate for code signing (-Type CodeSigningCert) and add it to current user's certificates (Cert:\CurrentUser\My)
# The private key is allowed to be exported by specifying -KeyExportPolicy Exportable.
$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Subject "CN=VBA Code Signing" -KeyAlgorithm RSA -KeyLength 2048 -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -KeyExportPolicy Exportable -KeyUsage DigitalSignature -Type CodeSigningCert
# Export certificate and private key to .pfx file. The private key is protected by a password.
$pwd = ConvertTo-SecureString -String "xlsxwriter" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath certificate.pfx -Password $pwd
# Import the certificate also as trusted root certificate.
# A popup window will occur when not running as administrator. The warning should be confirmed.
Import-PfxCertificate certificate.pfx -CertStoreLocation Cert:\CurrentUser\Root -Exportable -Password $pwd

View File

@ -1,6 +0,0 @@
# import certificate.pfx for current user
$pwd = ConvertTo-SecureString -String "xlsxwriter" -Force -AsPlainText
Import-PfxCertificate certificate.pfx -CertStoreLocation Cert:\CurrentUser\My -Exportable -Password $pwd
# import certificate.pfx also as trusted root certificate
Import-PfxCertificate certificate.pfx -CertStoreLocation Cert:\CurrentUser\Root -Exportable -Password $pwd

View File

@ -160,7 +160,7 @@ To add these files to the libxlsxwriter workbook use the
`workbook_add_signed_vba_project()` function: `workbook_add_signed_vba_project()` function:
@code @code
workbook_add_signed_vba_project(workbook, workbook_add_signed_vba_project(workbook,
"./vbaProject.bin", "./vbaProjectSignature.bin"); "./vbaProject.bin", "./vbaProjectSignature.bin");
@endcode @endcode

View File

@ -987,16 +987,16 @@ lxw_error workbook_add_vba_project(lxw_workbook *workbook,
const char *filename); const char *filename);
/** /**
* @brief Add a vbaProject binary and a vbaProjectSignature binary to the Excel * @brief Add a vbaProject binary and a vbaProjectSignature binary to the Excel
* workbook. * workbook.
* *
* @param workbook Pointer to a lxw_workbook instance. * @param workbook Pointer to a lxw_workbook instance.
* @param vba_project The path/filename of the vbaProject.bin file. * @param vba_project The path/filename of the vbaProject.bin file.
* @param signature The path/filename of the vbaProjectSignature.bin file. * @param signature The path/filename of the vbaProjectSignature.bin file.
* *
* The `%workbook_add_signed_vba_project()` function can be used to add digitally * The `%workbook_add_signed_vba_project()` function can be used to add digitally
* signed macros or functions to a workbook. The function adds a binary VBA project * signed macros or functions to a workbook. The function adds a binary VBA project
* file and a binary VBA project signature file that have been extracted from an * file and a binary VBA project signature file that have been extracted from an
* existing Excel xlsm file with digitally signed macros: * existing Excel xlsm file with digitally signed macros:
* *
* @code * @code

View File

@ -462,8 +462,6 @@ _add_vba_project_signature(lxw_packager *self)
if (!workbook->vba_project_signature) if (!workbook->vba_project_signature)
return LXW_NO_ERROR; return LXW_NO_ERROR;
if (!workbook->vba_project)
return LXW_NO_ERROR; // no VBA project: do not add signature
/* Check that the image file exists and can be opened. */ /* Check that the image file exists and can be opened. */
image_stream = lxw_fopen(workbook->vba_project_signature, "rb"); image_stream = lxw_fopen(workbook->vba_project_signature, "rb");
@ -1275,7 +1273,7 @@ _write_content_types_file(lxw_packager *self)
lxw_ct_add_override(content_types, "/xl/workbook.xml", lxw_ct_add_override(content_types, "/xl/workbook.xml",
LXW_APP_DOCUMENT "spreadsheetml.sheet.main+xml"); LXW_APP_DOCUMENT "spreadsheetml.sheet.main+xml");
if (workbook->vba_project && workbook->vba_project_signature) if (workbook->vba_project_signature)
lxw_ct_add_override(content_types, "/xl/vbaProjectSignature.bin", lxw_ct_add_override(content_types, "/xl/vbaProjectSignature.bin",
"application/vnd.ms-office.vbaProjectSignature"); "application/vnd.ms-office.vbaProjectSignature");
@ -1684,7 +1682,7 @@ _write_vba_project_rels_file(lxw_packager *self)
char *buffer = NULL; char *buffer = NULL;
size_t buffer_size = 0; size_t buffer_size = 0;
if (!workbook->vba_project || !workbook->vba_project_signature) if (!workbook->vba_project_signature)
return LXW_NO_ERROR; return LXW_NO_ERROR;
rels = lxw_relationships_new(); rels = lxw_relationships_new();

View File

@ -11,11 +11,11 @@
int main() { int main() {
lxw_workbook *workbook = workbook_new("test_macro_signed.xlsm"); lxw_workbook *workbook = workbook_new("test_macro04.xlsm");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "Foo"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "Foo");
workbook_add_signed_vba_project(workbook, workbook_add_signed_vba_project(workbook,
"images/vbaProject05.bin", "images/vbaProject05.bin",
"images/vbaProject05Signature.bin"); "images/vbaProject05Signature.bin");
worksheet_set_column(worksheet, COLS("A:A"), 30, NULL); worksheet_set_column(worksheet, COLS("A:A"), 30, NULL);

View File

@ -22,5 +22,5 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_macro03(self): def test_macro03(self):
self.run_exe_test('test_macro03', 'macro03.xlsm') self.run_exe_test('test_macro03', 'macro03.xlsm')
def test_macro_signed(self): def test_macro04(self):
self.run_exe_test('test_macro_signed', 'macro_signed.xlsm') self.run_exe_test('test_macro04', 'macro04.xlsm')