]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/NISCC/TLS_SSL/skipThisNisccCert/skipThisNisccCert.cpp
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / clxutils / NISCC / TLS_SSL / skipThisNisccCert / skipThisNisccCert.cpp
1 /*
2 * skipThisNisccCert.cpp - decide whether to use specified NISCC cert
3 * in SSL client tests.
4 */
5 #include <Security/cuFileIo.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <sys/param.h>
13
14 /*
15 * Currently, SecureTransport does not fragment protocol messages
16 * into record-size chunks. Max record size is 16K so our max cert
17 * size is a little less than that.
18 */
19 #define MAX_CERT_SIZE (16 * 1024)
20
21 static void usage(char **argv)
22 {
23 printf("usage: %s file\n", argv[0]);
24 exit(1);
25 }
26
27 /*
28 * Known file names to NOT parse
29 */
30 static const char *skipTheseFiles[] =
31 {
32 /* standard entries */
33 ".",
34 "..",
35 "CVS",
36 /* the certs we know seem to be fine */
37 #if 0
38 /* handled OK by the client now */
39 "00000023",
40 "00000098",
41 "00000116",
42 "00000117",
43 #endif
44 /* certs with undiagnosed problems */
45 NULL
46 };
47
48 /* returns true if specified fileName is in skipTheseFiles[] */
49 static bool shouldWeSkip(
50 const char *fullPath) // C string
51 {
52 /* strip off leading path components */
53 const char *lastSlash = NULL;
54 const char *cp;
55 for(cp=fullPath; *cp!=NULL; cp++) {
56 if(*cp == '/') {
57 lastSlash = cp;
58 }
59 }
60 if(lastSlash == NULL) {
61 /* no slashes, use full caller-specified filename */
62 cp = fullPath;
63 }
64 else {
65 /* start one char after last '/' */
66 cp++;
67 }
68 char fileName[MAXPATHLEN];
69 strcpy(fileName, cp);
70
71 for(const char **stf=skipTheseFiles; *stf!=NULL; stf++) {
72 const char *tf = *stf;
73 if(!strcmp(fileName, *stf)) {
74 return true;
75 }
76 }
77 return false;
78 }
79
80 int main(int argc, char **argv)
81 {
82 if(argc != 2 ) {
83 usage(argv);
84 }
85
86 /* in hard-coded list of files to skip? */
87 const char *filename = argv[1];
88 if(shouldWeSkip(filename)) {
89 exit(1);
90 }
91
92 /* file size too big? */
93 struct stat sb;
94 if(stat(filename, &sb)) {
95 perror(filename);
96 exit(2);
97 }
98 if(sb.st_size > MAX_CERT_SIZE) {
99 exit(1);
100 }
101
102 exit(0);
103 }
104