forked from ukoloff/win-ca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroots.c
35 lines (31 loc) · 784 Bytes
/
roots.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <Windows.h>
#include <stdio.h>
#include <Wincrypt.h>
static void dumpStore(const char*);
int main(int argc, char* argv[]) {
if (argc > 1) {
for (int i = 1; i < argc; ++i) {
dumpStore(argv[i]);
}
} else {
dumpStore("ROOT");
}
return 0;
}
static void dumpStore(const char* title) {
HCERTSTORE hStore = CertOpenSystemStoreA(0, title);
for (PCCERT_CONTEXT pCtx = 0;
pCtx = CertEnumCertificatesInStore(hStore, pCtx);) {
DWORD i;
BYTE* p;
for (i = pCtx->cbCertEncoded, p = pCtx->pbCertEncoded; i--; ++p) {
BYTE c = *p;
for (int i = 0; i < 2; ++i, c <<= 4) {
BYTE nibble = c >> 4;
putchar(nibble < 10 ? nibble + '0' : nibble + 'a' - 10);
}
}
puts("");
}
CertCloseStore(hStore, 0);
}