1 #define _XOPEN_SOURCE 500
10 isds_error
compute_message_hash(struct isds_ctx
*ctx
,
11 struct isds_message
*message
) {
13 struct isds_hash
*old_hash
;
15 /* Detach original hash */
16 old_hash
= message
->envelope
->hash
;
17 message
->envelope
->hash
= NULL
;
19 /* Recalculate hash */
20 printf("Calculating message hash\n");
21 err
= isds_compute_message_hash(ctx
, message
, old_hash
->algorithm
);
23 printf("isds_compute_message_hash() failed: %s: %s\n",
24 isds_strerror(err
), isds_long_message(ctx
));
26 printf("isds_compute_message_hash() succeeded:\n");
28 printf("Stored hash = ");
31 printf("Computed hash = ");
32 print_hash(message
->envelope
->hash
);
35 compare_hashes(old_hash
, message
->envelope
->hash
);
38 isds_hash_free(&old_hash
);
43 int main(int argc
, char **argv
) {
44 struct isds_ctx
*ctx
= NULL
;
47 setlocale(LC_ALL
, "");
51 printf("isds_init() failed: %s\n", isds_strerror(err
));
55 /*isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);*/
57 ctx
= isds_ctx_create();
59 printf("isds_ctx_create() failed");
64 /* Load plain received message */
65 struct isds_message
*message
= NULL
;
70 if (mmap_file(SRCDIR
"/server/messages/received_message-151916.xml",
71 &fd
, &buffer
, &length
)) {
72 fprintf(stderr
, "Could not map file with plain received message\n");
78 printf("Loading plain received message\n");
79 err
= isds_load_message(ctx
, RAWTYPE_INCOMING_MESSAGE
,
80 buffer
, length
, &message
, BUFFER_COPY
);
82 printf("isds_load_message() failed: %s: %s\n",
83 isds_strerror(err
), isds_long_message(ctx
));
85 printf("isds_load_message() succeeded\n");
86 compute_message_hash(ctx
, message
);
89 isds_message_free(&message
);
90 munmap_file(fd
, buffer
, length
);
95 /* Load plain signed message */
96 struct isds_message
*message
= NULL
;
101 if (mmap_file(SRCDIR
"/server/messages/sent_message-206720.xml",
102 &fd
, &buffer
, &length
)) {
103 fprintf(stderr
, "Could not map file with plain signed message\n");
109 printf("Loading plain signed sent message\n");
110 err
= isds_load_message(ctx
, RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE
,
111 buffer
, length
, &message
, BUFFER_COPY
);
113 printf("isds_load_message() failed: %s: %s\n",
114 isds_strerror(err
), isds_long_message(ctx
));
116 printf("isds_load_message() succeeded\n");
117 compute_message_hash(ctx
, message
);
120 isds_message_free(&message
);
121 munmap_file(fd
, buffer
, length
);
126 /* Load CMS signed message */
127 struct isds_message
*message
= NULL
;
132 if (mmap_file(SRCDIR
"/server/messages/signed_sent_message-151874.zfo",
133 &fd
, &buffer
, &length
)) {
134 fprintf(stderr
, "Could not map file with CMS signed message\n");
140 printf("Loading CMS signed sent message\n");
141 err
= isds_load_message(ctx
, RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE
,
142 buffer
, length
, &message
, BUFFER_COPY
);
144 printf("isds_load_message() failed: %s: %s\n",
145 isds_strerror(err
), isds_long_message(ctx
));
147 printf("isds_load_message() succeeded\n");
148 compute_message_hash(ctx
, message
);
151 isds_message_free(&message
);
152 munmap_file(fd
, buffer
, length
);
156 err
= isds_ctx_free(&ctx
);
158 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
162 err
= isds_cleanup();
164 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));