Back to index

opendkim  2.6.6
t-test53.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_test53_c_id[] = "@(#)$Id: t-test53.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 #define       MAXHDRCNT     64
00030 
00031 #define SIG2 "v=1; a=rsa-sha256; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID; z=Rec\r\n\teived:=20received=20data=201|Received:=20received=20data=202|Receiv\r\n\ted:=20received=20data=203=20part=201=0D=0A=09=20data=203=20part=202\r\n\t|From:=20Murray=20S.=20Kucherawy=20<msk@sendmail.com>|To:=20Sendmai\r\n\tl=20Test=20Address=20<sa-test@sendmail.net>|Date:=20Thu,=2005=20May\r\n\t=202005=2011:59:09=20-0700|Subject:=20DKIM=20test=20message|Message\r\n\t-ID:=20<439094BF.5010709@sendmail.com>; b=UfBRGUZXr6mCdxVNeavejTTWd\r\n\tWwZWarsUi90kj6K7AJWy4IWhYDpLPCt5tEYIQa4A6B/SkXHremA1QORVn8SW+7Z9xP4\r\n\tLNReV78biYbUnlncfHrEL3K7G3rR5bpa3bfNhdtGSVItLAg/f2XjHqiOQztjz1i4C/p\r\n\tD/pBm8XSWzlA="
00032 
00033 /*
00034 **  MAIN -- program mainline
00035 **
00036 **  Parameters:
00037 **     The usual.
00038 **
00039 **  Return value:
00040 **     Exit status.
00041 */
00042 
00043 int
00044 main(int argc, char **argv)
00045 {
00046 #ifdef TEST_KEEP_FILES
00047        u_int flags;
00048 #endif /* TEST_KEEP_FILES */
00049        int nhdrs;
00050        int nsigs;
00051        DKIM_STAT status;
00052        DKIM *dkim;
00053        DKIM_LIB *lib;
00054        DKIM_SIGINFO **sigs;
00055        dkim_query_t qtype = DKIM_QUERY_FILE;
00056        unsigned char hdr[MAXHEADER + 1];
00057        unsigned char *ohdrs[MAXHDRCNT];
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 with z-tags SKIPPED\n");
00070               dkim_close(lib);
00071               return 0;
00072        }
00073 
00074        printf("*** relaxed/simple rsa-sha256 verifying with z-tags\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        status = dkim_body(dkim, BODY00, strlen(BODY00));
00123        assert(status == DKIM_STAT_OK);
00124 
00125        status = dkim_body(dkim, BODY01, strlen(BODY01));
00126        assert(status == DKIM_STAT_OK);
00127 
00128        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00129        assert(status == DKIM_STAT_OK);
00130        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00131        assert(status == DKIM_STAT_OK);
00132        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00133        assert(status == DKIM_STAT_OK);
00134        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00135        assert(status == DKIM_STAT_OK);
00136        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00137        assert(status == DKIM_STAT_OK);
00138 
00139        status = dkim_body(dkim, BODY02, strlen(BODY02));
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, BODY04, strlen(BODY04));
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_body(dkim, BODY05, strlen(BODY05));
00155        assert(status == DKIM_STAT_OK);
00156 
00157        status = dkim_body(dkim, BODY03, strlen(BODY03));
00158        assert(status == DKIM_STAT_OK);
00159 
00160        status = dkim_body(dkim, BODY03, strlen(BODY03));
00161        assert(status == DKIM_STAT_OK);
00162 
00163        status = dkim_eom(dkim, NULL);
00164        assert(status == DKIM_STAT_OK);
00165 
00166        status = dkim_getsiglist(dkim, &sigs, &nsigs);
00167        assert(status == DKIM_STAT_OK);
00168        assert(sigs != NULL);
00169        assert(sigs[0] != NULL);
00170        assert(nsigs == 1);
00171 
00172        nhdrs = MAXHDRCNT;
00173        status = dkim_ohdrs(dkim, sigs[0], ohdrs, &nhdrs);
00174        assert(status == DKIM_STAT_OK);
00175        assert(nhdrs == 8);
00176        assert(strcmp(ohdrs[0], HEADER02) == 0);
00177        assert(strcmp(ohdrs[1], HEADER03) == 0);
00178        assert(strcmp(ohdrs[2], HEADER04) == 0);
00179        assert(strcmp(ohdrs[3], HEADER05) == 0);
00180        assert(strcmp(ohdrs[4], HEADER06) == 0);
00181        assert(strcmp(ohdrs[5], HEADER07) == 0);
00182        assert(strcmp(ohdrs[6], HEADER08) == 0);
00183        assert(strcmp(ohdrs[7], HEADER09) == 0);
00184 
00185        status = dkim_free(dkim);
00186        assert(status == DKIM_STAT_OK);
00187 
00188        dkim_close(lib);
00189 
00190        return 0;
00191 }