Back to index

opendkim  2.6.6
t-test90.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_test90_c_id[] = "@(#)$Id: t-test90.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/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="
00031 
00032 /*
00033 **  MAIN -- program mainline
00034 **
00035 **  Parameters:
00036 **     The usual.
00037 **
00038 **  Return value:
00039 **     Exit status.
00040 */
00041 
00042 int
00043 main(int argc, char **argv)
00044 {
00045        u_int flags;
00046        DKIM_STAT status;
00047        uint64_t fixed_time;
00048        DKIM *dkim;
00049        DKIM_LIB *lib;
00050        dkim_sigkey_t key;
00051        unsigned char hdr[MAXHEADER + 1];
00052 
00053        printf("*** relaxed/relaxed rsa-sha1 signing with CRLF fixing\n");
00054 
00055 #ifdef USE_GNUTLS
00056        (void) gnutls_global_init();
00057 #endif /* USE_GNUTLS */
00058 
00059        /* instantiate the library */
00060        lib = dkim_init(NULL, NULL);
00061        assert(lib != NULL);
00062 
00063        /* set flags */
00064        (void) dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_FLAGS, &flags,
00065                            sizeof flags);
00066        flags = DKIM_LIBFLAGS_FIXCRLF;
00067 #ifdef TEST_KEEP_FILES
00068        flags |= (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00069 #endif /* TEST_KEEP_FILES */
00070        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00071                            sizeof flags);
00072 
00073        key = KEY;
00074 
00075        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00076                         DKIM_CANON_RELAXED, DKIM_CANON_RELAXED,
00077                         DKIM_SIGN_RSASHA1, -1L, &status);
00078        assert(dkim != NULL);
00079 
00080        /* fix signing time */
00081        fixed_time = 1172620939;
00082        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00083                            &fixed_time, sizeof fixed_time);
00084 
00085        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00086        assert(status == DKIM_STAT_OK);
00087 
00088        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00089        assert(status == DKIM_STAT_OK);
00090 
00091        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00092        assert(status == DKIM_STAT_OK);
00093 
00094        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_eoh(dkim);
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_body(dkim, NBODY00, strlen(NBODY00));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_body(dkim, NBODY01, strlen(NBODY01));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_body(dkim, NBODY01A, strlen(NBODY01A));
00119        assert(status == DKIM_STAT_OK);
00120        status = dkim_body(dkim, NBODY01B, strlen(NBODY01B));
00121        assert(status == DKIM_STAT_OK);
00122        status = dkim_body(dkim, NBODY01C, strlen(NBODY01C));
00123        assert(status == DKIM_STAT_OK);
00124        status = dkim_body(dkim, NBODY01D, strlen(NBODY01D));
00125        assert(status == DKIM_STAT_OK);
00126        status = dkim_body(dkim, NBODY01E, strlen(NBODY01E));
00127        assert(status == DKIM_STAT_OK);
00128 
00129        status = dkim_body(dkim, NBODY02, strlen(NBODY02));
00130        assert(status == DKIM_STAT_OK);
00131 
00132        status = dkim_body(dkim, NBODY03, strlen(NBODY03));
00133        assert(status == DKIM_STAT_OK);
00134 
00135        status = dkim_body(dkim, NBODY04, strlen(NBODY04));
00136        assert(status == DKIM_STAT_OK);
00137 
00138        status = dkim_body(dkim, NBODY03, strlen(NBODY03));
00139        assert(status == DKIM_STAT_OK);
00140 
00141        status = dkim_body(dkim, NBODY03, strlen(NBODY03));
00142        assert(status == DKIM_STAT_OK);
00143 
00144        status = dkim_body(dkim, NBODY05, strlen(NBODY05));
00145        assert(status == DKIM_STAT_OK);
00146 
00147        status = dkim_body(dkim, NBODY03, strlen(NBODY03));
00148        assert(status == DKIM_STAT_OK);
00149 
00150        status = dkim_body(dkim, NBODY03, strlen(NBODY03));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_eom(dkim, NULL);
00154        assert(status == DKIM_STAT_OK);
00155 
00156        memset(hdr, '\0', sizeof hdr);
00157        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00158                                strlen(DKIM_SIGNHEADER) + 2);
00159        assert(status == DKIM_STAT_OK);
00160        assert(strcmp(SIG2, hdr) == 0);
00161 
00162        status = dkim_free(dkim);
00163        assert(status == DKIM_STAT_OK);
00164 
00165        dkim_close(lib);
00166 
00167        return 0;
00168 }