Overview
Comment: | Simplified test code for AFL and added it to the Makefile |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
79322b800c9e73918ca0b071926b9867 |
User & Date: | rkeene on 2015-07-27 15:41:04 |
Other Links: | manifest | tags |
Context
2015-08-30
| ||
03:21 | Updated to use older mechanism for activating gzip support in zlib, to support zlib older than zlib 1.2.4 check-in: ce2ae07c02 user: rkeene tags: trunk | |
2015-07-27
| ||
15:41 | Simplified test code for AFL and added it to the Makefile check-in: 79322b800c user: rkeene tags: trunk | |
2015-07-24
| ||
15:11 | Better cleanup now that we exclude some bytes in debug printing buffer check-in: 75b2699549 user: rkeene tags: trunk | |
Changes
Modified .fossil-settings/ignore-glob from [0b3e38b0b6] to [9166d2ec0f].
︙ | ︙ | |||
11 12 13 14 15 16 17 | configure install-sh libcackey_g.so libcackey.so libcackey.syms build/certs test | > > | 11 12 13 14 15 16 17 18 19 | configure install-sh libcackey_g.so libcackey.so libcackey.syms build/certs test test-afl test-afl.data |
Modified Makefile.in from [6f86f7629d] to [a9f033d493].
︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 41 42 43 44 45 | libcackey_g.@SHOBJEXT@: cackey_g.o $(CC) $(SHOBJFLAGS) $(DEBUGCPPFLAGS) $(DEBUGCFLAGS) $(SHOBJLDFLAGS) $(LDFLAGS) -o libcackey_g.@SHOBJEXT@ cackey_g.o $(LIBS) -@WEAKENSYMS@ "libcackey_g.@SHOBJEXT@" test: test.c libcackey_g.@SHOBJEXT@ $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test test.c -Wl,-R,. libcackey_g.@SHOBJEXT@ splint-cackey.txt: cackey.c cackey_builtin_certs.h asn1-x509.c asn1-x509.h config.h splint $(DEBUGCPPFLAGS) -DCACKEY_PARANOID=1 -weak +posixlib -I/usr/include/PCSC -Ipkcs11 cackey.c > splint-cackey.txt install: libcackey.@SHOBJEXT@ -mkdir -p "$(DESTDIR)$(libdir)" rm -f "$(DESTDIR)$(libdir)/libcackey.@SHOBJEXT@" rm -f "$(DESTDIR)$(libdir)/libcackey_g.@SHOBJEXT@" | > > > > > > > > > > > > | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | libcackey_g.@SHOBJEXT@: cackey_g.o $(CC) $(SHOBJFLAGS) $(DEBUGCPPFLAGS) $(DEBUGCFLAGS) $(SHOBJLDFLAGS) $(LDFLAGS) -o libcackey_g.@SHOBJEXT@ cackey_g.o $(LIBS) -@WEAKENSYMS@ "libcackey_g.@SHOBJEXT@" test: test.c libcackey_g.@SHOBJEXT@ $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test test.c -Wl,-R,. libcackey_g.@SHOBJEXT@ test-afl.data: test tmpLogFile='log.$(shell openssl rand -hex 16)'; \ ./test 2> $${tmpLogFile}; \ echo -ne "$$( \ grep 'Returned Value:' $${tmpLogFile} | sed 's@^.*/@@;s@ = {@ @;s@})$$@@;s@,@@g;s@ @\\x@g;s@\\@ \\@' | while IFS=' ' read -r count string; do \ printf '\\x%02x\\x%02x%s' $$[$${count} / 256] $$[$${count} % 256] "$${string}"; \ done \ )" > test-afl.data; rm -f $${tmpLogFile} test-afl: test-afl.data test.c cackey.c cackey_builtin_certs.h sha1.c sha1.h md5.c md5.h asn1-x509.c asn1-x509.h config.h $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DCACKEY_TEST_AFL -o test-afl test.c $(patsubst -lpcsclite,,$(LIBS)) splint-cackey.txt: cackey.c cackey_builtin_certs.h asn1-x509.c asn1-x509.h config.h splint $(DEBUGCPPFLAGS) -DCACKEY_PARANOID=1 -weak +posixlib -I/usr/include/PCSC -Ipkcs11 cackey.c > splint-cackey.txt install: libcackey.@SHOBJEXT@ -mkdir -p "$(DESTDIR)$(libdir)" rm -f "$(DESTDIR)$(libdir)/libcackey.@SHOBJEXT@" rm -f "$(DESTDIR)$(libdir)/libcackey_g.@SHOBJEXT@" |
︙ | ︙ |
Modified test.c from [7dfc56607f] to [b3c16cba8c].
1 2 3 4 5 6 | #include <sys/types.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | #include <sys/types.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #ifdef CACKEY_TEST_AFL #include <sys/types.h> #include <fcntl.h> static unsigned char *inputData; static unsigned long inputDataLen; /* Include the CACKey source */ #include "cackey.c" #undef CACKEY_DEBUG_PRINTF #define CACKEY_DEBUG_PRINTF(x...) /**/ #undef malloc #undef realloc #undef strdup /* Fake a smartcard */ const SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci; static int scard_inTransaction = 0; static LONG scard_protocol; PCSC_API LONG SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext) { CACKEY_DEBUG_PRINTF("Called"); *phContext = 42; return(SCARD_S_SUCCESS); } PCSC_API LONG SCardIsValidContext(SCARDCONTEXT hContext) { CACKEY_DEBUG_PRINTF("Called"); if (hContext != 42) { return(SCARD_E_INVALID_HANDLE); } return(SCARD_S_SUCCESS); } PCSC_API LONG SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders) { static char *readers = "READER0"; CACKEY_DEBUG_PRINTF("Called"); if (hContext != 42) { return(SCARD_E_INVALID_HANDLE); } *pcchReaders = strlen(readers) + 1; if (mszReaders == NULL) { return(SCARD_S_SUCCESS); } memcpy(mszReaders, readers, *pcchReaders); return(SCARD_S_SUCCESS); } PCSC_API LONG SCardBeginTransaction(SCARDHANDLE hCard) { CACKEY_DEBUG_PRINTF("Called"); if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } if (scard_inTransaction) { return(SCARD_E_SHARING_VIOLATION); } scard_inTransaction = 1; return(SCARD_S_SUCCESS); } PCSC_API LONG SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition) { CACKEY_DEBUG_PRINTF("Called"); if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } scard_inTransaction = 0; return(SCARD_S_SUCCESS); } PCSC_API LONG SCardStatus(SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) { LONG scardlistreaders_ret; CACKEY_DEBUG_PRINTF("Called"); if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } *pdwState = 0; scardlistreaders_ret = SCardListReaders(42, NULL, mszReaderName, pcchReaderLen); if (scardlistreaders_ret != SCARD_S_SUCCESS) { return(scardlistreaders_ret); } *pdwProtocol = scard_protocol; return(SCARD_S_SUCCESS); } PCSC_API LONG SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) { CACKEY_DEBUG_PRINTF("Called"); if (hContext != 42) { return(SCARD_E_INVALID_HANDLE); } if ((dwPreferredProtocols & SCARD_PROTOCOL_T0) == SCARD_PROTOCOL_T0) { *pdwActiveProtocol = SCARD_PROTOCOL_T0; } else { *pdwActiveProtocol = SCARD_PROTOCOL_T1; } scard_protocol = *pdwActiveProtocol; *phCard = 99; return(SCARD_S_SUCCESS); } PCSC_API LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition) { CACKEY_DEBUG_PRINTF("Called"); if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } return(SCARD_S_SUCCESS); } PCSC_API LONG SCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol) { CACKEY_DEBUG_PRINTF("Called"); if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } return(SCardConnect(42, NULL, dwShareMode, dwPreferredProtocols, NULL, pdwActiveProtocol)); } PCSC_API LONG SCardReleaseContext(SCARDCONTEXT hContext) { CACKEY_DEBUG_PRINTF("Called"); if (hContext != 42) { return(SCARD_E_INVALID_HANDLE); } return(SCARD_S_SUCCESS); } PCSC_API LONG SCardTransmit(SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) { CACKEY_DEBUG_PRINTF("Called"); unsigned int bytesToRead; if (hCard != 99) { return(SCARD_E_INVALID_HANDLE); } if (inputDataLen <= 1) { *pcbRecvLength = 0; return(SCARD_S_SUCCESS); } bytesToRead = (inputData[0] << 8) | inputData[1]; inputData += 2; inputDataLen -= 2; if (bytesToRead > inputDataLen) { bytesToRead = inputDataLen; } if (bytesToRead > *pcbRecvLength) { return(SCARD_E_INSUFFICIENT_BUFFER); } *pcbRecvLength = bytesToRead; memcpy(pbRecvBuffer, inputData, bytesToRead); inputData += bytesToRead; inputDataLen -= bytesToRead; return(SCARD_S_SUCCESS); } static void loadTestData(const char *fileName) { ssize_t read_ret; int fd; if (fileName == NULL) { goto cleanup; } fd = open(fileName, O_RDONLY); if (fd < 0) { goto cleanup; } inputDataLen = 16384; inputData = malloc(inputDataLen); read_ret = read(fd, inputData, inputDataLen); if (read_ret < 0) { goto cleanup; } inputDataLen = read_ret; inputData = realloc(inputData, inputDataLen); close(fd); cleanup: return; } #else #include "mypkcs11.h" static void loadTestData(const char *filename) { return; } #endif static char *pkcs11_attribute_to_name(CK_ATTRIBUTE_TYPE attrib) { static char retbuf[1024]; switch (attrib) { case 0x00000000: return "CKA_CLASS"; case 0x00000001: return "CKA_TOKEN"; |
︙ | ︙ | |||
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | if ((tokenInfo.flags & CKF_LOGIN_REQUIRED) == CKF_LOGIN_REQUIRED && (tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) { fgets_ret = NULL; while (fgets_ret == NULL) { printf("** ENTER PIN: "); fflush(stdout); fgets_ret = fgets((char *) user_pin, sizeof(user_pin), stdin); } if (strlen((char *) user_pin) >= 1) { while (user_pin[strlen((char *) user_pin) - 1] < ' ') { user_pin[strlen((char *) user_pin) - 1] = '\0'; } } | > > > > > | 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | if ((tokenInfo.flags & CKF_LOGIN_REQUIRED) == CKF_LOGIN_REQUIRED && (tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) == 0) { fgets_ret = NULL; while (fgets_ret == NULL) { printf("** ENTER PIN: "); fflush(stdout); #ifdef CACKEY_TEST_AFL memcpy(user_pin, "0000000", 8); fgets_ret = (char *) user_pin; #else fgets_ret = fgets((char *) user_pin, sizeof(user_pin), stdin); #endif } if (strlen((char *) user_pin) >= 1) { while (user_pin[strlen((char *) user_pin) - 1] < ' ') { user_pin[strlen((char *) user_pin) - 1] = '\0'; } } |
︙ | ︙ | |||
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | return(0); } int main(int argc, char **argv) { int retval = 0, ck_retval; printf("Testing libcackey...\n"); ck_retval = main_pkcs11(); if (ck_retval != 0) { retval = ck_retval; } printf("Testing libcackey... DONE. Status = %i\n", ck_retval); return(retval); | > > > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | return(0); } int main(int argc, char **argv) { int retval = 0, ck_retval; printf("Testing libcackey...\n"); if (argc > 1) { loadTestData(argv[1]); } ck_retval = main_pkcs11(); if (ck_retval != 0) { retval = ck_retval; } printf("Testing libcackey... DONE. Status = %i\n", ck_retval); return(retval); } |