Hi, On Thu, Mar 23, 2023 at 10:31 AM Frank Lichtenheld <fr...@lichtenheld.com> wrote:
> Currently this is not obvious since we never build the > UTs with MSVC, but it doesn't like the initializers with > "const" variables. They cause > error C2099: initializer is not a constant > when used in an initializer. > So change all of them to preprocessor defines instead. > > It also doesn't like the empty initializer. > error C2059: syntax error: '}' > > CC: Selva Nair <selva.n...@gmail.com> > Signed-off-by: Frank Lichtenheld <fr...@lichtenheld.com> > --- > tests/unit_tests/openvpn/cert_data.h | 240 +++++++++++----------- > tests/unit_tests/openvpn/test_cryptoapi.c | 10 +- > tests/unit_tests/openvpn/test_pkcs11.c | 10 +- > 3 files changed, 127 insertions(+), 133 deletions(-) > > Notes: > * this is an prereq for my CMake patch but is otherwise independent, > so submitting separately > * this is on top of Selva's "Unit tests: Test for PKCS#11 using a > softhsm2 token" > > diff --git a/tests/unit_tests/openvpn/cert_data.h > b/tests/unit_tests/openvpn/cert_data.h > index 33de35ec..359718bb 100644 > --- a/tests/unit_tests/openvpn/cert_data.h > +++ b/tests/unit_tests/openvpn/cert_data.h > @@ -36,131 +36,125 @@ > */ > ... > /* sample-ec.crt */ > +#define cd_cert1 "-----BEGIN CERTIFICATE-----\n" \ > + "MIIClzCCAX+gAwIBAgIRAIJr3cy95V63CPEtaAA8JN4wDQYJKoZIhvcNAQELBQAw\n" \ > + "GDEWMBQGA1UEAwwNT1ZQTiBURVNUIENBMTAgFw0yMzAzMTMxNjExMjhaGA8yMTIz\n" \ > + "MDIxNzE2MTEyOFowGDEWMBQGA1UEAwwNb3Zwbi10ZXN0LWVjMTBZMBMGByqGSM49\n" \ > + "AgEGCCqGSM49AwEHA0IABHhJG+dK4Z0mY+K0pupwVtyDLOwwGWHjBY6u3LgjRmUh\n" \ > + "fFjaoSfJvdgrPg50wbOkrsUt9Bl6EeDosZuVwuzgRbujgaQwgaEwCQYDVR0TBAIw\n" \ > + "ADAdBgNVHQ4EFgQUPWeU5BEmD8VEOSKeNf9kAvhcVuowUwYDVR0jBEwwSoAU3MLD\n" \ > + "NDOK13DqflQ8ra7FeGBXK06hHKQaMBgxFjAUBgNVBAMMDU9WUE4gVEVTVCBDQTGC\n" \ > + "FD55ErHXpK2JXS3WkfBm0NB1r3vKMBMGA1UdJQQMMAoGCCsGAQUFBwMCMAsGA1Ud\n" \ > + "DwQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEAhH/wOFqP4R+FK5QvU+oW/XacFMku\n" \ > + "+qT8lL9J7BG28WhZ0ZcAy/AmtnyynkDyuZSwnlzGgJ5m4L/RfwTzJKhEHiSU3BvB\n" \ > + "5C1Z1Q8k67MHSfb565iCn8GzPUQLK4zsILCoTkJPvimv2bJ/RZmNaD+D4LWiySD4\n" \ > + "tuOEdHKrxIrbJ5eAaN0WxRrvDdwGlyPvbMFvfhXzd/tbkP4R2xvlm7S2DPeSTJ8s\n" \ > + "srXMaPe0lAea4etMSZsjIRPwGRMXBrwbRmb6iN2Cq40867HdaJoAryYig7IiDwSX\n" \ > + "htCbOA6sX+60+FEOYDEx5cmkogl633Pw7LJ3ICkyzIrUSEt6BOT1Gsc1eQ==\n" \ > + "-----END CERTIFICATE-----\n" > I would like to avoid such long preprocessor #defines with continuation lines. Would the attached small patch be acceptable instead? It covers only test_cryptoapi --- if this will do, I can incorporate similar changes for test_pkcs11 into a v2 of the relevant patch as those have not been ACK-ed yet. > --- a/tests/unit_tests/openvpn/test_pkcs11.c > +++ b/tests/unit_tests/openvpn/test_pkcs11.c > @@ -113,11 +113,11 @@ static struct test_cert > uint8_t hash[HASHSIZE]; /* SHA1 fingerprint: computed and > filled in later */ > char *p11_id; /* PKCS#11 id -- filled in later > */ > } certs[] = { > - {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", {}, > NULL}, > - {cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", {}, > NULL}, > - {cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", {}, > NULL}, > - {cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", {}, > NULL}, > - {} > + {cd_cert1, cd_key1, cd_cname1, "OVPN TEST CA1", "OVPN Test Cert > 1", {}, NULL}, > Isn't it necessary to change these {} to {0} as well? The build may not report it now as we haven't yet enabled test_pkcs11 on Windows. > + {cd_cert2, cd_key2, cd_cname2, "OVPN TEST CA2", "OVPN Test Cert > 2", {}, NULL}, > + {cd_cert3, cd_key3, cd_cname3, "OVPN TEST CA1", "OVPN Test Cert > 3", {}, NULL}, > + {cd_cert4, cd_key4, cd_cname4, "OVPN TEST CA2", "OVPN Test Cert > 4", {}, NULL}, > + {NULL, NULL, NULL, NULL, NULL, > {}, NULL} > A single {0} should be enough here as well. Selva
From 08d4813fdc3c90969c49dc07be529111a7e84ac4 Mon Sep 17 00:00:00 2001 From: Selva Nair <selva.nair@gmail.com> Date: Thu, 23 Mar 2023 23:24:38 -0400 Subject: [PATCH 1/2] Make cert_data.h and test_cryptoapi.c MSVC compliant - Do not use non-literal initializers for static objects - Replace empty initializer {} by {0} Signed-off-by: Selva Nair <selva.nair@gmail.com> --- tests/unit_tests/openvpn/cert_data.h | 6 +++--- tests/unit_tests/openvpn/test_cryptoapi.c | 24 ++++++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/unit_tests/openvpn/cert_data.h b/tests/unit_tests/openvpn/cert_data.h index 33de35ec..0886b071 100644 --- a/tests/unit_tests/openvpn/cert_data.h +++ b/tests/unit_tests/openvpn/cert_data.h @@ -79,7 +79,7 @@ static const char *const cert2 = "HeTsAlHjfFEReVDiNCI9vMQLKFKKWnAorT2+iyRueA3bt2gchf863BBhZvJddL7Q\n" "KBa0osXw+eGBRAwsm7m1qCho3b3fN2nFAa+k07ptRkOeablmFdXE81nVlA==\n" "-----END CERTIFICATE-----\n"; -static const char *const key2 = key1; +#define key2 key1 static const char *const hash2 = "FA18FD34BAABE47D6E2910E080F421C109CA97F5"; static const char *const cname2 = "ovpn-test-ec2"; @@ -159,8 +159,8 @@ static const char *const cert4 = "353PpJJ9s2b/Fqoc4d7udqhQogA7jqbayTKhJxbT134l2NzqDROzuS0kXbX8bXCi\n" "mXSa4c8=\n" "-----END CERTIFICATE-----\n"; -static const char *const key4 = key3; +#define key4 key3 static const char *const hash4 = "E1401D4497C944783E3D62CDBD2A1F69F5E5071E"; -static const char *const cname4 = cname3; /* same CN as that of cert3 */ +#define cname4 cname3 /* same CN as that of cert3 */ #endif /* CERT_DATA_H */ diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tests/openvpn/test_cryptoapi.c index c8468103..2150b77c 100644 --- a/tests/unit_tests/openvpn/test_cryptoapi.c +++ b/tests/unit_tests/openvpn/test_cryptoapi.c @@ -99,17 +99,26 @@ static struct test_cert const char *const friendly_name; /* identifies certs loaded to the store -- keep unique */ const char *hash; /* SHA1 fingerprint */ int valid; /* nonzero if certificate has not expired */ -} certs[] = { - {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", hash1, 1}, - {cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", hash2, 1}, - {cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", hash3, 1}, - {cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0}, - {} -}; +} certs[5]; static bool certs_loaded; static HCERTSTORE user_store; +/* Fill-in certs[] array */ +void +init_cert_data() +{ + struct test_cert certs_local[] = { + {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", hash1, 1}, + {cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", hash2, 1}, + {cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", hash3, 1}, + {cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0}, + {0} + }; + assert(sizeof(certs_local) == sizeof(certs)); + memcpy(certs, certs_local, sizeof(certs_local)); +} + /* Lookup a certificate in our certificate/key db */ static struct test_cert * lookup_cert(const char *friendly_name) @@ -131,6 +140,7 @@ import_certs(void **state) { return; } + init_cert_data(); user_store = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER |CERT_STORE_OPEN_EXISTING_FLAG, L"MY"); assert_non_null(user_store); -- 2.34.1
_______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel