-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for adding VBA project signatures:
- workbook: add function workbook_add_vba_project_signature incl. documentation - packager: copy vbaProjectSignature.bin, create vbaProject.bin.rels - add functional test test_macro_signed - add examples/macro_signed - fix examples/vbaProject.bin: was corrupted; now the button press works again; VBA project is signed by "VBA Code Signing" - add examples/vbaProjectSignature.bin: contains "VBA Code Signing" certificate; based on dev/vba_code_signing/certificate.pfx (use import_certificate.ps1 to install on your computer to test VBA project is actually signed in Excel) - add dev/vba_code_signing: utilities for creating, exporting, and importing VBA code signing certificates
- Loading branch information
Showing
15 changed files
with
263 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/***************************************************************************** | ||
* | ||
* An example of adding signed macros to a libxlsxwriter file using a VBA | ||
* project file and a VBA project signature file extracted from an existing | ||
* Excel .xlsm file. | ||
* | ||
* The vba_extract.py utility from the libxlsxwriter examples directory can be | ||
* used to extract the vbaProject.bin file and the vbaProjectSignature.bin file | ||
* (if the macros were signed). | ||
* | ||
* This example connects the macro to a button (the only Excel/VBA form object | ||
* supported by libxlsxwriter) but that isn't a requirement for adding a macro | ||
* file to the workbook. | ||
* | ||
* Copyright 2014-2021, John McNamara, [email protected] | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
int main() { | ||
|
||
/* Note the xlsm extension of the filename */ | ||
lxw_workbook *workbook = workbook_new("macro_signed.xlsm"); | ||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); | ||
|
||
worksheet_set_column(worksheet, COLS("A:A"), 30, NULL); | ||
|
||
/* Add a macro file extracted from an Excel workbook. */ | ||
workbook_add_vba_project(workbook, "vbaProject.bin"); | ||
|
||
/* Add a VBA project signature file extracted from an Excel workbook. */ | ||
workbook_add_vba_project_signature(workbook, "vbaProjectSignature.bin"); | ||
|
||
worksheet_write_string(worksheet, 2, 0, "Press the button to say hello.", NULL); | ||
|
||
lxw_button_options options = {.caption = "Press Me", .macro = "say_hello", | ||
.width = 80, .height = 30}; | ||
|
||
worksheet_insert_button(worksheet, 2, 1, &options); | ||
|
||
|
||
return workbook_close(workbook); | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/***************************************************************************** | ||
* Test cases for libxlsxwriter. | ||
* | ||
* Test to compare output against Excel files. | ||
* | ||
* Copyright 2014-2022, John McNamara, [email protected] | ||
* | ||
*/ | ||
|
||
#include "xlsxwriter.h" | ||
|
||
int main() { | ||
|
||
lxw_workbook *workbook = workbook_new("test_macro_signed.xlsm"); | ||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "Foo"); | ||
|
||
workbook_add_vba_project(workbook, "images/vbaProject05.bin"); | ||
workbook_add_vba_project_signature(workbook, "images/vbaProject05Signature.bin"); | ||
|
||
worksheet_set_column(worksheet, COLS("A:A"), 30, NULL); | ||
worksheet_write_string(worksheet, 2, 0, "Press the button to say hello.", NULL); | ||
|
||
lxw_button_options options = { .caption = "Press Me", .macro = "say_hello", | ||
.width = 80, .height = 30 }; | ||
|
||
worksheet_insert_button(worksheet, 2, 1, &options); | ||
|
||
return workbook_close(workbook); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.