Back to index

opendkim  2.6.6
t-test142.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_test142_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 #define       MAXMSGSIZE    16384
00031 
00032 #define       TEST_KEEP_FILES      1
00033 
00034 #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="
00035 
00036 /*
00037 **  MAIN -- program mainline
00038 **
00039 **  Parameters:
00040 **     The usual.
00041 **
00042 **  Return value:
00043 **     Exit status.
00044 */
00045 
00046 int
00047 main(int argc, char **argv)
00048 {
00049        u_char *p;
00050        size_t len;
00051        u_int flags;
00052        DKIM_STAT status;
00053        DKIM *dkim;
00054        DKIM_LIB *lib;
00055        dkim_query_t qtype = DKIM_QUERY_FILE;
00056        unsigned char hdr[MAXHEADER + 1];
00057        unsigned char buf[MAXMSGSIZE];
00058 
00059        printf("*** relaxed/simple rsa-sha1 verifying using chunking API (single chunk, LF only, FIXCRLF)\n");
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        /* set flags */
00070        flags = DKIM_LIBFLAGS_FIXCRLF;
00071 #ifdef TEST_KEEP_FILES
00072        flags |= (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00073 #endif /* TEST_KEEP_FILES */
00074        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00075                            sizeof flags);
00076 
00077        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00078                            &qtype, sizeof qtype);
00079        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00080                            KEYFILE, strlen(KEYFILE));
00081 
00082        dkim = dkim_verify(lib, JOBID, NULL, &status);
00083        assert(dkim != NULL);
00084 
00085        memset(buf, '\0', sizeof buf);
00086 
00087        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00088        strlcpy(buf, hdr, MAXMSGSIZE);
00089        strlcat(buf, CRLF, MAXMSGSIZE);
00090 
00091        strlcat(buf, HEADER01, MAXMSGSIZE);
00092        strlcat(buf, CRLF, MAXMSGSIZE);
00093 
00094        strlcat(buf, HEADER02, MAXMSGSIZE);
00095        strlcat(buf, CRLF, MAXMSGSIZE);
00096 
00097        strlcat(buf, HEADER03, MAXMSGSIZE);
00098        strlcat(buf, CRLF, MAXMSGSIZE);
00099 
00100        strlcat(buf, HEADER04, MAXMSGSIZE);
00101        strlcat(buf, CRLF, MAXMSGSIZE);
00102 
00103        strlcat(buf, HEADER05, MAXMSGSIZE);
00104        strlcat(buf, CRLF, MAXMSGSIZE);
00105 
00106        strlcat(buf, HEADER06, MAXMSGSIZE);
00107        strlcat(buf, CRLF, MAXMSGSIZE);
00108 
00109        strlcat(buf, HEADER07, MAXMSGSIZE);
00110        strlcat(buf, CRLF, MAXMSGSIZE);
00111 
00112        strlcat(buf, HEADER08, MAXMSGSIZE);
00113        strlcat(buf, CRLF, MAXMSGSIZE);
00114 
00115        strlcat(buf, HEADER09, MAXMSGSIZE);
00116        strlcat(buf, CRLF, MAXMSGSIZE);
00117 
00118        strlcat(buf, CRLF, MAXMSGSIZE);
00119 
00120        strlcat(buf, BODY00, MAXMSGSIZE);
00121        strlcat(buf, BODY01, MAXMSGSIZE);
00122        strlcat(buf, BODY01A, MAXMSGSIZE);
00123        strlcat(buf, BODY01B, MAXMSGSIZE);
00124        strlcat(buf, BODY01C, MAXMSGSIZE);
00125        strlcat(buf, BODY01D, MAXMSGSIZE);
00126        strlcat(buf, BODY01E, MAXMSGSIZE);
00127        strlcat(buf, BODY02, MAXMSGSIZE);
00128        strlcat(buf, BODY03, MAXMSGSIZE);
00129        strlcat(buf, BODY04, MAXMSGSIZE);
00130        strlcat(buf, BODY03, MAXMSGSIZE);
00131        strlcat(buf, BODY03, MAXMSGSIZE);
00132        strlcat(buf, BODY05, MAXMSGSIZE);
00133        strlcat(buf, BODY03, MAXMSGSIZE);
00134        strlcat(buf, BODY03, MAXMSGSIZE);
00135 
00136        len = strlen(buf);
00137        for (p = buf; *p != '\0'; )
00138        {
00139               if (*p == '\r')
00140               {
00141                      memmove(p, p + 1, len);
00142                      len--;
00143               }
00144               else
00145               {
00146                      p++;
00147               }
00148        }
00149 
00150        status = dkim_chunk(dkim, buf, strlen(buf));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_eom(dkim, NULL);
00154        assert(status == DKIM_STAT_INVALID);
00155 
00156        status = dkim_chunk(dkim, NULL, 0);
00157        assert(status == DKIM_STAT_OK);
00158 
00159        status = dkim_eom(dkim, NULL);
00160        assert(status == DKIM_STAT_OK);
00161 
00162        status = dkim_free(dkim);
00163        assert(status == DKIM_STAT_OK);
00164 
00165        dkim_close(lib);
00166 
00167        return 0;
00168 }