1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2018-2018 Bareos GmbH & Co. KG
5 
6    This program is Free Software; you can redistribute it and/or
7    modify it under the terms of version three of the GNU Affero General Public
8    License as published by the Free Software Foundation and included
9    in the file LICENSE.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14    Affero General Public License for more details.
15 
16    You should have received a copy of the GNU Affero General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.
20 */
21 
22 #include "include/bareos.h"
23 #include "lib/tls_conf.h"
24 
TlsResource()25 TlsResource::TlsResource()
26     : authenticate_(false), tls_enable_(false), tls_require_(false)
27 {
28   return;
29 }
30 
IsTlsConfigured() const31 bool TlsResource::IsTlsConfigured() const
32 {
33   return tls_enable_ || tls_require_;
34 }
35 
GetPolicy() const36 TlsPolicy TlsResource::GetPolicy() const
37 {
38   TlsPolicy result = TlsPolicy::kBnetTlsNone;
39   if (tls_enable_) { result = TlsPolicy::kBnetTlsEnabled; }
40   if (tls_require_) { result = TlsPolicy::kBnetTlsRequired; }
41   return result;
42 }
43 
SelectTlsPolicy(TlsPolicy remote_policy) const44 int TlsResource::SelectTlsPolicy(TlsPolicy remote_policy) const
45 {
46   if (remote_policy == TlsPolicy::kBnetTlsAuto) {
47     return TlsPolicy::kBnetTlsAuto;
48   }
49   TlsPolicy local_policy = GetPolicy();
50 
51   if ((remote_policy == 0 && local_policy == 0) ||
52       (remote_policy == 0 && local_policy == 1) ||
53       (remote_policy == 1 && local_policy == 0)) {
54     return TlsPolicy::kBnetTlsNone;
55   }
56   if ((remote_policy == 0 && local_policy == 2) ||
57       (remote_policy == 2 && local_policy == 0)) {
58     return TlsPolicy::kBnetTlsDeny;
59   }
60   return TlsPolicy::kBnetTlsEnabled;
61 }
62