Fix OpenSSL version check issues
[freeradius.git] / src / main / version.c
1 /*
2  * version.c    Print version number and exit.
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 1999-2008  The FreeRADIUS server project
21  * Copyright 2000  Alan DeKok <aland@ox.org>
22  * Copyright 2000  Chris Parker <cparker@starnetusa.com>
23  */
24
25 #include <freeradius-devel/ident.h>
26 RCSID("$Id$")
27
28 #include <freeradius-devel/radiusd.h>
29
30
31 #ifdef HAVE_OPENSSL_CRYPTO_H
32 #include <openssl/crypto.h>
33 #include <openssl/opensslv.h>
34
35 static long ssl_built = OPENSSL_VERSION_NUMBER;
36
37 /** Print the current linked version of Openssl
38  *
39  * Print the currently linked version of the OpenSSL library.
40  */
41 const char *ssl_version(void)
42 {
43         return SSLeay_version(SSLEAY_VERSION);
44 }
45 #else
46 const char *ssl_version()
47 {
48         return "not linked";
49 }
50 #endif
51
52
53 /** Check built and linked versions of OpenSSL match
54  *
55  * OpenSSL version number consists of:
56  * MNNFFPPS: major minor fix patch status
57  *
58  * Where status >= 0 && < 10 means beta, and status 10 means release.
59  *
60  * Startup check for whether the linked version of OpenSSL matches the
61  * version the server was built against.
62  *
63  * @return 0 if ok, else -1
64  */
65 #if defined(HAVE_OPENSSL_CRYPTO_H) && defined(ENABLE_OPENSSL_VERSION_CHECK)
66 int ssl_check_version(int allow_vulnerable)
67 {
68         long ssl_linked;
69
70         ssl_linked = SSLeay();
71
72         /*
73          *      Status mismatch always triggers error.
74          */
75         if ((ssl_linked & 0x0000000f) != (ssl_built & 0x0000000f)) {
76         mismatch:
77                 radlog(L_ERR, "libssl version mismatch.  built: %lx linked: %lx",
78                        (unsigned long) ssl_built, (unsigned long) ssl_linked);
79
80                 return -1;
81         }
82
83         /*
84          *      Use the OpenSSH approach and relax fix checks after version
85          *      1.0.0 and only allow moving backwards within a patch
86          *      series.
87          */
88         if (ssl_built & 0xf0000000) {
89                 if ((ssl_built & 0xfffff000) != (ssl_linked & 0xfffff000) ||
90                     (ssl_built & 0x00000ff0) > (ssl_linked & 0x00000ff0)) goto mismatch;
91         /*
92          *      Before 1.0.0 we require the same major minor and fix version
93          *      and ignore the patch number.
94          */
95         } else if ((ssl_built & 0xfffff000) != (ssl_linked & 0xfffff000)) goto mismatch;
96
97         if (!allow_vulnerable) {
98                 /* Check for bad versions */
99                 /* 1.0.1 - 1.0.1f CVE-2014-0160 http://heartbleed.com */
100                 if ((ssl_linked >= 0x010001000) && (ssl_linked < 0x010001070)) {
101                         radlog(L_ERR, "Refusing to start with libssl version %s (in range 1.0.1 - 1.0.1f).  "
102                               "Security advisory CVE-2014-0160 (Heartbleed)", ssl_version());
103                         radlog(L_ERR, "For more information see http://heartbleed.com");
104
105                         return -1;
106                 }
107         }
108
109         return 0;
110 }
111 #endif
112
113 /*
114  *      Display the revision number for this program
115  */
116 void version(void)
117 {
118
119         radlog(L_INFO, "%s: %s", progname, radiusd_version);
120         DEBUG3("Server was built with: ");
121
122 #ifdef WITH_ACCOUNTING
123         DEBUG3("  accounting");
124 #endif
125         DEBUG3("  authentication"); /* always enabled */
126         /* here are all the conditional feature flags */
127 #if defined(WITH_DHCP)
128         DEBUG3(" WITH_DHCP");
129 #endif
130 #if defined(WITH_VMPS)
131         DEBUG3(" WITH_VMPS");
132 #endif
133 #if defined(OSFC2)
134         DEBUG3(" OSFC2");
135 #endif
136 #if defined(WITHOUT_PROXY)
137         DEBUG3(" WITHOUT_PROXY");
138 #endif
139 #if defined(WITHOUT_DETAIL)
140         DEBUG3(" WITHOUT_DETAIL");
141 #endif
142 #if defined(WITHOUT_SESSION_MGMT)
143         DEBUG3(" WITHOUT_SESSION_MGMT");
144 #endif
145 #if defined(WITHOUT_UNLANG)
146         DEBUG3(" WITHOUT_UNLANG");
147 #endif
148 #if defined(WITHOUT_ACCOUNTING)
149         DEBUG3(" WITHOUT_ACCOUNTING");
150 #endif
151 #if defined(WITHOUT_DYNAMIC_CLIENTS)
152         DEBUG3(" WITHOUT_DYNAMIC_CLIENTS");
153 #endif
154 #if defined(WITHOUT_STATS)
155         DEBUG3(" WITHOUT_STATS");
156 #endif
157 #if defined(WITHOUT_COMMAND_SOCKET)
158         DEBUG3(" WITHOUT_COMMAND_SOCKET");
159 #endif
160 #if defined(WITHOUT_COA)
161         DEBUG3(" WITHOUT_COA");
162 #endif
163         DEBUG3("Server core libs:");
164         DEBUG3("  ssl: %s", ssl_version());
165
166         radlog(L_INFO, "Copyright (C) 1999-2015 The FreeRADIUS server project and contributors.");
167         radlog(L_INFO, "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
168         radlog(L_INFO, "PARTICULAR PURPOSE.");
169         radlog(L_INFO, "You may redistribute copies of FreeRADIUS under the terms of the");
170         radlog(L_INFO, "GNU General Public License.");
171         radlog(L_INFO, "For more information about these matters, see the file named COPYRIGHT.");
172
173         fflush(NULL);
174 }
175