Back to index

opendkim  2.6.6
t-test144.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_test144_c_id[] = "@(#)$Id: t-test00.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 <stdio.h>
00018 #include <string.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 BADKEY              "-----BEGIN RSA PRIVATE KEY-----" \
00031        "MIICXQIBAAKBgQC4GUGr*d/6SFNzVLYpphnRd0QPGKz2uWnV65RAxa1Pw352Bqiz" \
00032        "qiKOBjgYGzj8pJQSs8tOvv/2k6jpI809RnESqOFgF0gu3UJbNnu3+cd8k/kiQj+q" \
00033        "4cKKRpAT92ccxc7svhCNgN1sBGmROYZuysG3Vu3Dyc079gSLtnSrgXb+gQIDAQAB" \
00034        "AoGAemlI0opm1Kvs2T4VliH8/tvX5FXbBH8LEZQAUwVeFTB/UQlieXyCV39pIxZO" \
00035        "0Sa50qm8YNL9rb5HTSZiHQFOwyAKNqS4m/7JCsbuH4gQkPgPF561BHNL9oKfYgJq" \
00036        "9P4kEFfDTBoXKBMxwWtT7AKV8dYvCa3vYzPQ/1BnqQdw2zECQQDyscdgR9Ih59PQ" \
00037        "b72ddibdsxS65uXS2vzYLe7SKl+4R5JgJzw0M6DTAnoYFf6JAsKGZM15PCC0E16t" \
00038        "RRo47U9VAkEAwjEVrlQ0/8yPACbDggDJg/Zz/uRu1wK0zjqj4vKjleubaX4SEvj7" \
00039        "r6xxZm9hC1pMJAC9y3bbkbgCRBjXfyY6fQJBANe5aq2MaZ41wTOPf45NjbKXEiAo" \
00040        "SbUpboKCIbyyaa8V/2h0t7D3C0dE9l4efsguqdZoF7Rh2/f1F70QpYRgfJkCQQCH" \
00041        "oRrAeGXP50JVW72fNgeJGH/pnghgOa6of0JpxwhENJuGMZxUDfxTtUA6yD3iXP3j" \
00042        "A3WL/wbaHsfOYf9Y+g1NAkAGLhx67Ah+uBNK4Xvfz0YPGINX20m+CMsxAw7FOaNv" \
00043        "IW2oWFfZCB4APkIis79Ql45AHpavwx5XodBMzZwJUvlL\n" \
00044        "-----END RSA PRIVATE KEY-----\n"
00045 
00046 /*
00047 **  MAIN -- program mainline
00048 **
00049 **  Parameters:
00050 **     The usual.
00051 **
00052 **  Return value:
00053 **     Exit status.
00054 */
00055 
00056 int
00057 main(int argc, char **argv)
00058 {
00059 #ifdef TEST_KEEP_FILES
00060        u_int flags;
00061 #endif /* TEST_KEEP_FILES */
00062        DKIM_STAT status;
00063        uint64_t fixed_time;
00064        DKIM *dkim;
00065        DKIM_LIB *lib;
00066        dkim_sigkey_t key;
00067        unsigned char hdr[MAXHEADER + 1];
00068 
00069        printf("*** signing attempt with an invalid key\n");
00070 
00071 #ifdef USE_GNUTLS
00072        (void) gnutls_global_init();
00073 #endif /* USE_GNUTLS */
00074 
00075        /* instantiate the library */
00076        lib = dkim_init(NULL, NULL);
00077        assert(lib != NULL);
00078 
00079 #ifdef TEST_KEEP_FILES
00080        /* set flags */
00081        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00082        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00083                            sizeof flags);
00084 #endif /* TEST_KEEP_FILES */
00085 
00086        key = BADKEY;
00087 
00088        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
00089                         DKIM_CANON_RELAXED, DKIM_CANON_RELAXED,
00090                         DKIM_SIGN_RSASHA1, -1L, &status);
00091        assert(dkim != NULL);
00092 
00093        /* fix signing time */
00094        fixed_time = 1172620939;
00095        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00096                            &fixed_time, sizeof fixed_time);
00097 
00098        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00099        assert(status == DKIM_STAT_OK);
00100 
00101        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00105        assert(status == DKIM_STAT_OK);
00106 
00107        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00108        assert(status == DKIM_STAT_OK);
00109 
00110        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00111        assert(status == DKIM_STAT_OK);
00112 
00113        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00114        assert(status == DKIM_STAT_OK);
00115 
00116        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00117        assert(status == DKIM_STAT_OK);
00118 
00119        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00120        assert(status == DKIM_STAT_OK);
00121 
00122        status = dkim_eoh(dkim);
00123        assert(status == DKIM_STAT_OK);
00124 
00125        status = dkim_body(dkim, BODY00, strlen(BODY00));
00126        assert(status == DKIM_STAT_OK);
00127 
00128        status = dkim_body(dkim, BODY01, strlen(BODY01));
00129        assert(status == DKIM_STAT_OK);
00130 
00131        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00132        assert(status == DKIM_STAT_OK);
00133        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00134        assert(status == DKIM_STAT_OK);
00135        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00136        assert(status == DKIM_STAT_OK);
00137        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00138        assert(status == DKIM_STAT_OK);
00139        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00140        assert(status == DKIM_STAT_OK);
00141 
00142        status = dkim_body(dkim, BODY02, strlen(BODY02));
00143        assert(status == DKIM_STAT_OK);
00144 
00145        status = dkim_body(dkim, BODY03, strlen(BODY03));
00146        assert(status == DKIM_STAT_OK);
00147 
00148        status = dkim_body(dkim, BODY04, strlen(BODY04));
00149        assert(status == DKIM_STAT_OK);
00150 
00151        status = dkim_body(dkim, BODY03, strlen(BODY03));
00152        assert(status == DKIM_STAT_OK);
00153 
00154        status = dkim_body(dkim, BODY03, strlen(BODY03));
00155        assert(status == DKIM_STAT_OK);
00156 
00157        status = dkim_body(dkim, BODY05, strlen(BODY05));
00158        assert(status == DKIM_STAT_OK);
00159 
00160        status = dkim_body(dkim, BODY03, strlen(BODY03));
00161        assert(status == DKIM_STAT_OK);
00162 
00163        status = dkim_body(dkim, BODY03, strlen(BODY03));
00164        assert(status == DKIM_STAT_OK);
00165 
00166        status = dkim_eom(dkim, NULL);
00167        assert(status == DKIM_STAT_NORESOURCE);
00168 
00169        memset(hdr, '\0', sizeof hdr);
00170        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00171                                strlen(DKIM_SIGNHEADER) + 2);
00172        assert(status == DKIM_STAT_INVALID);
00173 
00174        status = dkim_free(dkim);
00175        assert(status == DKIM_STAT_OK);
00176 
00177        dkim_close(lib);
00178 
00179        return 0;
00180 }