# HG changeset patch # User Andre Heinecke # Date 1395861410 -3600 # Node ID 57bef180d5607275fd638aacc4accd1c96f043bb # Parent 8fb12af98960f63c1fb573cfd3dc1e23c48f764a Add debug output and make windowsstore linkable from C++ code diff -r 8fb12af98960 -r 57bef180d560 cinst/windowsstore.c --- a/cinst/windowsstore.c Wed Mar 26 20:15:56 2014 +0100 +++ b/cinst/windowsstore.c Wed Mar 26 20:16:50 2014 +0100 @@ -32,7 +32,7 @@ return bufPtr; } -static void +void do_remove(HCERTSTORE hStore, char **to_remove) { PCCERT_CONTEXT pCert = NULL; @@ -48,6 +48,7 @@ char *asn1_data = NULL; size_t asn1_size = 0; int ret = -1; + DWORD j; PCCERT_CONTEXT pc_to_remove = NULL; ret = str_base64_decode (&asn1_data, &asn1_size, to_remove[i], @@ -61,6 +62,7 @@ continue; } + printf ("Deleting cert %s\n", to_remove[i]); pc_to_remove = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, (const PBYTE) asn1_data, @@ -86,6 +88,31 @@ pc_to_remove, NULL); + + { + char pszNameString[256]; + if(CertGetNameString( + pc_to_remove, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + NULL, + pszNameString, + 128)) + { + printf("wanted: %s \n",pszNameString); + } + if(CertGetNameString( + pCert, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + NULL, + pszNameString, + 128)) + { + printf("got: %s \n",pszNameString); + } + } + CertFreeCertificateContext (pc_to_remove); if (pCert == NULL) @@ -93,6 +120,18 @@ printf ("Did not find certificate\n"); continue; } + for (j = 0; j < pCert->cbCertEncoded; j++) { + if (asn1_data[j] != pCert->pbCertEncoded[j]) { + printf("%1x", (unsigned)(unsigned char)pCert->pbCertEncoded[j]); + } + } + printf("\nWanted: \n"); + for (j = 0; j < pCert->cbCertEncoded; j++) { + if (asn1_data[j] != pCert->pbCertEncoded[j]) { + printf("%1x", (unsigned)(unsigned char)asn1_data[j]); + } + } + printf("\n"); if (!CertDeleteCertificateFromStore (pCert)) { @@ -109,7 +148,7 @@ return; } -static void +void do_install(HCERTSTORE hStore, char **to_install) { int i = 0, diff -r 8fb12af98960 -r 57bef180d560 cinst/windowsstore.h --- a/cinst/windowsstore.h Wed Mar 26 20:15:56 2014 +0100 +++ b/cinst/windowsstore.h Wed Mar 26 20:16:50 2014 +0100 @@ -2,6 +2,10 @@ #ifndef WINDOWSSTORE_H #define WINDOWSSTORE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -18,5 +22,15 @@ int write_stores_win (char **to_install, char **to_remove, bool user_store); +/* The do_ functions are private helper functions and should not be used + * from other code. They are not static to allow it to use them directly + * in unit tests */ +void do_remove(HCERTSTORE hStore, char **to_remove); +void do_install(HCERTSTORE hStore, char **to_install); + +#ifdef __cplusplus +} +#endif + #endif // WINDOWSSTORE_H #endif // WIN32