Back to index

opendkim  2.6.6
t-test107.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_test107_c_id[] = "@(#)$Id: t-test107.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; 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="
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        int nsigs;
00049        DKIM_STAT status;
00050        DKIM *dkim;
00051        DKIM_LIB *lib;
00052        DKIM_SIGINFO **sigs;
00053        dkim_canon_t bcanon;
00054        dkim_query_t qtype = DKIM_QUERY_FILE;
00055        unsigned char hdr[MAXHEADER + 1];
00056 
00057        printf("*** relaxed/simple rsa-sha1 default body canonicalization\n");
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 #ifdef TEST_KEEP_FILES
00068        /* set flags */
00069        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00070        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00071                            sizeof flags);
00072 #endif /* TEST_KEEP_FILES */
00073 
00074        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00075                            &qtype, sizeof qtype);
00076        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00077                            KEYFILE, strlen(KEYFILE));
00078 
00079        dkim = dkim_verify(lib, JOBID, NULL, &status);
00080        assert(dkim != NULL);
00081 
00082        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00083        status = dkim_header(dkim, hdr, strlen(hdr));
00084        assert(status == DKIM_STAT_OK);
00085 
00086        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00087        assert(status == DKIM_STAT_OK);
00088 
00089        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00090        assert(status == DKIM_STAT_OK);
00091 
00092        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00093        assert(status == DKIM_STAT_OK);
00094 
00095        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00096        assert(status == DKIM_STAT_OK);
00097 
00098        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00099        assert(status == DKIM_STAT_OK);
00100 
00101        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_eoh(dkim);
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_getsiglist(dkim, &sigs, &nsigs);
00117        assert(status == DKIM_STAT_OK);
00118        assert(sigs != NULL);
00119        assert(nsigs != 0);
00120 
00121        status = dkim_sig_getcanons(sigs[0], NULL, &bcanon);
00122        assert(status == DKIM_STAT_OK);
00123        assert(bcanon == DKIM_CANON_SIMPLE);
00124 
00125        status = dkim_free(dkim);
00126        assert(status == DKIM_STAT_OK);
00127 
00128        dkim_close(lib);
00129 
00130        return 0;
00131 }