blob: 8647e6b2c8491d419f8adfe99cd146e160c05c8d [file] [log] [blame]
Lutz Justen51631092019-07-05 09:19:58 +02001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Felipe Andradea0cbde72020-04-01 15:40:10 +02005#include "kerberos/config_parser.h"
Lutz Justen51631092019-07-05 09:19:58 +02006
7#include <ostream>
8#include <string>
9
10#include <base/logging.h>
Qijiang Fan886c4692021-02-19 11:54:10 +090011#include <base/notreached.h>
Lutz Justen51631092019-07-05 09:19:58 +020012#include <gtest/gtest.h>
13
Felipe Andrade66aaf6b2020-03-24 13:05:57 +010014#include "kerberos/kerberos_metrics.h"
Lutz Justen51631092019-07-05 09:19:58 +020015#include "kerberos/proto_bindings/kerberos_service.pb.h"
16
17namespace kerberos {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +010018namespace {
19constexpr char kCompleteKrb5Conf[] = R"(
20# Comment
21; Another comment
22
23[libdefaults]
24 clockskew = 123
25 default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
26 default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
27 permitted_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
28 renew_lifetime* = 7d
29 ticket_lifetime* = 1d
30 A.EXAMPLE.COM = {
31 clockskew = 300
32 }
33 B.EXAMPLE.COM =
34 {
35 ; Tests = whether { can be on new line
36 clockskew = 500
37 }
38
39[realms]
40 kdc = 5.6.7.8
41 EXAMPLE.COM = {
42 kdc = 1.2.3.4
43 admin_server = kdc.example.com
44 auth_to_local = RULE:[2:$1](johndoe)s/^.*$/guest/
45 auth_to_local_names = {
46 hans = jack
47 joerg = jerk
48 }
49 }*
50
51[domain_realm]*
52 any.thing = IS.ACCEPTED.HERE
53
54[capaths]
55 here = AS.WELL)";
Sergey Poromov38cec242021-03-12 13:47:57 +010056
57std::string GenerateNestedGroups(int count) {
58 std::string result;
59 for (int i = 0; i < count; i++) {
60 result += "A={\n";
61 }
62 for (int i = 0; i < count; i++) {
63 result += "}\n";
64 }
65 return result;
66}
67
Felipe Andrade66aaf6b2020-03-24 13:05:57 +010068} // namespace
Lutz Justen51631092019-07-05 09:19:58 +020069
70std::ostream& operator<<(std::ostream& os, ConfigErrorCode code) {
71 switch (code) {
72 case CONFIG_ERROR_NONE:
73 return os << "OK";
74 case CONFIG_ERROR_SECTION_NESTED_IN_GROUP:
75 return os << "Section nested in group";
76 case CONFIG_ERROR_SECTION_SYNTAX:
77 return os << "ESection syntax error, expected '[section]'";
78 case CONFIG_ERROR_EXPECTED_OPENING_CURLY_BRACE:
79 return os << "Expected opening curly brace '{'";
80 case CONFIG_ERROR_EXTRA_CURLY_BRACE:
81 return os << "Extra curly brace";
82 case CONFIG_ERROR_RELATION_SYNTAX:
83 return os << "Relation syntax error, expected 'key = ...'";
84 case CONFIG_ERROR_KEY_NOT_SUPPORTED:
85 return os << "Key not supported";
86 case CONFIG_ERROR_SECTION_NOT_SUPPORTED:
87 return os << "Section not supported";
88 case CONFIG_ERROR_KRB5_FAILED_TO_PARSE:
89 return os << "KRB5 failed to parse";
Sergey Poromov38cec242021-03-12 13:47:57 +010090 case CONFIG_ERROR_TOO_MANY_NESTED_GROUPS:
91 return os << "Too many nested groups";
Lutz Justen51631092019-07-05 09:19:58 +020092 case CONFIG_ERROR_COUNT:
93 NOTREACHED();
94 }
95 return os;
96}
97
98std::ostream& operator<<(std::ostream& os, const ConfigErrorInfo& error_info) {
99 if (error_info.code() == CONFIG_ERROR_NONE)
100 return os << "[no error]";
101
102 return os << error_info.code() << " at line " << error_info.line_index();
103}
104
Felipe Andradea0cbde72020-04-01 15:40:10 +0200105class ConfigParserTest : public ::testing::Test {
Lutz Justen51631092019-07-05 09:19:58 +0200106 protected:
Sergey Poromov38cec242021-03-12 13:47:57 +0100107 void ExpectNoError(const std::string& krb5conf) {
Felipe Andradea0cbde72020-04-01 15:40:10 +0200108 ConfigErrorInfo error_info = config_parser_.Validate(krb5conf);
Lutz Justen51631092019-07-05 09:19:58 +0200109
110 EXPECT_TRUE(error_info.has_code()) << error_info;
111 EXPECT_EQ(CONFIG_ERROR_NONE, error_info.code()) << error_info;
112 EXPECT_FALSE(error_info.has_line_index()) << error_info;
113 }
114
Lutz Justen70496c12019-07-24 11:11:55 +0200115 void ExpectError(const std::string& krb5conf,
116 ConfigErrorCode code,
117 int line_index) {
Felipe Andradea0cbde72020-04-01 15:40:10 +0200118 ConfigErrorInfo error_info = config_parser_.Validate(krb5conf);
Lutz Justen51631092019-07-05 09:19:58 +0200119
120 EXPECT_TRUE(error_info.has_code()) << error_info;
121 EXPECT_EQ(code, error_info.code()) << error_info;
122 EXPECT_TRUE(error_info.has_line_index()) << error_info;
123 EXPECT_EQ(line_index, error_info.line_index()) << error_info;
124 }
125
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200126 void ExpectEncryptionTypes(
127 const std::string& krb5conf,
128 KerberosEncryptionTypes expected_encryption_types) {
129 KerberosEncryptionTypes encryption_types;
130
131 EXPECT_TRUE(config_parser_.GetEncryptionTypes(krb5conf, &encryption_types));
132 EXPECT_EQ(expected_encryption_types, encryption_types);
133 }
134
Felipe Andradea0cbde72020-04-01 15:40:10 +0200135 ConfigParser config_parser_;
Lutz Justen51631092019-07-05 09:19:58 +0200136};
137
Felipe Andradea0cbde72020-04-01 15:40:10 +0200138TEST_F(ConfigParserTest, ValidConfig) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100139 ExpectNoError(kCompleteKrb5Conf);
Lutz Justen51631092019-07-05 09:19:58 +0200140}
141
Felipe Andradea0cbde72020-04-01 15:40:10 +0200142TEST_F(ConfigParserTest, Empty) {
Lutz Justen51631092019-07-05 09:19:58 +0200143 ExpectNoError("");
144 ExpectNoError("\n");
145 ExpectNoError("\n\n\n");
146 ExpectNoError("[libdefaults]");
147 ExpectNoError("[libdefaults]\n");
148 ExpectNoError("[libdefaults]\n\n\n");
149}
150
Felipe Andradea0cbde72020-04-01 15:40:10 +0200151TEST_F(ConfigParserTest, ModulesAndIncludesBlocked) {
Lutz Justen51631092019-07-05 09:19:58 +0200152 ExpectError("module MODULEPATH:RESIDUAL", CONFIG_ERROR_KEY_NOT_SUPPORTED, 0);
153 ExpectError("include /path/to/file", CONFIG_ERROR_KEY_NOT_SUPPORTED, 0);
154 ExpectError("includedir /path/to/files", CONFIG_ERROR_KEY_NOT_SUPPORTED, 0);
155
156 constexpr char kKrb5Conf[] = R"(
157[libdefaults]
158 includedir /path/to/files)";
159 ExpectError(kKrb5Conf, CONFIG_ERROR_KEY_NOT_SUPPORTED, 2);
160}
161
Felipe Andradea0cbde72020-04-01 15:40:10 +0200162TEST_F(ConfigParserTest, UnsupportedLibdefaultsKey) {
Lutz Justen51631092019-07-05 09:19:58 +0200163 constexpr char kKrb5Conf[] = R"(
164[libdefaults]
165 stonkskew = 123)";
166 ExpectError(kKrb5Conf, CONFIG_ERROR_KEY_NOT_SUPPORTED, 2);
167}
168
Felipe Andradea0cbde72020-04-01 15:40:10 +0200169TEST_F(ConfigParserTest, UnsupportedNestedLibdefaultsKey) {
Lutz Justen51631092019-07-05 09:19:58 +0200170 constexpr char kKrb5Conf[] = R"(
171[libdefaults]
172 A.EXAMPLE.COM = {
173 stonkskew = 300
174 })";
175 ExpectError(kKrb5Conf, CONFIG_ERROR_KEY_NOT_SUPPORTED, 3);
176}
177
Felipe Andradea0cbde72020-04-01 15:40:10 +0200178TEST_F(ConfigParserTest, UnsupportedRealmKey) {
Lutz Justen51631092019-07-05 09:19:58 +0200179 constexpr char kKrb5Conf[] = R"(
180[realms]
181 BEISPIEL.FIR = {
182 meister_svz = svz.beispiel.fir
183 })";
184 ExpectError(kKrb5Conf, CONFIG_ERROR_KEY_NOT_SUPPORTED, 3);
185}
186
Felipe Andradea0cbde72020-04-01 15:40:10 +0200187TEST_F(ConfigParserTest, RelationSyntaxErrorKeyWithoutEquals) {
Lutz Justen51631092019-07-05 09:19:58 +0200188 constexpr char kKrb5Conf[] = R"(
189[libdefaults]
190 kdc: kdc.example.com
191)";
192 ExpectError(kKrb5Conf, CONFIG_ERROR_RELATION_SYNTAX, 2);
193}
194
Felipe Andradea0cbde72020-04-01 15:40:10 +0200195TEST_F(ConfigParserTest, UnsupportedSection) {
Lutz Justen51631092019-07-05 09:19:58 +0200196 ExpectError("[appdefaults]", CONFIG_ERROR_SECTION_NOT_SUPPORTED, 0);
197}
198
Felipe Andradea0cbde72020-04-01 15:40:10 +0200199TEST_F(ConfigParserTest, SectionNestedInGroup) {
Lutz Justen51631092019-07-05 09:19:58 +0200200 constexpr char kKrb5Conf[] = R"(
201[realms]
202 EXAMPLE.COM = {
203 [libdefaults]
204 })";
205 ExpectError(kKrb5Conf, CONFIG_ERROR_SECTION_NESTED_IN_GROUP, 3);
206}
207
Felipe Andradea0cbde72020-04-01 15:40:10 +0200208TEST_F(ConfigParserTest, MissingSectionBrackets) {
Lutz Justen51631092019-07-05 09:19:58 +0200209 ExpectError("[realms", CONFIG_ERROR_SECTION_SYNTAX, 0);
210}
211
Felipe Andradea0cbde72020-04-01 15:40:10 +0200212TEST_F(ConfigParserTest, SpacesBeforeSectionEndMarker) {
Lutz Justen51631092019-07-05 09:19:58 +0200213 // Note that the krb5 parser appears to accept spaces before the ']', but
214 // it's a different section than without the spaces, so we reject it.
215 ExpectError("[realms ]", CONFIG_ERROR_SECTION_NOT_SUPPORTED, 0);
216}
217
Felipe Andradea0cbde72020-04-01 15:40:10 +0200218TEST_F(ConfigParserTest, ExtraStuffBeforeSectionBrackets) {
Lutz Justen51631092019-07-05 09:19:58 +0200219 ExpectError("extra [realms]", CONFIG_ERROR_RELATION_SYNTAX, 0);
220}
221
Felipe Andradea0cbde72020-04-01 15:40:10 +0200222TEST_F(ConfigParserTest, ExtraStuffAfterSectionBrackets) {
Lutz Justen51631092019-07-05 09:19:58 +0200223 ExpectError("[realms] extra", CONFIG_ERROR_SECTION_SYNTAX, 0);
224}
225
Felipe Andradea0cbde72020-04-01 15:40:10 +0200226TEST_F(ConfigParserTest, FinalMarkersAllowed) {
Lutz Justen51631092019-07-05 09:19:58 +0200227 ExpectNoError("[libdefaults]* \nclockskew*=9");
228}
229
Felipe Andradea0cbde72020-04-01 15:40:10 +0200230TEST_F(ConfigParserTest, FinalMarkersWithSpacesNotAllowed) {
Lutz Justen51631092019-07-05 09:19:58 +0200231 ExpectError("[libdefaults] *)", CONFIG_ERROR_SECTION_SYNTAX, 0);
232 ExpectError("[libdefaults]\nclockskew *=9", CONFIG_ERROR_RELATION_SYNTAX, 1);
233}
234
Felipe Andradea0cbde72020-04-01 15:40:10 +0200235TEST_F(ConfigParserTest, RelationSyntaxError) {
Lutz Justen51631092019-07-05 09:19:58 +0200236 ExpectError("[libdefaults]\nclockskew", CONFIG_ERROR_RELATION_SYNTAX, 1);
237 ExpectError("[libdefaults]\nclockskew ", CONFIG_ERROR_RELATION_SYNTAX, 1);
238 ExpectError("[libdefaults]\nclockskew* ", CONFIG_ERROR_RELATION_SYNTAX, 1);
239 ExpectError("[libdefaults]\n=clockskew*", CONFIG_ERROR_RELATION_SYNTAX, 1);
240}
241
Felipe Andradea0cbde72020-04-01 15:40:10 +0200242TEST_F(ConfigParserTest, TwoEqualSignsAllowed) {
Lutz Justen51631092019-07-05 09:19:58 +0200243 ExpectNoError("[libdefaults]\nclockskew=1=2");
244}
245
Felipe Andradea0cbde72020-04-01 15:40:10 +0200246TEST_F(ConfigParserTest, RelationSyntaxEdgeCases) {
Lutz Justen51631092019-07-05 09:19:58 +0200247 ExpectError("*", CONFIG_ERROR_RELATION_SYNTAX, 0);
248 ExpectError("*=", CONFIG_ERROR_RELATION_SYNTAX, 0);
249 ExpectError("=", CONFIG_ERROR_RELATION_SYNTAX, 0);
250
251 ExpectError(" *", CONFIG_ERROR_RELATION_SYNTAX, 0);
252 ExpectError(" *=", CONFIG_ERROR_RELATION_SYNTAX, 0);
253 ExpectError(" =", CONFIG_ERROR_RELATION_SYNTAX, 0);
254
255 ExpectError("* ", CONFIG_ERROR_RELATION_SYNTAX, 0);
256 ExpectError("*= ", CONFIG_ERROR_RELATION_SYNTAX, 0);
257 ExpectError("= ", CONFIG_ERROR_RELATION_SYNTAX, 0);
258
259 ExpectError(" * ", CONFIG_ERROR_RELATION_SYNTAX, 0);
260 ExpectError(" *= ", CONFIG_ERROR_RELATION_SYNTAX, 0);
261 ExpectError(" = ", CONFIG_ERROR_RELATION_SYNTAX, 0);
262
263 ExpectError(" * = ", CONFIG_ERROR_RELATION_SYNTAX, 0);
264}
265
Felipe Andradea0cbde72020-04-01 15:40:10 +0200266TEST_F(ConfigParserTest, WhitespaceBeforeAndAfterSectionBrackets) {
Lutz Justen51631092019-07-05 09:19:58 +0200267 ExpectNoError(" [realms] ");
268}
269
Felipe Andradea0cbde72020-04-01 15:40:10 +0200270TEST_F(ConfigParserTest, MissingOpeningCurlyBrace) {
Lutz Justen51631092019-07-05 09:19:58 +0200271 constexpr char kKrb5Conf[] = R"(
272[realms]
273 EXAMPLE.COM =
274
275 kdc = kdc.example.com
276 })";
277 ExpectError(kKrb5Conf, CONFIG_ERROR_EXPECTED_OPENING_CURLY_BRACE, 3);
278}
279
Felipe Andradea0cbde72020-04-01 15:40:10 +0200280TEST_F(ConfigParserTest, ExtraCurlyBraceFound) {
Lutz Justen51631092019-07-05 09:19:58 +0200281 constexpr char kKrb5Conf[] = R"(
282 [realms]
283 EXAMPLE.COM =
284 {
285 kdc = kdc.example.com
286 }
287})";
288 ExpectError(kKrb5Conf, CONFIG_ERROR_EXTRA_CURLY_BRACE, 6);
289}
290
Lutz Justen70496c12019-07-24 11:11:55 +0200291// Things that the fuzzer found.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200292TEST_F(ConfigParserTest, FuzzerRegressionTests) {
Lutz Justen70496c12019-07-24 11:11:55 +0200293 // Code was looking at character after "include" to check if it's a space.
294 ExpectError("include", CONFIG_ERROR_KEY_NOT_SUPPORTED, 0);
295
296 // Code was accepting "[realms\0]" as a valid section. Embedded \0's should be
297 // handled in a c_str() kind of way.
298 std::string krb5confWithZero = "[realms\0]";
299 krb5confWithZero[7] = 0;
300 ExpectError(krb5confWithZero, CONFIG_ERROR_SECTION_SYNTAX, 0);
301
Felipe Andradea0cbde72020-04-01 15:40:10 +0200302 // Code was allowing spaces in keys. Note that ConfigParser allows all keys
Lutz Justen70496c12019-07-24 11:11:55 +0200303 // in the [domain_realm] section, but it should still check spaces!
304 ExpectError("[domain_realm]\nkey x=", CONFIG_ERROR_RELATION_SYNTAX, 1);
305
306 // \r should not be counted as newline character.
307 ExpectError("[domain_realm]\rkey=", CONFIG_ERROR_SECTION_SYNTAX, 0);
308
309 // Double == is always a relation, cannot be the start of a group.
310 ExpectError("[capaths]\nkey==\n{", CONFIG_ERROR_RELATION_SYNTAX, 2);
Sergey Poromov38cec242021-03-12 13:47:57 +0100311
312 // Too many nested groups should lead to an error preventing stack overflow
313 // in krb5 parser.
314 ExpectNoError(GenerateNestedGroups(1000));
315 ExpectError(GenerateNestedGroups(1001), CONFIG_ERROR_TOO_MANY_NESTED_GROUPS,
316 1000);
Lutz Justen70496c12019-07-24 11:11:55 +0200317}
318
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100319// |GetEncryptionTypes| with a complete config to be parsed.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200320TEST_F(ConfigParserTest, GetEncryptionTypesCompleteConfig) {
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200321 ExpectEncryptionTypes(kCompleteKrb5Conf, KerberosEncryptionTypes::kStrong);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100322}
323
324// |GetEncryptionTypes| with all encryption types allowed.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200325TEST_F(ConfigParserTest, GetEncryptionTypesAll) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100326 constexpr char kKrb5Conf[] = R"(
327[libdefaults]
328 default_tkt_enctypes = aes256-cts-hmac-sha1-96 arcfour-hmac-md5-exp
329 default_tgs_enctypes = aes256-cts-hmac-sha1-96 arcfour-hmac-md5-exp
330 permitted_enctypes = aes256-cts-hmac-sha1-96 arcfour-hmac-md5-exp)";
331
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200332 ExpectEncryptionTypes(kKrb5Conf, KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100333}
334
335// |GetEncryptionTypes| with only strong encryption types allowed.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200336TEST_F(ConfigParserTest, GetEncryptionTypesStrong) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100337 constexpr char kKrb5Conf[] = R"(
338[libdefaults]
339 default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
340 default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
341 permitted_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96)";
342
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200343 ExpectEncryptionTypes(kKrb5Conf, KerberosEncryptionTypes::kStrong);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100344}
345
346// |GetEncryptionTypes| with only legacy encryption types allowed.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200347TEST_F(ConfigParserTest, GetEncryptionTypesLegacy) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100348 constexpr char kKrb5Conf[] = R"(
349[libdefaults]
350 default_tkt_enctypes = arcfour-hmac-md5-exp des3-cbc-raw
351 default_tgs_enctypes = arcfour-hmac-md5-exp des3-cbc-raw
352 permitted_enctypes = arcfour-hmac-md5-exp des3-cbc-raw)";
353
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200354 ExpectEncryptionTypes(kKrb5Conf, KerberosEncryptionTypes::kLegacy);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100355}
356
357// |GetEncryptionTypes| with enctypes fields missing.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200358TEST_F(ConfigParserTest, GetEncryptionTypesMissingFields) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100359 // Empty config allows all encryption types.
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200360 ExpectEncryptionTypes("", KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100361
362 constexpr char kKrb5Conf1[] = R"(
363[libdefaults]
364 default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
365 default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96)";
366
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200367 ExpectEncryptionTypes(kKrb5Conf1, KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100368
369 constexpr char kKrb5Conf2[] = R"(
370[libdefaults]
371 default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
372 permitted_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96)";
373
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200374 ExpectEncryptionTypes(kKrb5Conf2, KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100375
376 constexpr char kKrb5Conf3[] = R"(
377[libdefaults]
378 default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96
379 permitted_enctypes =aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96)";
380
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200381 ExpectEncryptionTypes(kKrb5Conf3, KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100382}
383
384// |GetEncryptionTypes| with |DEFAULT| enctypes assigned.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200385TEST_F(ConfigParserTest, GetEncryptionTypesDefaultValues) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100386 constexpr char kKrb5Conf[] = R"(
387[libdefaults]
388 default_tkt_enctypes = DEFAULT
389 default_tgs_enctypes = DEFAULT
390 permitted_enctypes = DEFAULT)";
391
392 // |DEFAULT| value allows all encryption types.
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200393 ExpectEncryptionTypes(kKrb5Conf, KerberosEncryptionTypes::kAll);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100394}
395
396// |GetEncryptionTypes| with comma separated encryption types list.
Felipe Andradea0cbde72020-04-01 15:40:10 +0200397TEST_F(ConfigParserTest, GetEncryptionTypesCommaSeparated) {
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100398 constexpr char kKrb5Conf[] = R"(
399[libdefaults]
400 default_tkt_enctypes = aes256-cts-hmac-sha1-96, arcfour-hmac-md5-exp
401 default_tgs_enctypes = aes256-cts-hmac-sha1-96, arcfour-hmac-md5-exp
402 permitted_enctypes = aes256-cts-hmac-sha1-96,arcfour-hmac-md5-exp)";
403
Felipe Andrade90cb84e2020-04-07 20:28:33 +0200404 ExpectEncryptionTypes(kKrb5Conf, KerberosEncryptionTypes::kAll);
405}
406
407// |GetEncryptionTypes| with invalid config.
408TEST_F(ConfigParserTest, GetEncryptionTypesInvalidConfig) {
409 constexpr char kKrb5Conf[] = R"(
410[libdefaults]
411 stonkskew = 123)";
412
413 KerberosEncryptionTypes encryption_types;
414
415 EXPECT_FALSE(config_parser_.GetEncryptionTypes(kKrb5Conf, &encryption_types));
416 // |encryption_types| should've been set to the default value in our feature.
417 EXPECT_EQ(KerberosEncryptionTypes::kStrong, encryption_types);
Felipe Andrade66aaf6b2020-03-24 13:05:57 +0100418}
419
Lutz Justen51631092019-07-05 09:19:58 +0200420} // namespace kerberos