Back to index

opendkim  2.6.2
t-test122.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_test122_c_id[] = "@(#)$Id: t-test122.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 #include "../dkim-strl.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define       GIBBERISHLEN  (sizeof(GIBBERISH) - 1)
00032 
00033 #define SIG2 "v=1; a=rsa-sha256; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=5Z5kUG7FTM/P2DzvDVOdFzOUr6m33zc4K5qzpwn+jTc=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=qtj/DXxof5Ek/8aSXCGkyqpRCAviW6vmwx9feqGq/OnxMwYwCbwa5TOayfJHGdL1/\r\n\t IK7GL77WMa/Jn0d580YG/qS+wOE2cWas3rR2xnPwvjXpUr8ck/xMH8R79mEWbZ+wTT\r\n\t v0mKf0YcpyicBf+Y/OBQW930kmIqPzo1/qfwWhgc="
00034 
00035 /*
00036 **  MAIN -- program mainline
00037 **
00038 **  Parameters:
00039 **     The usual.
00040 **
00041 **  Return value:
00042 **     Exit status.
00043 */
00044 
00045 int
00046 main(int argc, char **argv)
00047 {
00048        size_t llen = 0;
00049        size_t wlen = LARGEBODYSIZE;
00050 # ifdef TEST_KEEP_FILES
00051        u_int flags;
00052 # endif /* TEST_KEEP_FILES */
00053        DKIM_STAT status;
00054        uint64_t fixed_time;
00055        u_char *p;
00056        DKIM *dkim;
00057        DKIM_LIB *lib;
00058        dkim_sigkey_t key;
00059        unsigned char gibline[sizeof(GIBBERISH) + 1];
00060        unsigned char hdr[MAXHEADER + 1];
00061        unsigned char body[LARGEBODYSIZE];
00062 
00063        strlcpy(gibline, GIBBERISH, sizeof gibline);
00064        p = strchr(gibline, '\r');
00065        if (p != NULL)
00066               *p = '\0';
00067 
00068 #ifdef USE_GNUTLS
00069        (void) gnutls_global_init();
00070 #endif /* USE_GNUTLS */
00071 
00072        /* instantiate the library */
00073        lib = dkim_init(NULL, NULL);
00074        assert(lib != NULL);
00075 
00076        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00077        {
00078               printf("*** relaxed/simple rsa-sha256 signing large lines SKIPPED\n");
00079               dkim_close(lib);
00080               return 0;
00081        }
00082 
00083        printf("*** relaxed/simple rsa-sha256 signing large lines\n");
00084 
00085 #ifdef TEST_KEEP_FILES
00086        /* set flags */
00087        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00088        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00089                            sizeof flags);
00090 #endif /* TEST_KEEP_FILES */
00091 
00092        key = KEY;
00093 
00094        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00095                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00096                         DKIM_SIGN_RSASHA256, -1L, &status);
00097        assert(dkim != NULL);
00098 
00099        /* fix signing time */
00100        fixed_time = 1172620939;
00101        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00102                            &fixed_time, sizeof fixed_time);
00103 
00104        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00120        assert(status == DKIM_STAT_OK);
00121 
00122        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00123        assert(status == DKIM_STAT_OK);
00124 
00125        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00126        assert(status == DKIM_STAT_OK);
00127 
00128        status = dkim_eoh(dkim);
00129        assert(status == DKIM_STAT_OK);
00130 
00131        memset(body, '\0', sizeof body);
00132 
00133        while (wlen > GIBBERISHLEN + 2)
00134        {
00135               strlcat(body, gibline, sizeof body);
00136               wlen -= strlen(gibline);
00137               llen += strlen(gibline);
00138 
00139               if (llen > LARGELINESIZE)
00140               {
00141                      strlcat(body, CRLF, sizeof body);
00142                      wlen -= 2;
00143                      llen = 0;
00144               }
00145        }
00146 
00147        strlcat(body, CRLF, sizeof body);
00148 
00149        status = dkim_body(dkim, body, strlen(body));
00150        assert(status == DKIM_STAT_OK);
00151        status = dkim_body(dkim, CRLF, strlen(CRLF));
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 }