Back to index

opendkim  2.6.2
t-test47.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_test47_c_id[] = "@(#)$Id: t-test47.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 char *always_sign[] = 
00031 {
00032        "Cc",
00033        NULL
00034 };
00035 
00036 #define       SIG2   "v=1; a=rsa-sha256; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID:Cc;\r\n\tb=AX9mksH+hDJ1UpZWbfKSLmErwcELCieKzn7eix6Af4iSj08EtnAkRaT1lIBPPJQdJ\r\n\t rJ5UDOTHQ3xxNiHpsWJscYpmbqiNaSldpG37kPS8uKuJLSRIZbkoHKP9xlI9tUe6YF\r\n\t j7UWDc53jqeUX2Ei19d0mzMQUOuyYBue3+oJDXqc="
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        uint64_t fixed_time;
00056        DKIM *dkim;
00057        DKIM_LIB *lib;
00058        dkim_sigkey_t key;
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("*** relaxed/simple rsa-sha256 signing absent headers SKIPPED\n");
00072               dkim_close(lib);
00073               return 0;
00074        }
00075 
00076        printf("*** relaxed/simple rsa-sha256 signing absent headers\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        key = KEY;
00086 
00087        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00088                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00089                         DKIM_SIGN_RSASHA256, -1L, &status);
00090        assert(dkim != NULL);
00091 
00092        /* fix signing time */
00093        fixed_time = 1172620939;
00094        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00095                            &fixed_time, sizeof fixed_time);
00096 
00097        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_ALWAYSHDRS,
00098                            &always_sign, sizeof (char **));
00099 
00100        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_eoh(dkim);
00125        assert(status == DKIM_STAT_OK);
00126 
00127        status = dkim_body(dkim, BODY00, strlen(BODY00));
00128        assert(status == DKIM_STAT_OK);
00129 
00130        status = dkim_body(dkim, BODY01, strlen(BODY01));
00131        assert(status == DKIM_STAT_OK);
00132 
00133        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00134        assert(status == DKIM_STAT_OK);
00135        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00136        assert(status == DKIM_STAT_OK);
00137        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00138        assert(status == DKIM_STAT_OK);
00139        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00140        assert(status == DKIM_STAT_OK);
00141        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00142        assert(status == DKIM_STAT_OK);
00143 
00144        status = dkim_body(dkim, BODY02, strlen(BODY02));
00145        assert(status == DKIM_STAT_OK);
00146 
00147        status = dkim_body(dkim, BODY03, strlen(BODY03));
00148        assert(status == DKIM_STAT_OK);
00149 
00150        status = dkim_body(dkim, BODY04, strlen(BODY04));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_body(dkim, BODY03, strlen(BODY03));
00154        assert(status == DKIM_STAT_OK);
00155 
00156        status = dkim_body(dkim, BODY03, strlen(BODY03));
00157        assert(status == DKIM_STAT_OK);
00158 
00159        status = dkim_body(dkim, BODY05, strlen(BODY05));
00160        assert(status == DKIM_STAT_OK);
00161 
00162        status = dkim_body(dkim, BODY03, strlen(BODY03));
00163        assert(status == DKIM_STAT_OK);
00164 
00165        status = dkim_body(dkim, BODY03, strlen(BODY03));
00166        assert(status == DKIM_STAT_OK);
00167 
00168        status = dkim_eom(dkim, NULL);
00169        assert(status == DKIM_STAT_OK);
00170 
00171        memset(hdr, '\0', sizeof hdr);
00172        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00173                                strlen(DKIM_SIGNHEADER) + 2);
00174        assert(status == DKIM_STAT_OK);
00175        assert(strcmp(SIG2, hdr) == 0);
00176 
00177        status = dkim_free(dkim);
00178        assert(status == DKIM_STAT_OK);
00179 
00180        dkim_close(lib);
00181 
00182        return 0;
00183 }