Back to index

opendkim  2.6.6
t-test67.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_test67_c_id[] = "@(#)$Id: t-test67.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 <stdlib.h>
00019 #include <stdio.h>
00020 
00021 #ifdef USE_GNUTLS
00022 # include <gnutls/gnutls.h>
00023 #endif /* USE_GNUTLS */
00024 
00025 /* libopendkim includes */
00026 #include "../dkim.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define SIG1 "v=1; a=rsa-sha1; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=ll/0h2aWgG+D3ewmE4Y3pY7Ukz8=; h=Received:Received:\r\n\t Received:From:To:Date:Subject:Message-ID; b=bj9kVUbnBYfe9sVzH9lT45\r\n\tTFKO3eQnDbXLfgmgu/b5QgxcnhT9ojnV2IAM4KUO8+hOo5sDEu5Co/0GASH0vHpSV4P\r\n\t377Iwew3FxvLpHsVbVKgXzoKD4QSbHRpWNxyL6LypaaqFa96YqjXuYXr0vpb88hticn\r\n\t6I16//WThMz8fMU="
00032 #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; b=hNR\r\n\tIcA7ZG6mZL9GPr5E9rJPQBy0DNnPSNAqYmtpbHJjhzWj3fsUKXDCEl8vJki6VuP0hDA\r\n\t4wRRJ6hkD0/u9iY2O+7xwAyuzkC3Z719CuGidnqlJt/1kJ4QW4KlcWJcj2v8SjD475G\r\n\tchVu0268Cz9PTJWSEqg/WZfWLQrji0gmy0="
00033 
00034 /*
00035 **  FINAL -- final signature processing
00036 **
00037 **  Parameters:
00038 **     dkim -- DKIM handle
00039 **     sigs -- array of DKIM_SIGINFO pointers
00040 **     nsigs -- how many sigs there were
00041 **
00042 **  Return value:
00043 **     DKIM_CBSTAT_CONTINUE (assuming no assertions fire).
00044 */
00045 
00046 DKIM_CBSTAT
00047 final(DKIM *dkim, DKIM_SIGINFO **sigs, int nsigs)
00048 {
00049        DKIM_STAT status;
00050        u_int flags;
00051 
00052        assert(sigs != NULL);
00053        assert(nsigs == 2);
00054 
00055        /* verify that the signatures are both okay */
00056        status = dkim_sig_process(dkim, sigs[0]);
00057        assert(status == DKIM_STAT_OK);
00058        flags = dkim_sig_getflags(sigs[0]);
00059        assert((flags & DKIM_SIGFLAG_PROCESSED) != 0);
00060        assert((flags & DKIM_SIGFLAG_IGNORE) == 0);
00061        assert((flags & DKIM_SIGFLAG_PASSED) != 0);
00062        assert(dkim_sig_getbh(sigs[0]) == DKIM_SIGBH_MATCH);
00063 
00064        status = dkim_sig_process(dkim, sigs[1]);
00065        assert(status == DKIM_STAT_OK);
00066        flags = dkim_sig_getflags(sigs[1]);
00067        assert((flags & DKIM_SIGFLAG_PROCESSED) != 0);
00068        assert((flags & DKIM_SIGFLAG_IGNORE) == 0);
00069        assert((flags & DKIM_SIGFLAG_PASSED) != 0);
00070        assert(dkim_sig_getbh(sigs[1]) == DKIM_SIGBH_MATCH);
00071 
00072        return DKIM_CBSTAT_CONTINUE;
00073 }
00074 
00075 /*
00076 **  MAIN -- program mainline
00077 **
00078 **  Parameters:
00079 **     The usual.
00080 **
00081 **  Return value:
00082 **     Exit status.
00083 */
00084 
00085 int
00086 main(int argc, char **argv)
00087 {
00088 #ifdef TEST_KEEP_FILES
00089        u_int flags;
00090 #endif /* TEST_KEEP_FILES */
00091        DKIM_STAT status;
00092        DKIM *dkim;
00093        DKIM_LIB *lib;
00094        dkim_query_t qtype = DKIM_QUERY_FILE;
00095        unsigned char hdr[MAXHEADER + 1];
00096 
00097 #ifdef USE_GNUTLS
00098        (void) gnutls_global_init();
00099 #endif /* USE_GNUTLS */
00100 
00101        /* instantiate the library */
00102        lib = dkim_init(NULL, NULL);
00103        assert(lib != NULL);
00104 
00105        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00106        {
00107               printf("*** relaxed/simple rsa-sha1/rsa-256 verifying SKIPPED\n");
00108               dkim_close(lib);
00109               return 0;
00110        }
00111 
00112        printf("*** relaxed/simple rsa-sha1/rsa-256 verifying\n");
00113 
00114 #ifdef TEST_KEEP_FILES
00115        /* set flags */
00116        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00117        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00118                            sizeof flags);
00119 #endif /* TEST_KEEP_FILES */
00120 
00121        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00122                            &qtype, sizeof qtype);
00123        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00124                            KEYFILE, strlen(KEYFILE));
00125 
00126        dkim = dkim_verify(lib, JOBID, NULL, &status);
00127        assert(dkim != NULL);
00128 
00129        (void) dkim_set_final(lib, final);
00130 
00131        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG1);
00132        status = dkim_header(dkim, hdr, strlen(hdr));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00136        status = dkim_header(dkim, hdr, strlen(hdr));
00137        assert(status == DKIM_STAT_OK);
00138 
00139        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00140        assert(status == DKIM_STAT_OK);
00141 
00142        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00143        assert(status == DKIM_STAT_OK);
00144 
00145        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00146        assert(status == DKIM_STAT_OK);
00147 
00148        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00149        assert(status == DKIM_STAT_OK);
00150 
00151        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00155        assert(status == DKIM_STAT_OK);
00156 
00157        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00158        assert(status == DKIM_STAT_OK);
00159 
00160        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00161        assert(status == DKIM_STAT_OK);
00162 
00163        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00164        assert(status == DKIM_STAT_OK);
00165 
00166        status = dkim_eoh(dkim);
00167        assert(status == DKIM_STAT_OK);
00168 
00169        status = dkim_body(dkim, BODY00, strlen(BODY00));
00170        assert(status == DKIM_STAT_OK);
00171 
00172        status = dkim_body(dkim, BODY01, strlen(BODY01));
00173        assert(status == DKIM_STAT_OK);
00174 
00175        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00176        assert(status == DKIM_STAT_OK);
00177        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00178        assert(status == DKIM_STAT_OK);
00179        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00180        assert(status == DKIM_STAT_OK);
00181        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00182        assert(status == DKIM_STAT_OK);
00183        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00184        assert(status == DKIM_STAT_OK);
00185 
00186        status = dkim_body(dkim, BODY02, strlen(BODY02));
00187        assert(status == DKIM_STAT_OK);
00188 
00189        status = dkim_body(dkim, BODY03, strlen(BODY03));
00190        assert(status == DKIM_STAT_OK);
00191 
00192        status = dkim_body(dkim, BODY04, strlen(BODY04));
00193        assert(status == DKIM_STAT_OK);
00194 
00195        status = dkim_body(dkim, BODY03, strlen(BODY03));
00196        assert(status == DKIM_STAT_OK);
00197 
00198        status = dkim_body(dkim, BODY03, strlen(BODY03));
00199        assert(status == DKIM_STAT_OK);
00200 
00201        status = dkim_body(dkim, BODY05, strlen(BODY05));
00202        assert(status == DKIM_STAT_OK);
00203 
00204        status = dkim_body(dkim, BODY03, strlen(BODY03));
00205        assert(status == DKIM_STAT_OK);
00206 
00207        status = dkim_body(dkim, BODY03, strlen(BODY03));
00208        assert(status == DKIM_STAT_OK);
00209 
00210        status = dkim_eom(dkim, NULL);
00211        assert(status == DKIM_STAT_OK);
00212 
00213        status = dkim_free(dkim);
00214        assert(status == DKIM_STAT_OK);
00215 
00216        dkim_close(lib);
00217 
00218        return 0;
00219 }