Back to index

opendkim  2.6.2
t-test88.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_test88_c_id[] = "@(#)$Id: t-test88.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 "../dkim-strl.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define       MAXMSGSIZE    16384
00032 
00033 #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="
00034 
00035 /*
00036 **  MAIN -- program mainline
00037 **
00038 **  Parameters:
00039 **     The usual.
00040 **
00041 **  Return value:
00042 **     Exit status.
00043 */
00044 
00045 int
00046 main(int argc, char **argv)
00047 {
00048 #ifdef TEST_KEEP_FILES
00049        u_int flags;
00050 #endif /* TEST_KEEP_FILES */
00051        DKIM_STAT status;
00052        DKIM *dkim;
00053        DKIM_LIB *lib;
00054        dkim_query_t qtype = DKIM_QUERY_FILE;
00055        unsigned char hdr[MAXHEADER + 1];
00056        unsigned char buf[MAXMSGSIZE];
00057 
00058        printf("*** relaxed/simple rsa-sha1 verifying using chunking API (single chunk)\n");
00059 
00060 #ifdef USE_GNUTLS
00061        (void) gnutls_global_init();
00062 #endif /* USE_GNUTLS */
00063 
00064        /* instantiate the library */
00065        lib = dkim_init(NULL, NULL);
00066        assert(lib != NULL);
00067 
00068 #ifdef TEST_KEEP_FILES
00069        /* set flags */
00070        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00071        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00072                            sizeof flags);
00073 #endif /* TEST_KEEP_FILES */
00074 
00075        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00076                            &qtype, sizeof qtype);
00077        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00078                            KEYFILE, strlen(KEYFILE));
00079 
00080        dkim = dkim_verify(lib, JOBID, NULL, &status);
00081        assert(dkim != NULL);
00082 
00083        memset(buf, '\0', sizeof buf);
00084 
00085        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00086        strlcpy(buf, hdr, MAXMSGSIZE);
00087        strlcat(buf, CRLF, MAXMSGSIZE);
00088 
00089        strlcat(buf, HEADER01, MAXMSGSIZE);
00090        strlcat(buf, CRLF, MAXMSGSIZE);
00091 
00092        strlcat(buf, HEADER02, MAXMSGSIZE);
00093        strlcat(buf, CRLF, MAXMSGSIZE);
00094 
00095        strlcat(buf, HEADER03, MAXMSGSIZE);
00096        strlcat(buf, CRLF, MAXMSGSIZE);
00097 
00098        strlcat(buf, HEADER04, MAXMSGSIZE);
00099        strlcat(buf, CRLF, MAXMSGSIZE);
00100 
00101        strlcat(buf, HEADER05, MAXMSGSIZE);
00102        strlcat(buf, CRLF, MAXMSGSIZE);
00103 
00104        strlcat(buf, HEADER06, MAXMSGSIZE);
00105        strlcat(buf, CRLF, MAXMSGSIZE);
00106 
00107        strlcat(buf, HEADER07, MAXMSGSIZE);
00108        strlcat(buf, CRLF, MAXMSGSIZE);
00109 
00110        strlcat(buf, HEADER08, MAXMSGSIZE);
00111        strlcat(buf, CRLF, MAXMSGSIZE);
00112 
00113        strlcat(buf, HEADER09, MAXMSGSIZE);
00114        strlcat(buf, CRLF, MAXMSGSIZE);
00115 
00116        strlcat(buf, CRLF, MAXMSGSIZE);
00117 
00118        strlcat(buf, BODY00, MAXMSGSIZE);
00119        strlcat(buf, BODY01, MAXMSGSIZE);
00120        strlcat(buf, BODY01A, MAXMSGSIZE);
00121        strlcat(buf, BODY01B, MAXMSGSIZE);
00122        strlcat(buf, BODY01C, MAXMSGSIZE);
00123        strlcat(buf, BODY01D, MAXMSGSIZE);
00124        strlcat(buf, BODY01E, MAXMSGSIZE);
00125        strlcat(buf, BODY02, MAXMSGSIZE);
00126        strlcat(buf, BODY03, MAXMSGSIZE);
00127        strlcat(buf, BODY04, MAXMSGSIZE);
00128        strlcat(buf, BODY03, MAXMSGSIZE);
00129        strlcat(buf, BODY03, MAXMSGSIZE);
00130        strlcat(buf, BODY05, MAXMSGSIZE);
00131        strlcat(buf, BODY03, MAXMSGSIZE);
00132        strlcat(buf, BODY03, MAXMSGSIZE);
00133 
00134        status = dkim_chunk(dkim, buf, strlen(buf));
00135        assert(status == DKIM_STAT_OK);
00136 
00137        status = dkim_eom(dkim, NULL);
00138        assert(status == DKIM_STAT_INVALID);
00139 
00140        status = dkim_chunk(dkim, NULL, 0);
00141        assert(status == DKIM_STAT_OK);
00142 
00143        status = dkim_eom(dkim, NULL);
00144        assert(status == DKIM_STAT_OK);
00145 
00146        status = dkim_free(dkim);
00147        assert(status == DKIM_STAT_OK);
00148 
00149        dkim_close(lib);
00150 
00151        return 0;
00152 }