Back to index

opendkim  2.6.4
t-test51.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_test51_c_id[] = "@(#)$Id: t-test51.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; s=brisbane; d=example.com;\r\n" \
00031        "      c=simple/simple; q=dns/txt; i=joe@football.example.com;\r\n" \
00032        "      h=Received : From : To : Subject : Date : Message-ID;\r\n" \
00033        "      bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;\r\n" \
00034        "      b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB\r\n" \
00035        "        4nujc7YopdG5dWLSdNg6xNAZpOPr+kHxt1IrE+NahM6L/LbvaHut\r\n" \
00036        "        KVdkLLkpVaVVQPzeRDI009SO2Il5Lu7rDNH6mZckBdrIx0orEtZV\r\n" \
00037        "        4bmp/YzhwvcubU4=;"
00038 
00039 /*
00040 **  MAIN -- program mainline
00041 **
00042 **  Parameters:
00043 **     The usual.
00044 **
00045 **  Return value:
00046 **     Exit status.
00047 */
00048 
00049 int
00050 main(int argc, char **argv)
00051 {
00052 #ifdef TEST_KEEP_FILES
00053        u_int flags;
00054 #endif /* TEST_KEEP_FILES */
00055        DKIM_STAT status;
00056        DKIM *dkim;
00057        DKIM_LIB *lib;
00058        dkim_query_t qtype = DKIM_QUERY_FILE;
00059        unsigned char hdr[MAXHEADER + 1];
00060 
00061 #ifdef USE_GNUTLS
00062        (void) gnutls_global_init();
00063 #endif /* USE_GNUTLS */
00064 
00065        /* instantiate the library */
00066        lib = dkim_init(NULL, NULL);
00067        assert(lib != NULL);
00068 
00069        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00070        {
00071               printf("*** simple/simple rsa-sha256 verifying published example SKIPPED\n");
00072               dkim_close(lib);
00073               return 0;
00074        }
00075 
00076        printf("*** simple/simple rsa-sha256 verifying published example\n");
00077 
00078 #ifdef TEST_KEEP_FILES
00079        /* set flags */
00080        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00081        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00082                            sizeof flags);
00083 #endif /* TEST_KEEP_FILES */
00084 
00085        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00086                            &qtype, sizeof qtype);
00087        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00088                            KEYFILE, strlen(KEYFILE));
00089 
00090        dkim = dkim_verify(lib, JOBID, NULL, &status);
00091        assert(dkim != NULL);
00092 
00093        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00094        status = dkim_header(dkim, hdr, strlen(hdr));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, THEADER00, strlen(THEADER00));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, THEADER01, strlen(THEADER01));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, THEADER02, strlen(THEADER02));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, THEADER03, strlen(THEADER03));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, THEADER04, strlen(THEADER04));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, THEADER05, strlen(THEADER05));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_eoh(dkim);
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_body(dkim, TBODY, strlen(TBODY));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_eom(dkim, NULL);
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_free(dkim);
00125        assert(status == DKIM_STAT_OK);
00126 
00127        dkim_close(lib);
00128 
00129        return 0;
00130 }