Back to index

opendkim  2.6.6
t-test71.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_test71_c_id[] = "@(#)$Id: t-test71.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-sha1; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=ll/0h2aWgG+D3ewmE4Y3pY7Ukz8=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Cc:Message-ID;\r\n\tb=qo5Fy/OvM4nsRiazb81pxpjrUIhX0hHoXt3EchKVHklnI6vLKJPKRhChg6NCPcY20\r\n\t OVw8G0OqVhVxjUFb2By97EBJSECIjJabsvDsvjEfsrafj+f4H/FS1KauEBNNaP8KfN\r\n\t aLDkJzE2mKjcxoXBStRYq6iEsbyiAm57PVF4IoEQ="
00031 
00032 #define       XHDRNAME      "Cc: "
00033 #define       XHDRADDR      "nosuchuser@nosuchdomain.com"
00034 #define       XHDRVALEOL    ",\r\n\t"
00035 #define       XHDRVAL              XHDRADDR XHDRVALEOL \
00036                      XHDRADDR XHDRVALEOL \
00037                      XHDRADDR XHDRVALEOL \
00038                      XHDRADDR XHDRVALEOL \
00039                      XHDRADDR XHDRVALEOL \
00040                      XHDRADDR XHDRVALEOL \
00041                      XHDRADDR XHDRVALEOL \
00042                      XHDRADDR XHDRVALEOL \
00043                      XHDRADDR XHDRVALEOL \
00044                      XHDRADDR XHDRVALEOL \
00045                      XHDRADDR XHDRVALEOL \
00046                      XHDRADDR XHDRVALEOL \
00047                      XHDRADDR XHDRVALEOL \
00048                      XHDRADDR XHDRVALEOL \
00049                      XHDRADDR XHDRVALEOL \
00050                      XHDRADDR XHDRVALEOL \
00051                      XHDRADDR XHDRVALEOL \
00052                      XHDRADDR XHDRVALEOL \
00053                      XHDRADDR XHDRVALEOL \
00054                      XHDRADDR XHDRVALEOL \
00055                      XHDRADDR XHDRVALEOL \
00056                      XHDRADDR XHDRVALEOL \
00057                      XHDRADDR XHDRVALEOL \
00058                      XHDRADDR XHDRVALEOL \
00059                      XHDRADDR XHDRVALEOL \
00060                      XHDRADDR XHDRVALEOL \
00061                      XHDRADDR XHDRVALEOL \
00062                      XHDRADDR XHDRVALEOL \
00063                      XHDRADDR XHDRVALEOL \
00064                      XHDRADDR XHDRVALEOL \
00065                      XHDRADDR XHDRVALEOL \
00066                      XHDRADDR XHDRVALEOL \
00067                      XHDRADDR XHDRVALEOL \
00068                      XHDRADDR XHDRVALEOL \
00069                      XHDRADDR XHDRVALEOL \
00070                      XHDRADDR XHDRVALEOL \
00071                      XHDRADDR XHDRVALEOL \
00072                      XHDRADDR XHDRVALEOL \
00073                      XHDRADDR XHDRVALEOL \
00074                      XHDRADDR XHDRVALEOL \
00075                      XHDRADDR XHDRVALEOL \
00076                      XHDRADDR XHDRVALEOL \
00077                      XHDRADDR XHDRVALEOL \
00078                      XHDRADDR XHDRVALEOL \
00079                      XHDRADDR XHDRVALEOL \
00080                      XHDRADDR XHDRVALEOL \
00081                      XHDRADDR XHDRVALEOL \
00082                      XHDRADDR XHDRVALEOL \
00083                      XHDRADDR XHDRVALEOL \
00084                      XHDRADDR XHDRVALEOL \
00085                      XHDRADDR XHDRVALEOL \
00086                      XHDRADDR XHDRVALEOL \
00087                      XHDRADDR XHDRVALEOL \
00088                      XHDRADDR XHDRVALEOL \
00089                      XHDRADDR XHDRVALEOL \
00090                      XHDRADDR XHDRVALEOL \
00091                      XHDRADDR XHDRVALEOL \
00092                      XHDRADDR XHDRVALEOL \
00093                      XHDRADDR XHDRVALEOL \
00094                      XHDRADDR XHDRVALEOL \
00095                      XHDRADDR XHDRVALEOL \
00096                      XHDRADDR XHDRVALEOL \
00097                      XHDRADDR XHDRVALEOL \
00098                      XHDRADDR XHDRVALEOL \
00099                      XHDRADDR XHDRVALEOL \
00100                      XHDRADDR XHDRVALEOL \
00101                      XHDRADDR XHDRVALEOL \
00102                      XHDRADDR XHDRVALEOL \
00103                      XHDRADDR XHDRVALEOL \
00104                      XHDRADDR XHDRVALEOL \
00105                      XHDRADDR XHDRVALEOL \
00106                      XHDRADDR XHDRVALEOL \
00107                      XHDRADDR XHDRVALEOL \
00108                      XHDRADDR XHDRVALEOL \
00109                      XHDRADDR XHDRVALEOL \
00110                      XHDRADDR XHDRVALEOL \
00111                      XHDRADDR XHDRVALEOL \
00112                      XHDRADDR XHDRVALEOL \
00113                      XHDRADDR XHDRVALEOL \
00114                      XHDRADDR XHDRVALEOL \
00115                      XHDRADDR XHDRVALEOL \
00116                      XHDRADDR XHDRVALEOL \
00117                      XHDRADDR XHDRVALEOL \
00118                      XHDRADDR XHDRVALEOL \
00119                      XHDRADDR XHDRVALEOL \
00120                      XHDRADDR XHDRVALEOL \
00121                      XHDRADDR XHDRVALEOL \
00122                      XHDRADDR XHDRVALEOL \
00123                      XHDRADDR XHDRVALEOL \
00124                      XHDRADDR XHDRVALEOL \
00125                      XHDRADDR XHDRVALEOL \
00126                      XHDRADDR XHDRVALEOL \
00127                      XHDRADDR XHDRVALEOL \
00128                      XHDRADDR XHDRVALEOL \
00129                      XHDRADDR XHDRVALEOL \
00130                      XHDRADDR XHDRVALEOL \
00131                      XHDRADDR XHDRVALEOL \
00132                      XHDRADDR XHDRVALEOL \
00133                      XHDRADDR XHDRVALEOL \
00134                      XHDRADDR XHDRVALEOL \
00135                      XHDRADDR XHDRVALEOL \
00136                      XHDRADDR XHDRVALEOL \
00137                      XHDRADDR XHDRVALEOL \
00138                      XHDRADDR XHDRVALEOL \
00139                      XHDRADDR XHDRVALEOL \
00140                      XHDRADDR XHDRVALEOL \
00141                      XHDRADDR XHDRVALEOL \
00142                      XHDRADDR XHDRVALEOL \
00143                      XHDRADDR XHDRVALEOL \
00144                      XHDRADDR XHDRVALEOL \
00145                      XHDRADDR XHDRVALEOL \
00146                      XHDRADDR XHDRVALEOL \
00147                      XHDRADDR XHDRVALEOL \
00148                      XHDRADDR XHDRVALEOL \
00149                      XHDRADDR XHDRVALEOL \
00150                      XHDRADDR XHDRVALEOL \
00151                      XHDRADDR XHDRVALEOL \
00152                      XHDRADDR XHDRVALEOL \
00153                      XHDRADDR XHDRVALEOL \
00154                      XHDRADDR XHDRVALEOL \
00155                      XHDRADDR XHDRVALEOL \
00156                      XHDRADDR XHDRVALEOL \
00157                      XHDRADDR XHDRVALEOL \
00158                      XHDRADDR XHDRVALEOL \
00159                      XHDRADDR XHDRVALEOL \
00160                      XHDRADDR XHDRVALEOL \
00161                      XHDRADDR XHDRVALEOL \
00162                      XHDRADDR XHDRVALEOL \
00163                      XHDRADDR XHDRVALEOL \
00164                      XHDRADDR XHDRVALEOL \
00165                      XHDRADDR XHDRVALEOL \
00166                      XHDRADDR XHDRVALEOL \
00167                      XHDRADDR XHDRVALEOL \
00168                      XHDRADDR XHDRVALEOL \
00169                      XHDRADDR XHDRVALEOL \
00170                      XHDRADDR XHDRVALEOL \
00171                      XHDRADDR XHDRVALEOL \
00172                      XHDRADDR XHDRVALEOL \
00173                      XHDRADDR XHDRVALEOL \
00174                      XHDRADDR XHDRVALEOL \
00175                      XHDRADDR XHDRVALEOL \
00176                      XHDRADDR XHDRVALEOL \
00177                      XHDRADDR XHDRVALEOL \
00178                      XHDRADDR XHDRVALEOL \
00179                      XHDRADDR XHDRVALEOL \
00180                      XHDRADDR XHDRVALEOL \
00181                      XHDRADDR XHDRVALEOL \
00182                      XHDRADDR XHDRVALEOL \
00183                      XHDRADDR XHDRVALEOL \
00184                      XHDRADDR XHDRVALEOL \
00185                      XHDRADDR XHDRVALEOL \
00186                      XHDRADDR
00187 #define       XHEADERCC     XHDRNAME XHDRVAL
00188 
00189 /*
00190 **  MAIN -- program mainline
00191 **
00192 **  Parameters:
00193 **     The usual.
00194 **
00195 **  Return value:
00196 **     Exit status.
00197 */
00198 
00199 int
00200 main(int argc, char **argv)
00201 {
00202 #ifdef TEST_KEEP_FILES
00203        u_int flags;
00204 #endif /* TEST_KEEP_FILES */
00205        DKIM_STAT status;
00206        uint64_t fixed_time;
00207        DKIM *dkim;
00208        DKIM_LIB *lib;
00209        dkim_sigkey_t key;
00210        unsigned char hdr[MAXHEADER + 1];
00211 
00212        printf("*** relaxed/simple rsa-sha1 signing with large headers\n");
00213 
00214 #ifdef USE_GNUTLS
00215        (void) gnutls_global_init();
00216 #endif /* USE_GNUTLS */
00217 
00218        /* instantiate the library */
00219        lib = dkim_init(NULL, NULL);
00220        assert(lib != NULL);
00221 
00222 #ifdef TEST_KEEP_FILES
00223        /* set flags */
00224        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00225        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00226                            sizeof flags);
00227 #endif /* TEST_KEEP_FILES */
00228 
00229        key = KEY;
00230 
00231        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00232                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00233                         DKIM_SIGN_RSASHA1, -1L, &status);
00234        assert(dkim != NULL);
00235 
00236        /* fix signing time */
00237        fixed_time = 1172620939;
00238        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00239                            &fixed_time, sizeof fixed_time);
00240 
00241        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00242        assert(status == DKIM_STAT_OK);
00243 
00244        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00245        assert(status == DKIM_STAT_OK);
00246 
00247        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00248        assert(status == DKIM_STAT_OK);
00249 
00250        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00251        assert(status == DKIM_STAT_OK);
00252 
00253        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00254        assert(status == DKIM_STAT_OK);
00255 
00256        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00257        assert(status == DKIM_STAT_OK);
00258 
00259        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00260        assert(status == DKIM_STAT_OK);
00261 
00262        status = dkim_header(dkim, XHEADERCC, strlen(XHEADERCC));
00263        assert(status == DKIM_STAT_OK);
00264 
00265        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00266        assert(status == DKIM_STAT_OK);
00267 
00268        status = dkim_eoh(dkim);
00269        assert(status == DKIM_STAT_OK);
00270 
00271        status = dkim_body(dkim, BODY00, strlen(BODY00));
00272        assert(status == DKIM_STAT_OK);
00273 
00274        status = dkim_body(dkim, BODY01, strlen(BODY01));
00275        assert(status == DKIM_STAT_OK);
00276 
00277        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00278        assert(status == DKIM_STAT_OK);
00279        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00280        assert(status == DKIM_STAT_OK);
00281        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00282        assert(status == DKIM_STAT_OK);
00283        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00284        assert(status == DKIM_STAT_OK);
00285        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00286        assert(status == DKIM_STAT_OK);
00287 
00288        status = dkim_body(dkim, BODY02, strlen(BODY02));
00289        assert(status == DKIM_STAT_OK);
00290 
00291        status = dkim_body(dkim, BODY03, strlen(BODY03));
00292        assert(status == DKIM_STAT_OK);
00293 
00294        status = dkim_body(dkim, BODY04, strlen(BODY04));
00295        assert(status == DKIM_STAT_OK);
00296 
00297        status = dkim_body(dkim, BODY03, strlen(BODY03));
00298        assert(status == DKIM_STAT_OK);
00299 
00300        status = dkim_body(dkim, BODY03, strlen(BODY03));
00301        assert(status == DKIM_STAT_OK);
00302 
00303        status = dkim_body(dkim, BODY05, strlen(BODY05));
00304        assert(status == DKIM_STAT_OK);
00305 
00306        status = dkim_body(dkim, BODY03, strlen(BODY03));
00307        assert(status == DKIM_STAT_OK);
00308 
00309        status = dkim_body(dkim, BODY03, strlen(BODY03));
00310        assert(status == DKIM_STAT_OK);
00311 
00312        status = dkim_eom(dkim, NULL);
00313        assert(status == DKIM_STAT_OK);
00314 
00315        memset(hdr, '\0', sizeof hdr);
00316        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00317                                strlen(DKIM_SIGNHEADER) + 2);
00318        assert(status == DKIM_STAT_OK);
00319        assert(strcmp(SIG2, hdr) == 0);
00320 
00321        status = dkim_free(dkim);
00322        assert(status == DKIM_STAT_OK);
00323 
00324        dkim_close(lib);
00325 
00326        return 0;
00327 }