Back to index

opendkim  2.6.6
t-test98.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_test98_c_id[] = "@(#)$Id: t-test98.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 
00030 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/relaxed; d=example.com; s=test;\r\n\tt=1172620939; bh=Z9ONHHsBrKN0pbfrOu025VfbdR4=; l=340; h=Received:\r\n\t Received:Received:From:To:Date:Subject:Message-ID; b=NiN+5WZz+O0jY\r\n\t+OH1mCVhv3zM+SrJ6i0wTrhoaDOawOTwW10dF/ZTaMdFmrjJkQfxQenKQN0hmxRNm0Q\r\n\tabHoiaaO1N5owKY0/cUV78U5Z05bNjGl9P9goSgNsLGukRgjb+ellUI8U97Xi9mFjOG\r\n\tWm1iJ2FIq31Bh1mybmvlveKA="
00031 
00032 /*
00033 **  MAIN -- program mainline
00034 **
00035 **  Parameters:
00036 **     The usual.
00037 **
00038 **  Return value:
00039 **     Exit status.
00040 */
00041 
00042 int
00043 main(int argc, char **argv)
00044 {
00045        u_int flags;
00046        DKIM_STAT status;
00047        DKIM *dkim;
00048        DKIM_LIB *lib;
00049        DKIM_SIGINFO *sig;
00050        dkim_query_t qtype = DKIM_QUERY_FILE;
00051        unsigned char hdr[MAXHEADER + 1];
00052 
00053        printf("*** relaxed/relaxed rsa-sha1 verifying with oversized l= value (failure)\n");
00054 
00055 #ifdef USE_GNUTLS
00056        (void) gnutls_global_init();
00057 #endif /* USE_GNUTLS */
00058 
00059        /* instantiate the library */
00060        lib = dkim_init(NULL, NULL);
00061        assert(lib != NULL);
00062 
00063 #ifdef TEST_KEEP_FILES
00064        /* set flags */
00065        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00066        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00067                            sizeof flags);
00068 #endif /* TEST_KEEP_FILES */
00069 
00070        (void) dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_FLAGS, &flags,
00071                            sizeof flags);
00072        flags |= DKIM_LIBFLAGS_SIGNLEN;
00073        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00074                            sizeof flags);
00075 
00076        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00077                            &qtype, sizeof qtype);
00078        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00079                            KEYFILE, strlen(KEYFILE));
00080 
00081        dkim = dkim_verify(lib, JOBID, NULL, &status);
00082        assert(dkim != NULL);
00083 
00084        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00085        status = dkim_header(dkim, hdr, strlen(hdr));
00086        assert(status == DKIM_STAT_OK);
00087 
00088        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00089        assert(status == DKIM_STAT_OK);
00090 
00091        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00092        assert(status == DKIM_STAT_OK);
00093 
00094        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_eoh(dkim);
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_body(dkim, BODY00, strlen(BODY00));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_body(dkim, BODY01, strlen(BODY01));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00125        assert(status == DKIM_STAT_OK);
00126        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00127        assert(status == DKIM_STAT_OK);
00128        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00129        assert(status == DKIM_STAT_OK);
00130        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00131        assert(status == DKIM_STAT_OK);
00132        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00133        assert(status == DKIM_STAT_OK);
00134 
00135 /*
00136        status = dkim_body(dkim, BODY02, strlen(BODY02));
00137        assert(status == DKIM_STAT_OK);
00138 
00139        status = dkim_body(dkim, BODY03, strlen(BODY03));
00140        assert(status == DKIM_STAT_OK);
00141 
00142        status = dkim_body(dkim, BODY04, strlen(BODY04));
00143        assert(status == DKIM_STAT_OK);
00144 
00145        status = dkim_body(dkim, BODY03, strlen(BODY03));
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, BODY05, strlen(BODY05));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_body(dkim, BODY03, strlen(BODY03));
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, BODY06, strlen(BODY06));
00161        assert(status == DKIM_STAT_OK);
00162 */
00163 
00164        status = dkim_eom(dkim, NULL);
00165        assert(status == DKIM_STAT_CANTVRFY);
00166 
00167        sig = dkim_getsignature(dkim);
00168        assert(sig != NULL);
00169        assert(dkim_sig_geterror(sig) == DKIM_SIGERROR_TOOLARGE_L);
00170 
00171        status = dkim_free(dkim);
00172        assert(status == DKIM_STAT_OK);
00173 
00174        dkim_close(lib);
00175 
00176        return 0;
00177 }