xref: /freebsd/crypto/openssh/openbsd-compat/regress/opensslvertest.c (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1 /*
2  * Copyright (c) 2014 Darren Tucker
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include "includes.h"
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 
22 int ssh_compatible_openssl(long, long);
23 
24 struct version_test {
25 	long headerver;
26 	long libver;
27 	int result;
28 } version_tests[] = {
29 	/* built with 1.0.1b release headers */
30 	{ 0x1000101fL, 0x1000101fL, 1},/* exact match */
31 	{ 0x1000101fL, 0x1000102fL, 1},	/* newer library patch version: ok */
32 	{ 0x1000101fL, 0x1000100fL, 1},	/* older library patch version: ok */
33 	{ 0x1000101fL, 0x1000201fL, 1},	/* newer library fix version: ok */
34 	{ 0x1000101fL, 0x1000001fL, 0},	/* older library fix version: NO */
35 	{ 0x1000101fL, 0x1010101fL, 0},	/* newer library minor version: NO */
36 	{ 0x1000101fL, 0x0000101fL, 0},	/* older library major version: NO */
37 	{ 0x1000101fL, 0x2000101fL, 0},	/* newer library major version: NO */
38 
39 	/* built with 1.1.1b release headers */
40 	{ 0x1010101fL, 0x1010101fL, 1},/* exact match */
41 	{ 0x1010101fL, 0x1010102fL, 1},	/* newer library patch version: ok */
42 	{ 0x1010101fL, 0x1010100fL, 1},	/* older library patch version: ok */
43 	{ 0x1010101fL, 0x1010201fL, 1},	/* newer library fix version: ok */
44 	{ 0x1010101fL, 0x1010001fL, 0},	/* older library fix version: NO */
45 	{ 0x1010101fL, 0x1020001fL, 0},	/* newer library minor version: NO */
46 	{ 0x1010101fL, 0x0010101fL, 0},	/* older library major version: NO */
47 	{ 0x1010101fL, 0x2010101fL, 0},	/* newer library major version: NO */
48 
49 	/* built with 3.0.1 release headers */
50 	{ 0x3010101fL, 0x3010101fL, 1},/* exact match */
51 	{ 0x3010101fL, 0x3010102fL, 1},	/* newer library patch version: ok */
52 	{ 0x3010101fL, 0x3010100fL, 1},	/* older library patch version: ok */
53 	{ 0x3010101fL, 0x3010201fL, 1},	/* newer library fix version: ok */
54 	{ 0x3010101fL, 0x3010001fL, 1},	/* older library fix version: ok */
55 	{ 0x3010101fL, 0x3020001fL, 1},	/* newer library minor version: ok */
56 	{ 0x3010101fL, 0x1010101fL, 0},	/* older library major version: NO */
57 	{ 0x3010101fL, 0x4010101fL, 0},	/* newer library major version: NO */
58 };
59 
60 void
61 fail(long hver, long lver, int result)
62 {
63 	fprintf(stderr, "opensslver: header %lx library %lx != %d \n", hver, lver, result);
64 	exit(1);
65 }
66 
67 int
68 main(void)
69 {
70 #ifdef WITH_OPENSSL
71 	unsigned int i;
72 	int res;
73 	long hver, lver;
74 
75 	for (i = 0; i < sizeof(version_tests) / sizeof(version_tests[0]); i++) {
76 		hver = version_tests[i].headerver;
77 		lver = version_tests[i].libver;
78 		res = version_tests[i].result;
79 		if (ssh_compatible_openssl(hver, lver) != res)
80 			fail(hver, lver, res);
81 	}
82 #endif
83 	exit(0);
84 }
85