Back to index

opendkim  2.6.4
t-test56.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_test56_c_id[] = "@(#)$Id: t-test56.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; b=aMD\r\n\tMwcz08Na0zYLrEZnUMBUipMh3blE+pWiBSvX+t2ynaDUGTqd27xuR5JddL9y1T6h0Lk\r\n\tUMIcijsPBWa1WWfKL23QceksV75Y1/Tt6gmVi3SdVAoJbbZImrOaAQ3YQAn64dp1vI0\r\n\tZ8gSashYlwy+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        DKIM *dkim;
00054        DKIM_LIB *lib;
00055        dkim_query_t qtype = DKIM_QUERY_FILE;
00056        unsigned char hdr[MAXHEADER + 1];
00057        unsigned char body[LARGEBODYSIZE];
00058 
00059 #ifdef USE_GNUTLS
00060        (void) gnutls_global_init();
00061 #endif /* USE_GNUTLS */
00062 
00063        /* instantiate the library */
00064        lib = dkim_init(NULL, NULL);
00065        assert(lib != NULL);
00066 
00067        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00068        {
00069               printf("*** relaxed/simple rsa-sha256 verifying large bodies SKIPPED\n");
00070               dkim_close(lib);
00071               return 0;
00072        }
00073 
00074        printf("*** relaxed/simple rsa-sha256 verifying large bodies\n");
00075 
00076 #ifdef TEST_KEEP_FILES
00077        /* set flags */
00078        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00079        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00080                            sizeof flags);
00081 #endif /* TEST_KEEP_FILES */
00082 
00083        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00084                            &qtype, sizeof qtype);
00085        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00086                            KEYFILE, strlen(KEYFILE));
00087 
00088        dkim = dkim_verify(lib, JOBID, NULL, &status);
00089        assert(dkim != NULL);
00090 
00091        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00092        status = dkim_header(dkim, hdr, strlen(hdr));
00093        assert(status == DKIM_STAT_OK);
00094 
00095        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00096        assert(status == DKIM_STAT_OK);
00097 
00098        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00099        assert(status == DKIM_STAT_OK);
00100 
00101        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_eoh(dkim);
00120        assert(status == DKIM_STAT_OK);
00121 
00122        memset(body, '\0', sizeof body);
00123 
00124        while (wlen > GIBBERISHLEN)
00125        {
00126               strlcat(body, GIBBERISH, sizeof body);
00127               wlen -= GIBBERISHLEN;
00128        }
00129 
00130        status = dkim_body(dkim, body, strlen(body));
00131        assert(status == DKIM_STAT_OK);
00132        status = dkim_body(dkim, CRLF, strlen(CRLF));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        status = dkim_eom(dkim, NULL);
00136        assert(status == DKIM_STAT_OK);
00137 
00138        status = dkim_free(dkim);
00139        assert(status == DKIM_STAT_OK);
00140 
00141        dkim_close(lib);
00142 
00143        return 0;
00144 }