Back to index

opendkim  2.6.4
t-test137.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_test137_c_id[] = "@(#)$Id: t-test137.c,v 1.2 2010/08/30 22:01:56 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 #include <arpa/nameser.h>
00020 
00021 #ifdef USE_GNUTLS
00022 # include <gnutls/gnutls.h>
00023 #endif /* USE_GNUTLS */
00024 
00025 /* libopendkim includes */
00026 #include "../dkim.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define SIG1 "v=1; a=rsa-sha1; c=simple/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=ll/0h2aWgG+D3ewmE4Y3pY7Ukz8=; h=Received:Received:\r\n\t Received:From:To:Date:Subject:Message-ID; b=V+wiYd1cE70A40eDNUtYwU\r\n\tvqi727NN/vVo/OdC7jG4zvztIXCRjPKDXEfiZdW+6PZ08M4zA3GmLZI2p+IJTza+VDQ\r\n\tbohnvIUSRR6q9+Nddqz1qTCL0gNM5d64xKwrLUesk/3wb/Cvua6Atr+VBMFVCwQmSDf\r\n\trs4brLkqMyFOkCE="
00032 #define SIG2 "v=1; a=rsa-sha256; c=simple/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID; b=12345678Y3y\r\n\tVeA3WZdCZl1sGuOZNC3BBRhtGCOExkZdw5xQoGPvSX/q6AC1SAJvOUWOri95AZAUGs0\r\n\t/bIDzzt23ei9jc+rptlavrl/5ijMrl6ShmvkACk6It62KPkJcDpoGfi5AZkrfX1Ou/z\r\n\tqGg5xJX86Kqd7FgNolMg7PbfyWliK2Yb84="
00033 #define SIG3 "v=1; a=rsa-sha256; c=simple/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=yHBAX+3IwxTZIynBuB/5tlsBInJq9n8qz5fgAycHi80=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID; b=12345678Y4y\r\n\tVeA3WZdCZl1sGuOZNC3BBRhtGCOExkZdw5xQoGPvSX/q6AC1SAJvOUWOri95AZAUGs0\r\n\t/bIDzzt23ei9jc+rptlavrl/5ijMrl6ShmvkACk6It62KPkJcDpoGfi5AZkrfX1Ou/z\r\n\tqGg5xJX86Kqd7FgNolMg7PbfyWliK2Yb84="
00034 
00035 /*
00036 **  MAIN -- program mainline
00037 **
00038 **  Parameters:
00039 **     The usual.
00040 **
00041 **  Return value:
00042 **     Exit status.
00043 */
00044 
00045 int
00046 main(int argc, char **argv)
00047 {
00048 #ifdef TEST_KEEP_FILES
00049        u_int flags;
00050 #endif /* TEST_KEEP_FILES */
00051        int nsigs;
00052        size_t hdrlen;
00053        DKIM_STAT status;
00054        DKIM *dkim;
00055        DKIM_SIGINFO **sigs;
00056        DKIM_LIB *lib;
00057        dkim_query_t qtype = DKIM_QUERY_FILE;
00058        unsigned char hdr[MAXHEADER + 1];
00059 
00060 #ifdef USE_GNUTLS
00061        (void) gnutls_global_init();
00062 #endif /* USE_GNUTLS */
00063 
00064        /* instantiate the library */
00065        lib = dkim_init(NULL, NULL);
00066        assert(lib != NULL);
00067 
00068        if (!dkim_libfeature(lib, DKIM_FEATURE_SHA256))
00069        {
00070               printf("*** simple/simple rsa-sha256 signature substrings SKIPPED\n");
00071               dkim_close(lib);
00072               return 0;
00073        }
00074 
00075        printf("*** simple/simple rsa-sha256 verifying signature substrings\n");
00076 
00077 #ifdef TEST_KEEP_FILES
00078        /* set flags */
00079        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00080        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00081                            sizeof flags);
00082 #endif /* TEST_KEEP_FILES */
00083 
00084        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00085                            &qtype, sizeof qtype);
00086        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00087                            KEYFILE, strlen(KEYFILE));
00088 
00089        dkim = dkim_verify(lib, JOBID, NULL, &status);
00090        assert(dkim != NULL);
00091 
00092        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG1);
00093        status = dkim_header(dkim, hdr, strlen(hdr));
00094        assert(status == DKIM_STAT_OK);
00095 
00096        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00097        status = dkim_header(dkim, hdr, strlen(hdr));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00119        assert(status == DKIM_STAT_OK);
00120 
00121        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00122        assert(status == DKIM_STAT_OK);
00123 
00124        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00125        assert(status == DKIM_STAT_OK);
00126 
00127        status = dkim_eoh(dkim);
00128        assert(status == DKIM_STAT_OK);
00129 
00130        status = dkim_getsiglist(dkim, &sigs, &nsigs);
00131        assert(status == DKIM_STAT_OK);
00132        assert(nsigs == 2);
00133 
00134        memset(hdr, '\0', sizeof hdr);
00135        hdrlen = sizeof hdr - 1;
00136        status = dkim_get_sigsubstring(dkim, sigs[0], hdr, &hdrlen);
00137        assert(status == DKIM_STAT_OK);
00138        assert(hdrlen == 8);
00139        assert(strcmp(hdr, "V+wiYd1c") == 0);
00140        status = dkim_get_sigsubstring(dkim, sigs[1], hdr, &hdrlen);
00141        assert(status == DKIM_STAT_OK);
00142        assert(hdrlen == 8);
00143        assert(strcmp(hdr, "12345678") == 0);
00144 
00145        status = dkim_free(dkim);
00146        assert(status == DKIM_STAT_OK);
00147 
00148        dkim = dkim_verify(lib, JOBID, NULL, &status);
00149        assert(dkim != NULL);
00150 
00151        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG1);
00152        status = dkim_header(dkim, hdr, strlen(hdr));
00153        assert(status == DKIM_STAT_OK);
00154 
00155        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00156        status = dkim_header(dkim, hdr, strlen(hdr));
00157        assert(status == DKIM_STAT_OK);
00158 
00159        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG3);
00160        status = dkim_header(dkim, hdr, strlen(hdr));
00161        assert(status == DKIM_STAT_OK);
00162 
00163        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00164        assert(status == DKIM_STAT_OK);
00165 
00166        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00167        assert(status == DKIM_STAT_OK);
00168 
00169        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00170        assert(status == DKIM_STAT_OK);
00171 
00172        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00173        assert(status == DKIM_STAT_OK);
00174 
00175        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00176        assert(status == DKIM_STAT_OK);
00177 
00178        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00179        assert(status == DKIM_STAT_OK);
00180 
00181        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00182        assert(status == DKIM_STAT_OK);
00183 
00184        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00185        assert(status == DKIM_STAT_OK);
00186 
00187        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00188        assert(status == DKIM_STAT_OK);
00189 
00190        status = dkim_eoh(dkim);
00191        assert(status == DKIM_STAT_OK);
00192 
00193        status = dkim_getsiglist(dkim, &sigs, &nsigs);
00194        assert(status == DKIM_STAT_OK);
00195        assert(nsigs == 3);
00196 
00197        memset(hdr, '\0', sizeof hdr);
00198        hdrlen = sizeof hdr - 1;
00199        status = dkim_get_sigsubstring(dkim, sigs[0], hdr, &hdrlen);
00200        assert(status == DKIM_STAT_OK);
00201        assert(hdrlen == 10);
00202        assert(strcmp(hdr, "V+wiYd1cE7") == 0);
00203        status = dkim_get_sigsubstring(dkim, sigs[1], hdr, &hdrlen);
00204        assert(status == DKIM_STAT_OK);
00205        assert(hdrlen == 10);
00206        assert(strcmp(hdr, "12345678Y3") == 0);
00207        status = dkim_get_sigsubstring(dkim, sigs[2], hdr, &hdrlen);
00208        assert(status == DKIM_STAT_OK);
00209        assert(hdrlen == 10);
00210        assert(strcmp(hdr, "12345678Y4") == 0);
00211 
00212        status = dkim_free(dkim);
00213        assert(status == DKIM_STAT_OK);
00214 
00215        dkim_close(lib);
00216 
00217        return 0;
00218 }