xref: /openbsd-src/usr.bin/openssl/version.c (revision 418576f2eb23b048c55e12aeba7494f8dc6148c8)
1*418576f2Stb /* $OpenBSD: version.c,v 1.12 2023/07/27 07:01:50 tb Exp $ */
2dab3f910Sjsing /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3dab3f910Sjsing  * All rights reserved.
4dab3f910Sjsing  *
5dab3f910Sjsing  * This package is an SSL implementation written
6dab3f910Sjsing  * by Eric Young (eay@cryptsoft.com).
7dab3f910Sjsing  * The implementation was written so as to conform with Netscapes SSL.
8dab3f910Sjsing  *
9dab3f910Sjsing  * This library is free for commercial and non-commercial use as long as
10dab3f910Sjsing  * the following conditions are aheared to.  The following conditions
11dab3f910Sjsing  * apply to all code found in this distribution, be it the RC4, RSA,
12dab3f910Sjsing  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13dab3f910Sjsing  * included with this distribution is covered by the same copyright terms
14dab3f910Sjsing  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15dab3f910Sjsing  *
16dab3f910Sjsing  * Copyright remains Eric Young's, and as such any Copyright notices in
17dab3f910Sjsing  * the code are not to be removed.
18dab3f910Sjsing  * If this package is used in a product, Eric Young should be given attribution
19dab3f910Sjsing  * as the author of the parts of the library used.
20dab3f910Sjsing  * This can be in the form of a textual message at program startup or
21dab3f910Sjsing  * in documentation (online or textual) provided with the package.
22dab3f910Sjsing  *
23dab3f910Sjsing  * Redistribution and use in source and binary forms, with or without
24dab3f910Sjsing  * modification, are permitted provided that the following conditions
25dab3f910Sjsing  * are met:
26dab3f910Sjsing  * 1. Redistributions of source code must retain the copyright
27dab3f910Sjsing  *    notice, this list of conditions and the following disclaimer.
28dab3f910Sjsing  * 2. Redistributions in binary form must reproduce the above copyright
29dab3f910Sjsing  *    notice, this list of conditions and the following disclaimer in the
30dab3f910Sjsing  *    documentation and/or other materials provided with the distribution.
31dab3f910Sjsing  * 3. All advertising materials mentioning features or use of this software
32dab3f910Sjsing  *    must display the following acknowledgement:
33dab3f910Sjsing  *    "This product includes cryptographic software written by
34dab3f910Sjsing  *     Eric Young (eay@cryptsoft.com)"
35dab3f910Sjsing  *    The word 'cryptographic' can be left out if the rouines from the library
36dab3f910Sjsing  *    being used are not cryptographic related :-).
37dab3f910Sjsing  * 4. If you include any Windows specific code (or a derivative thereof) from
38dab3f910Sjsing  *    the apps directory (application code) you must include an acknowledgement:
39dab3f910Sjsing  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40dab3f910Sjsing  *
41dab3f910Sjsing  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42dab3f910Sjsing  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43dab3f910Sjsing  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44dab3f910Sjsing  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45dab3f910Sjsing  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46dab3f910Sjsing  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47dab3f910Sjsing  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48dab3f910Sjsing  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49dab3f910Sjsing  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50dab3f910Sjsing  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51dab3f910Sjsing  * SUCH DAMAGE.
52dab3f910Sjsing  *
53dab3f910Sjsing  * The licence and distribution terms for any publically available version or
54dab3f910Sjsing  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55dab3f910Sjsing  * copied and put under another distribution licence
56dab3f910Sjsing  * [including the GNU Public Licence.]
57dab3f910Sjsing  */
58dab3f910Sjsing /* ====================================================================
59dab3f910Sjsing  * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
60dab3f910Sjsing  *
61dab3f910Sjsing  * Redistribution and use in source and binary forms, with or without
62dab3f910Sjsing  * modification, are permitted provided that the following conditions
63dab3f910Sjsing  * are met:
64dab3f910Sjsing  *
65dab3f910Sjsing  * 1. Redistributions of source code must retain the above copyright
66dab3f910Sjsing  *    notice, this list of conditions and the following disclaimer.
67dab3f910Sjsing  *
68dab3f910Sjsing  * 2. Redistributions in binary form must reproduce the above copyright
69dab3f910Sjsing  *    notice, this list of conditions and the following disclaimer in
70dab3f910Sjsing  *    the documentation and/or other materials provided with the
71dab3f910Sjsing  *    distribution.
72dab3f910Sjsing  *
73dab3f910Sjsing  * 3. All advertising materials mentioning features or use of this
74dab3f910Sjsing  *    software must display the following acknowledgment:
75dab3f910Sjsing  *    "This product includes software developed by the OpenSSL Project
76dab3f910Sjsing  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77dab3f910Sjsing  *
78dab3f910Sjsing  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79dab3f910Sjsing  *    endorse or promote products derived from this software without
80dab3f910Sjsing  *    prior written permission. For written permission, please contact
81dab3f910Sjsing  *    openssl-core@openssl.org.
82dab3f910Sjsing  *
83dab3f910Sjsing  * 5. Products derived from this software may not be called "OpenSSL"
84dab3f910Sjsing  *    nor may "OpenSSL" appear in their names without prior written
85dab3f910Sjsing  *    permission of the OpenSSL Project.
86dab3f910Sjsing  *
87dab3f910Sjsing  * 6. Redistributions of any form whatsoever must retain the following
88dab3f910Sjsing  *    acknowledgment:
89dab3f910Sjsing  *    "This product includes software developed by the OpenSSL Project
90dab3f910Sjsing  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91dab3f910Sjsing  *
92dab3f910Sjsing  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93dab3f910Sjsing  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94dab3f910Sjsing  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95dab3f910Sjsing  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
96dab3f910Sjsing  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97dab3f910Sjsing  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98dab3f910Sjsing  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99dab3f910Sjsing  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100dab3f910Sjsing  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101dab3f910Sjsing  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102dab3f910Sjsing  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103dab3f910Sjsing  * OF THE POSSIBILITY OF SUCH DAMAGE.
104dab3f910Sjsing  * ====================================================================
105dab3f910Sjsing  *
106dab3f910Sjsing  * This product includes cryptographic software written by Eric Young
107dab3f910Sjsing  * (eay@cryptsoft.com).  This product includes software written by Tim
108dab3f910Sjsing  * Hudson (tjh@cryptsoft.com).
109dab3f910Sjsing  *
110dab3f910Sjsing  */
111dab3f910Sjsing 
112dab3f910Sjsing #include <stdio.h>
113dab3f910Sjsing #include <stdlib.h>
114dab3f910Sjsing #include <string.h>
115dab3f910Sjsing 
116dab3f910Sjsing #include "apps.h"
117dab3f910Sjsing 
118dab3f910Sjsing #include <openssl/bn.h>
119dab3f910Sjsing #include <openssl/crypto.h>
120dab3f910Sjsing #include <openssl/evp.h>
121dab3f910Sjsing 
122dab3f910Sjsing #ifndef OPENSSL_NO_BF
123dab3f910Sjsing #include <openssl/blowfish.h>
124dab3f910Sjsing #endif
125dab3f910Sjsing 
126dab3f910Sjsing #ifndef OPENSSL_NO_DES
127dab3f910Sjsing #include <openssl/des.h>
128dab3f910Sjsing #endif
129dab3f910Sjsing 
130dab3f910Sjsing #ifndef OPENSSL_NO_IDEA
131dab3f910Sjsing #include <openssl/idea.h>
132dab3f910Sjsing #endif
133dab3f910Sjsing 
134dab3f910Sjsing #ifndef OPENSSL_NO_RC4
135dab3f910Sjsing #include <openssl/rc4.h>
136dab3f910Sjsing #endif
137dab3f910Sjsing 
13818feb1b6Sjsing static struct {
13918feb1b6Sjsing 	int cflags;
14018feb1b6Sjsing 	int date;
14118feb1b6Sjsing 	int dir;
14218feb1b6Sjsing 	int options;
14318feb1b6Sjsing 	int platform;
14418feb1b6Sjsing 	int version;
145e7718adaStb } cfg;
14618feb1b6Sjsing 
14718feb1b6Sjsing static int
version_all_opts(void)148d16f2e55Sjsing version_all_opts(void)
14918feb1b6Sjsing {
150e7718adaStb 	cfg.cflags = 1;
151e7718adaStb 	cfg.date = 1;
152e7718adaStb 	cfg.dir= 1;
153e7718adaStb 	cfg.options = 1;
154e7718adaStb 	cfg.platform = 1;
155e7718adaStb 	cfg.version = 1;
15618feb1b6Sjsing 
15718feb1b6Sjsing 	return (0);
15818feb1b6Sjsing }
15918feb1b6Sjsing 
160ea149709Sguenther static const struct option version_options[] = {
16118feb1b6Sjsing 	{
16218feb1b6Sjsing 		.name = "a",
16318feb1b6Sjsing 		.desc = "All information (same as setting all other flags)",
16418feb1b6Sjsing 		.type = OPTION_FUNC,
165d16f2e55Sjsing 		.opt.func = version_all_opts,
16618feb1b6Sjsing 	},
16718feb1b6Sjsing 	{
16818feb1b6Sjsing 		.name = "b",
16918feb1b6Sjsing 		.desc = "Date the current version of OpenSSL was built",
17018feb1b6Sjsing 		.type = OPTION_FLAG,
171e7718adaStb 		.opt.flag = &cfg.date,
17218feb1b6Sjsing 	},
17318feb1b6Sjsing 	{
17418feb1b6Sjsing 		.name = "d",
17518feb1b6Sjsing 		.desc = "OPENSSLDIR value",
17618feb1b6Sjsing 		.type = OPTION_FLAG,
177e7718adaStb 		.opt.flag = &cfg.dir,
17818feb1b6Sjsing 	},
17918feb1b6Sjsing 	{
18018feb1b6Sjsing 		.name = "f",
18118feb1b6Sjsing 		.desc = "Compilation flags",
18218feb1b6Sjsing 		.type = OPTION_FLAG,
183e7718adaStb 		.opt.flag = &cfg.cflags,
18418feb1b6Sjsing 	},
18518feb1b6Sjsing 	{
18618feb1b6Sjsing 		.name = "o",
18718feb1b6Sjsing 		.type = OPTION_FLAG,
188e7718adaStb 		.opt.flag = &cfg.options,
18918feb1b6Sjsing 	},
19018feb1b6Sjsing 	{
19118feb1b6Sjsing 		.name = "p",
19218feb1b6Sjsing 		.desc = "Platform settings",
19318feb1b6Sjsing 		.type = OPTION_FLAG,
194e7718adaStb 		.opt.flag = &cfg.platform,
19518feb1b6Sjsing 	},
19618feb1b6Sjsing 	{
19718feb1b6Sjsing 		.name = "v",
19818feb1b6Sjsing 		.desc = "Current OpenSSL version",
19918feb1b6Sjsing 		.type = OPTION_FLAG,
200e7718adaStb 		.opt.flag = &cfg.version,
20118feb1b6Sjsing 	},
202d220e929Sbcook 	{NULL},
20318feb1b6Sjsing };
20418feb1b6Sjsing 
20518feb1b6Sjsing static void
version_usage(void)20618feb1b6Sjsing version_usage(void)
20718feb1b6Sjsing {
208*418576f2Stb 	fprintf(stderr, "usage: version [-abdfpv]\n");
20918feb1b6Sjsing 	options_usage(version_options);
21018feb1b6Sjsing }
21118feb1b6Sjsing 
212dab3f910Sjsing int
version_main(int argc,char ** argv)213dab3f910Sjsing version_main(int argc, char **argv)
214dab3f910Sjsing {
215e370f0eeSdoug 	if (pledge("stdio", NULL) == -1) {
2169bc487adSdoug 		perror("pledge");
217e370f0eeSdoug 		exit(1);
218e370f0eeSdoug 	}
2199bc487adSdoug 
220e7718adaStb 	memset(&cfg, 0, sizeof(cfg));
22118feb1b6Sjsing 
222beba0da1Sjsing 	if (options_parse(argc, argv, version_options, NULL, NULL) != 0) {
22318feb1b6Sjsing 		version_usage();
22418feb1b6Sjsing 		return (1);
22518feb1b6Sjsing 	}
226dab3f910Sjsing 
227dab3f910Sjsing 	if (argc == 1)
228e7718adaStb 		cfg.version = 1;
229dab3f910Sjsing 
230e7718adaStb 	if (cfg.version) {
231dab3f910Sjsing 		if (SSLeay() == SSLEAY_VERSION_NUMBER) {
232dab3f910Sjsing 			printf("%s\n", SSLeay_version(SSLEAY_VERSION));
233dab3f910Sjsing 		} else {
234dab3f910Sjsing 			printf("%s (Library: %s)\n",
235dab3f910Sjsing 			    OPENSSL_VERSION_TEXT,
236dab3f910Sjsing 			    SSLeay_version(SSLEAY_VERSION));
237dab3f910Sjsing 		}
238dab3f910Sjsing 	}
239e7718adaStb 	if (cfg.date)
240dab3f910Sjsing 		printf("%s\n", SSLeay_version(SSLEAY_BUILT_ON));
241e7718adaStb 	if (cfg.platform)
242dab3f910Sjsing 		printf("%s\n", SSLeay_version(SSLEAY_PLATFORM));
243e7718adaStb 	if (cfg.cflags)
244dab3f910Sjsing 		printf("%s\n", SSLeay_version(SSLEAY_CFLAGS));
245e7718adaStb 	if (cfg.dir)
246dab3f910Sjsing 		printf("%s\n", SSLeay_version(SSLEAY_DIR));
247dab3f910Sjsing 
24818feb1b6Sjsing 	return (0);
249dab3f910Sjsing }
250