Increase version to 0.10.2
[libisds.git] / client / authenticatemessage.c
blob9052f681b85d2c76ff178a03bc979615955d48ec
1 #define _XOPEN_SOURCE 500
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <locale.h>
5 #include <time.h>
6 #include <string.h>
7 #include <isds.h>
8 #include "common.h"
9 #include <libgen.h>
12 int main(int argc, char **argv) {
13 struct isds_ctx *ctx = NULL;
14 isds_error err;
16 setlocale(LC_ALL, "");
18 if (argc != 2 || !argv[1] || !*argv[1]) {
19 printf("Usage: %s CMS_SIGNED_MESSAGE_IN_LOCAL_FILE\n",
20 basename(argv[0]));
21 exit(EXIT_FAILURE);
24 err = isds_init();
25 if (err) {
26 printf("isds_init() failed: %s\n", isds_strerror(err));
27 exit(EXIT_FAILURE);
30 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
32 ctx = isds_ctx_create();
33 if (!ctx) {
34 printf("isds_ctx_create() failed");
37 err = isds_set_timeout(ctx, 10000);
38 if (err) {
39 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
42 err = isds_login(ctx, url, username(), password(), NULL, NULL);
43 if (err) {
44 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
45 isds_long_message(ctx));
46 } else {
47 printf("Logged in :)\n");
52 /* Authenticate message saved in local file */
53 int fd;
54 void *buffer;
55 size_t length;
57 if (mmap_file(argv[1], &fd, &buffer, &length))
58 exit(EXIT_FAILURE);
60 printf("Sending message from file `%s' to ISDS for authenticity "
61 "check...\n", argv[1]);
62 err = isds_authenticate_message(ctx, buffer, length);
63 if (!err)
64 printf("ISDS states: message is original\n");
65 else if (err == IE_NOTEQUAL)
66 printf("ISDS states: message is unkown or tampered\n");
67 else
68 printf("isds_authenticate_message() failed: %s: %s\n",
69 isds_strerror(err), isds_long_message(ctx));
71 munmap_file(fd, buffer,length);
75 err = isds_logout(ctx);
76 if (err) {
77 printf("isds_logout() failed: %s\n", isds_strerror(err));
80 err = isds_ctx_free(&ctx);
81 if (err) {
82 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
85 err = isds_cleanup();
86 if (err) {
87 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
90 exit (EXIT_SUCCESS);