~ubuntu-branches/ubuntu/lucid/opendkim/lucid-backports

« back to all changes in this revision

Viewing changes to libopendkim/t-test73.c

  • Committer: Bazaar Package Importer
  • Author(s): Mike Markley
  • Date: 2010-03-17 13:04:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100317130428-i5klbz2debsy0aku
Tags: 2.0.0+dfsg-1
* New upstream version.
* The libopendkim ABI has changed, resulting in an soname change.
  - libopendkim0 package renamed to libopendkim1.
* New LDAP and Lua support have been enabled.
* Wrote clearer package descriptions. Closes: #572725
* Added build-dependency on autotools-dev. For now, the package ships with
  very old config.sub and config.guess files, but this will be resolved
  upstream in the near future.
  - Also removed extraneous top-level config.{sub,guess} files.
* Applied two upstream patches for off-by-one errors, including one that can
  cause crashes when signing.
* debian/copyright file was not accurate; it has been updated to reflect the
  fork from the dkim-milter project. The dkim-milter license should be fully
  compatible with the BSD license of this fork.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
**  Copyright (c) 2005-2008 Sendmail, Inc. and its suppliers.
3
 
**    All rights reserved.
4
 
**
5
 
**  Copyright (c) 2009, The OpenDKIM Project.  All rights reserved.
6
 
*/
7
 
 
8
 
#ifndef lint
9
 
static char t_test73_c_id[] = "@(#)$Id: t-test73.c,v 1.3 2009/07/23 17:40:24 cm-msk Exp $";
10
 
#endif /* !lint */
11
 
 
12
 
/* system includes */
13
 
#include <sys/types.h>
14
 
#include <unistd.h>
15
 
#include <assert.h>
16
 
#include <string.h>
17
 
#include <stdio.h>
18
 
 
19
 
 
20
 
/* libopendkim includes */
21
 
#include "dkim.h"
22
 
#include "t-testdata.h"
23
 
 
24
 
#define MAXHEADER       4096
25
 
 
26
 
#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=Y3y\r\n\tVeA3WZdCZl1sGuOZNC3BBRhtGCOExkZdw5xQoGPvSX/q6AC1SAJvOUWOri95AZAUGs0\r\n\t/bIDzzt23ei9jc+rptlavrl/5ijMrl6ShmvkACk6It62KPkJcDpoGfi5AZkrfX1Ou/z\r\n\tqGg5xJX86Kqd7FgNolMg7PbfyWliK2Yb84="
27
 
 
28
 
/*
29
 
**  MAIN -- program mainline
30
 
**
31
 
**  Parameters:
32
 
**      The usual.
33
 
**
34
 
**  Return value:
35
 
**      Exit status.
36
 
*/
37
 
 
38
 
int
39
 
main(int argc, char **argv)
40
 
{
41
 
#ifndef DKIM_SIGN_RSASHA256
42
 
        printf("*** simple/simple rsa-sha256 verifying with extra signature spaces and reportinfo (failure) SKIPPED\n");
43
 
 
44
 
#else /* ! DKIM_SIGN_RSASHA256 */
45
 
 
46
 
        int hfd;
47
 
        int bfd;
48
 
        dkim_policy_t pcode = DKIM_POLICY_NONE;
49
 
        u_int flags;
50
 
        DKIM_STAT status;
51
 
        DKIM *dkim;
52
 
        DKIM_LIB *lib;
53
 
        DKIM_SIGINFO *sig;
54
 
        dkim_query_t qtype = DKIM_QUERY_FILE;
55
 
        unsigned char hdr[MAXHEADER + 1];
56
 
        unsigned char addr[MAXADDRESS + 1];
57
 
        unsigned char fmt[BUFRSZ];
58
 
        unsigned char opts[BUFRSZ];
59
 
        unsigned char smtp[BUFRSZ];
60
 
 
61
 
        printf("*** simple/simple rsa-sha256 verifying with extra signature spaces and reportinfo (failure)\n");
62
 
 
63
 
        /* instantiate the library */
64
 
        lib = dkim_init(NULL, NULL);
65
 
        assert(lib != NULL);
66
 
 
67
 
        /* set flags */
68
 
        flags = DKIM_LIBFLAGS_TMPFILES;
69
 
# ifdef TEST_KEEP_FILES
70
 
        flags |= DKIM_LIBFLAGS_KEEPFILES;
71
 
# endif /* TEST_KEEP_FILES */
72
 
        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
73
 
                            sizeof flags);
74
 
 
75
 
        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
76
 
                            &qtype, sizeof qtype);
77
 
        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
78
 
                            KEYFILE, strlen(KEYFILE));
79
 
 
80
 
        dkim = dkim_verify(lib, JOBID, NULL, &status);
81
 
        assert(dkim != NULL);
82
 
 
83
 
        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
84
 
        status = dkim_header(dkim, hdr, strlen(hdr));
85
 
        assert(status == DKIM_STAT_OK);
