Back to index

opendkim  2.6.2
t-test83.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_test83_c_id[] = "@(#)$Id: t-test83.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-sha256; c=relaxed/simple; d=sendmail.com; s=test;\r\n\tt=1172620939; i=@eng.sendmail.com;\r\n\tbh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=TE4MmJAd1K2WvqOU1hlKCYJLsfCXvzObRYjAUdRk0PHwK17OyUnBh+i6jJkyzPOsf\r\n\t 5Fjspu2AfD5vh9CVTmnKCAQG6/FzXKNxHluXGJJBv5E3YQtUcQ6jOmA6wD2jTvjIEC\r\n\t M/wq57hPa8SH+118tog/ymOj4TRbFOiBVNBbN9/M="
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 #ifdef TEST_KEEP_FILES
00046        u_int flags;
00047 #endif /* TEST_KEEP_FILES */
00048        DKIM_STAT status;
00049        uint64_t fixed_time;
00050        DKIM *dkim;
00051        DKIM_LIB *lib;
00052        dkim_sigkey_t key;
00053        unsigned char hdr[MAXHEADER + 1];
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        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00064        {
00065               printf("*** relaxed/simple rsa-sha256 signing subdomain with i= SKIPPED\n");
00066               dkim_close(lib);
00067               return 0;
00068        }
00069 
00070        printf("*** relaxed/simple rsa-sha256 signing subdomain with i=\n");
00071 
00072 #ifdef TEST_KEEP_FILES
00073        /* set flags */
00074        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00075        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00076                            sizeof flags);
00077 #endif /* TEST_KEEP_FILES */
00078 
00079        key = KEY;
00080 
00081        dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN2,
00082                         DKIM_CANON_RELAXED, DKIM_CANON_SIMPLE,
00083                         DKIM_SIGN_RSASHA256, -1L, &status);
00084        assert(dkim != NULL);
00085 
00086        /* fix signing time */
00087        fixed_time = 1172620939;
00088        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00089                            &fixed_time, sizeof fixed_time);
00090 
00091        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00092        assert(status == DKIM_STAT_OK);
00093 
00094        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00098        assert(status == DKIM_STAT_OK);
00099 
00100 #define       XHEADER05     "From: Murray S. Kucherawy <msk@eng.sendmail.com>"
00101        status = dkim_header(dkim, XHEADER05, strlen(XHEADER05));
00102        assert(status == DKIM_STAT_OK);
00103 
00104        (void) dkim_set_signer(dkim, "@eng.sendmail.com");
00105 
00106        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_eoh(dkim);
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_body(dkim, BODY00, strlen(BODY00));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_body(dkim, BODY01, strlen(BODY01));
00125        assert(status == DKIM_STAT_OK);
00126 
00127        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00128        assert(status == DKIM_STAT_OK);
00129        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00130        assert(status == DKIM_STAT_OK);
00131        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00132        assert(status == DKIM_STAT_OK);
00133        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00134        assert(status == DKIM_STAT_OK);
00135        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00136        assert(status == DKIM_STAT_OK);
00137 
00138        status = dkim_body(dkim, BODY02, strlen(BODY02));
00139        assert(status == DKIM_STAT_OK);
00140 
00141        status = dkim_body(dkim, BODY03, strlen(BODY03));
00142        assert(status == DKIM_STAT_OK);
00143 
00144        status = dkim_body(dkim, BODY04, strlen(BODY04));
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, BODY03, strlen(BODY03));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_body(dkim, BODY05, strlen(BODY05));
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, BODY03, strlen(BODY03));
00160        assert(status == DKIM_STAT_OK);
00161 
00162        status = dkim_eom(dkim, NULL);
00163        assert(status == DKIM_STAT_OK);
00164 
00165        memset(hdr, '\0', sizeof hdr);
00166        status = dkim_getsighdr(dkim, hdr, sizeof hdr,
00167                                strlen(DKIM_SIGNHEADER) + 2);
00168        assert(status == DKIM_STAT_OK);
00169        assert(strcmp(SIG2, hdr) == 0);
00170 
00171        status = dkim_free(dkim);
00172        assert(status == DKIM_STAT_OK);
00173 
00174        dkim_close(lib);
00175 
00176        return 0;
00177 }