aboutsummaryrefslogtreecommitdiffstats
path: root/src/ssl/tls_policy.cpp
blob: 42e8553799f4942c3a26d4312e039cecc104424a (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Policies Source File
* (C) 2004-2006 Jack Lloyd
*
* Released under the terms of the Botan license
*/

#include <botan/tls_policy.h>
#include <botan/tls_exceptn.h>

namespace Botan {

/**
* Return allowed ciphersuites
*/
std::vector<u16bit> Policy::ciphersuites() const
   {
   return suite_list(allow_static_rsa(), allow_edh_rsa(), allow_edh_dsa());
   }

/**
* Return allowed ciphersuites
*/
std::vector<u16bit> Policy::suite_list(bool use_rsa, bool use_edh_rsa,
                                       bool use_edh_dsa) const
   {
   std::vector<u16bit> suites;

   if(use_edh_dsa)
      {
      suites.push_back(DHE_DSS_AES256_SHA);
      suites.push_back(DHE_DSS_AES128_SHA);
      suites.push_back(DHE_DSS_3DES_SHA);
      }

   if(use_edh_rsa)
      {
      suites.push_back(DHE_RSA_AES256_SHA);
      suites.push_back(DHE_RSA_AES128_SHA);
      suites.push_back(DHE_RSA_3DES_SHA);
      }

   if(use_rsa)
      {
      suites.push_back(RSA_AES256_SHA);
      suites.push_back(RSA_AES128_SHA);
      suites.push_back(RSA_3DES_SHA);
      suites.push_back(RSA_RC4_SHA);
      suites.push_back(RSA_RC4_MD5);
      }

   if(suites.size() == 0)
      throw TLS_Exception(INTERNAL_ERROR,
                          "Policy error: All ciphersuites disabled");

   return suites;
   }

/**
* Return allowed compression algorithms
*/
std::vector<byte> Policy::compression() const
   {
   std::vector<byte> algs;
   algs.push_back(NO_COMPRESSION);
   return algs;
   }

/**
* Choose which ciphersuite to use
*/
u16bit Policy::choose_suite(const std::vector<u16bit>& c_suites,
                            bool have_rsa, bool have_dsa) const
   {
   bool use_static_rsa = allow_static_rsa() && have_rsa;
   bool use_edh_rsa = allow_edh_rsa() && have_rsa;
   bool use_edh_dsa = allow_edh_dsa() && have_dsa;

   std::vector<u16bit> s_suites = suite_list(use_static_rsa, use_edh_rsa,
                                             use_edh_dsa);

   for(u32bit j = 0; j != s_suites.size(); j++)
      for(u32bit k = 0; k != c_suites.size(); k++)
         if(s_suites[j] == c_suites[k])
            return s_suites[j];

   return 0;
   }

/**
* Choose which compression algorithm to use
*/
byte Policy::choose_compression(const std::vector<byte>& c_comp) const
   {
   std::vector<byte> s_comp = compression();

   for(u32bit j = 0; j != s_comp.size(); j++)
      for(u32bit k = 0; k != c_comp.size(); k++)
         if(s_comp[j] == c_comp[k])
            return s_comp[j];

   return NO_COMPRESSION;
   }

/**
* Return the minimum acceptable SSL/TLS version
*/
Version_Code Policy::min_version() const
   {
   return SSL_V3;
   }

/**
* Return the preferable SSL/TLS version
*/
Version_Code Policy::pref_version() const
   {
   return TLS_V10;
   }

/**
* Check if static RSA keying is allowed
*/
bool Policy::allow_static_rsa() const
   {
   return true;
   }

/**
* Check if RSA with empheral DH is allowed
*/
bool Policy::allow_edh_rsa() const
   {
   return true;
   }

/**
* Check if DSA with empheral DH is allowed
*/
bool Policy::allow_edh_dsa() const
   {
   return true;
   }

/**
* Check if client authentication is required
*/
bool Policy::require_client_auth() const
   {
   return false;
   }

/**
* Return the group to use for empheral DH
*/
DL_Group Policy::dh_group() const
   {
   return DL_Group("IETF-1024");
   }

/**
* Return the size to use for an empheral RSA key
*/
u32bit Policy::rsa_export_keysize() const
   {
   return 512;
   }

/**
* Default certificate check
*/
bool Policy::check_cert(const std::vector<X509_Certificate>&,
                        const std::string&) const
   {
   return true;
   }

}