]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/vfyCert/vfyCert.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / clxutils / vfyCert / vfyCert.c
1 /*
2 * vfyCert.c - simple "verify one cert with another"
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 rootCertFile [subjCertFile]\n", argv[0]);
15 exit(1);
16 }
17
18 int main(int argc, char **argv)
19 {
20 CSSM_DATA rootCert;
21 CSSM_DATA subjCert;
22 int rtn;
23 CSSM_CL_HANDLE clHand;
24 CSSM_RETURN crtn;
25 char *subjName;
26 unsigned len;
27
28 if((argc < 2) || (argc > 3)) {
29 usage(argv);
30 }
31 rtn = readFile(argv[1], &rootCert.Data, &len);
32 if(rtn) {
33 printf("Error reading %s; %s\n", argv[1], strerror(rtn));
34 exit(1);
35 }
36 rootCert.Length = len;
37
38 if(argc == 2) {
39 subjName = argv[1]; // vfy a root cert
40 }
41 else {
42 subjName = argv[2];
43 }
44 rtn = readFile(subjName, &subjCert.Data, (unsigned *)&subjCert.Length);
45 if(rtn) {
46 printf("Error reading %s; %s\n", argv[1], strerror(rtn));
47 exit(1);
48 }
49 clHand = clStartup();
50 if(clHand == CSSM_INVALID_HANDLE) {
51 return 1;
52 }
53 crtn = CSSM_CL_CertVerify(
54 clHand,
55 CSSM_INVALID_HANDLE, // CCHandle
56 &subjCert,
57 &rootCert,
58 NULL, // VerifyScope
59 0); // ScopeSize
60 if(crtn) {
61 printError("CSSM_CL_CertVerify", crtn);
62 }
63 else {
64 printf("cert %s verifies OK\n", subjName);
65 }
66 return 0;
67 }
68