Back to index

opendkim  2.6.2
t-test127.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_test127_c_id[] = "@(#)$Id: t-test127.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=NYK+FZAKLNXv1Oj/E6kV0EOStBU=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=G9BZ+aZqLU7j3DnHe1s/qgrJagml7UDFUxOEQ/uCwWGvOgrDn3PBE/Nb1OwpGzuFJ\r\n\t AOCTpNGrK2sw4pfEAk+/uOBGjZsMTBe9uqIA7w3tQFkF3yIRv6zqa/rccbWa5d0wYn\r\n\t S534UHVEyPXjXQ5x/yspDXF+v3geyISQ+oHf9hro="
00034 
00035 #define       CRLFBODY00    "test\r\n"
00036 
00037 #define       BOUNDARY      9
00038 
00039 /*
00040 **  MAIN -- program mainline
00041 **
00042 **  Parameters:
00043 **     The usual.
00044 **
00045 **  Return value:
00046 **     Exit status.
00047 */
00048 
00049 int
00050 main(int argc, char **argv)
00051 {
00052 #ifdef TEST_KEEP_FILES
00053        u_int flags;
00054 #endif /* TEST_KEEP_FILES */
00055        DKIM_STAT status;
00056        uint64_t fixed_time;
00057        DKIM *dkim;
00058        DKIM_LIB *lib;
00059        dkim_sigkey_t key;
00060        unsigned char hdr[MAXHEADER + 1];
00061        unsigned char buf[MAXMSGSIZE];
00062 
00063        printf("*** relaxed/simple rsa-sha1 signing with split CRLFs and blank counting\n");
00064 
00065 #ifdef USE_GNUTLS
00066        (void) gnutls_global_init();
00067 #endif /* USE_GNUTLS */
00068 
00069        /* instantiate the library */
00070        lib = dkim_init(NULL, NULL);
00071        assert(lib != NULL);
00072 
00073 #ifdef TEST_KEEP_FILES
00074        /* set flags */
00075        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00076        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00077                            sizeof flags);
00078 #endif /* TEST_KEEP_FILES */
00079 
00080        key = KEY;
00081 
00082        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00083                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00084                         DKIM_SIGN_RSASHA1, -1L, &status);
00085        assert(dkim != NULL);
00086 
00087        /* fix signing time */
00088        fixed_time = 1172620939;
00089        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00090                            &fixed_time, sizeof fixed_time);
00091 
00092        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00093        assert(status == DKIM_STAT_OK);
00094 
00095        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00096        assert(status == DKIM_STAT_OK);
00097 
00098        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00099        assert(status == DKIM_STAT_OK);
00100 
00101        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_eoh(dkim);
00117        assert(status == DKIM_STAT_OK);
00118 
00119        memset(buf, '\0', sizeof buf);
00120 
00121        dkim_strlcpy(buf, CRLFBODY00, sizeof buf);
00122 
00123        while (strlen(buf) < BOUNDARY)
00124               dkim_strlcat(buf, CRLF, sizeof buf);
00125 
00126        dkim_strlcat(buf, CRLFBODY00, sizeof buf);
00127 
00128        assert(strlen(buf) > BOUNDARY);
00129 
00130        status = dkim_body(dkim, buf, BOUNDARY);
00131        assert(status == DKIM_STAT_OK);
00132 
00133        status = dkim_body(dkim, buf + BOUNDARY, strlen(buf) - BOUNDARY);
00134        assert(status == DKIM_STAT_OK);
00135 
00136        status = dkim_eom(dkim, NULL);
00137        assert(status == DKIM_STAT_OK);
00138 
00139        memset(hdr, '\0', sizeof hdr);
00140        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00141                                strlen(DKIM_SIGNHEADER) + 2);
00142        assert(status == DKIM_STAT_OK);
00143        assert(strcmp(SIG2, hdr) == 0);
00144 
00145        status = dkim_free(dkim);
00146        assert(status == DKIM_STAT_OK);
00147 
00148        dkim_close(lib);
00149 
00150        return 0;
00151 }