File: serverhash.c

package info (click to toggle)
openconnect 9.12-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,012 kB
  • sloc: ansic: 40,813; sh: 7,073; xml: 3,785; python: 1,791; makefile: 973; java: 475; sed: 10
file content (69 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * OpenConnect (SSL + DTLS) VPN client
 *
 * Copyright © 2008-2016 Intel Corporation.
 *
 * Author: David Woodhouse <dwmw2@infradead.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

/* Normally it's nice for header files to automatically include anything
 * they need. But winsock is a horrid can of worms; we 're not going to
 * make openconnect.h include anything for itself. So just do this... */
#ifdef _WIN32
#define SOCKET int
#endif

#include "../openconnect.h"

static void progress(void *privdata, int level, const char *fmt, ...)
{
	va_list args;

	if (level > PRG_ERR)
		return;

	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
	va_end(args);
}

static int validate_peer_cert(void *_vpninfo, const char *reason)
{
	printf("%s\n", openconnect_get_peer_cert_hash(_vpninfo));
	exit(0);
}

/* We do this in a separate test tool because we *really* don't want
 * people scripting it to recover the --no-cert-check functionality.
 * Validate your server certs properly, people! */
int main(int argc, char **argv)
{
	struct openconnect_info *vpninfo;

	if (argc != 2) {
		fprintf(stderr, "usage: serverhash <server>\n");
		exit(1);
	}
	openconnect_init_ssl();
	vpninfo = openconnect_vpninfo_new(NULL, validate_peer_cert, NULL, NULL, progress, NULL);
	if (openconnect_parse_url(vpninfo, argv[1])) {
		fprintf(stderr, "Failed to parse URL\n");
		exit(1);
	}
	openconnect_set_system_trust(vpninfo, 0);
	openconnect_obtain_cookie(vpninfo);
	return -1;
}