Back to index

opendkim  2.6.4
t-test118.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_test118_c_id[] = "@(#)$Id: t-test118.c,v 1.4 2010/09/02 05:10:57 cm-msk Exp $";
00010 #endif /* !lint */
00011 
00012 #include "build-config.h"
00013 
00014 /* system includes */
00015 #include <sys/types.h>
00016 #include <arpa/nameser.h>
00017 #include <assert.h>
00018 #include <string.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 "../dkim-test.h"
00028 #include "t-testdata.h"
00029 
00030 #define       MAXHEADER     4096
00031 
00032 #define SIG2 "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="
00033 
00034 #define       ADSPNAME      "_adsp._domainkey.example.com"
00035 #define       KEYNAME              "test._domainkey.example.com"
00036 #define       POLICY        "dkim=all; t=s"
00037 
00038 /*
00039 **  MAIN -- program mainline
00040 **
00041 **  Parameters:
00042 **     The usual.
00043 **
00044 **  Return value:
00045 **     Exit status.
00046 */
00047 
00048 int
00049 main(int argc, char **argv)
00050 {
00051 #ifdef TEST_KEEP_FILES
00052        u_int flags;
00053 #endif /* TEST_KEEP_FILES */
00054        DKIM_STAT status;
00055        int presult;
00056        dkim_policy_t pcode;
00057        dkim_query_t qtype = DKIM_QUERY_FILE;
00058        DKIM *dkim;
00059        DKIM_LIB *lib;
00060        unsigned char hdr[MAXHEADER + 1];
00061 
00062        printf("*** relaxed/simple rsa-sha1 verifying with simulated DNS\n");
00063 
00064 #ifdef USE_GNUTLS
00065        (void) gnutls_global_init();
00066 #endif /* USE_GNUTLS */
00067 
00068        /* instantiate the library */
00069        lib = dkim_init(NULL, NULL);
00070        assert(lib != NULL);
00071 
00072 #ifdef TEST_KEEP_FILES
00073        /* set flags */
00074        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00075        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00076                            sizeof flags);
00077 #endif /* TEST_KEEP_FILES */
00078 
00079        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00080                            &qtype, sizeof qtype);
00081        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00082                            KEYFILE, strlen(KEYFILE));
00083 
00084        dkim = dkim_verify(lib, JOBID, NULL, &status);
00085        assert(dkim != NULL);
00086 
00087        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00088        status = dkim_header(dkim, hdr, strlen(hdr));
00089        assert(status == DKIM_STAT_OK);
00090 
00091        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00092        assert(status == DKIM_STAT_OK);
00093 
00094        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        /* queue up a DNS reply for the key */
00119        status = dkim_test_dns_put(dkim, C_IN, T_TXT, 0, KEYNAME, PUBLICKEY);
00120        assert(status == 0);
00121 
00122        /* queue up a DNS reply for the policy */
00123        status = dkim_test_dns_put(dkim, C_IN, T_TXT, 0, ADSPNAME, POLICY);
00124        assert(status == 0);
00125 
00126        status = dkim_eoh(dkim);
00127        assert(status == DKIM_STAT_OK);
00128 
00129        status = dkim_body(dkim, BODY00, strlen(BODY00));
00130        assert(status == DKIM_STAT_OK);
00131 
00132        status = dkim_body(dkim, BODY01, strlen(BODY01));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00136        assert(status == DKIM_STAT_OK);
00137        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00138        assert(status == DKIM_STAT_OK);
00139        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00140        assert(status == DKIM_STAT_OK);
00141        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00142        assert(status == DKIM_STAT_OK);
00143        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00144        assert(status == DKIM_STAT_OK);
00145 
00146        status = dkim_body(dkim, BODY02, strlen(BODY02));
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, BODY04, strlen(BODY04));
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_body(dkim, BODY05, strlen(BODY05));
00162        assert(status == DKIM_STAT_OK);
00163 
00164        status = dkim_body(dkim, BODY03, strlen(BODY03));
00165        assert(status == DKIM_STAT_OK);
00166 
00167        status = dkim_body(dkim, BODY03, strlen(BODY03));
00168        assert(status == DKIM_STAT_OK);
00169 
00170        status = dkim_eom(dkim, NULL);
00171        assert(status == DKIM_STAT_OK);
00172 
00173        status = dkim_policy(dkim, &pcode, NULL);
00174        assert(status == DKIM_STAT_OK);
00175 
00176        presult = dkim_getpresult(dkim);
00177        assert(pcode == DKIM_POLICY_ALL);
00178        assert(presult == DKIM_PRESULT_FOUND);
00179 
00180        status = dkim_free(dkim);
00181        assert(status == DKIM_STAT_OK);
00182 
00183        dkim_close(lib);
00184 
00185        return 0;
00186 }