86
 
 
87
 
        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
88
 
        assert(status == DKIM_STAT_OK);
89
 
 
90
 
        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
91
 
        assert(status == DKIM_STAT_OK);
92
 
 
93
 
        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
94
 
        assert(status == DKIM_STAT_OK);
95
 
 
96
 
        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
97
 
        assert(status == DKIM_STAT_OK);
98
 
 
99
 
        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
100
 
        assert(status == DKIM_STAT_OK);
101
 
 
102
 
        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
103
 
        assert(status == DKIM_STAT_OK);
104
 
 
105
 
        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
106
 
        assert(status == DKIM_STAT_OK);
107
 
 
108
 
        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
109
 
        assert(status == DKIM_STAT_OK);
110
 
 
111
 
        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
112
 
        assert(status == DKIM_STAT_OK);
113
 
 
114
 
        status = dkim_eoh(dkim);
115
 
        assert(status == DKIM_STAT_OK);
116
 
 
117
 
        status = dkim_body(dkim, BODY00, strlen(BODY00));
118
 
        assert(status == DKIM_STAT_OK);
119
 
 
120
 
        status = dkim_body(dkim, BODY01, strlen(BODY01));
121
 
        assert(status == DKIM_STAT_OK);
122
 
 
123
 
        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
124
 
        assert(status == DKIM_STAT_OK);
125
 
        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
126
 
        assert(status == DKIM_STAT_OK);
127
 
        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
128
 
        assert(status == DKIM_STAT_OK);
129
 
        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
130
 
        assert(status == DKIM_STAT_OK);
131
 
        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
132
 
        assert(status == DKIM_STAT_OK);
133
 
 
134
 
        status = dkim_body(dkim, BODY02, strlen(BODY02));
135
 
        assert(status == DKIM_STAT_OK);
136
 
 
137
 
        status = dkim_body(dkim, BODY03, strlen(BODY03));
138
 
        assert(status == DKIM_STAT_OK);
139
 
 
140
 
        status = dkim_body(dkim, BODY04, strlen(BODY04));
141
 
        assert(status == DKIM_STAT_OK);
142
 
 
143
 
        status = dkim_body(dkim, BODY03, strlen(BODY03));
144
 
        assert(status == DKIM_STAT_OK);
145
 
 
146
 
        status = dkim_body(dkim, BODY03, strlen(BODY03));
147
 
        assert(status == DKIM_STAT_OK);
148
 
 
149
 
        status = dkim_body(dkim, BODY05, strlen(BODY05));
150
 
        assert(status == DKIM_STAT_OK);
151
 
 
152
 
        status = dkim_body(dkim, BODY03, strlen(BODY03));
153
 
        assert(status == DKIM_STAT_OK);
154
 
 
155
 
        status = dkim_body(dkim, BODY03, strlen(BODY03));
156
 
        assert(status == DKIM_STAT_OK);
157
 
 
158
 
        status = dkim_eom(dkim, NULL);
159
 
        assert(status == DKIM_STAT_BADSIG);
160
 
 
161
 
        /* set up for the rest */
162
 
        hfd = -1;
163
 
        bfd = -1;
164
 
        sig = dkim_getsignature(dkim);
165
 
        assert(sig != NULL);
166
 
 
167
 
        /* policy query, verify correct result */
168
 
        status = dkim_policy(dkim, &pcode, NULL);
169
 
        assert(status == DKIM_STAT_OK);
170
 
        assert(pcode == DKIM_POLICY_ALL);
171
 
 
172
 
        /* request report info, verify valid descriptors and address */
173
 
        memset(addr, '\0', sizeof addr);
174
 
        memset(fmt, '\0', sizeof fmt);
175
 
        memset(opts, '\0', sizeof opts);
176
 
        memset(smtp, '\0', sizeof smtp);
177
 
        status = dkim_sig_getreportinfo(dkim, sig, &hfd, &bfd,
178
 
                                        addr, sizeof addr,
179
 
                                        fmt, sizeof fmt,
180
 
                                        opts, sizeof opts,
181
 
                                        smtp, sizeof smtp, NULL);
182
 
        assert(status == DKIM_STAT_OK);
183
 
        assert(hfd > 2);
184
 
        assert(bfd > 2);
185
 
        assert(strcmp(addr, REPLYADDRESS) == 0);
186
 
        assert(strcmp(smtp, SMTPTOKEN) == 0);
187
 
 
188
 
        /* test descriptors */
189
 
        status = lseek(hfd, 0, SEEK_CUR);
190
 
        assert(status >= 0);
191
 
        status = lseek(bfd, 0, SEEK_CUR);
192
 
        assert(status >= 0);
193
 
 
194
 
        status = dkim_free(dkim);
195
 
        assert(status == DKIM_STAT_OK);
196
 
 
197
 
        dkim_close(lib);
198
 
#endif /* ! DKIM_SIGN_RSASHA256 */
199
 
 
200
 
        return 0;
201
 
}