Back to index

opendkim  2.6.6
t-test131.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2005-2008 Sendmail, Inc. and its suppliers.
00003 **    All rights reserved.
00004 **
00005 **  Copyright (c) 2009, 2011, The OpenDKIM Project.  All rights reserved.
00006 */
00007 
00008 #ifndef lint
00009 static char t_test131_c_id[] = "@(#)$Id: t-test131.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $";
00010 #endif /* !lint */
00011 
00012 #include "build-config.h"
00013 
00014 /* system includes */
00015 #include <sys/types.h>
00016 #include <assert.h>
00017 #include <string.h>
00018 #include <stdio.h>
00019 #include <ctype.h>
00020 
00021 #ifdef USE_GNUTLS
00022 # include <gnutls/gnutls.h>
00023 #endif /* USE_GNUTLS */
00024 
00025 /* libopendkim includes */
00026 #include "../dkim.h"
00027 #include "t-testdata.h"
00028 #include "../dkim-strl.h"
00029 
00030 #define       MAXHEADER     4096
00031 
00032 #define       NULLBH        "bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="
00033 
00034 /*
00035 **  EATWS -- eat whitespace
00036 **
00037 **  Parameters:
00038 **     str -- string to crush
00039 **
00040 **  Return value:
00041 **     None.
00042 */
00043 
00044 void
00045 eatws(char *str)
00046 {
00047        char *p;
00048        char *q;
00049 
00050        for (p = str, q = str; *p != '\0'; p++)
00051        {
00052               if (!isascii(*p) || !isspace(*p))
00053               {
00054                      *q = *p;
00055                      q++;
00056               }
00057        }
00058 
00059        *q = '\0';
00060 }
00061 
00062 /*
00063 **  MAIN -- program mainline
00064 **
00065 **  Parameters:
00066 **     The usual.
00067 **
00068 **  Return value:
00069 **     Exit status.
00070 */
00071 
00072 int
00073 main(int argc, char **argv)
00074 {
00075        size_t llen = 0;
00076        size_t wlen = LARGEBODYSIZE;
00077 #ifdef TEST_KEEP_FILES
00078        u_int flags;
00079 #endif /* TEST_KEEP_FILES */
00080        DKIM_STAT status;
00081        uint64_t fixed_time;
00082        u_char *p;
00083        char *last;
00084        DKIM *dkim;
00085        DKIM_LIB *lib;
00086        dkim_sigkey_t key;
00087        unsigned char hdr[MAXHEADER + 1];
00088        unsigned char hdr2[MAXHEADER + 1];
00089 
00090 #ifdef USE_GNUTLS
00091        (void) gnutls_global_init();
00092 #endif /* USE_GNUTLS */
00093 
00094        /* instantiate the library */
00095        lib = dkim_init(NULL, NULL);
00096        assert(lib != NULL);
00097 
00098        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00099        {
00100               printf("*** relaxed/relaxed rsa-sha256 body blank reduction SKIPPED\n");
00101               dkim_close(lib);
00102               return 0;
00103        }
00104 
00105        printf("*** relaxed/relaxed rsa-sha256 body blank reduction\n");
00106 
00107 #ifdef TEST_KEEP_FILES
00108        /* set flags */
00109        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00110        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00111                            sizeof flags);
00112 #endif /* TEST_KEEP_FILES */
00113 
00114        key = KEY;
00115 
00116        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00117                         DKIM_CANON_RELAXED, DKIM_CANON_RELAXED,
00118                         DKIM_SIGN_RSASHA256, -1L, &status);
00119        assert(dkim != NULL);
00120 
00121        /* fix signing time */
00122        fixed_time = 1172620939;
00123        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00124                            &fixed_time, sizeof fixed_time);
00125 
00126        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00127        assert(status == DKIM_STAT_OK);
00128 
00129        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00130        assert(status == DKIM_STAT_OK);
00131 
00132        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00136        assert(status == DKIM_STAT_OK);
00137 
00138        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00139        assert(status == DKIM_STAT_OK);
00140 
00141        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00142        assert(status == DKIM_STAT_OK);
00143 
00144        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00145        assert(status == DKIM_STAT_OK);
00146 
00147        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00148        assert(status == DKIM_STAT_OK);
00149 
00150        status = dkim_eoh(dkim);
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_eom(dkim, NULL);
00154        assert(status == DKIM_STAT_OK);
00155 
00156        memset(hdr, '\0', sizeof hdr);
00157        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00158                                strlen(DKIM_SIGNHEADER) + 2);
00159        assert(status == DKIM_STAT_OK);
00160 
00161        strlcpy(hdr2, hdr, sizeof hdr2);
00162        for (p = strtok_r(hdr2, ";", &last);
00163             p != NULL;
00164             p = strtok_r(NULL, ";", &last))
00165        {
00166               eatws(p);
00167               if (strncmp(p, "bh=", 3) == 0)
00168                      assert(strcmp(p, NULLBH) == 0);
00169        }
00170 
00171        status = dkim_free(dkim);
00172        assert(status == DKIM_STAT_OK);
00173 
00174        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00175                         DKIM_CANON_RELAXED, DKIM_CANON_RELAXED,
00176                         DKIM_SIGN_RSASHA256, -1L, &status);
00177        assert(dkim != NULL);
00178 
00179        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00180        assert(status == DKIM_STAT_OK);
00181 
00182        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00183        assert(status == DKIM_STAT_OK);
00184 
00185        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00186        assert(status == DKIM_STAT_OK);
00187 
00188        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00189        assert(status == DKIM_STAT_OK);
00190 
00191        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00192        assert(status == DKIM_STAT_OK);
00193 
00194        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00195        assert(status == DKIM_STAT_OK);
00196 
00197        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00198        assert(status == DKIM_STAT_OK);
00199 
00200        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00201        assert(status == DKIM_STAT_OK);
00202 
00203        status = dkim_eoh(dkim);
00204        assert(status == DKIM_STAT_OK);
00205 
00206        status = dkim_body(dkim, CRLF, 2);
00207        assert(status == DKIM_STAT_OK);
00208 
00209        status = dkim_eom(dkim, NULL);
00210        assert(status == DKIM_STAT_OK);
00211 
00212        memset(hdr2, '\0', sizeof hdr2);
00213        status = dkim_getsighdr(dkim, hdr2, sizeof hdr2,
00214                                strlen(DKIM_SIGNHEADER) + 2);
00215        assert(status == DKIM_STAT_OK);
00216        assert(strcmp(hdr2, hdr) == 0);
00217 
00218        status = dkim_free(dkim);
00219        assert(status == DKIM_STAT_OK);
00220 
00221        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00222                         DKIM_CANON_RELAXED, DKIM_CANON_RELAXED,
00223                         DKIM_SIGN_RSASHA256, -1L, &status);
00224        assert(dkim != NULL);
00225 
00226        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00227        assert(status == DKIM_STAT_OK);
00228 
00229        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00230        assert(status == DKIM_STAT_OK);
00231 
00232        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00233        assert(status == DKIM_STAT_OK);
00234 
00235        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00236        assert(status == DKIM_STAT_OK);
00237 
00238        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00239        assert(status == DKIM_STAT_OK);
00240 
00241        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00242        assert(status == DKIM_STAT_OK);
00243 
00244        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00245        assert(status == DKIM_STAT_OK);
00246 
00247        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00248        assert(status == DKIM_STAT_OK);
00249 
00250        status = dkim_eoh(dkim);
00251        assert(status == DKIM_STAT_OK);
00252 
00253        status = dkim_body(dkim, CRLF CRLF SP SP CRLF, 2);
00254        assert(status == DKIM_STAT_OK);
00255 
00256        status = dkim_eom(dkim, NULL);
00257        assert(status == DKIM_STAT_OK);
00258 
00259        memset(hdr2, '\0', sizeof hdr2);
00260        status = dkim_getsighdr(dkim, hdr2, sizeof hdr2,
00261                                strlen(DKIM_SIGNHEADER) + 2);
00262        assert(status == DKIM_STAT_OK);
00263        assert(strcmp(hdr2, hdr) == 0);
00264 
00265        status = dkim_free(dkim);
00266        assert(status == DKIM_STAT_OK);
00267 
00268        dkim_close(lib);
00269 
00270        return 0;
00271 }