Mercurial > trustbridge
comparison cinst/windowsstore.c @ 219:57bef180d560
Add debug output and make windowsstore linkable from C++ code
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 20:16:50 +0100 |
parents | 8fb12af98960 |
children | 53ea9b975d1c |
comparison
equal
deleted
inserted
replaced
218:8fb12af98960 | 219:57bef180d560 |
---|---|
30 if (!bufPtr) | 30 if (!bufPtr) |
31 printf ("Error getting last error for code: %lx \n", err); | 31 printf ("Error getting last error for code: %lx \n", err); |
32 return bufPtr; | 32 return bufPtr; |
33 } | 33 } |
34 | 34 |
35 static void | 35 void |
36 do_remove(HCERTSTORE hStore, char **to_remove) | 36 do_remove(HCERTSTORE hStore, char **to_remove) |
37 { | 37 { |
38 PCCERT_CONTEXT pCert = NULL; | 38 PCCERT_CONTEXT pCert = NULL; |
39 unsigned int i = 0; | 39 unsigned int i = 0; |
40 | 40 |
46 for (i=0; to_remove[i]; i++) | 46 for (i=0; to_remove[i]; i++) |
47 { | 47 { |
48 char *asn1_data = NULL; | 48 char *asn1_data = NULL; |
49 size_t asn1_size = 0; | 49 size_t asn1_size = 0; |
50 int ret = -1; | 50 int ret = -1; |
51 DWORD j; | |
51 PCCERT_CONTEXT pc_to_remove = NULL; | 52 PCCERT_CONTEXT pc_to_remove = NULL; |
52 | 53 |
53 ret = str_base64_decode (&asn1_data, &asn1_size, to_remove[i], | 54 ret = str_base64_decode (&asn1_data, &asn1_size, to_remove[i], |
54 strnlen(to_remove[i], MAX_LINE_LENGTH)); | 55 strnlen(to_remove[i], MAX_LINE_LENGTH)); |
55 /* Decoding / parsing errors in here should not happen at all. | 56 /* Decoding / parsing errors in here should not happen at all. |
59 { | 60 { |
60 printf ("Error base64 certificate.\n"); | 61 printf ("Error base64 certificate.\n"); |
61 continue; | 62 continue; |
62 } | 63 } |
63 | 64 |
65 printf ("Deleting cert %s\n", to_remove[i]); | |
64 pc_to_remove = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT, | 66 pc_to_remove = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT, |
65 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, | 67 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, |
66 (const PBYTE) asn1_data, | 68 (const PBYTE) asn1_data, |
67 (DWORD) asn1_size, | 69 (DWORD) asn1_size, |
68 0, | 70 0, |
84 0, | 86 0, |
85 CERT_FIND_EXISTING, | 87 CERT_FIND_EXISTING, |
86 pc_to_remove, | 88 pc_to_remove, |
87 NULL); | 89 NULL); |
88 | 90 |
91 | |
92 { | |
93 char pszNameString[256]; | |
94 if(CertGetNameString( | |
95 pc_to_remove, | |
96 CERT_NAME_SIMPLE_DISPLAY_TYPE, | |
97 0, | |
98 NULL, | |
99 pszNameString, | |
100 128)) | |
101 { | |
102 printf("wanted: %s \n",pszNameString); | |
103 } | |
104 if(CertGetNameString( | |
105 pCert, | |
106 CERT_NAME_SIMPLE_DISPLAY_TYPE, | |
107 0, | |
108 NULL, | |
109 pszNameString, | |
110 128)) | |
111 { | |
112 printf("got: %s \n",pszNameString); | |
113 } | |
114 } | |
115 | |
89 CertFreeCertificateContext (pc_to_remove); | 116 CertFreeCertificateContext (pc_to_remove); |
90 | 117 |
91 if (pCert == NULL) | 118 if (pCert == NULL) |
92 { | 119 { |
93 printf ("Did not find certificate\n"); | 120 printf ("Did not find certificate\n"); |
94 continue; | 121 continue; |
95 } | 122 } |
123 for (j = 0; j < pCert->cbCertEncoded; j++) { | |
124 if (asn1_data[j] != pCert->pbCertEncoded[j]) { | |
125 printf("%1x", (unsigned)(unsigned char)pCert->pbCertEncoded[j]); | |
126 } | |
127 } | |
128 printf("\nWanted: \n"); | |
129 for (j = 0; j < pCert->cbCertEncoded; j++) { | |
130 if (asn1_data[j] != pCert->pbCertEncoded[j]) { | |
131 printf("%1x", (unsigned)(unsigned char)asn1_data[j]); | |
132 } | |
133 } | |
134 printf("\n"); | |
96 | 135 |
97 if (!CertDeleteCertificateFromStore (pCert)) | 136 if (!CertDeleteCertificateFromStore (pCert)) |
98 { | 137 { |
99 /* From MSDN: | 138 /* From MSDN: |
100 The CertDeleteCertificateFromStore function always frees | 139 The CertDeleteCertificateFromStore function always frees |
107 } | 146 } |
108 } | 147 } |
109 return; | 148 return; |
110 } | 149 } |
111 | 150 |
112 static void | 151 void |
113 do_install(HCERTSTORE hStore, char **to_install) | 152 do_install(HCERTSTORE hStore, char **to_install) |
114 { | 153 { |
115 int i = 0, | 154 int i = 0, |
116 ret = -1; | 155 ret = -1; |
117 | 156 |