Back to index

opendkim  2.6.2
t-test37.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_test37_c_id[] = "@(#)$Id: t-test37.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-sha256; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939;\r\n\tbh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID; b=hNR\r\n\tIcA7ZG6mZL9GPr5E9rJPQBy0DNnPSNAqYmtpbHJjhzWj3fsUKXDCEl8vJki6VuP0hDA\r\n\t4wRRJ6hkD0/u9iY2O+7xwAyuzkC3Z719CuGidnqlJt/1kJ4QW4KlcWJcj2v8SjD475G\r\n\tchVu0268Cz9PTJWSEqg/WZfWLQrji0gmy0="
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 #ifdef TEST_KEEP_FILES
00046        u_int flags;
00047 #endif /* TEST_KEEP_FILES */
00048        DKIM_STAT status;
00049        DKIM *dkim;
00050        DKIM_LIB *lib;
00051        dkim_query_t qtype = DKIM_QUERY_FILE;
00052        unsigned char hdr[MAXHEADER + 1];
00053 
00054 #ifdef USE_GNUTLS
00055        (void) gnutls_global_init();
00056 #endif /* USE_GNUTLS */
00057 
00058        /* instantiate the library */
00059        lib = dkim_init(NULL, NULL);
00060        assert(lib != NULL);
00061 
00062        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00063        {
00064               printf("*** relaxed/simple rsa-sha256 verifying with signature re-wrapping SKIPPED\n");
00065               dkim_close(lib);
00066               return 0;
00067        }
00068 
00069        printf("*** relaxed/simple rsa-sha256 verifying with signature re-wrapping\n");
00070 
00071 #ifdef TEST_KEEP_FILES
00072        /* set flags */
00073        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00074        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00075                            sizeof flags);
00076 #endif /* TEST_KEEP_FILES */
00077 
00078        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00079                            &qtype, sizeof qtype);
00080        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00081                            KEYFILE, strlen(KEYFILE));
00082 
00083        dkim = dkim_verify(lib, JOBID, NULL, &status);
00084        assert(dkim != NULL);
00085 
00086        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00087        status = dkim_header(dkim, hdr, strlen(hdr));
00088        assert(status == DKIM_STAT_OK);
00089 
00090        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00091        assert(status == DKIM_STAT_OK);
00092 
00093        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00094        assert(status == DKIM_STAT_OK);
00095 
00096        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00097        assert(status == DKIM_STAT_OK);
00098 
00099        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00100        assert(status == DKIM_STAT_OK);
00101 
00102        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00103        assert(status == DKIM_STAT_OK);
00104 
00105        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00106        assert(status == DKIM_STAT_OK);
00107 
00108        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00109        assert(status == DKIM_STAT_OK);
00110 
00111        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00112        assert(status == DKIM_STAT_OK);
00113 
00114        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00115        assert(status == DKIM_STAT_OK);
00116 
00117        status = dkim_eoh(dkim);
00118        assert(status == DKIM_STAT_OK);
00119 
00120        status = dkim_body(dkim, BODY00, strlen(BODY00));
00121        assert(status == DKIM_STAT_OK);
00122 
00123        status = dkim_body(dkim, BODY01, strlen(BODY01));
00124        assert(status == DKIM_STAT_OK);
00125 
00126        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00127        assert(status == DKIM_STAT_OK);
00128        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00129        assert(status == DKIM_STAT_OK);
00130        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00131        assert(status == DKIM_STAT_OK);
00132        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00133        assert(status == DKIM_STAT_OK);
00134        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00135        assert(status == DKIM_STAT_OK);
00136 
00137        status = dkim_body(dkim, BODY02, strlen(BODY02));
00138        assert(status == DKIM_STAT_OK);
00139 
00140        status = dkim_body(dkim, BODY03, strlen(BODY03));
00141        assert(status == DKIM_STAT_OK);
00142 
00143        status = dkim_body(dkim, BODY04, strlen(BODY04));
00144        assert(status == DKIM_STAT_OK);
00145 
00146        status = dkim_body(dkim, BODY03, strlen(BODY03));
00147        assert(status == DKIM_STAT_OK);
00148 
00149        status = dkim_body(dkim, BODY03, strlen(BODY03));
00150        assert(status == DKIM_STAT_OK);
00151 
00152        status = dkim_body(dkim, BODY05, strlen(BODY05));
00153        assert(status == DKIM_STAT_OK);
00154 
00155        status = dkim_body(dkim, BODY03, strlen(BODY03));
00156        assert(status == DKIM_STAT_OK);
00157 
00158        status = dkim_body(dkim, BODY03, strlen(BODY03));
00159        assert(status == DKIM_STAT_OK);
00160 
00161        status = dkim_eom(dkim, NULL);
00162        assert(status == DKIM_STAT_OK);
00163 
00164        status = dkim_free(dkim);
00165        assert(status == DKIM_STAT_OK);
00166 
00167        dkim_close(lib);
00168 
00169        return 0;
00170 }