Back to index

opendkim  2.6.4
t-test44.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_test44_c_id[] = "@(#)$Id: t-test44.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 #define SIG2 "v=1; a=rsa-sha256; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=hNRIcA7ZG6mZL9GPr5E9rJPQBy0DNnPSNAqYmtpbHJjhzWj3fsUKXDCEl8vJki6Vu\r\n\t P0hDA4wRRJ6hkD0/u9iY2O+7xwAyuzkC3Z719CuGidnqlJt/1kJ4QW4KlcWJcj2v8S\r\n\t jD475GchVu0268Cz9PTJWSEqg/WZfWLQrji0gmy0="
00031 
00032 #define       SKIPHEADER    "Return-Path: <msk@sendmail.com>"
00033 
00034 char *skipheaders[] =
00035 {
00036        "Return-Path",
00037        NULL
00038 };
00039 
00040 /*
00041 **  MAIN -- program mainline
00042 **
00043 **  Parameters:
00044 **     The usual.
00045 **
00046 **  Return value:
00047 **     Exit status.
00048 */
00049 
00050 int
00051 main(int argc, char **argv)
00052 {
00053 #ifdef TEST_KEEP_FILES
00054        u_int flags;
00055 #endif /* TEST_KEEP_FILES */
00056        DKIM_STAT status;
00057        uint64_t fixed_time;
00058        DKIM *dkim;
00059        DKIM_LIB *lib;
00060        dkim_sigkey_t key;
00061        unsigned char hdr[MAXHEADER + 1];
00062 
00063 #ifdef USE_GNUTLS
00064        (void) gnutls_global_init();
00065 #endif /* USE_GNUTLS */
00066 
00067        /* instantiate the library */
00068        lib = dkim_init(NULL, NULL);
00069        assert(lib != NULL);
00070 
00071        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00072        {
00073               printf("*** relaxed/simple rsa-sha256 signing with header omission SKIPPED\n");
00074               dkim_close(lib);
00075               return 0;
00076        }
00077 
00078        printf("*** relaxed/simple rsa-sha256 signing with header omission\n");
00079 
00080 #ifdef TEST_KEEP_FILES
00081        /* set flags */
00082        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00083        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00084                            sizeof flags);
00085 #endif /* TEST_KEEP_FILES */
00086 
00087        key = KEY;
00088 
00089        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00090                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00091                         DKIM_SIGN_RSASHA256, -1L, &status);
00092        assert(dkim != NULL);
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        /* arrange to skip headers */
00100        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_SKIPHDRS,
00101                            skipheaders, sizeof(char **));
00102 
00103        status = dkim_header(dkim, SKIPHEADER, strlen(SKIPHEADER));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00125        assert(status == DKIM_STAT_OK);
00126 
00127        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00128        assert(status == DKIM_STAT_OK);
00129 
00130        status = dkim_eoh(dkim);
00131        assert(status == DKIM_STAT_OK);
00132 
00133        status = dkim_body(dkim, BODY00, strlen(BODY00));
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_body(dkim, BODY01, strlen(BODY01));
00137        assert(status == DKIM_STAT_OK);
00138 
00139        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00140        assert(status == DKIM_STAT_OK);
00141        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00142        assert(status == DKIM_STAT_OK);
00143        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00144        assert(status == DKIM_STAT_OK);
00145        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00146        assert(status == DKIM_STAT_OK);
00147        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00148        assert(status == DKIM_STAT_OK);
00149 
00150        status = dkim_body(dkim, BODY02, strlen(BODY02));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_body(dkim, BODY03, strlen(BODY03));
00154        assert(status == DKIM_STAT_OK);
00155 
00156        status = dkim_body(dkim, BODY04, strlen(BODY04));
00157        assert(status == DKIM_STAT_OK);
00158 
00159        status = dkim_body(dkim, BODY03, strlen(BODY03));
00160        assert(status == DKIM_STAT_OK);
00161 
00162        status = dkim_body(dkim, BODY03, strlen(BODY03));
00163        assert(status == DKIM_STAT_OK);
00164 
00165        status = dkim_body(dkim, BODY05, strlen(BODY05));
00166        assert(status == DKIM_STAT_OK);
00167 
00168        status = dkim_body(dkim, BODY03, strlen(BODY03));
00169        assert(status == DKIM_STAT_OK);
00170 
00171        status = dkim_body(dkim, BODY03, strlen(BODY03));
00172        assert(status == DKIM_STAT_OK);
00173 
00174        status = dkim_eom(dkim, NULL);
00175        assert(status == DKIM_STAT_OK);
00176 
00177        memset(hdr, '\0', sizeof hdr);
00178        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00179                                strlen(DKIM_SIGNHEADER) + 2);
00180        assert(status == DKIM_STAT_OK);
00181        assert(strcmp(SIG2, hdr) == 0);
00182 
00183        status = dkim_free(dkim);
00184        assert(status == DKIM_STAT_OK);
00185 
00186        dkim_close(lib);
00187 
00188        return 0;
00189 }