]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/certInCrl/certInCrl.cpp
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / clxutils / certInCrl / certInCrl.cpp
1 /*
2 * certInCrl.c - simple "see if cert is in CRL"
3 */
4 #include <security_cdsa_utils/cuFileIo.h>
5 #include <utilLib/common.h>
6 #include <clAppUtils/clutils.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <Security/cssm.h>
11
12 static void usage(char **argv)
13 {
14 printf("Usage: %s certFile crlFile [l=loops]\n", argv[0]);
15 exit(1);
16 }
17
18 int main(int argc, char **argv)
19 {
20 CSSM_DATA cert;
21 CSSM_DATA crl;
22 int rtn;
23 CSSM_CL_HANDLE clHand;
24 CSSM_RETURN crtn;
25 int loops = 1;
26 int loop;
27 int arg;
28
29 if(argc < 3) {
30 usage(argv);
31 }
32 for(arg=3; arg<argc; arg++) {
33 switch(argv[arg][0]) {
34 case 'l':
35 loops = atoi(&argv[arg][2]);
36 break;
37 default:
38 usage(argv);
39 }
40 }
41 unsigned len;
42 rtn = readFile(argv[1], &cert.Data, &len);
43 if(rtn) {
44 printf("Error reading %s; %s\n", argv[1], strerror(rtn));
45 exit(1);
46 }
47 cert.Length = len;
48 rtn = readFile(argv[2], &crl.Data, &len);
49 if(rtn) {
50 printf("Error reading %s; %s\n", argv[1], strerror(rtn));
51 exit(1);
52 }
53 crl.Length = len;
54
55 clHand = clStartup();
56 if(clHand == CSSM_INVALID_HANDLE) {
57 return 1;
58 }
59 CSSM_BOOL found;
60 for(loop=0; loop<loops; loop++) {
61 crtn = CSSM_CL_IsCertInCrl(
62 clHand,
63 &cert,
64 &crl,
65 &found);
66 if(crtn) {
67 printError("CSSM_CL_IsCertInCrl", crtn);
68 goto abort;
69 }
70 if(found) {
71 printf("CertFound TRUE\n");
72 }
73 else {
74 printf("CertFound FALSE\n");
75 }
76 if(loops != 1) {
77 fpurge(stdin);
78 printf("CR to continue, q to quit: ");
79 char c = getchar();
80 if(c == 'q') {
81 break;
82 }
83 }
84 }
85 abort:
86 free(cert.Data);
87 free(crl.Data);
88 return 0;
89 }
90