File: vendoridcheck.c

package info (click to toggle)
libreswan 5.2-2.3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 81,644 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (88 lines) | stat: -rw-r--r-- 2,759 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Dump known vendor IDs, for libreswan.
 *
 * Copyright (C) 2002-2003 Mathieu Lafon - Arkoon Network Security
 * Copyright (C) 2005-2008 Michael Richardson <mcr@xelerance.com>
 * Copyright (C) 2007 Ken Bantoft <ken@xelerance.com>
 * Copyright (C) 2008-2011 Paul Wouters <paul@xelerance.com>
 * Copyright (C) 2012 Paul Wouters <paul@libreswan.org>
 * Copyright (C) 2013-2018 Paul Wouters <pwouters@redhat.com>
 * Copyright (C) 2013 D. Hugh Redelmeier <hugh@mimosa.com>
 * Copyright (C) 2013 Wolfgang Nothdurft <wolfgang@linogate.de>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <https://www.gnu.org/licenses/gpl2.txt>.
 *
 * 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 General Public License
 * for more details.
 */

#include <stdlib.h>	/* for exit() */

#include "lswtool.h"
#include "vendorid.h"
#include "lswlog.h"	/* for log_to_stderr */
#include "lswnss.h"

int main(int argc, char *argv[])
{
#if 0
	log_to_stderr = true;
	cur_debugging = DBG_BASE | DBG_TMI;
#endif
	struct logger *logger = tool_logger(argc, argv);

	if (argc != 1) {
		fprintf(stderr, ("usage:\n"
				 "\tipsec _vendoridcheck\n"
				 "list known Vendor IDs\n"));
		exit(1);
	}

	/*
	 * init_vendorid() uses MD5 which requires NSS!
	 *
	 * Should just hardwire those hashes.
	 */
	init_nss(NULL, (struct nss_flags) { .open_readonly = true}, logger);
	init_vendorid(logger);
	llog_vendorids(NO_PREFIX|WHACK_STREAM, logger);

	/* shhh; try some bonus searches */
	static const struct {
		enum known_vendorid id;
		const char *vid;
	} tests[] = {
		{ VID_OPENSWANORG,   "\x4f\x45", },
		{ VID_OPENSWANORG,   "\x4f\x45\x01", },
		{ VID_OPENSWANORG,   "\x4f\x45\x4f\x01", },
		{ VID_LIBRESWAN_OLD, "\x4f\x45\x4e", },
		{ VID_LIBRESWAN_OLD, "\x4f\x45\x4e\x01", },
		{ VID_LIBRESWAN,     "\x4f\x45\x2d\x4c\x69\x62\x72\x65\x73\x77\x61\x6e\x2d", },
		{ VID_LIBRESWAN,     "\x4f\x45\x2d\x4c\x69\x62\x72\x65\x73\x77\x61\x6e\x2d\x01", },
	};

	FOR_EACH_ELEMENT(t, tests) {
		shunk_t vid = shunk1(t->vid);
		if (DBGP(DBG_TMI)) {
			enum_buf tidb;
			DBG_log("looking up %d [%s]",
				t->id, str_vendorid(t->id, &tidb));
			DBG_dump_hunk(NULL, vid);
		}

		enum known_vendorid id = vendorid_by_shunk(vid);
		if (id != t->id) {
			enum_buf idb, tidb;
			llog_passert(logger, HERE,
				     "lookup for %d [%s] returned %d [%s]",
				     t->id, str_vendorid(t->id, &tidb),
				     id, str_vendorid(id, &idb));
		}
	}

	exit(0);
}