Back to index

opendkim  2.6.6
t-test55.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_test55_c_id[] = "@(#)$Id: t-test55.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 "../dkim-strl.h"
00027 #include "t-testdata.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=TRy6u0KYixKENCPL95G1Y1uwclQ9rWthX6rFgE7gWb8=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=aMDMwcz08Na0zYLrEZnUMBUipMh3blE+pWiBSvX+t2ynaDUGTqd27xuR5JddL9y1T\r\n\t 6h0LkUMIcijsPBWa1WWfKL23QceksV75Y1/Tt6gmVi3SdVAoJbbZImrOaAQ3YQAn64\r\n\t dp1vI0Z8gSashYlwy+7gtmVSLAj/fpcAF6yNDPuE="
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 wlen = LARGEBODYSIZE;
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 *dkim;
00055        DKIM_LIB *lib;
00056        dkim_sigkey_t key;
00057        unsigned char hdr[MAXHEADER + 1];
00058        unsigned char body[LARGEBODYSIZE];
00059 
00060 #ifdef USE_GNUTLS
00061        (void) gnutls_global_init();
00062 #endif /* USE_GNUTLS */
00063 
00064        /* instantiate the library */
00065        lib = dkim_init(NULL, NULL);
00066        assert(lib != NULL);
00067 
00068        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00069        {
00070               printf("*** relaxed/simple rsa-sha256 signing large bodies SKIPPED\n");
00071               dkim_close(lib);
00072               return 0;
00073        }
00074 
00075        printf("*** relaxed/simple rsa-sha256 signing large bodies\n");
00076 
00077 #ifdef TEST_KEEP_FILES
00078        /* set flags */
00079        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00080        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00081                            sizeof flags);
00082 #endif /* TEST_KEEP_FILES */
00083 
00084        key = KEY;
00085 
00086        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00087                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00088                         DKIM_SIGN_RSASHA256, -1L, &status);
00089        assert(dkim != NULL);
00090 
00091        /* fix signing time */
00092        fixed_time = 1172620939;
00093        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00094                            &fixed_time, sizeof fixed_time);
00095 
00096        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00097        assert(status == DKIM_STAT_OK);
00098 
00099        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00100        assert(status == DKIM_STAT_OK);
00101 
00102        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00103        assert(status == DKIM_STAT_OK);
00104 
00105        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00106        assert(status == DKIM_STAT_OK);
00107 
00108        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00109        assert(status == DKIM_STAT_OK);
00110 
00111        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00112        assert(status == DKIM_STAT_OK);
00113 
00114        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00115        assert(status == DKIM_STAT_OK);
00116 
00117        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00118        assert(status == DKIM_STAT_OK);
00119 
00120        status = dkim_eoh(dkim);
00121        assert(status == DKIM_STAT_OK);
00122 
00123        memset(body, '\0', sizeof body);
00124 
00125        while (wlen > GIBBERISHLEN)
00126        {
00127               strlcat(body, GIBBERISH, sizeof body);
00128               wlen -= GIBBERISHLEN;
00129        }
00130 
00131        status = dkim_body(dkim, body, strlen(body));
00132        assert(status == DKIM_STAT_OK);
00133        status = dkim_body(dkim, CRLF, strlen(CRLF));
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_eom(dkim, NULL);
00137        assert(status == DKIM_STAT_OK);
00138 
00139        memset(hdr, '\0', sizeof hdr);
00140        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00141                                strlen(DKIM_SIGNHEADER) + 2);
00142        assert(status == DKIM_STAT_OK);
00143        assert(strcmp(SIG2, hdr) == 0);
00144 
00145        status = dkim_free(dkim);
00146        assert(status == DKIM_STAT_OK);
00147 
00148        dkim_close(lib);
00149 
00150        return 0;
00151 }