Back to index

opendkim  2.6.2
t-test132.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_test132_c_id[] = "@(#)$Id: t-test132.c,v 1.1 2010/03/01 18:22:31 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/simple; d=example.com;\r\n\ts=brisbane; t=1172620939; i=msk@sendmail.com; bh=ll/0h2aWgG+D3ewmE4\r\n\tY3pY7Ukz8=; h=subject:to:date; b=k1ZKkMnlh62VdAwa3umwZf6yhF9TWF4PERI5OXKoxU2TAtvwNZ6Q\r\n\tLMlELWHEG0Q1OORyb4cpQPfgGdOc6m38r0o/+k4rvlwnWsejpMWJgd4mD4e6U0b+pEt\r\n\txO704bDKUlzV83MAqIN/QdxW5dvwOyr1/1OrVu2fTUlUp6SWaa2o="
00031 #define       IDENT "msk@sendmail.com"
00032 
00033 /*
00034 **  MAIN -- program mainline
00035 **
00036 **  Parameters:
00037 **     The usual.
00038 **
00039 **  Return value:
00040 **     Exit status.
00041 */
00042 
00043 int
00044 main(int argc, char **argv)
00045 {
00046 #ifdef TEST_KEEP_FILES
00047        u_int flags;
00048 #endif /* TEST_KEEP_FILES */
00049        DKIM_STAT status;
00050        DKIM *dkim;
00051        DKIM_SIGINFO *sig;
00052        DKIM_LIB *lib;
00053        dkim_query_t qtype = DKIM_QUERY_FILE;
00054        unsigned char smallbuf[8];
00055        unsigned char largebuf[1024];
00056        unsigned char hdr[MAXHEADER + 1];
00057 
00058        printf("*** testing dkim_sig_getidentity()\n");
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 #ifdef TEST_KEEP_FILES
00069        /* set flags */
00070        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00071        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00072                            sizeof flags);
00073 #endif /* TEST_KEEP_FILES */
00074 
00075        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00076                            &qtype, sizeof qtype);
00077        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00078                            KEYFILE, strlen(KEYFILE));
00079 
00080        dkim = dkim_verify(lib, JOBID, NULL, &status);
00081        assert(dkim != NULL);
00082 
00083        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00084        status = dkim_header(dkim, hdr, strlen(hdr));
00085        assert(status == DKIM_STAT_OK);
00086 
00087        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00088        assert(status == DKIM_STAT_OK);
00089 
00090        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00091        assert(status == DKIM_STAT_OK);
00092 
00093        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00094        assert(status == DKIM_STAT_OK);
00095 
00096        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00097        assert(status == DKIM_STAT_OK);
00098 
00099        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00100        assert(status == DKIM_STAT_OK);
00101 
00102        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00103        assert(status == DKIM_STAT_OK);
00104 
00105        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00106        assert(status == DKIM_STAT_OK);
00107 
00108        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00109        assert(status == DKIM_STAT_OK);
00110 
00111        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00112        assert(status == DKIM_STAT_OK);
00113 
00114        status = dkim_eoh(dkim);
00115        assert(status == DKIM_STAT_OK);
00116 
00117        status = dkim_body(dkim, BODY00, strlen(BODY00));
00118        assert(status == DKIM_STAT_OK);
00119 
00120        status = dkim_body(dkim, BODY01, strlen(BODY01));
00121        assert(status == DKIM_STAT_OK);
00122 
00123        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00124        assert(status == DKIM_STAT_OK);
00125        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00126        assert(status == DKIM_STAT_OK);
00127        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00128        assert(status == DKIM_STAT_OK);
00129        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00130        assert(status == DKIM_STAT_OK);
00131        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00132        assert(status == DKIM_STAT_OK);
00133 
00134        status = dkim_body(dkim, BODY02, strlen(BODY02));
00135        assert(status == DKIM_STAT_OK);
00136 
00137        status = dkim_body(dkim, BODY03, strlen(BODY03));
00138        assert(status == DKIM_STAT_OK);
00139 
00140        status = dkim_body(dkim, BODY04, strlen(BODY04));
00141        assert(status == DKIM_STAT_OK);
00142 
00143        status = dkim_body(dkim, BODY03, strlen(BODY03));
00144        assert(status == DKIM_STAT_OK);
00145 
00146        status = dkim_body(dkim, BODY03, strlen(BODY03));
00147        assert(status == DKIM_STAT_OK);
00148 
00149        status = dkim_body(dkim, BODY05, strlen(BODY05));
00150        assert(status == DKIM_STAT_OK);
00151 
00152        status = dkim_body(dkim, BODY03, strlen(BODY03));
00153        assert(status == DKIM_STAT_OK);
00154 
00155        status = dkim_body(dkim, BODY03, strlen(BODY03));
00156        assert(status == DKIM_STAT_OK);
00157 
00158        status = dkim_eom(dkim, NULL);
00159        assert(status == DKIM_STAT_CANTVRFY);
00160 
00161        sig = dkim_getsignature(dkim);
00162        assert(sig != NULL);
00163 
00164        memset(largebuf, '\0', sizeof largebuf);
00165        status = dkim_sig_getidentity(dkim, sig, smallbuf, sizeof smallbuf);
00166        assert(status == DKIM_STAT_NORESOURCE);
00167        assert(memcmp(smallbuf, IDENT, sizeof smallbuf) == 0);
00168        status = dkim_sig_getidentity(dkim, sig, largebuf, sizeof largebuf);
00169        assert(status == DKIM_STAT_OK);
00170        assert(strcmp(largebuf, IDENT) == 0);
00171 
00172        status = dkim_free(dkim);
00173        assert(status == DKIM_STAT_OK);
00174 
00175        dkim_close(lib);
00176 
00177        return 0;
00178 }