diff options
Diffstat (limited to 'extra')
30 files changed, 779 insertions, 709 deletions
diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index f8f71b00743..585b5aef6f6 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -75,11 +75,29 @@ ENDIF() MYSQL_ADD_EXECUTABLE(replace replace.c COMPONENT Server) TARGET_LINK_LIBRARIES(replace mysys) IF(UNIX) - MYSQL_ADD_EXECUTABLE(innochecksum innochecksum.c) - MYSQL_ADD_EXECUTABLE(resolve_stack_dump resolve_stack_dump.c) TARGET_LINK_LIBRARIES(resolve_stack_dump mysys) MYSQL_ADD_EXECUTABLE(mysql_waitpid mysql_waitpid.c COMPONENT Client) TARGET_LINK_LIBRARIES(mysql_waitpid mysys) ENDIF() + + + # Add path to the InnoDB headers + INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/storage/innobase/include + ${CMAKE_SOURCE_DIR}/sql) + + # We use the InnoDB code directly in case the code changes. + ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM") + SET(INNOBASE_SOURCES + ../storage/innobase/buf/buf0checksum.cc + ../storage/innobase/ut/ut0crc32.cc + ../storage/innobase/ut/ut0ut.cc + ../storage/innobase/page/page0zip.cc + ) + + MYSQL_ADD_EXECUTABLE(innochecksum innochecksum.cc ${INNOBASE_SOURCES}) + TARGET_LINK_LIBRARIES(innochecksum mysys mysys_ssl) + ADD_DEPENDENCIES(innochecksum GenError) + diff --git a/extra/comp_err.c b/extra/comp_err.c index f0396bc5878..3fc4b05fa61 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -30,11 +30,11 @@ #include <my_sys.h> #include <m_string.h> #include <my_getopt.h> -#include <assert.h> #include <my_dir.h> -#define MAX_ROWS 1000 +#define MAX_ROWS 2000 #define HEADER_LENGTH 32 /* Length of header in errmsg.sys */ +#define ERRMSG_VERSION 3 /* Version number of errmsg.sys */ #define DEFAULT_CHARSET_DIR "../sql/share/charsets" #define ER_PREFIX "ER_" #define ER_PREFIX2 "MARIA_ER_" @@ -50,9 +50,9 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace"; #endif /* Header for errmsg.sys files */ -uchar file_head[]= { 254, 254, 2, 1 }; +uchar file_head[]= { 254, 254, 2, ERRMSG_VERSION }; /* Store positions to each error message row to store in errmsg.sys header */ -uint file_pos[MAX_ROWS]; +uint file_pos[MAX_ROWS+1]; const char *empty_string= ""; /* For empty states */ /* @@ -371,17 +371,19 @@ static int create_sys_files(struct languages *lang_head, bzero((uchar*) head, HEADER_LENGTH); bmove((uchar *) head, (uchar *) file_head, 4); head[4]= 1; - int2store(head + 6, length); - int2store(head + 8, row_count); + int4store(head + 6, length); + int2store(head + 10, row_count); head[30]= csnum; my_fseek(to, 0l, MY_SEEK_SET, MYF(0)); if (my_fwrite(to, (uchar*) head, HEADER_LENGTH, MYF(MY_WME | MY_FNABP))) goto err; + file_pos[row_count]= (ftell(to) - start_pos); for (i= 0; i < row_count; i++) { - int2store(head, file_pos[i]); + /* Store length of each string */ + int2store(head, file_pos[i+1] - file_pos[i]); if (my_fwrite(to, (uchar*) head, 2, MYF(MY_WME | MY_FNABP))) goto err; } @@ -714,12 +716,12 @@ static ha_checksum checksum_format_specifier(const char* msg) } else if (start) { - switch(*p) - { + switch(*p) { case 'd': case 'u': case 'x': case 's': + case 'M': chksum= my_checksum(chksum, (uchar*) start, (uint) (p + 1 - start)); start= 0; /* Not in format specifier anymore */ break; @@ -894,7 +896,7 @@ static struct errors *generate_empty_message(uint d_code) if (!(new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME)))) return(0); - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 1)) + if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 1, MYF(0))) return(0); /* OOM: Fatal error */ new_error->er_name= NULL; @@ -928,7 +930,7 @@ static struct errors *parse_error_string(char *str, int er_count) MYF(MY_WME)))) DBUG_RETURN(0); - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0)) + if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0, MYF(0))) DBUG_RETURN(0); /* OOM: Fatal error */ /* getting the error name */ diff --git a/extra/innochecksum.c b/extra/innochecksum.c deleted file mode 100644 index ed4dfc48789..00000000000 --- a/extra/innochecksum.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - Copyright (c) 2005, 2011, Oracle and/or its affiliates - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/* - InnoDB offline file checksum utility. 85% of the code in this file - was taken wholesale fron the InnoDB codebase. - - The final 15% was originally written by Mark Smith of Danga - Interactive, Inc. <junior@danga.com> - - Published with a permission. -*/ - -#include <my_global.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -/* all of these ripped from InnoDB code from MySQL 4.0.22 */ -#define UT_HASH_RANDOM_MASK 1463735687 -#define UT_HASH_RANDOM_MASK2 1653893711 -#define FIL_PAGE_LSN 16 -#define FIL_PAGE_FILE_FLUSH_LSN 26 -#define FIL_PAGE_OFFSET 4 -#define FIL_PAGE_DATA 38 -#define FIL_PAGE_END_LSN_OLD_CHKSUM 8 -#define FIL_PAGE_SPACE_OR_CHKSUM 0 -#define UNIV_PAGE_SIZE (2 * 8192) - -/* command line argument to do page checks (that's it) */ -/* another argument to specify page ranges... seek to right spot and go from there */ - -typedef unsigned long int ulint; - -/* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */ -ulint mach_read_from_4(uchar *b) -{ - return( ((ulint)(b[0]) << 24) - + ((ulint)(b[1]) << 16) - + ((ulint)(b[2]) << 8) - + (ulint)(b[3]) - ); -} - -ulint -ut_fold_ulint_pair( -/*===============*/ - /* out: folded value */ - ulint n1, /* in: ulint */ - ulint n2) /* in: ulint */ -{ - return(((((n1 ^ n2 ^ UT_HASH_RANDOM_MASK2) << 8) + n1) - ^ UT_HASH_RANDOM_MASK) + n2); -} - -ulint -ut_fold_binary( -/*===========*/ - /* out: folded value */ - uchar* str, /* in: string of bytes */ - ulint len) /* in: length */ -{ - ulint i; - ulint fold= 0; - - for (i= 0; i < len; i++) - { - fold= ut_fold_ulint_pair(fold, (ulint)(*str)); - - str++; - } - - return(fold); -} - -ulint -buf_calc_page_new_checksum( -/*=======================*/ - /* out: checksum */ - uchar* page) /* in: buffer page */ -{ - ulint checksum; - - /* Since the fields FIL_PAGE_FILE_FLUSH_LSN and ..._ARCH_LOG_NO - are written outside the buffer pool to the first pages of data - files, we have to skip them in the page checksum calculation. - We must also skip the field FIL_PAGE_SPACE_OR_CHKSUM where the - checksum is stored, and also the last 8 bytes of page because - there we store the old formula checksum. */ - - checksum= ut_fold_binary(page + FIL_PAGE_OFFSET, - FIL_PAGE_FILE_FLUSH_LSN - FIL_PAGE_OFFSET) - + ut_fold_binary(page + FIL_PAGE_DATA, - UNIV_PAGE_SIZE - FIL_PAGE_DATA - - FIL_PAGE_END_LSN_OLD_CHKSUM); - checksum= checksum & 0xFFFFFFFF; - - return(checksum); -} - -ulint -buf_calc_page_old_checksum( -/*=======================*/ - /* out: checksum */ - uchar* page) /* in: buffer page */ -{ - ulint checksum; - - checksum= ut_fold_binary(page, FIL_PAGE_FILE_FLUSH_LSN); - - checksum= checksum & 0xFFFFFFFF; - - return(checksum); -} - - -int main(int argc, char **argv) -{ - FILE *f; /* our input file */ - uchar *p; /* storage of pages read */ - int bytes; /* bytes read count */ - ulint ct; /* current page number (0 based) */ - int now; /* current time */ - int lastt; /* last time */ - ulint oldcsum, oldcsumfield, csum, csumfield, logseq, logseqfield; /* ulints for checksum storage */ - struct stat st; /* for stat, if you couldn't guess */ - unsigned long long int size; /* size of file (has to be 64 bits) */ - ulint pages; /* number of pages in file */ - ulint start_page= 0, end_page= 0, use_end_page= 0; /* for starting and ending at certain pages */ - off_t offset= 0; - int just_count= 0; /* if true, just print page count */ - int verbose= 0; - int debug= 0; - int c; - int fd; - - /* remove arguments */ - while ((c= getopt(argc, argv, "cvds:e:p:")) != -1) - { - switch (c) - { - case 'v': - verbose= 1; - break; - case 'c': - just_count= 1; - break; - case 's': - start_page= atoi(optarg); - break; - case 'e': - end_page= atoi(optarg); - use_end_page= 1; - break; - case 'p': - start_page= atoi(optarg); - end_page= atoi(optarg); - use_end_page= 1; - break; - case 'd': - debug= 1; - break; - case ':': - fprintf(stderr, "option -%c requires an argument\n", optopt); - return 1; - break; - case '?': - fprintf(stderr, "unrecognized option: -%c\n", optopt); - return 1; - break; - } - } - - /* debug implies verbose... */ - if (debug) verbose= 1; - - /* make sure we have the right arguments */ - if (optind >= argc) - { - printf("InnoDB offline file checksum utility.\n"); - printf("usage: %s [-c] [-s <start page>] [-e <end page>] [-p <page>] [-v] [-d] <filename>\n", argv[0]); - printf("\t-c\tprint the count of pages in the file\n"); - printf("\t-s n\tstart on this page number (0 based)\n"); - printf("\t-e n\tend at this page number (0 based)\n"); - printf("\t-p n\tcheck only this page (0 based)\n"); - printf("\t-v\tverbose (prints progress every 5 seconds)\n"); - printf("\t-d\tdebug mode (prints checksums for each page)\n"); - return 1; - } - - /* stat the file to get size and page count */ - if (stat(argv[optind], &st)) - { - perror("error statting file"); - return 1; - } - size= st.st_size; - pages= size / UNIV_PAGE_SIZE; - if (just_count) - { - printf("%lu\n", pages); - return 0; - } - else if (verbose) - { - printf("file %s = %llu bytes (%lu pages)...\n", argv[optind], size, pages); - printf("checking pages in range %lu to %lu\n", start_page, use_end_page ? end_page : (pages - 1)); - } - - /* open the file for reading */ - f= fopen(argv[optind], "r"); - if (!f) - { - perror("error opening file"); - return 1; - } - - /* seek to the necessary position */ - if (start_page) - { - fd= fileno(f); - if (!fd) - { - perror("unable to obtain file descriptor number"); - return 1; - } - - offset= (off_t)start_page * (off_t)UNIV_PAGE_SIZE; - - if (lseek(fd, offset, SEEK_SET) != offset) - { - perror("unable to seek to necessary offset"); - return 1; - } - } - - /* allocate buffer for reading (so we don't realloc every time) */ - p= (uchar *)malloc(UNIV_PAGE_SIZE); - - /* main checksumming loop */ - ct= start_page; - lastt= 0; - while (!feof(f)) - { - bytes= fread(p, 1, UNIV_PAGE_SIZE, f); - if (!bytes && feof(f)) return 0; - if (bytes != UNIV_PAGE_SIZE) - { - fprintf(stderr, "bytes read (%d) doesn't match universal page size (%d)\n", bytes, UNIV_PAGE_SIZE); - return 1; - } - - /* check the "stored log sequence numbers" */ - logseq= mach_read_from_4(p + FIL_PAGE_LSN + 4); - logseqfield= mach_read_from_4(p + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM + 4); - if (debug) - printf("page %lu: log sequence number: first = %lu; second = %lu\n", ct, logseq, logseqfield); - if (logseq != logseqfield) - { - fprintf(stderr, "page %lu invalid (fails log sequence number check)\n", ct); - return 1; - } - - /* check old method of checksumming */ - oldcsum= buf_calc_page_old_checksum(p); - oldcsumfield= mach_read_from_4(p + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM); - if (debug) - printf("page %lu: old style: calculated = %lu; recorded = %lu\n", ct, oldcsum, oldcsumfield); - if (oldcsumfield != mach_read_from_4(p + FIL_PAGE_LSN) && oldcsumfield != oldcsum) - { - fprintf(stderr, "page %lu invalid (fails old style checksum)\n", ct); - return 1; - } - - /* now check the new method */ - csum= buf_calc_page_new_checksum(p); - csumfield= mach_read_from_4(p + FIL_PAGE_SPACE_OR_CHKSUM); - if (debug) - printf("page %lu: new style: calculated = %lu; recorded = %lu\n", ct, csum, csumfield); - if (csumfield != 0 && csum != csumfield) - { - fprintf(stderr, "page %lu invalid (fails new style checksum)\n", ct); - return 1; - } - - /* end if this was the last page we were supposed to check */ - if (use_end_page && (ct >= end_page)) - return 0; - - /* do counter increase and progress printing */ - ct++; - if (verbose) - { - if (ct % 64 == 0) - { - now= time(0); - if (!lastt) lastt= now; - if (now - lastt >= 1) - { - printf("page %lu okay: %.3f%% done\n", (ct - 1), (float) ct / pages * 100); - lastt= now; - } - } - } - } - return 0; -} - diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc new file mode 100644 index 00000000000..6018a4884ea --- /dev/null +++ b/extra/innochecksum.cc @@ -0,0 +1,453 @@ +/* + Copyright (c) 2005, 2012, Oracle and/or its affiliates. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + InnoDB offline file checksum utility. 85% of the code in this utility + is included from the InnoDB codebase. + + The final 15% was originally written by Mark Smith of Danga + Interactive, Inc. <junior@danga.com> + + Published with a permission. +*/ + +#include <my_global.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#ifndef __WIN__ +# include <unistd.h> +#endif +#include <my_getopt.h> +#include <m_string.h> +#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ +#include <string.h> + +/* Only parts of these files are included from the InnoDB codebase. +The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */ + +#include "univ.i" /* include all of this */ + +#define FLST_NODE_SIZE (2 * FIL_ADDR_SIZE) +#define FSEG_PAGE_DATA FIL_PAGE_DATA + +#include "ut0ut.h" +#include "ut0byte.h" +#include "mach0data.h" +#include "fsp0types.h" +#include "rem0rec.h" +#include "buf0checksum.h" /* buf_calc_page_*() */ +#include "fil0fil.h" /* FIL_* */ +#include "page0page.h" /* PAGE_* */ +#include "page0zip.h" /* page_zip_*() */ +#include "trx0undo.h" /* TRX_* */ +#include "fsp0fsp.h" /* fsp_flags_get_page_size() & + fsp_flags_get_zip_size() */ +#include "mach0data.h" /* mach_read_from_4() */ +#include "ut0crc32.h" /* ut_crc32_init() */ + +#ifdef UNIV_NONINL +# include "fsp0fsp.ic" +# include "mach0data.ic" +# include "ut0rnd.ic" +#endif + +/* Global variables */ +static my_bool verbose; +static my_bool debug; +static my_bool skip_corrupt; +static my_bool just_count; +static ulong start_page; +static ulong end_page; +static ulong do_page; +static my_bool use_end_page; +static my_bool do_one_page; +ulong srv_page_size; /* replaces declaration in srv0srv.c */ +static ulong physical_page_size; /* Page size in bytes on disk. */ +static ulong logical_page_size; /* Page size when uncompressed. */ +static bool compressed= false; /* Is tablespace compressed */ + +/* Get the page size of the filespace from the filespace header. */ +static +my_bool +get_page_size( +/*==========*/ + FILE* f, /*!< in: file pointer, must be open + and set to start of file */ + byte* buf, /*!< in: buffer used to read the page */ + ulong* logical_page_size, /*!< out: Logical/Uncompressed page size */ + ulong* physical_page_size) /*!< out: Physical/Commpressed page size */ +{ + ulong flags; + + int bytes= fread(buf, 1, UNIV_PAGE_SIZE_MIN, f); + + if (ferror(f)) + { + perror("Error reading file header"); + return FALSE; + } + + if (bytes != UNIV_PAGE_SIZE_MIN) + { + fprintf(stderr, "Error; Was not able to read the minimum page size "); + fprintf(stderr, "of %d bytes. Bytes read was %d\n", UNIV_PAGE_SIZE_MIN, bytes); + return FALSE; + } + + rewind(f); + + flags = mach_read_from_4(buf + FIL_PAGE_DATA + FSP_SPACE_FLAGS); + + /* srv_page_size is used by InnoDB code as UNIV_PAGE_SIZE */ + srv_page_size = *logical_page_size = fsp_flags_get_page_size(flags); + + /* fsp_flags_get_zip_size() will return zero if not compressed. */ + *physical_page_size = fsp_flags_get_zip_size(flags); + if (*physical_page_size == 0) + { + *physical_page_size= *logical_page_size; + } + else + { + compressed= true; + } + return TRUE; +} + + +/* command line argument to do page checks (that's it) */ +/* another argument to specify page ranges... seek to right spot and go from there */ + +static struct my_option innochecksum_options[] = +{ + {"help", '?', "Displays this help and exits.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"info", 'I', "Synonym for --help.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"version", 'V', "Displays version information and exits.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Verbose (prints progress every 5 seconds).", + &verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"debug", 'd', "Debug mode (prints checksums for each page, implies verbose).", + &debug, &debug, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"skip_corrupt", 'u', "Skip corrupt pages.", + &skip_corrupt, &skip_corrupt, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"count", 'c', "Print the count of pages in the file.", + &just_count, &just_count, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"start_page", 's', "Start on this page number (0 based).", + &start_page, &start_page, 0, GET_ULONG, REQUIRED_ARG, + 0, 0, (longlong) 2L*1024L*1024L*1024L, 0, 1, 0}, + {"end_page", 'e', "End at this page number (0 based).", + &end_page, &end_page, 0, GET_ULONG, REQUIRED_ARG, + 0, 0, (longlong) 2L*1024L*1024L*1024L, 0, 1, 0}, + {"page", 'p', "Check only this page (0 based).", + &do_page, &do_page, 0, GET_ULONG, REQUIRED_ARG, + 0, 0, (longlong) 2L*1024L*1024L*1024L, 0, 1, 0}, + {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; + +static void print_version(void) +{ + printf("%s Ver %s, for %s (%s)\n", + my_progname, INNODB_VERSION_STR, + SYSTEM_TYPE, MACHINE_TYPE); +} + +static void usage(void) +{ + print_version(); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000")); + printf("InnoDB offline file checksum utility.\n"); + printf("Usage: %s [-c] [-s <start page>] [-e <end page>] [-p <page>] [-v] [-d] <filename>\n", my_progname); + my_print_help(innochecksum_options); + my_print_variables(innochecksum_options); +} + +extern "C" my_bool +innochecksum_get_one_option( +/*========================*/ + int optid, + const struct my_option *opt __attribute__((unused)), + char *argument __attribute__((unused))) +{ + switch (optid) { + case 'd': + verbose=1; /* debug implies verbose... */ + break; + case 'e': + use_end_page= 1; + break; + case 'p': + end_page= start_page= do_page; + use_end_page= 1; + do_one_page= 1; + break; + case 'V': + print_version(); + exit(0); + break; + case 'I': + case '?': + usage(); + exit(0); + break; + } + return 0; +} + +static int get_options( +/*===================*/ + int *argc, + char ***argv) +{ + int ho_error; + + if ((ho_error=handle_options(argc, argv, innochecksum_options, innochecksum_get_one_option))) + exit(ho_error); + + /* The next arg must be the filename */ + if (!*argc) + { + usage(); + return 1; + } + return 0; +} /* get_options */ + +int main(int argc, char **argv) +{ + FILE* f; /* our input file */ + char* filename; /* our input filename. */ + unsigned char *big_buf= 0, *buf; + + ulong bytes; /* bytes read count */ + ulint ct; /* current page number (0 based) */ + time_t now; /* current time */ + time_t lastt; /* last time */ + ulint oldcsum, oldcsumfield, csum, csumfield, crc32, logseq, logseqfield; + /* ulints for checksum storage */ + struct stat st; /* for stat, if you couldn't guess */ + unsigned long long int size; /* size of file (has to be 64 bits) */ + ulint pages; /* number of pages in file */ + off_t offset= 0; + int fd; + + printf("InnoDB offline file checksum utility.\n"); + + ut_crc32_init(); + + MY_INIT(argv[0]); + + if (get_options(&argc,&argv)) + exit(1); + + if (verbose) + my_print_variables(innochecksum_options); + + /* The file name is not optional */ + filename = *argv; + if (*filename == '\0') + { + fprintf(stderr, "Error; File name missing\n"); + goto error; + } + + /* stat the file to get size and page count */ + if (stat(filename, &st)) + { + fprintf(stderr, "Error; %s cannot be found\n", filename); + goto error; + } + size= st.st_size; + + /* Open the file for reading */ + f= fopen(filename, "rb"); + if (f == NULL) + { + fprintf(stderr, "Error; %s cannot be opened", filename); + perror(" "); + goto error; + } + + big_buf = (unsigned char *)malloc(2 * UNIV_PAGE_SIZE_MAX); + if (big_buf == NULL) + { + fprintf(stderr, "Error; failed to allocate memory\n"); + perror(""); + goto error; + } + + /* Make sure the page is aligned */ + buf = (unsigned char*)ut_align_down(big_buf + + UNIV_PAGE_SIZE_MAX, UNIV_PAGE_SIZE_MAX); + + if (!get_page_size(f, buf, &logical_page_size, &physical_page_size)) + goto error; + + if (compressed) + { + printf("Table is compressed\n"); + printf("Key block size is %lu\n", physical_page_size); + } + else + { + printf("Table is uncompressed\n"); + printf("Page size is %lu\n", physical_page_size); + } + + pages= (ulint) (size / physical_page_size); + + if (just_count) + { + if (verbose) + printf("Number of pages: "); + printf("%lu\n", pages); + goto ok; + } + else if (verbose) + { + printf("file %s = %llu bytes (%lu pages)...\n", filename, size, pages); + if (do_one_page) + printf("InnoChecksum; checking page %lu\n", do_page); + else + printf("InnoChecksum; checking pages in range %lu to %lu\n", start_page, use_end_page ? end_page : (pages - 1)); + } + +#ifdef UNIV_LINUX + if (posix_fadvise(fileno(f), 0, 0, POSIX_FADV_SEQUENTIAL) || + posix_fadvise(fileno(f), 0, 0, POSIX_FADV_NOREUSE)) + { + perror("posix_fadvise failed"); + } +#endif + + /* seek to the necessary position */ + if (start_page) + { + fd= fileno(f); + if (!fd) + { + perror("Error; Unable to obtain file descriptor number"); + goto error; + } + + offset= (off_t)start_page * (off_t)physical_page_size; + + if (lseek(fd, offset, SEEK_SET) != offset) + { + perror("Error; Unable to seek to necessary offset"); + goto error; + } + } + + /* main checksumming loop */ + ct= start_page; + lastt= 0; + while (!feof(f)) + { + bytes= fread(buf, 1, physical_page_size, f); + if (!bytes && feof(f)) + goto ok; + + if (ferror(f)) + { + fprintf(stderr, "Error reading %lu bytes", physical_page_size); + perror(" "); + goto error; + } + + if (compressed) { + /* compressed pages */ + if (!page_zip_verify_checksum(buf, physical_page_size)) { + fprintf(stderr, "Fail; page %lu invalid (fails compressed page checksum).\n", ct); + if (!skip_corrupt) + goto error; + } + } else { + + /* check the "stored log sequence numbers" */ + logseq= mach_read_from_4(buf + FIL_PAGE_LSN + 4); + logseqfield= mach_read_from_4(buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM + 4); + if (debug) + printf("page %lu: log sequence number: first = %lu; second = %lu\n", ct, logseq, logseqfield); + if (logseq != logseqfield) + { + fprintf(stderr, "Fail; page %lu invalid (fails log sequence number check)\n", ct); + if (!skip_corrupt) + goto error; + } + + /* check old method of checksumming */ + oldcsum= buf_calc_page_old_checksum(buf); + oldcsumfield= mach_read_from_4(buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM); + if (debug) + printf("page %lu: old style: calculated = %lu; recorded = %lu\n", ct, oldcsum, oldcsumfield); + if (oldcsumfield != mach_read_from_4(buf + FIL_PAGE_LSN) && oldcsumfield != oldcsum) + { + fprintf(stderr, "Fail; page %lu invalid (fails old style checksum)\n", ct); + if (!skip_corrupt) + goto error; + } + + /* now check the new method */ + csum= buf_calc_page_new_checksum(buf); + crc32= buf_calc_page_crc32(buf); + csumfield= mach_read_from_4(buf + FIL_PAGE_SPACE_OR_CHKSUM); + if (debug) + printf("page %lu: new style: calculated = %lu; crc32 = %lu; recorded = %lu\n", + ct, csum, crc32, csumfield); + if (csumfield != 0 && crc32 != csumfield && csum != csumfield) + { + fprintf(stderr, "Fail; page %lu invalid (fails innodb and crc32 checksum)\n", ct); + if (!skip_corrupt) + goto error; + } + } + /* end if this was the last page we were supposed to check */ + if (use_end_page && (ct >= end_page)) + goto ok; + + /* do counter increase and progress printing */ + ct++; + if (verbose) + { + if (ct % 64 == 0) + { + now= time(0); + if (!lastt) lastt= now; + if (now - lastt >= 1) + { + printf("page %lu okay: %.3f%% done\n", (ct - 1), (float) ct / pages * 100); + lastt= now; + } + } + } + } + +ok: + free(big_buf); + my_end(0); + exit(0); + +error: + free(big_buf); + my_end(0); + exit(1); +} diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 7558d6d00ae..e91163dde1c 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -26,6 +26,7 @@ #include <my_sys.h> #include <m_string.h> #include <my_getopt.h> +#include <my_default.h> #include <mysql_version.h> #define load_default_groups mysqld_groups @@ -33,6 +34,7 @@ #undef load_default_groups my_bool opt_mysqld; + const char *config_file="my"; /* Default config file */ uint verbose= 0, opt_defaults_file_used= 0; const char *default_dbug_option="d:t:o,/tmp/my_print_defaults.trace"; diff --git a/extra/perror.c b/extra/perror.c index c4ee6087d50..8aa6aa35b08 100644 --- a/extra/perror.c +++ b/extra/perror.c @@ -32,8 +32,8 @@ static my_bool verbose, print_all_codes; -#include "../include/my_base.h" -#include "../mysys/my_handler_errors.h" +#include <my_base.h> +#include <my_handler_errors.h> #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE static my_bool ndb_code; diff --git a/extra/resolve_stack_dump.c b/extra/resolve_stack_dump.c index dd77e1785d0..576710e0bde 100644 --- a/extra/resolve_stack_dump.c +++ b/extra/resolve_stack_dump.c @@ -223,7 +223,7 @@ static void init_sym_table() { char buf[512]; if (my_init_dynamic_array(&sym_table, sizeof(SYM_ENTRY), INIT_SYM_TABLE, - INC_SYM_TABLE)) + INC_SYM_TABLE, MYF(0))) die("Failed in my_init_dynamic_array() -- looks like out of memory problem"); while (fgets(buf, sizeof(buf), fp_sym)) diff --git a/extra/yassl/CMakeLists.txt b/extra/yassl/CMakeLists.txt index 5c5e4922b1d..f3232896c6a 100644 --- a/extra/yassl/CMakeLists.txt +++ b/extra/yassl/CMakeLists.txt @@ -20,20 +20,13 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/mySTL) ADD_DEFINITIONS(${SSL_DEFINES}) -IF(CMAKE_COMPILER_IS_GNUXX) - #Remove -fno-implicit-templates - #(yassl sources cannot be compiled with it) - STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS -${CMAKE_CXX_FLAGS}) -ENDIF() +#Remove -fno-implicit-templates +#(yassl sources cannot be compiled with it) +STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) SET(YASSL_SOURCES src/buffer.cpp src/cert_wrapper.cpp src/crypto_wrapper.cpp src/handshake.cpp src/lock.cpp src/log.cpp src/socket_wrapper.cpp src/ssl.cpp src/timer.cpp src/yassl_error.cpp src/yassl_imp.cpp src/yassl_int.cpp) -IF(HAVE_EXPLICIT_TEMPLATE_INSTANTIATION) - SET(YASSL_SOURCES ${YASSL_SOURCES} src/template_instnt.cpp) -ENDIF() - ADD_CONVENIENCE_LIBRARY(yassl ${YASSL_SOURCES}) RESTRICT_SYMBOL_EXPORTS(yassl) diff --git a/extra/yassl/include/cert_wrapper.hpp b/extra/yassl/include/cert_wrapper.hpp index 7e9f197e58d..ad4c34d65c7 100644 --- a/extra/yassl/include/cert_wrapper.hpp +++ b/extra/yassl/include/cert_wrapper.hpp @@ -78,6 +78,7 @@ class CertManager { CertList peerList_; // peer input_buffer peerPublicKey_; X509* peerX509_; // peer's openSSL X509 + X509* selfX509_; // our own openSSL X509 SignatureAlgorithm keyType_; // self key type SignatureAlgorithm peerKeyType_; // peer's key type @@ -105,6 +106,7 @@ public: const opaque* get_peerKey() const; const opaque* get_privateKey() const; X509* get_peerX509() const; + X509* get_selfX509() const; SignatureAlgorithm get_keyType() const; SignatureAlgorithm get_peerKeyType() const; diff --git a/extra/yassl/include/openssl/prefix_ssl.h b/extra/yassl/include/openssl/prefix_ssl.h index 22b3f4de34b..19725206cf8 100644 --- a/extra/yassl/include/openssl/prefix_ssl.h +++ b/extra/yassl/include/openssl/prefix_ssl.h @@ -178,6 +178,7 @@ #define SSL_get1_session yaSSL_get1_session #define X509_get_notBefore yaX509_get_notBefore #define X509_get_notAfter yaX509_get_notAfter +#define yaSSL_ASN1_TIME_to_string ya_SSL_ASN1_TIME_to_string #define MD4_Init yaMD4_Init #define MD4_Update yaMD4_Update #define MD4_Final yaMD4_Final diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h index 83daf3cc81f..c95eb1ed887 100644 --- a/extra/yassl/include/openssl/ssl.h +++ b/extra/yassl/include/openssl/ssl.h @@ -1,6 +1,5 @@ /* - Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. - Use is subject to license terms. + Copyright (c) 2005, 2014, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -539,11 +538,23 @@ void MD5_Final(unsigned char*, MD5_CTX*); #define SSL_DEFAULT_CIPHER_LIST "" /* default all */ -/* yaSSL adds */ +/* yaSSL extensions */ int SSL_set_compression(SSL*); /* turn on yaSSL zlib compression */ +char *yaSSL_ASN1_TIME_to_string(ASN1_TIME *time, char *buf, size_t len); +#include "transport_types.h" +/* + Set functions for yaSSL to use in order to send and receive data. + + These hooks are offered in order to enable non-blocking I/O. If + not set, yaSSL defaults to using send() and recv(). + @todo Remove hooks and accompanying code when yaSSL is fixed. +*/ +void yaSSL_transport_set_ptr(SSL *, void *); +void yaSSL_transport_set_recv_function(SSL *, yaSSL_recv_func_t); +void yaSSL_transport_set_send_function(SSL *, yaSSL_send_func_t); #if defined(__cplusplus) && !defined(YASSL_MYSQL_COMPATIBLE) } /* namespace */ diff --git a/extra/yassl/include/openssl/transport_types.h b/extra/yassl/include/openssl/transport_types.h new file mode 100644 index 00000000000..229d7c14eb3 --- /dev/null +++ b/extra/yassl/include/openssl/transport_types.h @@ -0,0 +1,26 @@ +/* + Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA. +*/ + +#ifndef yaSSL_transport_types_h__ +#define yaSSL_transport_types_h__ + +/* Type of transport functions used for sending and receiving data. */ +typedef long (*yaSSL_recv_func_t) (void *, void *, size_t, int); +typedef long (*yaSSL_send_func_t) (void *, const void *, size_t, int); + +#endif diff --git a/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp index c9f1e3af09c..ee4c1fbc79a 100644 --- a/extra/yassl/include/socket_wrapper.hpp +++ b/extra/yassl/include/socket_wrapper.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,7 +54,9 @@ typedef unsigned int uint; const int SOCKET_ERROR = -1; #endif - + extern "C" { + #include "openssl/transport_types.h" + } typedef unsigned char byte; @@ -64,6 +66,9 @@ class Socket { socket_t socket_; // underlying socket descriptor bool wouldBlock_; // if non-blocking data, for last read bool nonBlocking_; // is option set + void *ptr_; // Argument to transport function + yaSSL_send_func_t send_func_; // Function to send data + yaSSL_recv_func_t recv_func_; // Function to receive data public: explicit Socket(socket_t s = INVALID_SOCKET); ~Socket(); @@ -72,11 +77,15 @@ public: uint get_ready() const; socket_t get_fd() const; + void set_transport_ptr(void *ptr); + void set_transport_recv_function(yaSSL_recv_func_t recv_func); + void set_transport_send_function(yaSSL_send_func_t send_func); + uint send(const byte* buf, unsigned int len, unsigned int& sent, int flags = 0); uint receive(byte* buf, unsigned int len, int flags = 0); - bool wait(); + bool WouldBlock() const; bool IsNonBlocking() const; diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index d046d4f0743..781eaa38dda 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -212,7 +212,7 @@ private: class StringHolder { ASN1_STRING asnString_; public: - StringHolder(const char* str, int sz); + StringHolder(const char* str, int sz, byte type= 0); ~StringHolder(); ASN1_STRING* GetString(); @@ -230,7 +230,7 @@ class X509 { StringHolder afterDate_; // not valid after public: X509(const char* i, size_t, const char* s, size_t, - const char* b, int, const char* a, int, int, int, int, int); + ASN1_STRING *b, ASN1_STRING *a, int, int, int, int); ~X509() {} X509_NAME* GetIssuer(); diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp index f620f5efce0..1092e428351 100644 --- a/extra/yassl/src/cert_wrapper.cpp +++ b/extra/yassl/src/cert_wrapper.cpp @@ -90,7 +90,7 @@ opaque* x509::use_buffer() //CertManager CertManager::CertManager() - : peerX509_(0), verifyPeer_(false), verifyNone_(false), failNoCert_(false), + : peerX509_(0), selfX509_(0), verifyPeer_(false), verifyNone_(false), failNoCert_(false), sendVerify_(false), sendBlankCert_(false), verifyCallback_(0) {} @@ -98,6 +98,7 @@ CertManager::CertManager() CertManager::~CertManager() { ysDelete(peerX509_); + ysDelete(selfX509_); STL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ; @@ -219,6 +220,12 @@ X509* CertManager::get_peerX509() const } +X509* CertManager::get_selfX509() const +{ + return selfX509_; +} + + SignatureAlgorithm CertManager::get_peerKeyType() const { return peerKeyType_; @@ -289,14 +296,18 @@ int CertManager::Validate() size_t iSz = strlen(cert.GetIssuer()) + 1; size_t sSz = strlen(cert.GetCommonName()) + 1; - int bSz = (int)strlen(cert.GetBeforeDate()) + 1; - int aSz = (int)strlen(cert.GetAfterDate()) + 1; + ASN1_STRING beforeDate, afterDate; + beforeDate.data= (unsigned char *) cert.GetBeforeDate(); + beforeDate.type= cert.GetBeforeDateType(); + beforeDate.length= strlen((char *) beforeDate.data) + 1; + afterDate.data= (unsigned char *) cert.GetAfterDate(); + afterDate.type= cert.GetAfterDateType(); + afterDate.length= strlen((char *) afterDate.data) + 1; peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(), - sSz, cert.GetBeforeDate(), bSz, - cert.GetAfterDate(), aSz, - cert.GetIssuerCnStart(), cert.GetIssuerCnLength(), - cert.GetSubjectCnStart(), cert.GetSubjectCnLength() - ); + sSz, &beforeDate, &afterDate, + cert.GetIssuerCnStart(), cert.GetIssuerCnLength(), + cert.GetSubjectCnStart(), cert.GetSubjectCnLength() + ); if (err == TaoCrypt::SIG_OTHER_E && verifyCallback_) { X509_STORE_CTX store; @@ -331,6 +342,20 @@ int CertManager::SetPrivateKey(const x509& key) keyType_ = rsa_sa_algo; else keyType_ = dsa_sa_algo; + + size_t iSz = strlen(cd.GetIssuer()) + 1; + size_t sSz = strlen(cd.GetCommonName()) + 1; + ASN1_STRING beforeDate, afterDate; + beforeDate.data= (unsigned char *) cd.GetBeforeDate(); + beforeDate.type= cd.GetBeforeDateType(); + beforeDate.length= strlen((char *) beforeDate.data) + 1; + afterDate.data= (unsigned char *) cd.GetAfterDate(); + afterDate.type= cd.GetAfterDateType(); + afterDate.length= strlen((char *) afterDate.data) + 1; + selfX509_ = NEW_YS X509(cd.GetIssuer(), iSz, cd.GetCommonName(), + sSz, &beforeDate, &afterDate, + cd.GetIssuerCnStart(), cd.GetIssuerCnLength(), + cd.GetSubjectCnStart(), cd.GetSubjectCnLength()); } return 0; } @@ -347,8 +372,7 @@ void CertManager::setPeerX509(X509* x) ASN1_STRING* after = x->GetAfter(); peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(), - subject->GetName(), subject->GetLength(), (const char*) before->data, - before->length, (const char*) after->data, after->length, + subject->GetName(), subject->GetLength(), before, after, issuer->GetCnPosition(), issuer->GetCnLength(), subject->GetCnPosition(), subject->GetCnLength()); } diff --git a/extra/yassl/src/crypto_wrapper.cpp b/extra/yassl/src/crypto_wrapper.cpp index c40599880b2..031f7560801 100644 --- a/extra/yassl/src/crypto_wrapper.cpp +++ b/extra/yassl/src/crypto_wrapper.cpp @@ -995,25 +995,4 @@ x509* PemToDer(FILE* file, CertType type, EncryptedInfo* info) } // namespace - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION -namespace yaSSL { -template void ysDelete<DiffieHellman::DHImpl>(DiffieHellman::DHImpl*); -template void ysDelete<Integer::IntegerImpl>(Integer::IntegerImpl*); -template void ysDelete<RSA::RSAImpl>(RSA::RSAImpl*); -template void ysDelete<DSS::DSSImpl>(DSS::DSSImpl*); -template void ysDelete<RandomPool::RandomImpl>(RandomPool::RandomImpl*); -template void ysDelete<AES::AESImpl>(AES::AESImpl*); -template void ysDelete<RC4::RC4Impl>(RC4::RC4Impl*); -template void ysDelete<DES_EDE::DES_EDEImpl>(DES_EDE::DES_EDEImpl*); -template void ysDelete<DES::DESImpl>(DES::DESImpl*); -template void ysDelete<HMAC_RMD::HMAC_RMDImpl>(HMAC_RMD::HMAC_RMDImpl*); -template void ysDelete<HMAC_SHA::HMAC_SHAImpl>(HMAC_SHA::HMAC_SHAImpl*); -template void ysDelete<HMAC_MD5::HMAC_MD5Impl>(HMAC_MD5::HMAC_MD5Impl*); -template void ysDelete<RMD::RMDImpl>(RMD::RMDImpl*); -template void ysDelete<SHA::SHAImpl>(SHA::SHAImpl*); -template void ysDelete<MD5::MD5Impl>(MD5::MD5Impl*); -} -#endif // HAVE_EXPLICIT_TEMPLATE_INSTANTIATION - #endif // !USE_CRYPTOPP_LIB diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp index aa2de39333c..407e4092ccc 100644 --- a/extra/yassl/src/handshake.cpp +++ b/extra/yassl/src/handshake.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2014, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -747,7 +747,8 @@ int DoProcessReply(SSL& ssl) return 0; } uint ready = ssl.getSocket().get_ready(); - if (!ready) return 1; + if (!ready) + ready= 64; // add buffered data if its there input_buffer* buffered = ssl.useBuffers().TakeRawInput(); diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp index 7afd4d41d1d..9b099973578 100644 --- a/extra/yassl/src/socket_wrapper.cpp +++ b/extra/yassl/src/socket_wrapper.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -52,11 +52,33 @@ #endif // _WIN32 +namespace { + + +extern "C" long system_recv(void *ptr, void *buf, size_t count, int flags) +{ + yaSSL::socket_t *socket = (yaSSL::socket_t *) ptr; + return ::recv(*socket, reinterpret_cast<char *>(buf), count, flags); +} + + +extern "C" long system_send(void *ptr, const void *buf, size_t count, + int flags) +{ + yaSSL::socket_t *socket = (yaSSL::socket_t *) ptr; + return ::send(*socket, reinterpret_cast<const char *>(buf), count, flags); +} + + +} + + namespace yaSSL { Socket::Socket(socket_t s) - : socket_(s), wouldBlock_(false), nonBlocking_(false) + : socket_(s), wouldBlock_(false), nonBlocking_(false), + ptr_(&socket_), send_func_(system_send), recv_func_(system_recv) {} @@ -108,8 +130,25 @@ uint Socket::get_ready() const return ready; } +void Socket::set_transport_ptr(void *ptr) +{ + ptr_ = ptr; +} + + +void Socket::set_transport_recv_function(yaSSL_recv_func_t recv_func) +{ + recv_func_ = recv_func; +} + + +void Socket::set_transport_send_function(yaSSL_send_func_t send_func) +{ + send_func_ = send_func; +} + -uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written, +uint Socket::send(const byte* buf, unsigned int sz, unsigned int &written, int flags) { const byte* pos = buf; @@ -117,22 +156,23 @@ uint Socket::send(const byte* buf, unsigned int sz, unsigned int& written, wouldBlock_ = false; - while (pos != end) { - int sent = ::send(socket_, reinterpret_cast<const char *>(pos), - static_cast<int>(end - pos), flags); - if (sent == -1) { - if (get_lastError() == SOCKET_EWOULDBLOCK || - get_lastError() == SOCKET_EAGAIN) { - wouldBlock_ = true; // would have blocked this time only - nonBlocking_ = true; // nonblocking, win32 only way to tell - return 0; - } - return static_cast<uint>(-1); + while (pos != end) + { + int sent = send_func_(ptr_, pos, static_cast<int>(end - pos), flags); + if (sent == -1) + { + if (get_lastError() == SOCKET_EWOULDBLOCK || + get_lastError() == SOCKET_EAGAIN) + { + wouldBlock_ = true; // would have blocked this time only + nonBlocking_ = true; // nonblocking, win32 only way to tell + return 0; } - pos += sent; - written += sent; + return static_cast<uint>(-1); + } + pos += sent; + written += sent; } - return sz; } @@ -141,7 +181,7 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) { wouldBlock_ = false; - int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags); + int recvd = recv_func_(ptr_, buf, sz, flags); // idea to seperate error from would block by arnetheduck@gmail.com if (recvd == -1) { @@ -162,8 +202,22 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) // wait if blocking for input, return false for error bool Socket::wait() { - byte b; - return receive(&b, 1, MSG_PEEK) != static_cast<uint>(-1); + char b; + int recvd = ::recv(socket_, &b, 1, MSG_PEEK); + + if (recvd == -1) { + if (get_lastError() == SOCKET_EWOULDBLOCK || + get_lastError() == SOCKET_EAGAIN) { + wouldBlock_ = true; // would have blocked this time only + nonBlocking_ = true; // socket nonblocking, win32 only way to tell + return 1; + } + } + else if (recvd == 0) + return 0; // Non blocking & no data + + return 1; // Data can be read + } diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 778c6a8630b..57542f174c9 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2014, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ #include "rsa.hpp" // for TaoCrypt RSA key decode #include "dsa.hpp" // for TaoCrypt DSA key decode #include <stdio.h> +#include <time.h> #ifdef _WIN32 #include <windows.h> // FindFirstFile etc.. @@ -1224,8 +1225,7 @@ void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX* ctx, void* userdata) X509* SSL_get_certificate(SSL* ssl) { - // only used to pass to get_privatekey which isn't used - return 0; + return ssl->getCrypto().get_certManager().get_selfX509(); } @@ -1693,7 +1693,6 @@ unsigned long ERR_get_error() // TODO: } - SSL_CIPHER* SSL_get_current_cipher(SSL*) { // TODO: @@ -1707,10 +1706,41 @@ unsigned long ERR_get_error() return 0; } + // end stunnel needs + + char *yaSSL_ASN1_TIME_to_string(ASN1_TIME *time, char *buf, size_t len) + { + tm t; + static const char *month_names[12]= + { + "Jan","Feb","Mar","Apr","May","Jun", + "Jul","Aug","Sep","Oct","Nov","Dec" + }; + + TaoCrypt::ASN1_TIME_extract(time->data, time->type, &t); + snprintf(buf, len, "%s %2d %02d:%02d:%02d %d GMT", + month_names[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min, + t.tm_sec, t.tm_year + 1900); + return buf; + } - // end stunnel needs + void yaSSL_transport_set_ptr(SSL *ssl, void *ptr) + { + ssl->useSocket().set_transport_ptr(ptr); + } + + + void yaSSL_transport_set_recv_function(SSL *ssl, yaSSL_recv_func_t func) + { + ssl->useSocket().set_transport_recv_function(func); + } + + void yaSSL_transport_set_send_function(SSL *ssl, yaSSL_send_func_t func) + { + ssl->useSocket().set_transport_send_function(func); + } } // extern "C" } // namespace diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp deleted file mode 100644 index f0f0f095f99..00000000000 --- a/extra/yassl/src/template_instnt.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - Copyright (c) 2000-2008 MySQL AB - Use is subject to license terms - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - MA 02110-1301 USA. -*/ - - -/* Explicit template instantiation requests - */ - - -#include "runtime.hpp" -#include "handshake.hpp" -#include "yassl_int.hpp" -#include "crypto_wrapper.hpp" -#include "hmac.hpp" -#include "md5.hpp" -#include "sha.hpp" -#include "ripemd.hpp" -#include "openssl/ssl.h" - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION - -namespace mySTL { -template class list<unsigned char*>; -template yaSSL::del_ptr_zero for_each(mySTL::list<unsigned char*>::iterator, mySTL::list<unsigned char*>::iterator, yaSSL::del_ptr_zero); -template pair<int, yaSSL::Message* (*)()>* uninit_copy<mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*>(mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*); -template pair<int, yaSSL::HandShakeBase* (*)()>* uninit_copy<mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*>(mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*); -template void destroy<mySTL::pair<int, yaSSL::Message* (*)()>*>(mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*); -template void destroy<mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*>(mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*); -template pair<int, yaSSL::ServerKeyBase* (*)()>* uninit_copy<mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*); -template void destroy<mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*); -template pair<int, yaSSL::ClientKeyBase* (*)()>* uninit_copy<mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*); -template class list<TaoCrypt::Signer*>; -template class list<yaSSL::SSL_SESSION*>; -template class list<yaSSL::input_buffer*>; -template class list<yaSSL::output_buffer*>; -template class list<yaSSL::x509*>; -template class list<yaSSL::Digest*>; -template class list<yaSSL::BulkCipher*>; -template void destroy<mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*); -template yaSSL::del_ptr_zero for_each<mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<TaoCrypt::Signer*>::iterator, mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::SSL_SESSION*>::iterator, mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::output_buffer*>::iterator, mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::x509*>::iterator, mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::Digest*>::iterator, mySTL::list<yaSSL::Digest*>::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero for_each<mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::BulkCipher*>::iterator, mySTL::list<yaSSL::BulkCipher*>::iterator, yaSSL::del_ptr_zero); -template bool list<yaSSL::ThreadError>::erase(list<yaSSL::ThreadError>::iterator); -template void list<yaSSL::ThreadError>::push_back(yaSSL::ThreadError); -template void list<yaSSL::ThreadError>::pop_front(); -template void list<yaSSL::ThreadError>::pop_back(); -template list<yaSSL::ThreadError>::~list(); -template pair<int, yaSSL::Message* (*)()>* GetArrayMemory<pair<int, yaSSL::Message* (*)()> >(size_t); -template void FreeArrayMemory<pair<int, yaSSL::Message* (*)()> >(pair<int, yaSSL::Message* (*)()>*); -template pair<int, yaSSL::HandShakeBase* (*)()>* GetArrayMemory<pair<int, yaSSL::HandShakeBase* (*)()> >(size_t); -template void FreeArrayMemory<pair<int, yaSSL::HandShakeBase* (*)()> >(pair<int, yaSSL::HandShakeBase* (*)()>*); -template pair<int, yaSSL::ServerKeyBase* (*)()>* GetArrayMemory<pair<int, yaSSL::ServerKeyBase* (*)()> >(size_t); -template void FreeArrayMemory<pair<int, yaSSL::ServerKeyBase* (*)()> >(pair<int, yaSSL::ServerKeyBase* (*)()>*); -template pair<int, yaSSL::ClientKeyBase* (*)()>* GetArrayMemory<pair<int, yaSSL::ClientKeyBase* (*)()> >(size_t); -template void FreeArrayMemory<pair<int, yaSSL::ClientKeyBase* (*)()> >(pair<int, yaSSL::ClientKeyBase* (*)()>*); -} - -namespace yaSSL { -template void ysDelete<SSL_CTX>(yaSSL::SSL_CTX*); -template void ysDelete<SSL>(yaSSL::SSL*); -template void ysDelete<BIGNUM>(yaSSL::BIGNUM*); -template void ysDelete<unsigned char>(unsigned char*); -template void ysDelete<DH>(yaSSL::DH*); -template void ysDelete<TaoCrypt::Signer>(TaoCrypt::Signer*); -template void ysDelete<SSL_SESSION>(yaSSL::SSL_SESSION*); -template void ysDelete<input_buffer>(input_buffer*); -template void ysDelete<output_buffer>(output_buffer*); -template void ysDelete<x509>(x509*); -template void ysDelete<Auth>(Auth*); -template void ysDelete<HandShakeBase>(HandShakeBase*); -template void ysDelete<ServerKeyBase>(ServerKeyBase*); -template void ysDelete<ClientKeyBase>(ClientKeyBase*); -template void ysDelete<SSL_METHOD>(SSL_METHOD*); -template void ysDelete<DiffieHellman>(DiffieHellman*); -template void ysDelete<BulkCipher>(BulkCipher*); -template void ysDelete<Digest>(Digest*); -template void ysDelete<X509>(X509*); -template void ysDelete<Message>(Message*); -template void ysDelete<sslFactory>(sslFactory*); -template void ysDelete<Sessions>(Sessions*); -template void ysDelete<Errors>(Errors*); -template void ysArrayDelete<unsigned char>(unsigned char*); -template void ysArrayDelete<char>(char*); - -template int min<int>(int, int); -template uint16 min<uint16>(uint16, uint16); -template unsigned int min<unsigned int>(unsigned int, unsigned int); -template unsigned long min<unsigned long>(unsigned long, unsigned long); -} - -#endif // HAVE_EXPLICIT_TEMPLATE_INSTANTIATION - diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp index fec6a3394ca..f339655be3d 100644 --- a/extra/yassl/src/yassl_error.cpp +++ b/extra/yassl/src/yassl_error.cpp @@ -121,11 +121,11 @@ void SetErrorString(YasslError error, char* buffer) break; case certificate_error : - strncpy(buffer, "unable to proccess cerificate", max); + strncpy(buffer, "unable to process cerificate", max); break; case privateKey_error : - strncpy(buffer, "unable to proccess private key, bad format", max); + strncpy(buffer, "unable to process private key, bad format", max); break; case badVersion_error : diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp index 5158bd2d004..a481812b3e0 100644 --- a/extra/yassl/src/yassl_imp.cpp +++ b/extra/yassl/src/yassl_imp.cpp @@ -24,7 +24,7 @@ #include "handshake.hpp" #include "asn.hpp" // provide crypto wrapper?? - +#include <my_attribute.h> namespace yaSSL { @@ -963,7 +963,7 @@ void Alert::Process(input_buffer& input, SSL& ssl) if (ssl.getSecurity().get_parms().cipher_type_ == block) { int ivExtra = 0; - opaque fill; + opaque fill __attribute__((unused)); if (ssl.isTLSv1_1()) ivExtra = ssl.getCrypto().get_cipher().get_blockSize(); @@ -2418,7 +2418,7 @@ void Finished::Process(input_buffer& input, SSL& ssl) if (ssl.isTLSv1_1()) ivExtra = ssl.getCrypto().get_cipher().get_blockSize(); - opaque fill; + opaque fill __attribute__((unused)); int padSz = ssl.getSecurity().get_parms().encrypt_size_ - ivExtra - HANDSHAKE_HEADER - finishedSz - digestSz; for (int i = 0; i < padSz; i++) diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp index 215628c93cc..ff9c8155d0c 100644 --- a/extra/yassl/src/yassl_int.cpp +++ b/extra/yassl/src/yassl_int.cpp @@ -1550,12 +1550,11 @@ void SSL_SESSION::CopyX509(X509* x) X509_NAME* issuer = x->GetIssuer(); X509_NAME* subject = x->GetSubject(); - ASN1_STRING* before = x->GetBefore(); - ASN1_STRING* after = x->GetAfter(); + ASN1_TIME* before = x->GetBefore(); + ASN1_TIME* after = x->GetAfter(); peerX509_ = NEW_YS X509(issuer->GetName(), issuer->GetLength(), - subject->GetName(), subject->GetLength(), (const char*) before->data, - before->length, (const char*) after->data, after->length, + subject->GetName(), subject->GetLength(), before, after, issuer->GetCnPosition(), issuer->GetCnLength(), subject->GetCnPosition(), subject->GetCnLength()); } @@ -2505,10 +2504,12 @@ size_t X509_NAME::GetLength() const X509::X509(const char* i, size_t iSz, const char* s, size_t sSz, - const char* b, int bSz, const char* a, int aSz, int issPos, - int issLen, int subPos, int subLen) + ASN1_STRING *b, ASN1_STRING *a, + int issPos, int issLen, + int subPos, int subLen) : issuer_(i, iSz, issPos, issLen), subject_(s, sSz, subPos, subLen), - beforeDate_(b, bSz), afterDate_(a, aSz) + beforeDate_((char *) b->data, b->length, b->type), + afterDate_((char *) a->data, a->length, a->type) {} @@ -2524,13 +2525,13 @@ X509_NAME* X509::GetSubject() } -ASN1_STRING* X509::GetBefore() +ASN1_TIME* X509::GetBefore() { return beforeDate_.GetString(); } -ASN1_STRING* X509::GetAfter() +ASN1_TIME* X509::GetAfter() { return afterDate_.GetString(); } @@ -2560,12 +2561,12 @@ ASN1_STRING* X509_NAME::GetEntry(int i) } -StringHolder::StringHolder(const char* str, int sz) +StringHolder::StringHolder(const char* str, int sz, byte type) { asnString_.length = sz; asnString_.data = NEW_YS byte[sz + 1]; memcpy(asnString_.data, str, sz); - asnString_.type = 0; // not used for now + asnString_.type = type; } @@ -2697,13 +2698,3 @@ extern "C" void yaSSL_CleanUp() yaSSL::errorsInstance = 0; } - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION -namespace mySTL { -template yaSSL::yassl_int_cpp_local1::SumData for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumData); -template yaSSL::yassl_int_cpp_local1::SumBuffer for_each<mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumBuffer>(mySTL::list<yaSSL::output_buffer*>::iterator, mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::yassl_int_cpp_local1::SumBuffer); -template mySTL::list<yaSSL::SSL_SESSION*>::iterator find_if<mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::yassl_int_cpp_local2::sess_match>(mySTL::list<yaSSL::SSL_SESSION*>::iterator, mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::yassl_int_cpp_local2::sess_match); -template mySTL::list<yaSSL::ThreadError>::iterator find_if<mySTL::list<yaSSL::ThreadError>::iterator, yaSSL::yassl_int_cpp_local2::thr_match>(mySTL::list<yaSSL::ThreadError>::iterator, mySTL::list<yaSSL::ThreadError>::iterator, yaSSL::yassl_int_cpp_local2::thr_match); -} -#endif - diff --git a/extra/yassl/taocrypt/CMakeLists.txt b/extra/yassl/taocrypt/CMakeLists.txt index a08089870a3..eeed35fd6f4 100644 --- a/extra/yassl/taocrypt/CMakeLists.txt +++ b/extra/yassl/taocrypt/CMakeLists.txt @@ -29,10 +29,6 @@ SET(TAOCRYPT_SOURCES src/aes.cpp src/aestables.cpp src/algebra.cpp src/arc4.cpp include/random.hpp include/ripemd.hpp include/rsa.hpp include/sha.hpp include/rabbit.hpp include/hc128.hpp) -IF(HAVE_EXPLICIT_TEMPLATE_INSTANTIATION) - SET(TAOCRYPT_SOURCES ${TAOCRYPT_SOURCES} src/template_instnt.cpp) -ENDIF() - ADD_CONVENIENCE_LIBRARY(taocrypt ${TAOCRYPT_SOURCES}) RESTRICT_SYMBOL_EXPORTS(taocrypt) diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp index 9a10064ce02..999e853b941 100644 --- a/extra/yassl/taocrypt/include/asn.hpp +++ b/extra/yassl/taocrypt/include/asn.hpp @@ -32,7 +32,7 @@ #else #include "list.hpp" #endif - +#include <time.h> namespace STL = STL_NAMESPACE; @@ -282,7 +282,9 @@ public: const char* GetCommonName() const { return subject_; } const byte* GetHash() const { return subjectHash_; } const char* GetBeforeDate() const { return beforeDate_; } + byte GetBeforeDateType() const { return beforeDateType_; } const char* GetAfterDate() const { return afterDate_; } + byte GetAfterDateType() const { return afterDateType_; } int GetSubjectCnStart() const { return subCnPos_; } int GetIssuerCnStart() const { return issCnPos_; } int GetSubjectCnLength() const { return subCnLen_; } @@ -306,7 +308,9 @@ private: char issuer_[ASN_NAME_MAX]; // Names char subject_[ASN_NAME_MAX]; // Names char beforeDate_[MAX_DATE_SZ+1]; // valid before date, +null term + byte beforeDateType_; // beforeDate time type char afterDate_[MAX_DATE_SZ+1]; // valid after date, +null term + byte afterDateType_; // afterDate time type bool verify_; // Default to yes, but could be off void ReadHeader(); @@ -379,6 +383,9 @@ int GetCert(Source&); // Get Cert in PEM format from pkcs12 file int GetPKCS_Cert(const char* password, Source&); +void ASN1_TIME_extract(const unsigned char* date, unsigned char format, + tm *parsed_time); + } // namespace diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp index 69c326d7561..cb4d26e70c6 100644 --- a/extra/yassl/taocrypt/include/misc.hpp +++ b/extra/yassl/taocrypt/include/misc.hpp @@ -143,13 +143,9 @@ void CleanUp(); // Turn on ia32 ASM for Big Integer // CodeWarrior defines _MSC_VER -// -// Do not use assembler with GCC, as the implementation for it is broken; -// it does not use proper GCC asm contraints and makes assumptions about -// frame pointers and so on, which breaks depending on GCC version and -// optimization level. #if !defined(TAOCRYPT_DISABLE_X86ASM) && ((defined(_MSC_VER) && \ - !defined(__MWERKS__) && defined(_M_IX86))) + !defined(__MWERKS__) && defined(_M_IX86)) || \ + (defined(__GNUC__) && defined(__i386__))) #define TAOCRYPT_X86ASM_AVAILABLE #endif @@ -754,7 +750,11 @@ private: byte *m_block; }; -template <class T, class B, bool A=true> +/* + XXX MYSQL: Setting A (assumeAligned) to false, + keeping it true might trigger segfault on SPARC. +*/ +template <class T, class B, bool A= false> struct BlockGetAndPut { // function needed because of C++ grammatical ambiguity between diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp index 8b4ab9c87cd..7dae7d6a917 100644 --- a/extra/yassl/taocrypt/src/algebra.cpp +++ b/extra/yassl/taocrypt/src/algebra.cpp @@ -325,13 +325,3 @@ void AbstractRing::SimultaneousExponentiate(Integer *results, } // namespace - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION -namespace mySTL { -template TaoCrypt::WindowSlider* uninit_copy<TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*); -template void destroy<TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*); -template TaoCrypt::WindowSlider* GetArrayMemory<TaoCrypt::WindowSlider>(size_t); -template void FreeArrayMemory<TaoCrypt::WindowSlider>(TaoCrypt::WindowSlider*); -} -#endif - diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp index a210d805452..0474e7c21d5 100644 --- a/extra/yassl/taocrypt/src/asn.cpp +++ b/extra/yassl/taocrypt/src/asn.cpp @@ -32,10 +32,55 @@ #include "coding.hpp" #include <time.h> // gmtime(); #include "memory.hpp" // some auto_ptr don't have reset, also need auto_array - +#include <assert.h> namespace TaoCrypt { +// like atoi but only use first byte +word32 btoi(byte b) +{ + return b - 0x30; +} + + +// two byte date/time, add to value +void GetTime(int *value, const byte* date, int& i) +{ + *value += btoi(date[i++]) * 10; + *value += btoi(date[i++]); +} + + +void ASN1_TIME_extract(const unsigned char* date, unsigned char format, + tm *t) +{ + int i = 0; + memset(t, 0, sizeof (tm)); + + assert(format == UTC_TIME || format == GENERALIZED_TIME); + + if (format == UTC_TIME) { + if (btoi(date[0]) >= 5) + t->tm_year = 1900; + else + t->tm_year = 2000; + } + else { // format == GENERALIZED_TIME + t->tm_year += btoi(date[i++]) * 1000; + t->tm_year += btoi(date[i++]) * 100; + } + + GetTime(&t->tm_year, date, i); t->tm_year -= 1900; // adjust + GetTime(&t->tm_mon, date, i); t->tm_mon -= 1; // adjust + GetTime(&t->tm_mday, date, i); + GetTime(&t->tm_hour, date, i); + GetTime(&t->tm_min, date, i); + GetTime(&t->tm_sec, date, i); + + assert(date[i] == 'Z'); // only Zulu supported for this profile +} + + namespace { // locals @@ -75,52 +120,15 @@ bool operator<(tm& a, tm&b) } -// like atoi but only use first byte -word32 btoi(byte b) -{ - return b - 0x30; -} - - -// two byte date/time, add to value -void GetTime(int& value, const byte* date, int& i) -{ - value += btoi(date[i++]) * 10; - value += btoi(date[i++]); -} - - // Make sure before and after dates are valid bool ValidateDate(const byte* date, byte format, CertDecoder::DateType dt) { tm certTime; - memset(&certTime, 0, sizeof(certTime)); - int i = 0; - - if (format == UTC_TIME) { - if (btoi(date[0]) >= 5) - certTime.tm_year = 1900; - else - certTime.tm_year = 2000; - } - else { // format == GENERALIZED_TIME - certTime.tm_year += btoi(date[i++]) * 1000; - certTime.tm_year += btoi(date[i++]) * 100; - } - - GetTime(certTime.tm_year, date, i); certTime.tm_year -= 1900; // adjust - GetTime(certTime.tm_mon, date, i); certTime.tm_mon -= 1; // adjust - GetTime(certTime.tm_mday, date, i); - GetTime(certTime.tm_hour, date, i); - GetTime(certTime.tm_min, date, i); - GetTime(certTime.tm_sec, date, i); - - if (date[i] != 'Z') // only Zulu supported for this profile - return false; - time_t ltime = time(0); tm* localTime = gmtime(<ime); + ASN1_TIME_extract(date, format, &certTime); + if (dt == CertDecoder::BEFORE) { if (*localTime < certTime) return false; @@ -895,10 +903,12 @@ void CertDecoder::GetDate(DateType dt) if (dt == BEFORE) { memcpy(beforeDate_, date, length); beforeDate_[length] = 0; + beforeDateType_= b; } else { // after memcpy(afterDate_, date, length); afterDate_[length] = 0; + afterDateType_= b; } } diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp index d8510066d04..fb8d9276bd9 100644 --- a/extra/yassl/taocrypt/src/integer.cpp +++ b/extra/yassl/taocrypt/src/integer.cpp @@ -3887,17 +3887,5 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, return p * (u * (xq-xp) % q) + xp; } - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION -#ifndef TAOCRYPT_NATIVE_DWORD_AVAILABLE -template hword DivideThreeWordsByTwo<hword, Word>(hword*, hword, hword, Word*); -#endif -template word DivideThreeWordsByTwo<word, DWord>(word*, word, word, DWord*); -#ifdef SSE2_INTRINSICS_AVAILABLE -template class AlignedAllocator<word>; -#endif -#endif - - } // namespace diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp deleted file mode 100644 index de0137dda7c..00000000000 --- a/extra/yassl/taocrypt/src/template_instnt.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - MA 02110-1301 USA. -*/ - - -/* Explicit template instantiation requests - */ - - -#include "runtime.hpp" -#include "integer.hpp" -#include "rsa.hpp" -#include "sha.hpp" -#include "md5.hpp" -#include "hmac.hpp" -#include "ripemd.hpp" -#include "pwdbased.hpp" -#include "algebra.hpp" -#include "vector.hpp" -#include "hash.hpp" - -#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION -namespace TaoCrypt { - -#if defined(SSE2_INTRINSICS_AVAILABLE) -template AlignedAllocator<unsigned int>::pointer StdReallocate<unsigned int, AlignedAllocator<unsigned int> >(AlignedAllocator<unsigned int>&, unsigned int*, AlignedAllocator<unsigned int>::size_type, AlignedAllocator<unsigned int>::size_type, bool); -#endif - -template class RSA_Decryptor<RSA_BlockType2>; -template class RSA_Encryptor<RSA_BlockType1>; -template class RSA_Encryptor<RSA_BlockType2>; -template void tcDelete<HASH>(HASH*); -template void tcDelete<Integer>(Integer*); -template void tcArrayDelete<byte>(byte*); -template AllocatorWithCleanup<byte>::pointer StdReallocate<byte, AllocatorWithCleanup<byte> >(AllocatorWithCleanup<byte>&, byte*, AllocatorWithCleanup<byte>::size_type, AllocatorWithCleanup<byte>::size_type, bool); -template void tcArrayDelete<word>(word*); -template AllocatorWithCleanup<word>::pointer StdReallocate<word, AllocatorWithCleanup<word> >(AllocatorWithCleanup<word>&, word*, AllocatorWithCleanup<word>::size_type, AllocatorWithCleanup<word>::size_type, bool); - -#ifndef TAOCRYPT_SLOW_WORD64 // defined when word != word32 -template void tcArrayDelete<word32>(word32*); -template AllocatorWithCleanup<word32>::pointer StdReallocate<word32, AllocatorWithCleanup<word32> >(AllocatorWithCleanup<word32>&, word32*, AllocatorWithCleanup<word32>::size_type, AllocatorWithCleanup<word32>::size_type, bool); -#endif - -template void tcArrayDelete<char>(char*); - -template class PBKDF2_HMAC<SHA>; -template class HMAC<MD5>; -template class HMAC<SHA>; -template class HMAC<RIPEMD160>; -} - -namespace mySTL { -template vector<TaoCrypt::Integer>* uninit_fill_n<vector<TaoCrypt::Integer>*, size_t, vector<TaoCrypt::Integer> >(vector<TaoCrypt::Integer>*, size_t, vector<TaoCrypt::Integer> const&); -template void destroy<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, vector<TaoCrypt::Integer>*); -template TaoCrypt::Integer* uninit_copy<TaoCrypt::Integer*, TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*); -template TaoCrypt::Integer* uninit_fill_n<TaoCrypt::Integer*, size_t, TaoCrypt::Integer>(TaoCrypt::Integer*, size_t, TaoCrypt::Integer const&); -template void destroy<TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*); -template TaoCrypt::byte* GetArrayMemory<TaoCrypt::byte>(size_t); -template void FreeArrayMemory<TaoCrypt::byte>(TaoCrypt::byte*); -template TaoCrypt::Integer* GetArrayMemory<TaoCrypt::Integer>(size_t); -template void FreeArrayMemory<TaoCrypt::Integer>(TaoCrypt::Integer*); -template vector<TaoCrypt::Integer>* GetArrayMemory<vector<TaoCrypt::Integer> >(size_t); -template void FreeArrayMemory<vector<TaoCrypt::Integer> >(vector<TaoCrypt::Integer>*); -template void FreeArrayMemory<void>(void*); -} - -#endif |