Branch data Line data Source code
1 : : /* zxencdectest.c - Test XML encoding and decoding using zx generated code
2 : : * Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
3 : : * Copyright (c) 2006-2007 Symlabs (symlabs@symlabs.com), All Rights Reserved.
4 : : * Author: Sampo Kellomaki (sampo@iki.fi)
5 : : * This is confidential unpublished proprietary source code of the author.
6 : : * NO WARRANTY, not even implied warranties. Contains trade secrets.
7 : : * Distribution prohibited unless authorized in writing.
8 : : * Licensed under Apache License 2.0, see file COPYING.
9 : : * $Id: zxencdectest.c,v 1.9 2009-11-24 23:53:40 sampo Exp $
10 : : *
11 : : * 1.7.2006, started --Sampo
12 : : * 9.2.2007, improved to make basis of a test suite tool --Sampo
13 : : *
14 : : * Test encoding and decoding SAML 2.0 assertions and other related stuff.
15 : : */
16 : :
17 : : #include <signal.h>
18 : : #include <fcntl.h>
19 : : #include <netdb.h>
20 : : #include <string.h>
21 : : #include <stdio.h>
22 : : #include <stdlib.h>
23 : : #include <errno.h>
24 : : #include <sys/types.h>
25 : : #include <sys/stat.h>
26 : : #include <sys/wait.h>
27 : : #include <openssl/x509.h>
28 : :
29 : : #include "errmac.h"
30 : :
31 : : #include "zx.h"
32 : : #include "zxid.h"
33 : : #include "zxidpriv.h"
34 : : #include "zxidutil.h"
35 : : #include "saml2.h"
36 : : #include "c/zxidvers.h"
37 : : #include "c/zx-data.h"
38 : : #include "c/zx-const.h"
39 : : #include "c/zx-ns.h"
40 : :
41 : : int read_all_fd(int fd, char* p, int want, int* got_all);
42 : :
43 : : char* help =
44 : : "zxencdectest - ZX encoding and decoding tester - R" ZXID_REL "\n\
45 : : Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.\n\
46 : : Copyright (c) 2006-2007 Symlabs (symlabs@symlabs.com), All Rights Reserved.\n\
47 : : Author: Sampo Kellomaki (sampo@iki.fi)\n\
48 : : NO WARRANTY, not even implied warranties. Licensed under Apache License v2.0\n\
49 : : See http://www.apache.org/licenses/LICENSE-2.0\n\
50 : : Send well researched bug reports to the author. Home: zxid.org\n\
51 : : \n\
52 : : Usage: zxencdectest [options] <foo.xml >reencoded-foo.xml\n\
53 : : -r N Run test number N. 1 = IBM cert dec, 2 = IBM cert enc dec\n\
54 : : -i N Number of iterations to benchmark (default 1).\n\
55 : : -t SECONDS Timeout. Default: 0=no timeout.\n\
56 : : -c CIPHER Enable crypto on DTS interface using specified cipher. Use '?' for list.\n\
57 : : -k FDNUMBER File descriptor for reading symmetric key. Use 0 for stdin.\n\
58 : : -egd PATH Specify path of Entropy Gathering Daemon socket, default\n\
59 : : on Solaris: /tmp/entropy; Linux: /dev/urandom\n\
60 : : See http://www.lothar.com/tech/crypto/ or\n\
61 : : http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html\n\
62 : : -rand PATH Location of random number seed file. On Solaris EGD is used.\n\
63 : : On Linux the default is /dev/urandom. See RFC1750.\n\
64 : : -wo PATH File to write wire order encoding in\n\
65 : : -v Verbose messages.\n\
66 : : -q Be extra quiet.\n\
67 : : -d Turn on debugging.\n\
68 : : -license Show licensing and NO WARRANTY details.\n\
69 : : -h This help message\n\
70 : : -- End of options\n";
71 : :
72 : : #define DIE(reason) MB fprintf(stderr, "%s\n", reason); exit(2); ME
73 : : char buf[256*1024];
74 : :
75 : : /* Called by: opt x2 */
76 : : void test_ibm_cert_problem() /* -r 1 */
77 : 1 : {
78 : : int len, got_all;
79 : : zxid_conf* cf;
80 : : struct zx_root_s* r;
81 : : struct zx_sp_LogoutRequest_s* req;
82 : :
83 : 1 : len = read_all_fd(0, buf, sizeof(buf)-1, &got_all);
84 [ - + ]: 1 : if (got_all <= 0) DIE("Missing data");
85 : 1 : buf[got_all] = 0;
86 : :
87 : : /* IBM padding debug */
88 : 1 : cf = zxid_new_conf("/var/zxid/");
89 : 1 : r = zx_dec_zx_root(cf->ctx, got_all, buf, "zxencdectest");
90 [ + - - + : 1 : if (!r || !r->Envelope || r->Envelope->Body || r->Envelope->Body->LogoutRequest)
# # # # ]
91 : 1 : DIE("Decode failure");
92 : :
93 : : #if 1
94 : 0 : cf->enc_pkey = zxid_read_private_key(cf, "sym-idp-enc.pem");
95 : : #else
96 : : cf->enc_pkey = zxid_read_private_key(cf, "ibm-idp-enc.pem");
97 : : #endif
98 : :
99 : 0 : req = r->Envelope->Body->LogoutRequest;
100 : 0 : req->NameID = zxid_decrypt_nameid(cf, req->NameID, req->EncryptedID);
101 [ # # # # : 0 : printf("r1 nid(%.*s)\n", ZX_GET_CONTENT_LEN(req->NameID), ZX_GET_CONTENT_S(req->NameID));
# # # # #
# # # ]
102 : 0 : }
103 : :
104 : : /* Called by: opt x2 */
105 : : void test_ibm_cert_problem_enc_dec() /* -r 2 */
106 : 1 : {
107 : : zxid_conf* cf;
108 : : struct zx_sp_LogoutRequest_s* req;
109 : : zxid_nid* nameid;
110 : : zxid_entity* idp_meta;
111 : :
112 : 1 : cf = zxid_new_conf("/var/zxid/");
113 : :
114 : 1 : nameid = zx_NEW_sa_NameID(cf->ctx,0);
115 : 1 : nameid->Format = zx_ref_attr(cf->ctx, &nameid->gg, zx_Format_ATTR, "persistent");
116 : 1 : nameid->NameQualifier = zx_ref_attr(cf->ctx, &nameid->gg, zx_NameQualifier_ATTR, "ibmidp");
117 : : /*nameid->SPNameQualifier = zx_ref_attr(cf->ctx, &nameid->gg, zx_SPNameQualifier_ATTR, spqual);*/
118 : 1 : zx_add_content(cf->ctx, &nameid->gg, zx_ref_str(cf->ctx, "a-persistent-nid"));
119 : :
120 : : #if 0
121 : : cf->enc_pkey = zxid_read_private_key(cf, "sym-idp-enc.pem");
122 : : #else
123 : 1 : cf->enc_pkey = zxid_read_private_key(cf, "ibm-idp-enc.pem");
124 : 1 : idp_meta = zxid_get_ent_file(cf, "N9zsU-AwbI1O-U3mvjLmOALtbtU"); /* IBMIdP */
125 : : #endif
126 : :
127 : 1 : req = zxid_mk_logout(cf, nameid, 0, idp_meta);
128 : 1 : req->NameID = zxid_decrypt_nameid(cf, req->NameID, req->EncryptedID);
129 [ + - + - : 1 : printf("r2 nid(%.*s) should be(a-persistent-nid)\n", ZX_GET_CONTENT_LEN(req->NameID), ZX_GET_CONTENT_S(req->NameID));
+ - + - +
- + - ]
130 : 1 : }
131 : :
132 : : /* Called by: opt */
133 : : void so_enc_dec() /* -r 3 */
134 : 2 : {
135 : : zxid_conf* cf;
136 : : struct zx_sp_Status_s* st;
137 : : struct zx_str* ss;
138 : 2 : cf = zxid_new_conf("/var/zxid/");
139 : 2 : st = zxid_mk_Status(cf, 0, "SC1", "SC2", "MESSAGE");
140 : 2 : ss = zx_easy_enc_elem_opt(cf, &st->gg);
141 : 2 : printf("%.*s", ss->len, ss->s); zx_dump_ns_tab(cf->ctx, 0);
142 : 2 : }
143 : :
144 : : /* Called by: opt */
145 : : void attribute_sort_test() /* -r 4 */
146 : 2 : {
147 : : zxid_conf* cf;
148 : : struct zx_xasp_XACMLAuthzDecisionQuery_s* q;
149 : : struct zx_xaspcd1_XACMLAuthzDecisionQuery_s* q2;
150 : : struct zx_str* ss;
151 : 2 : cf = zxid_new_conf("/var/zxid/");
152 : 2 : q = zxid_mk_az(cf, 0, 0, 0, 0);
153 : 2 : ss = zx_easy_enc_elem_sig(cf, &q->gg);
154 : 2 : printf("%.*s", ss->len, ss->s);
155 : :
156 : 2 : q2 = zxid_mk_az_cd1(cf, 0, 0, 0, 0);
157 : 2 : ss = zx_easy_enc_elem_sig(cf, &q2->gg);
158 : 2 : printf("CD1: %.*s", ss->len, ss->s);
159 : 2 : }
160 : :
161 : : /* Called by: opt */
162 : : void a7n_test() /* -r 6 */
163 : 1 : {
164 : : struct timeval srctss;
165 : : zxid_conf* cf;
166 : : zxid_cgi cgi;
167 : : zxid_ses sess;
168 : : zxid_nid* nameid;
169 : : struct zx_str* issuer;
170 : : struct zx_sp_AuthnRequest_s* ar;
171 : : zxid_entity* sp_meta;
172 : : zxid_a7n* a7n;
173 : 1 : memset(&cgi, 0, sizeof(cgi));
174 : 1 : memset(&sess, 0, sizeof(sess));
175 : 1 : memset(&srctss, 0, sizeof(srctss));
176 : :
177 : 1 : sess.sid = "MSES1234";
178 : 1 : sess.uid = "test";
179 : 1 : cf = zxid_new_conf_to_cf("PATH=/var/zxid/&URL=http://sp1.zxidsp.org:8081/zxidhlo");
180 : : #if 1
181 : 1 : ar = zxid_mk_authn_req(cf, &cgi);
182 [ + - + - : 1 : issuer = ZX_GET_CONTENT(ar->Issuer);
+ - ]
183 [ - + # # ]: 1 : D("issuer(%.*s)", issuer->len, issuer->s);
184 : 1 : sp_meta = zxid_get_ent_ss(cf, issuer);
185 : 1 : a7n = zxid_sso_issue_a7n(cf, &cgi, &sess, &srctss, sp_meta, 0, &nameid, 0, ar);
186 : : #else
187 : : a7n = zxid_mk_usr_a7n_to_sp(cf, &sess, const char* uid, zxid_nid* nameid, zxid_entity* sp_meta, const char* sp_name_buf, 0);
188 : : #endif
189 : 1 : zxid_find_attribute(a7n, 0, 0, 0, 0, 0, 0, 1);
190 : : //zxid_ssos_anreq(cf, a7n, ar, ZX_GET_CONTENT(ar->Issuer));
191 : 1 : zxid_mni_do_ss(cf, &cgi, &sess, zxid_mk_mni(cf, nameid, zx_ref_str(cf->ctx, "newnym"), sp_meta), zx_ref_str(cf->ctx, "loc-dummy"));
192 : 1 : zxid_sp_mni_soap(cf, &cgi, &sess, zx_ref_str(cf->ctx, "newnym"));
193 : 1 : }
194 : :
195 : : /* Called by: opt */
196 : : void x509_test() /* -r 7 */
197 : 1 : {
198 : : struct timeval srctss;
199 : : zxid_conf* cf;
200 : : zxid_cgi cgi;
201 : : zxid_ses sess;
202 : : zxid_nid* nameid;
203 : : char buf[4096];
204 : 1 : memset(&cgi, 0, sizeof(cgi));
205 : 1 : memset(&sess, 0, sizeof(sess));
206 : 1 : memset(&srctss, 0, sizeof(srctss));
207 : :
208 : 1 : sess.uid = "test";
209 : 1 : cf = zxid_new_conf("/var/zxid/");
210 : :
211 : : #if 1
212 : 1 : nameid = zx_NEW_sa_NameID(cf->ctx,0);
213 : 1 : nameid->Format = zx_ref_attr(cf->ctx, &nameid->gg, zx_Format_ATTR, "persistent");
214 : 1 : nameid->NameQualifier = zx_ref_attr(cf->ctx, &nameid->gg, zx_NameQualifier_ATTR, "http://myidp?o=B");
215 : 1 : nameid->SPNameQualifier = zx_ref_attr(cf->ctx, &nameid->gg, zx_SPNameQualifier_ATTR, "http://mysp?o=B");
216 : 1 : zx_add_content(cf->ctx, &nameid->gg, zx_ref_str(cf->ctx, "a-persistent-nid"));
217 : : #else
218 : : struct zx_sp_AuthnRequest_s* ar;
219 : : zxid_entity* sp_meta;
220 : : zxid_a7n* a7n;
221 : : ar = zxid_mk_authn_req(cf, &cgi);
222 : : sp_meta = zxid_get_ent_ss(cf, ZX_GET_CONTENT(ar->Issuer));
223 : : a7n = zxid_sso_issue_a7n(cf, &cgi, &sess, &srctss, sp_meta, 0, &nameid, 0, ar);
224 : : #endif
225 : 1 : zxid_mk_at_cert(cf, sizeof(buf), buf, "test", nameid, "1.2.826.0.1.3344810.1.1.14", zx_ref_str(cf->ctx, "Role0"));
226 : 1 : printf("%s",buf);
227 : 1 : }
228 : :
229 : : const char foobar[] = "foobar";
230 : : const char goobar[] = "goo\r\n~[]";
231 : :
232 : : /* Called by: opt */
233 : : void covimp_test() /* -r 5 */
234 : 1 : {
235 : : char buf[256];
236 : : int outlen;
237 : : char* out;
238 : : char* sigval;
239 : : char* sigmsg;
240 : : struct zx_str* ss;
241 : : struct zx_e_Envelope_s* env;
242 : : zxid_fault* flt;
243 : : zxid_tas3_status* st;
244 : : zxid_entity* meta;
245 : : zxid_conf* cf;
246 : : zxid_cgi cgi;
247 : 1 : zxid_ses sess;
248 : 1 : memset(&cgi, 0, sizeof(cgi));
249 : : memset(&sess, 0, sizeof(sess));
250 : 1 :
251 : 1 : printf("version(%x)\n", zxid_version());
252 : 1 : cf = zxid_new_conf("/var/zxid/");
253 : 1 : printf("urlenc(%s)\n", zx_url_encode(cf->ctx, sizeof("test1://foo?a=b&c=d e")-1, "test1://foo?a=b&c=d e", &outlen));
254 : 1 : zx_hexdec(buf, "313233", 6, hex_trans);
255 : 1 : printf("hexdec(%.3s)\n", buf);
256 : 1 : hexdmp("test2: ", (char*)foobar, sizeof(foobar), 1000);
257 : 1 : hexdmp("test2b: ", (char*)goobar, sizeof(goobar), 1000);
258 : 1 : copy_file("t/XML1.out","tmp/foo3","test3",0);
259 : 1 : copy_file("t/XML1.out","tmp/foo4","test4",1);
260 : 1 : copy_file("t/XML1.out","tmp/foo5","test5",2);
261 : 1 : copy_file("/impossible","tmp/foo5a","test5a",0);
262 : 1 : copy_file("t/XML1.out","tmp/impossiblefoo5b","test5b",0);
263 : 1 : read_all(sizeof(buf), buf, "test5c", 1, "/impossible");
264 : 1 : read_all_alloc(cf->ctx, "test5d", 1, &outlen, "/impossible");
265 : 1 : zx_prepare_dec_ctx(cf->ctx, zx_ns_tab, zx__NS_MAX, foobar, foobar+sizeof(foobar));
266 : 1 : zx_format_parse_error(cf->ctx, buf, sizeof(buf), "test6");
267 : 1 : printf("parse err(%s)\n", buf);
268 : 1 : zx_xml_parse_err(cf->ctx, '?', __FUNCTION__, "test7");
269 : 1 : printf("memmem(%s)\n", zx_memmem("foobar", 6, "oba", 3));
270 : 1 : ss = zx_ref_str(cf->ctx, "abc");
271 : 1 : zx_str_conv(ss, &outlen, &out);
272 : 1 : zxid_wsp_decorate(cf, &sess, 0, "<foo/>");
273 : 1 : setenv("HTTP_COOKIE", "_liberty_idp=\"test8\"", 1);
274 : 1 : zxid_cdc_read(cf, &cgi);
275 : 1 : cgi.cdc = "test9";
276 : 1 : zxid_cdc_check(cf, &cgi);
277 : : zxid_new_cgi(cf, "=test10&ok=1&okx=2&s=S123&c=test11&e=abc&d=def&&l=x&l1=y&l1foo=z&inv=qwe&fg=1&fh=7&fr=RS&gu=1&gn=asa&ge=1&an=&aw=&at=&SAMLart=artti&SAMLResponse=respis");
278 : 1 :
279 : 1 : printf("n=%s\n", zxid_saml2_map_nid_fmt("n"));
280 : 1 : printf("p=%s\n", zxid_saml2_map_nid_fmt("p"));
281 : 1 : printf("t=%s\n", zxid_saml2_map_nid_fmt("t"));
282 : 1 : printf("u=%s\n", zxid_saml2_map_nid_fmt("u"));
283 : 1 : printf("e=%s\n", zxid_saml2_map_nid_fmt("e"));
284 : 1 : printf("x=%s\n", zxid_saml2_map_nid_fmt("x"));
285 : 1 : printf("w=%s\n", zxid_saml2_map_nid_fmt("w"));
286 : 1 : printf("k=%s\n", zxid_saml2_map_nid_fmt("k"));
287 : 1 : printf("s=%s\n", zxid_saml2_map_nid_fmt("s"));
288 : : printf("X=%s\n", zxid_saml2_map_nid_fmt("X"));
289 : 1 :
290 : 1 : printf("r=%s\n", zxid_saml2_map_protocol_binding("r"));
291 : 1 : printf("a=%s\n", zxid_saml2_map_protocol_binding("a"));
292 : 1 : printf("p=%s\n", zxid_saml2_map_protocol_binding("p"));
293 : 1 : printf("q=%s\n", zxid_saml2_map_protocol_binding("q"));
294 : 1 : printf("s=%s\n", zxid_saml2_map_protocol_binding("s"));
295 : 1 : printf("e=%s\n", zxid_saml2_map_protocol_binding("e"));
296 : : printf("X=%s\n", zxid_saml2_map_protocol_binding("X"));
297 : 1 :
298 : 1 : printf("NULL=%d\n", zxid_protocol_binding_map_saml2(0));
299 : 1 : printf("SAML2_REDIR=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_REDIR)));
300 : 1 : printf("SAML2_ART=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_ART)));
301 : 1 : printf("SAML2_POST=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_POST)));
302 : 1 : printf("SAML2_POST_SIMPLE_SIGN=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_POST_SIMPLE_SIGN)));
303 : 1 : printf("SAML2_SOAP=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_SOAP)));
304 : 1 : printf("SAML2_PAOS=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, SAML2_PAOS)));
305 : : printf("unknown=%d\n", zxid_protocol_binding_map_saml2(zx_ref_str(cf->ctx, "unknown")));
306 : 1 :
307 : 1 : printf("n=%s\n", zxid_saml2_map_authn_ctx("n"));
308 : 1 : printf("pwp=%s\n", zxid_saml2_map_authn_ctx("pwp"));
309 : 1 : printf("pw=%s\n", zxid_saml2_map_authn_ctx("pw"));
310 : 1 : printf("prvses=%s\n", zxid_saml2_map_authn_ctx("prvses"));
311 : 1 : printf("clicert=%s\n", zxid_saml2_map_authn_ctx("clicert"));
312 : 1 : printf("unspcf=%s\n", zxid_saml2_map_authn_ctx("unspcf"));
313 : 1 : printf("ip=%s\n", zxid_saml2_map_authn_ctx("ip"));
314 : : printf("X=%s\n", zxid_saml2_map_authn_ctx("X"));
315 : 1 :
316 : 1 : zxid_sigres_map(ZXSIG_OK, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
317 : 1 : zxid_sigres_map(ZXSIG_BAD_DALGO, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
318 : 1 : zxid_sigres_map(ZXSIG_DIGEST_LEN, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
319 : 1 : zxid_sigres_map(ZXSIG_BAD_DIGEST, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
320 : 1 : zxid_sigres_map(ZXSIG_BAD_SALGO, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
321 : 1 : zxid_sigres_map(ZXSIG_BAD_CERT, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
322 : 1 : zxid_sigres_map(ZXSIG_VFY_FAIL, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
323 : 1 : zxid_sigres_map(ZXSIG_NO_SIG, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
324 : 1 : zxid_sigres_map(ZXSIG_TIMEOUT, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
325 : 1 : zxid_sigres_map(ZXSIG_AUDIENCE, &sigval, &sigmsg); printf("%s %s\n", sigval, sigmsg);
326 : : zxid_sigres_map(99, &sigval, &sigmsg); printf("%s %s (other)\n", sigval, sigmsg);
327 : 1 :
328 : : printf("fake_sso=%d\n", zxid_sp_anon_finalize(cf, &cgi, &sess));
329 : 1 :
330 : 1 : setenv("HTTP_PAOS", SAML2_SSO_ECP, 1);
331 : : zxid_lecp_check(cf, &cgi); /* *** should test in realistic context */
332 : 1 :
333 : 1 : meta = zxid_get_ent_file(cf, "N9zsU-AwbI1O-U3mvjLmOALtbtU"); /* IBMIdP */
334 : : zxid_mk_art_deref(cf, meta, "ART124121"); /* *** should test in realistic context */
335 : 1 :
336 : 1 : zxid_mk_lu_Status(cf, 0, 0, "SC2-dummy", "MSG-dummy", "REF-dummy");
337 : 1 : st = zxid_mk_tas3_status(cf, 0, 0, 0, "SC2-dummy", "MSG-dummy", "REF-dummy");
338 : 1 : zxid_get_fault(cf, &sess);
339 : : zxid_get_tas3_status(cf, &sess);
340 : 1 :
341 : 1 : zxid_get_tas3_fault_sc1(cf, 0);
342 : 1 : zxid_get_tas3_fault_sc2(cf, 0);
343 : 1 : zxid_get_tas3_fault_comment(cf, 0);
344 : 1 : zxid_get_tas3_fault_ref(cf, 0);
345 : : zxid_get_tas3_fault_actor(cf, 0);
346 : 1 :
347 : 1 : zxid_get_tas3_status_sc1(cf, 0);
348 : 1 : zxid_get_tas3_status_sc2(cf, 0);
349 : 1 : zxid_get_tas3_status_comment(cf, 0);
350 : 1 : zxid_get_tas3_status_ref(cf, 0);
351 : : zxid_get_tas3_status_ctlpt(cf, 0);
352 : 1 :
353 : 1 : flt = zxid_mk_fault(cf, 0, "actor", "fc1", "fault string", "SC1", "SC2", "MSG", "REF");
354 : 1 : zxid_get_tas3_fault_sc1(cf, flt);
355 : 1 : zxid_get_tas3_fault_sc2(cf, flt);
356 : 1 : zxid_get_tas3_fault_comment(cf, flt);
357 : 1 : zxid_get_tas3_fault_ref(cf, flt);
358 : : zxid_get_tas3_fault_actor(cf, flt);
359 : 1 :
360 : 1 : zxid_get_tas3_status_sc1(cf, st);
361 : 1 : zxid_get_tas3_status_sc2(cf, st);
362 : 1 : zxid_get_tas3_status_comment(cf, st);
363 : 1 : zxid_get_tas3_status_ref(cf, st);
364 : : zxid_get_tas3_status_ctlpt(cf, st);
365 : :
366 : 1 : /* *** should test in realistic context */
367 : : zxid_mk_dap_query(cf, 0,
368 : : zxid_mk_dap_test_item(cf, 0,
369 : : zxid_mk_dap_testop(cf, 0, 0, 0, 0, 1, 2, 3, 4, 5),
370 : : 0, 0),
371 : : zxid_mk_dap_query_item(cf, 0,
372 : : zxid_mk_dap_select(cf, 0, 0, 0, 0, 0, 1, 0, 0, 0),
373 : : 0, 0, 0, 0, 1, 2, 3, 0, 0, 0),
374 : : zxid_mk_dap_subscription(cf, 0, "SUBSID", "#ITEMID",
375 : : zxid_mk_dap_resquery(cf, 0,
376 : : zxid_mk_dap_select(cf, 0, 0, 0, 0, 0, 1, 0, 0, 0),
377 : : 0, 0, 0, 0, 1, 0),
378 : 1 : 0, 0, 0, 0, 1, 0, 0));
379 : 1 :
380 : : zxid_wsf_decor(cf,0,0,0);
381 : : zxid_map_sec_mech(0);
382 : : zxid_wsc_valid_re_env(cf,0,0,0,0);
383 : : env = zx_NEW_e_Envelope(cf->ctx, 0);
384 : : zxid_wsc_valid_re_env(cf,0,0,env,0);
385 : : zxid_wsf_decor(cf,0,env,0);
386 : : zxid_wsc_valid_re_env(cf,0,0,env,0);
387 : : printf("covimp ok\n");
388 : : }
389 : :
390 : : int afr_buf_size = 0;
391 : : int verbose = 1;
392 : : extern int debug;
393 : : int timeout = 0;
394 : : int gcthreshold = 0;
395 : : int leak_free = 0;
396 : : extern int assert_nonfatal;
397 : : int drop_uid = 0;
398 : : int drop_gid = 0;
399 : 43 : char* rand_path;
400 [ + - ]: 43 : char* egd_path;
401 : : char symmetric_key[1024];
402 : : int symmetric_key_len;
403 : 84 : int n_iter = 1;
404 : : char* wo_path = 0;
405 [ + + + - ]: 84 :
406 : : /* Called by: main x8, zxcall_main, zxcot_main, zxdecode_main */
407 [ + + - + : 53 : void opt(int* argc, char*** argv, char*** env)
+ + + + +
- - + +
+ ]
408 [ + - ]: 1 : {
409 : 1 : if (*argc < 1) goto argerr;
410 : :
411 : 1 : while (1) {
412 : : ++(*argv); --(*argc);
413 [ + - ]: 31 :
414 : 31 : if (!(*argc) || ((*argv)[0][0] != '-')) break;
415 [ + - ]: 31 :
416 : 31 : switch ((*argv)[0][1]) {
417 : 31 : case '-': if ((*argv)[0][2]) break;
418 : : ++(*argv); --(*argc);
419 [ # # ]: 0 : DD("End of options by --");
420 : 0 : return; /* -- ends the options */
421 [ # # ]: 0 :
422 : 0 : case 'i': if ((*argv)[0][2]) break;
423 : 0 : ++(*argv); --(*argc);
424 : : if (!(*argc)) break;
425 : : n_iter = atoi((*argv)[0]);
426 [ + + - ]: 2 : continue;
427 : :
428 : 1 : case 't': if ((*argv)[0][2]) break;
429 : 1 : ++(*argv); --(*argc);
430 [ + - ]: 1 : if (!(*argc)) break;
431 : 1 : timeout = atoi((*argv)[0]);
432 [ + - ]: 1 : continue;
433 : 1 :
434 : 1 : case 'd':
435 : : switch ((*argv)[0][2]) {
436 : 0 : case '\0':
437 : : ++zx_debug;
438 : : continue;
439 [ + - ]: 1 : case 'i': if ((*argv)[0][3]) break;
440 : : ++(*argv); --(*argc);
441 : 1 : if (!(*argc)) break;
442 : 1 : strncpy(zx_instance, (*argv)[0], sizeof(zx_instance));
443 : : continue;
444 : 0 : }
445 : : break;
446 : :
447 [ + - ]: 1 : case 'v':
448 : : switch ((*argv)[0][2]) {
449 : 1 : case '\0':
450 : 1 : ++verbose;
451 : : continue;
452 : 0 : }
453 : : break;
454 : :
455 [ + - ]: 1 : case 'q':
456 [ + - + - ]: 1 : switch ((*argv)[0][2]) {
457 : 1 : case '\0':
458 [ + - ]: 1 : verbose = 0;
459 : 1 : continue;
460 : 1 : }
461 : : break;
462 : 0 :
463 : : case 'e':
464 : : switch ((*argv)[0][2]) {
465 [ + + + + : 12 : case 'g': if ((*argv)[0][3] != 'd' || (*argv)[0][4]) break;
- ]
466 : : ++(*argv); --(*argc);
467 : 9 : if (!(*argc)) break;
468 [ + - ]: 9 : egd_path = (*argv)[0];
469 [ + + + + : 9 : continue;
+ + + - ]
470 : 1 : }
471 : 1 : break;
472 : 2 :
473 : 2 : case 'r':
474 : 1 : switch ((*argv)[0][2]) {
475 : 1 : case '\0':
476 : 1 : ++(*argv); --(*argc);
477 : : if (!(*argc)) break;
478 : 8 : switch (atoi((*argv)[0])) {
479 : : case 1: test_ibm_cert_problem(); break;
480 : : case 2: test_ibm_cert_problem_enc_dec(); break;
481 : : case 3: so_enc_dec(); break;
482 : : case 4: attribute_sort_test(); break;
483 : 1 : case 5: covimp_test(); break;
484 : : case 6: a7n_test(); break;
485 : 1 : case 7: x509_test(); break;
486 : 1 : }
487 : : exit(0);
488 : :
489 : : case 'f':
490 : : /*AFR_TS(LEAK, 0, "memory leaks enabled");*/
491 : : #if 1
492 : : ERR("*** WARNING: You have turned memory frees to memory leaks. We will (eventually) run out of memory. Using -rf is not recommended. %d\n", 0);
493 : : #endif
494 : : ++leak_free;
495 : : continue;
496 : : #if 0
497 : : case 'e':
498 : : if ((*argv)[0][3]) break;
499 : : ++(*argv); --(*argc);
500 : : if ((*argc) < 4) break;
501 : : sscanf((*argv)[0], "%i", &abort_funcno);
502 : : ++(*argv); --(*argc);
503 : : sscanf((*argv)[0], "%i", &abort_line);
504 [ + - ]: 1 : ++(*argv); --(*argc);
505 : 1 : sscanf((*argv)[0], "%i", &abort_error_code);
506 [ + - ]: 1 : ++(*argv); --(*argc);
507 : 1 : sscanf((*argv)[0], "%i", &abort_iter);
508 [ + - ]: 1 : fprintf(stderr, "Will force core upon %x:%x err=%d iter=%d\n",
509 : 1 : abort_funcno, abort_line, abort_error_code, abort_iter);
510 : 1 : continue;
511 : : #endif
512 [ - + ]: 1 : case 'g':
513 : : if ((*argv)[0][3]) break;
514 : : ++(*argv); --(*argc);
515 : 0 : if (!(*argc)) break;
516 : : gcthreshold = atoi((*argv)[0]);
517 : 0 : if (!gcthreshold)
518 : 0 : ERR("*** WARNING: You have disabled garbage collection. This may lead to increased memory consumption for scripts that handle a lot of PDUs or run for long time. Using `-rg 0' is not recommended. %d\n", 0);
519 : : continue;
520 [ + - ]: 1 : case 'a':
521 : 1 : if ((*argv)[0][3] == 0) {
522 [ + - ]: 1 : /*AFR_TS(ASSERT_NONFATAL, 0, "assert nonfatal enabled");*/
523 : 1 : #if 1
524 : 1 : ERR("*** WARNING: YOU HAVE TURNED ASSERTS OFF USING -ra FLAG. THIS MEANS THAT YOU WILL NOT BE ABLE TO OBTAIN ANY SUPPORT. IF PROGRAM NOW TRIES TO ASSERT IT MAY MYSTERIOUSLY AND UNPREDICTABLY CRASH INSTEAD, AND NOBODY WILL BE ABLE TO FIGURE OUT WHAT WENT WRONG OR HOW MUCH DAMAGE MAY BE DONE. USING -ra IS NOT RECOMMENDED. %d\n", assert_nonfatal);
525 : : #endif
526 : : ++assert_nonfatal;
527 : : continue;
528 : 0 : }
529 : : if (!strcmp((*argv)[0],"-rand")) {
530 : : ++(*argv); --(*argc);
531 [ + - ]: 1 : if (!(*argc)) break;
532 [ + - ]: 1 : rand_path = (*argv)[0];
533 : 1 : continue;
534 [ + - ]: 1 : }
535 : 1 : break;
536 : 1 : }
537 : : break;
538 : 0 :
539 : : case 'w':
540 : : switch ((*argv)[0][2]) {
541 [ # # ]: 0 : case 'o': if ((*argv)[0][3]) break;
542 : : ++(*argv); --(*argc);
543 : 0 : if (!(*argc)) break;
544 [ # # ]: 0 : wo_path = (*argv)[0];
545 : 0 : continue;
546 [ # # # # ]: 0 : }
547 : 0 : break;
548 : :
549 : 0 : case 'k':
550 : : switch ((*argv)[0][2]) {
551 [ # # ]: 0 : case '\0':
552 : 0 : ++(*argv); --(*argc);
553 [ # # ]: 0 : if (!(*argc)) break;
554 : : read_all_fd(atoi((*argv)[0]), symmetric_key, sizeof(symmetric_key), &symmetric_key_len);
555 : 0 : D("Got %d characters of symmetric key", symmetric_key_len);
556 : : continue;
557 : 0 : }
558 : : break;
559 : :
560 [ + - ]: 1 : case 'c': if ((*argv)[0][2]) break;
561 [ + - + - ]: 1 : ++(*argv); --(*argc);
562 : 1 : if (!(*argc)) break;
563 [ + - ]: 1 : #ifndef ENCRYPTION
564 : 1 : ERR("Encryption not compiled in. %d",0);
565 : 1 : #endif
566 : : continue;
567 : 0 :
568 : : case 'u':
569 : : switch ((*argv)[0][2]) {
570 [ + - ]: 1 : case 'i': if ((*argv)[0][3] != 'd' || (*argv)[0][4]) break;
571 : : ++(*argv); --(*argc);
572 [ + - ]: 1 : if (!(*argc)) break;
573 : : sscanf((*argv)[0], "%i:%i", &drop_uid, &drop_gid);
574 : 1 : continue;
575 : 1 : }
576 : : break;
577 : :
578 : : case 'l':
579 : : switch ((*argv)[0][2]) {
580 : : case 'i':
581 : : if (!strcmp((*argv)[0],"-license")) {
582 : : extern char* license;
583 [ + - ]: 1 : fprintf(stderr, license);
584 : 1 : exit(0);
585 : 1 : }
586 : 1 : break;
587 : 1 : }
588 : 41 : break;
589 : :
590 : : }
591 : : /* fall thru means unrecognized flag */
592 : : if (*argc)
593 : : fprintf(stderr, "Unrecognized flag `%s'\n", (*argv)[0]);
594 : : argerr:
595 : 43 : fprintf(stderr, help);
596 : : exit(3);
597 : : }
598 : : }
599 : :
600 : : /* ============== M A I N ============== */
601 : 43 :
602 : : /* Called by: */
603 : 32 : int main(int argc, char** argv, char** env)
604 [ + + ]: 32 : {
605 : 31 : struct zx_ctx ctx;
606 : : struct zx_root_s* r;
607 [ - + # # ]: 31 : int got_all, len_wo;
608 : : char wo_out[256*1024];
609 [ + + ]: 18152 : char* wo_p;
610 : 18121 : opt(&argc, &argv, &env);
611 : 18121 :
612 [ - + ]: 18121 : len_wo = read_all_fd(0, buf, sizeof(buf)-1, &got_all);
613 : 0 : if (got_all <= 0) DIE("Missing data");
614 : : buf[got_all] = 0;
615 : 18121 :
616 [ - + # # ]: 18121 : D("Decoding %d chars, n_iter(%d)\n", got_all, n_iter);
617 : :
618 : 18121 : for (; n_iter; --n_iter) {
619 : 18121 : ZERO(&ctx, sizeof(ctx));
620 [ - + ]: 18121 : r = zx_dec_zx_root(&ctx, got_all, buf, "zxencdectest main"); /* n_decode=1000 ?!? */
621 : 0 : if (!r)
622 : : DIE("Decode failure");
623 : 18121 :
624 : : len_wo = zx_LEN_WO_any_elem(&ctx, &r->gg);
625 : : D("Enc wo len %d chars", len_wo);
626 [ + + ]: 31 :
627 : 16 : ctx.bas = wo_out;
628 : : wo_p = zx_ENC_WO_any_elem(&ctx, &r->gg, wo_out);
629 [ + + ]: 31 : if (!wo_p)
630 : 14 : DIE("encoding error");
631 : :
632 [ - + ]: 31 : zx_free_elem(&ctx, &r->gg, 0);
633 : 0 : }
634 : 31 :
635 : : if (got_all != len_wo)
636 [ - + ]: 31 : printf("Original and WO are different lengths %d != %d\n", got_all, len_wo);
637 : 0 :
638 : 31 : if (memcmp(buf, wo_out, MIN(got_all, len_wo)))
639 : : printf("Original and WO differ.\n");
640 : :
641 : : if (wo_p - wo_out != len_wo)
642 : : ERR("WO encode length mismatch %d vs %d (len)", wo_p - wo_out, len_wo);
643 : : printf("Re-encoded result WO (len=%d):\n%.*s\n\n", len_wo, len_wo, wo_out);
644 : :
645 : : if (wo_path)
646 : : write_all_path_fmt("WO", sizeof(buf), buf, "%s", wo_path, 0, "%.*s", len_wo, wo_out);
647 : : return 0;
648 : : }
649 : :
650 : : /* EOF -- zxencdectest.c */
|