Back to index

opendkim  2.6.6
t-test136.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_test136_c_id[] = "@(#)$Id: t-test136.c,v 1.2 2010/04/30 17:01:28 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 #include <ctype.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-strl.h"
00028 #include "t-testdata.h"
00029 
00030 #define       MAXHEADER     4096
00031 
00032 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/relaxed; d=example.com; s=test;\r\n\tt=1172620939; bh=Z9ONHHsBrKN0pbfrOu025VfbdR4=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=Jf+j2RDZRkpIF1KaL5ByhHFPWj5RMeX5764IVlwIc11equjQND51K9FfL5pyjXvwj\r\n\t FoFPW0PGJb3liej6iDDEHgYpXR4p5qqlGx/C1Q9gf/MQN/Xlkv6ZXgR38QnWAfZxh5\r\n\t N1f5xUg+SJb5yBDoXklG62IRdia1Hq9MuiGumrGM="
00033 
00034 /*
00035 **  LOWERHDR -- lowercase-ize a header field name
00036 **
00037 **  Parameters:
00038 **     str -- string to update
00039 **
00040 **  Return value:
00041 **     None.
00042 */
00043 
00044 void
00045 lowerhdr(char *str)
00046 {
00047        char *p;
00048 
00049        assert(str != NULL);
00050 
00051        for (p = str; *p != ':' && *p != '\0'; p++)
00052        {
00053               if (isupper(*p))
00054                      *p = tolower(*p);
00055        }
00056 }
00057 
00058 /*
00059 **  MAIN -- program mainline
00060 **
00061 **  Parameters:
00062 **     The usual.
00063 **
00064 **  Return value:
00065 **     Exit status.
00066 */
00067 
00068 int
00069 main(int argc, char **argv)
00070 {
00071 #ifdef TEST_KEEP_FILES
00072        u_int flags;
00073 #endif /* TEST_KEEP_FILES */
00074        DKIM_STAT status;
00075        DKIM *dkim;
00076        DKIM_LIB *lib;
00077        dkim_query_t qtype = DKIM_QUERY_FILE;
00078        unsigned char hdr[MAXHEADER + 1];
00079 
00080        printf("*** relaxed/relaxed rsa-sha1 verifying with header field name case change\n");
00081 
00082 #ifdef USE_GNUTLS
00083        (void) gnutls_global_init();
00084 #endif /* USE_GNUTLS */
00085 
00086        /* instantiate the library */
00087        lib = dkim_init(NULL, NULL);
00088        assert(lib != NULL);
00089 
00090 #ifdef TEST_KEEP_FILES
00091        /* set flags */
00092        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00093        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00094                            sizeof flags);
00095 #endif /* TEST_KEEP_FILES */
00096 
00097        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00098                            &qtype, sizeof qtype);
00099        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00100                            KEYFILE, strlen(KEYFILE));
00101 
00102        dkim = dkim_verify(lib, JOBID, NULL, &status);
00103        assert(dkim != NULL);
00104 
00105        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00106        status = dkim_header(dkim, hdr, strlen(hdr));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        strlcpy(hdr, HEADER01, sizeof hdr);
00110        lowerhdr(hdr);
00111        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00112        assert(status == DKIM_STAT_OK);
00113 
00114        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00115        assert(status == DKIM_STAT_OK);
00116 
00117        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00118        assert(status == DKIM_STAT_OK);
00119 
00120        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00121        assert(status == DKIM_STAT_OK);
00122 
00123        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00124        assert(status == DKIM_STAT_OK);
00125 
00126        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00127        assert(status == DKIM_STAT_OK);
00128 
00129        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00130        assert(status == DKIM_STAT_OK);
00131 
00132        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00136        assert(status == DKIM_STAT_OK);
00137 
00138        status = dkim_eoh(dkim);
00139        assert(status == DKIM_STAT_OK);
00140 
00141        status = dkim_body(dkim, BODY00, strlen(BODY00));
00142        assert(status == DKIM_STAT_OK);
00143 
00144        status = dkim_body(dkim, BODY01, strlen(BODY01));
00145        assert(status == DKIM_STAT_OK);
00146 
00147        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00148        assert(status == DKIM_STAT_OK);
00149        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00150        assert(status == DKIM_STAT_OK);
00151        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00152        assert(status == DKIM_STAT_OK);
00153        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00154        assert(status == DKIM_STAT_OK);
00155        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00156        assert(status == DKIM_STAT_OK);
00157 
00158        status = dkim_body(dkim, BODY02, strlen(BODY02));
00159        assert(status == DKIM_STAT_OK);
00160 
00161        status = dkim_body(dkim, BODY03, strlen(BODY03));
00162        assert(status == DKIM_STAT_OK);
00163 
00164        status = dkim_body(dkim, BODY04, strlen(BODY04));
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_body(dkim, BODY03, strlen(BODY03));
00171        assert(status == DKIM_STAT_OK);
00172 
00173        status = dkim_body(dkim, BODY05, strlen(BODY05));
00174        assert(status == DKIM_STAT_OK);
00175 
00176        status = dkim_body(dkim, BODY03, strlen(BODY03));
00177        assert(status == DKIM_STAT_OK);
00178 
00179        status = dkim_body(dkim, BODY03, strlen(BODY03));
00180        assert(status == DKIM_STAT_OK);
00181 
00182        status = dkim_eom(dkim, NULL);
00183        assert(status == DKIM_STAT_OK);
00184 
00185        status = dkim_free(dkim);
00186        assert(status == DKIM_STAT_OK);
00187 
00188        dkim_close(lib);
00189 
00190        return 0;
00191 }