Back to index

opendkim  2.6.6
t-test123.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_test123_c_id[] = "@(#)$Id: t-test123.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; b=qtj\r\n\t/DXxof5Ek/8aSXCGkyqpRCAviW6vmwx9feqGq/OnxMwYwCbwa5TOayfJHGdL1/IK7GL\r\n\t77WMa/Jn0d580YG/qS+wOE2cWas3rR2xnPwvjXpUr8ck/xMH8R79mEWbZ+wTTv0mKf0\r\n\tYcpyicBf+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        u_char *p;
00055        DKIM *dkim;
00056        DKIM_LIB *lib;
00057        dkim_query_t qtype = DKIM_QUERY_FILE;
00058        unsigned char gibline[sizeof(GIBBERISH) + 1];
00059        unsigned char hdr[MAXHEADER + 1];
00060        unsigned char body[LARGEBODYSIZE];
00061 
00062        strlcpy(gibline, GIBBERISH, sizeof gibline);
00063        p = strchr(gibline, '\r');
00064        if (p != NULL)
00065               *p = '\0';
00066 
00067 #ifdef USE_GNUTLS
00068        (void) gnutls_global_init();
00069 #endif /* USE_GNUTLS */
00070 
00071        /* instantiate the library */
00072        lib = dkim_init(NULL, NULL);
00073        assert(lib != NULL);
00074 
00075        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00076        {
00077               printf("*** relaxed/simple rsa-sha256 verifying large lines SKIPPED\n");
00078               dkim_close(lib);
00079               return 0;
00080        }
00081 
00082        printf("*** relaxed/simple rsa-sha256 verifying large lines\n");
00083 
00084 #ifdef TEST_KEEP_FILES
00085        /* set flags */
00086        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00087        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00088                            sizeof flags);
00089 #endif /* TEST_KEEP_FILES */
00090 
00091        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00092                            &qtype, sizeof qtype);
00093        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00094                            KEYFILE, strlen(KEYFILE));
00095 
00096        dkim = dkim_verify(lib, JOBID, NULL, &status);
00097        assert(dkim != NULL);
00098 
00099        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00100        status = dkim_header(dkim, hdr, strlen(hdr));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00125        assert(status == DKIM_STAT_OK);
00126 
00127        status = dkim_eoh(dkim);
00128        assert(status == DKIM_STAT_OK);
00129 
00130        memset(body, '\0', sizeof body);
00131 
00132        while (wlen > GIBBERISHLEN + 2)
00133        {
00134               strlcat(body, gibline, sizeof body);
00135               wlen -= strlen(gibline);
00136               llen += strlen(gibline);
00137 
00138               if (llen > LARGELINESIZE)
00139               {
00140                      strlcat(body, CRLF, sizeof body);
00141                      wlen -= 2;
00142                      llen = 0;
00143               }
00144        }
00145 
00146        strlcat(body, CRLF, sizeof body);
00147 
00148        status = dkim_body(dkim, body, strlen(body));
00149        assert(status == DKIM_STAT_OK);
00150        status = dkim_body(dkim, CRLF, strlen(CRLF));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_eom(dkim, NULL);
00154        assert(status == DKIM_STAT_OK);
00155 
00156        status = dkim_free(dkim);
00157        assert(status == DKIM_STAT_OK);
00158 
00159        dkim_close(lib);
00160 
00161        return 0;
00162 }