Back to index

opendkim  2.6.4
t-test148.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, 2012, The OpenDKIM Project.  All rights reserved.
00006 */
00007 
00008 #ifndef lint
00009 static char t_test148_c_id[] = "@(#)$Id: t-test83.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 /*
00031 **  MAIN -- program mainline
00032 **
00033 **  Parameters:
00034 **     The usual.
00035 **
00036 **  Return value:
00037 **     Exit status.
00038 */
00039 
00040 int
00041 main(int argc, char **argv)
00042 {
00043 #ifdef TEST_KEEP_FILES
00044        u_int flags;
00045 #endif /* TEST_KEEP_FILES */
00046        DKIM_STAT status;
00047        uint64_t fixed_time;
00048        DKIM *dkim;
00049        DKIM_LIB *lib;
00050        dkim_sigkey_t key;
00051        unsigned char hdr[MAXHEADER + 1];
00052 
00053 #ifdef USE_GNUTLS
00054        (void) gnutls_global_init();
00055 #endif /* USE_GNUTLS */
00056 
00057        /* instantiate the library */
00058        lib = dkim_init(NULL, NULL);
00059        assert(lib != NULL);
00060 
00061        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00062        {
00063               printf("*** relaxed/simple rsa-sha256 signing subdomain with invalid i= SKIPPED\n");
00064               dkim_close(lib);
00065               return 0;
00066        }
00067 
00068        printf("*** relaxed/simple rsa-sha256 signing subdomain with invalid i=\n");
00069 
00070 #ifdef TEST_KEEP_FILES
00071        /* set flags */
00072        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00073        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00074                            sizeof flags);
00075 #endif /* TEST_KEEP_FILES */
00076 
00077        key = KEY;
00078 
00079        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN2,
00080                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00081                         DKIM_SIGN_RSASHA256, -1L, &status);
00082        assert(dkim != NULL);
00083 
00084        /* fix signing time */
00085        fixed_time = 1172620939;
00086        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00087                            &fixed_time, sizeof fixed_time);
00088 
00089        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00090        assert(status == DKIM_STAT_OK);
00091 
00092        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00093        assert(status == DKIM_STAT_OK);
00094 
00095        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00096        assert(status == DKIM_STAT_OK);
00097 
00098 #define       XHEADER05     "From: Murray S. Kucherawy <msk@eng.sendmail.com>"
00099        status = dkim_header(dkim, XHEADER05, strlen(XHEADER05));
00100        assert(status == DKIM_STAT_OK);
00101 
00102        (void) dkim_set_signer(dkim, "@" DOMAIN);
00103 
00104        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_eoh(dkim);
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_body(dkim, BODY00, strlen(BODY00));
00120        assert(status == DKIM_STAT_OK);
00121 
00122        status = dkim_body(dkim, BODY01, strlen(BODY01));
00123        assert(status == DKIM_STAT_OK);
00124 
00125        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00126        assert(status == DKIM_STAT_OK);
00127        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00128        assert(status == DKIM_STAT_OK);
00129        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00130        assert(status == DKIM_STAT_OK);
00131        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00132        assert(status == DKIM_STAT_OK);
00133        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_body(dkim, BODY02, strlen(BODY02));
00137        assert(status == DKIM_STAT_OK);
00138 
00139        status = dkim_body(dkim, BODY03, strlen(BODY03));
00140        assert(status == DKIM_STAT_OK);
00141 
00142        status = dkim_body(dkim, BODY04, strlen(BODY04));
00143        assert(status == DKIM_STAT_OK);
00144 
00145        status = dkim_body(dkim, BODY03, strlen(BODY03));
00146        assert(status == DKIM_STAT_OK);
00147 
00148        status = dkim_body(dkim, BODY03, strlen(BODY03));
00149        assert(status == DKIM_STAT_OK);
00150 
00151        status = dkim_body(dkim, BODY05, strlen(BODY05));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_body(dkim, BODY03, strlen(BODY03));
00155        assert(status == DKIM_STAT_OK);
00156 
00157        status = dkim_body(dkim, BODY03, strlen(BODY03));
00158        assert(status == DKIM_STAT_OK);
00159 
00160        status = dkim_eom(dkim, NULL);
00161        assert(status == DKIM_STAT_INVALID);
00162 
00163        memset(hdr, '\0', sizeof hdr);
00164        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00165                                strlen(DKIM_SIGNHEADER) + 2);
00166        assert(status == DKIM_STAT_INVALID);
00167 
00168        status = dkim_free(dkim);
00169        assert(status == DKIM_STAT_OK);
00170 
00171        dkim_close(lib);
00172 
00173        return 0;
00174 }