Back to index

opendkim  2.6.4
t-test79.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_test79_c_id[] = "@(#)$Id: t-test79.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-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="
00031 
00032 /*
00033 **  MAIN -- program mainline
00034 **
00035 **  Parameters:
00036 **     The usual.
00037 **
00038 **  Return value:
00039 **     Exit status.
00040 */
00041 
00042 int
00043 main(int argc, char **argv)
00044 {
00045 #ifdef TEST_KEEP_FILES
00046        u_int flags;
00047 #endif /* TEST_KEEP_FILES */
00048        DKIM_STAT status;
00049        uint64_t fixed_time;
00050        DKIM *dkim;
00051        DKIM_LIB *lib;
00052        dkim_sigkey_t key;
00053        unsigned char hdr[MAXHEADER + 1];
00054 
00055        printf("*** relaxed/simple rsa-sha1 signing with space-laden header names\n");
00056 
00057 #ifdef USE_GNUTLS
00058        (void) gnutls_global_init();
00059 #endif /* USE_GNUTLS */
00060 
00061        /* instantiate the library */
00062        lib = dkim_init(NULL, NULL);
00063        assert(lib != NULL);
00064 
00065 #ifdef TEST_KEEP_FILES
00066        /* set flags */
00067        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00068        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00069                            sizeof flags);
00070 #endif /* TEST_KEEP_FILES */
00071 
00072        key = KEY;
00073 
00074        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00075                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00076                         DKIM_SIGN_RSASHA1, -1L, &status);
00077        assert(dkim != NULL);
00078 
00079        /* fix signing time */
00080        fixed_time = 1172620939;
00081        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00082                            &fixed_time, sizeof fixed_time);
00083 
00084        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00085        assert(status == DKIM_STAT_OK);
00086 
00087        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00088        assert(status == DKIM_STAT_OK);
00089 
00090        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00091        assert(status == DKIM_STAT_OK);
00092 
00093        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00094        assert(status == DKIM_STAT_OK);
00095 
00096        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00097        assert(status == DKIM_STAT_OK);
00098 
00099 #define XHEADER07        "Date   : Thu, 05 May 2005 11:59:09 -0700"
00100 
00101        status = dkim_header(dkim, XHEADER07, strlen(XHEADER07));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_eoh(dkim);
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_body(dkim, BODY00, strlen(BODY00));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_body(dkim, BODY01, strlen(BODY01));
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00120        assert(status == DKIM_STAT_OK);
00121        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00122        assert(status == DKIM_STAT_OK);
00123        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00124        assert(status == DKIM_STAT_OK);
00125        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00126        assert(status == DKIM_STAT_OK);
00127        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00128        assert(status == DKIM_STAT_OK);
00129 
00130        status = dkim_body(dkim, BODY02, strlen(BODY02));
00131        assert(status == DKIM_STAT_OK);
00132 
00133        status = dkim_body(dkim, BODY03, strlen(BODY03));
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_body(dkim, BODY04, strlen(BODY04));
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, BODY03, strlen(BODY03));
00143        assert(status == DKIM_STAT_OK);
00144 
00145        status = dkim_body(dkim, BODY05, strlen(BODY05));
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, BODY03, strlen(BODY03));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_eom(dkim, NULL);
00155        assert(status == DKIM_STAT_OK);
00156 
00157        memset(hdr, '\0', sizeof hdr);
00158        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00159                                strlen(DKIM_SIGNHEADER) + 2);
00160        assert(status == DKIM_STAT_OK);
00161        assert(strcmp(SIG2, hdr) == 0);
00162 
00163        status = dkim_free(dkim);
00164        assert(status == DKIM_STAT_OK);
00165 
00166        dkim_close(lib);
00167 
00168        return 0;
00169 }