Back to index

opendkim  2.6.4
t-test128.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_test128_c_id[] = "@(#)$Id: t-test128.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 
00020 #ifdef USE_GNUTLS
00021 # include <gnutls/gnutls.h>
00022 #endif /* USE_GNUTLS */
00023 
00024 /* libopendkim includes */
00025 #include "../dkim.h"
00026 #include "t-testdata.h"
00027 
00028 #define       MAXHEADER     4096
00029 
00030 #ifndef TRUE
00031 # define TRUE        1
00032 #endif /* ! TRUE */
00033 
00034 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=ll/0h2aWgG+D3ewmE4Y3pY7Ukz8=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=Q4G/ki/5soDXGxs43JfV+qEKDr5X3GgTDNeZqWL3zLLC5DXWWzmnKRcU8NH4Wsfkh\r\n\t o5tMo4NRmqnB2eZtozsyXdHo2ekUPLxuAQJomM4JHaPTfsraHwkibQIkPpW5hf/Rc2\r\n\t 0QgP48iQBjxqcOSn/Vwk5QDup4Qj1vgOxBqTqwdg="
00035 
00036 /*
00037 **  MAIN -- program mainline
00038 **
00039 **  Parameters:
00040 **     The usual.
00041 **
00042 **  Return value:
00043 **     Exit status.
00044 */
00045 
00046 int
00047 main(int argc, char **argv)
00048 {
00049 #ifdef TEST_KEEP_FILES
00050        u_int flags;
00051 #endif /* TEST_KEEP_FILES */
00052        DKIM_STAT status;
00053        uint64_t fixed_time;
00054        dkim_sigkey_t key;
00055        DKIM *dkim;
00056        DKIM *resign;
00057        DKIM_LIB *lib;
00058        dkim_query_t qtype = DKIM_QUERY_FILE;
00059        unsigned char hdr[MAXHEADER + 1];
00060        unsigned char hdr2[MAXHEADER + 1];
00061 
00062        key = KEY;
00063 
00064 #ifdef USE_GNUTLS
00065        (void) gnutls_global_init();
00066 #endif /* USE_GNUTLS */
00067 
00068        /* instantiate the library */
00069        lib = dkim_init(NULL, NULL);
00070        assert(lib != NULL);
00071 
00072        if (!dkim_libfeature(lib, DKIM_FEATURE_RESIGN))
00073        {
00074               printf("*** relaxed/simple rsa-sha1 re-signing with header binding SKIPPED\n");
00075               dkim_close(lib);
00076               return 0;
00077        }
00078 
00079        printf("*** relaxed/simple rsa-sha1 re-signing with header binding\n");
00080 
00081 #ifdef TEST_KEEP_FILES
00082        /* set flags */
00083        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00084        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00085                            sizeof flags);
00086 #endif /* TEST_KEEP_FILES */
00087 
00088        /* test mode */
00089        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00090                            &qtype, sizeof qtype);
00091        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00092                            KEYFILE, strlen(KEYFILE));
00093 
00094        /* fix signing time */
00095        fixed_time = 1172620939;
00096        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00097                            &fixed_time, sizeof fixed_time);
00098 
00099        /* restrict signed headers */
00100        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_SIGNHDRS,
00101                            dkim_should_signhdrs, sizeof(u_char **));
00102 
00103        dkim = dkim_verify(lib, JOBID, NULL, &status);
00104        assert(dkim != NULL);
00105 
00106        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00107        status = dkim_header(dkim, hdr, strlen(hdr));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00120        assert(status == DKIM_STAT_OK);
00121 
00122        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00123        assert(status == DKIM_STAT_OK);
00124 
00125        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00126        assert(status == DKIM_STAT_OK);
00127 
00128        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00129        assert(status == DKIM_STAT_OK);
00130 
00131        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00132        assert(status == DKIM_STAT_OK);
00133 
00134        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00135        assert(status == DKIM_STAT_OK);
00136 
00137        resign = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00138                           DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00139                           DKIM_SIGN_RSASHA1, -1L, &status);
00140        assert(resign != NULL);
00141 
00142        status = dkim_resign(dkim, resign, TRUE);
00143        assert(status == DKIM_STAT_INVALID);
00144 
00145        status = dkim_resign(resign, dkim, TRUE);
00146        assert(status == DKIM_STAT_OK);
00147 
00148        status = dkim_eoh(dkim);
00149        assert(status == DKIM_STAT_OK);
00150 
00151        status = dkim_eoh(resign);
00152        assert(status == DKIM_STAT_INVALID);
00153 
00154        status = dkim_body(dkim, BODY00, strlen(BODY00));
00155        assert(status == DKIM_STAT_OK);
00156 
00157        status = dkim_body(resign, BODY00, strlen(BODY00));
00158        assert(status == DKIM_STAT_INVALID);
00159 
00160        status = dkim_body(dkim, BODY01, strlen(BODY01));
00161        assert(status == DKIM_STAT_OK);
00162 
00163        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00164        assert(status == DKIM_STAT_OK);
00165        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00166        assert(status == DKIM_STAT_OK);
00167        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00168        assert(status == DKIM_STAT_OK);
00169        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00170        assert(status == DKIM_STAT_OK);
00171        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00172        assert(status == DKIM_STAT_OK);
00173 
00174        status = dkim_body(dkim, BODY02, strlen(BODY02));
00175        assert(status == DKIM_STAT_OK);
00176 
00177        status = dkim_body(dkim, BODY03, strlen(BODY03));
00178        assert(status == DKIM_STAT_OK);
00179 
00180        status = dkim_body(dkim, BODY04, strlen(BODY04));
00181        assert(status == DKIM_STAT_OK);
00182 
00183        status = dkim_body(dkim, BODY03, strlen(BODY03));
00184        assert(status == DKIM_STAT_OK);
00185 
00186        status = dkim_body(dkim, BODY03, strlen(BODY03));
00187        assert(status == DKIM_STAT_OK);
00188 
00189        status = dkim_body(dkim, BODY05, strlen(BODY05));
00190        assert(status == DKIM_STAT_OK);
00191 
00192        status = dkim_body(dkim, BODY03, strlen(BODY03));
00193        assert(status == DKIM_STAT_OK);
00194 
00195        status = dkim_body(dkim, BODY03, strlen(BODY03));
00196        assert(status == DKIM_STAT_OK);
00197 
00198        status = dkim_eom(resign, NULL);
00199        assert(status == DKIM_STAT_INVALID);
00200 
00201        status = dkim_eom(dkim, NULL);
00202        assert(status == DKIM_STAT_OK);
00203 
00204        status = dkim_eom(resign, NULL);
00205        assert(status == DKIM_STAT_OK);
00206 
00207        memset(hdr, '\0', sizeof hdr);
00208        status = dkim_getsighdr(resign, hdr, sizeof hdr,
00209                                strlen(DKIM_SIGNHEADER) + 2);
00210        assert(status == DKIM_STAT_OK);
00211 
00212        status = dkim_free(dkim);
00213        assert(status == DKIM_STAT_INVALID);
00214 
00215        status = dkim_free(resign);
00216        assert(status == DKIM_STAT_OK);
00217 
00218        status = dkim_free(dkim);
00219        assert(status == DKIM_STAT_OK);
00220 
00221        /* now see if that one was valid */
00222        dkim = dkim_verify(lib, JOBID, NULL, &status);
00223        assert(dkim != NULL);
00224 
00225        snprintf(hdr2, sizeof hdr2, "%s: %s", DKIM_SIGNHEADER, hdr);
00226        status = dkim_header(dkim, hdr2, strlen(hdr2));
00227        assert(status == DKIM_STAT_OK);
00228 
00229        snprintf(hdr2, sizeof hdr2, "%s: %s", DKIM_SIGNHEADER, SIG2);
00230        status = dkim_header(dkim, hdr2, strlen(hdr2));
00231        assert(status == DKIM_STAT_OK);
00232 
00233        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00234        assert(status == DKIM_STAT_OK);
00235 
00236        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00237        assert(status == DKIM_STAT_OK);
00238 
00239        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00240        assert(status == DKIM_STAT_OK);
00241 
00242        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00243        assert(status == DKIM_STAT_OK);
00244 
00245        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00246        assert(status == DKIM_STAT_OK);
00247 
00248        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00249        assert(status == DKIM_STAT_OK);
00250 
00251        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00252        assert(status == DKIM_STAT_OK);
00253 
00254        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00255        assert(status == DKIM_STAT_OK);
00256 
00257        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00258        assert(status == DKIM_STAT_OK);
00259 
00260        status = dkim_eoh(dkim);
00261        assert(status == DKIM_STAT_OK);
00262 
00263        status = dkim_body(dkim, BODY00, strlen(BODY00));
00264        assert(status == DKIM_STAT_OK);
00265 
00266        status = dkim_body(dkim, BODY01, strlen(BODY01));
00267        assert(status == DKIM_STAT_OK);
00268 
00269        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00270        assert(status == DKIM_STAT_OK);
00271        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00272        assert(status == DKIM_STAT_OK);
00273        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00274        assert(status == DKIM_STAT_OK);
00275        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00276        assert(status == DKIM_STAT_OK);
00277        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00278        assert(status == DKIM_STAT_OK);
00279 
00280        status = dkim_body(dkim, BODY02, strlen(BODY02));
00281        assert(status == DKIM_STAT_OK);
00282 
00283        status = dkim_body(dkim, BODY03, strlen(BODY03));
00284        assert(status == DKIM_STAT_OK);
00285 
00286        status = dkim_body(dkim, BODY04, strlen(BODY04));
00287        assert(status == DKIM_STAT_OK);
00288 
00289        status = dkim_body(dkim, BODY03, strlen(BODY03));
00290        assert(status == DKIM_STAT_OK);
00291 
00292        status = dkim_body(dkim, BODY03, strlen(BODY03));
00293        assert(status == DKIM_STAT_OK);
00294 
00295        status = dkim_body(dkim, BODY05, strlen(BODY05));
00296        assert(status == DKIM_STAT_OK);
00297 
00298        status = dkim_body(dkim, BODY03, strlen(BODY03));
00299        assert(status == DKIM_STAT_OK);
00300 
00301        status = dkim_body(dkim, BODY03, strlen(BODY03));
00302        assert(status == DKIM_STAT_OK);
00303 
00304        status = dkim_eom(dkim, NULL);
00305        assert(status == DKIM_STAT_OK);
00306 
00307        status = dkim_free(dkim);
00308        assert(status == DKIM_STAT_OK);
00309 
00310        dkim_close(lib);
00311 
00312        return 0;
00313 }