@@ -252,23 +252,25 @@ class OpenSSLCipherConfigurationParser {
252
252
static constexpr auto COMPLEMENTOFDEFAULT = " COMPLEMENTOFDEFAULT" ;
253
253
static constexpr auto ALL = " ALL" ;
254
254
255
- void moveToEnd (const AliasMap &aliases, std::vector<Cipher> &ciphers, std::string_view cipher) {
255
+ void moveToEnd (const AliasMap &aliases, std::vector<Cipher> &ciphers,
256
+ std::string_view cipher) const {
256
257
this ->moveToEnd (ciphers, aliases.at (cipher));
257
258
}
258
259
259
- void moveToEnd (std::vector<Cipher> &ciphers, const std::vector<Cipher> &ciphersToMoveToEnd) {
260
+ void moveToEnd (std::vector<Cipher> &ciphers,
261
+ const std::vector<Cipher> &ciphersToMoveToEnd) const {
260
262
std::stable_partition (ciphers.begin (), ciphers.end (), [ciphersToMoveToEnd](auto cipher) {
261
263
return std::find (ciphersToMoveToEnd.begin (), ciphersToMoveToEnd.end (), cipher) ==
262
264
ciphersToMoveToEnd.end ();
263
265
});
264
266
}
265
267
266
- void add (const AliasMap &aliases, std::vector<Cipher> &ciphers, std::string_view alias) {
268
+ void add (const AliasMap &aliases, std::vector<Cipher> &ciphers, std::string_view alias) const {
267
269
auto toAdd = aliases.at (alias);
268
270
ciphers.insert (ciphers.end (), toAdd.begin (), toAdd.end ());
269
271
}
270
272
271
- void remove (const AliasMap &aliases, std::vector<Cipher> &ciphers, std::string_view alias) {
273
+ void remove (const AliasMap &aliases, std::vector<Cipher> &ciphers, std::string_view alias) const {
272
274
auto &toRemove = aliases.at (alias);
273
275
ciphers.erase (std::remove_if (ciphers.begin (), ciphers.end (),
274
276
[&](auto x) {
@@ -278,7 +280,7 @@ class OpenSSLCipherConfigurationParser {
278
280
ciphers.end ());
279
281
}
280
282
281
- void strengthSort (std::vector<Cipher> &ciphers) {
283
+ void strengthSort (std::vector<Cipher> &ciphers) const {
282
284
/*
283
285
* This routine sorts the ciphers with descending strength. The sorting
284
286
* must keep the pre-sorted sequence.
@@ -291,13 +293,13 @@ class OpenSSLCipherConfigurationParser {
291
293
* See
292
294
* https://github.com/openssl/openssl/blob/709651c9022e7be7e69cf8a2f6edf2c8722a6a1e/ssl/ssl_ciph.c#L1455
293
295
*/
294
- void defaultSort (std::vector<Cipher> &ciphers) {
296
+ void defaultSort (std::vector<Cipher> &ciphers) const {
295
297
auto byStrength = [](auto &l, auto &r) { return l.strength_bits > r.strength_bits ; };
296
298
// order all ciphers by strength first
297
299
std::sort (ciphers.begin (), ciphers.end (), byStrength);
298
300
299
- auto it =
300
- std::stable_partition (ciphers. begin (), ciphers. end (), this ->byKeyExchange (KeyExchange::EECDH));
301
+ auto it = std::stable_partition (ciphers. begin (), ciphers. end (),
302
+ this ->byKeyExchange (KeyExchange::EECDH));
301
303
302
304
/* AES is our preferred symmetric cipher */
303
305
auto aes = {Encryption::AES128, Encryption::AES128GCM, Encryption::AES256,
@@ -307,40 +309,40 @@ class OpenSSLCipherConfigurationParser {
307
309
it = std::stable_partition (it, ciphers.end (), this ->byEncryption (aes));
308
310
309
311
/* Move ciphers without forward secrecy to the end */ ;
310
- std::stable_partition (it, ciphers. end (), [compare = this -> byKeyExchange (KeyExchange::RSA)]( auto &c) {
311
- return ! compare (c);
312
- });
312
+ std::stable_partition (
313
+ it, ciphers. end (),
314
+ [compare = this -> byKeyExchange (KeyExchange::RSA)]( auto &c) { return ! compare (c); });
313
315
}
314
316
315
- std::function<bool (const Cipher &)> byProtocol (Protocol val) {
317
+ std::function<bool (const Cipher &)> byProtocol (Protocol val) const {
316
318
return [val](auto &c) { return c.protocol == val; };
317
319
}
318
320
319
- std::function<bool (const Cipher &)> byKeyExchange (KeyExchange val) {
321
+ std::function<bool (const Cipher &)> byKeyExchange (KeyExchange val) const {
320
322
return [val](auto &c) { return c.kx == val; };
321
323
}
322
324
323
- std::function<bool (const Cipher &)> byAuthentication (Authentication val) {
325
+ std::function<bool (const Cipher &)> byAuthentication (Authentication val) const {
324
326
return [val](auto &c) { return c.au == val; };
325
327
}
326
328
327
- std::function<bool (const Cipher &)> byEncryption (std::set<Encryption> vals) {
329
+ std::function<bool (const Cipher &)> byEncryption (std::set<Encryption> vals) const {
328
330
return [vals](auto &c) { return vals.find (c.enc ) != vals.end (); };
329
331
}
330
332
331
- std::function<bool (const Cipher &)> byEncryption (Encryption val) {
333
+ std::function<bool (const Cipher &)> byEncryption (Encryption val) const {
332
334
return [val](auto &c) { return c.enc == val; };
333
335
}
334
336
335
- std::function<bool (const Cipher &)> byEncryptionLevel (EncryptionLevel val) {
337
+ std::function<bool (const Cipher &)> byEncryptionLevel (EncryptionLevel val) const {
336
338
return [val](auto &c) { return c.level == val; };
337
339
}
338
340
339
- std::function<bool (const Cipher &)> byMessageDigest (MessageDigest val) {
341
+ std::function<bool (const Cipher &)> byMessageDigest (MessageDigest val) const {
340
342
return [val](auto &c) { return c.mac == val; };
341
343
}
342
344
343
- std::vector<std::string_view> split (std::string_view s, std::string_view delimiter) {
345
+ std::vector<std::string_view> split (std::string_view s, std::string_view delimiter) const {
344
346
size_t pos_start = 0 , pos_end, delim_len = delimiter.length ();
345
347
std::string token;
346
348
std::vector<std::string_view> res;
@@ -355,7 +357,7 @@ class OpenSSLCipherConfigurationParser {
355
357
return res;
356
358
}
357
359
358
- std::pair<std::string_view, std::string_view> split_on (std::string_view str, char c) {
360
+ std::pair<std::string_view, std::string_view> split_on (std::string_view str, char c) const {
359
361
auto ix = str.find (c);
360
362
if (ix == str.npos ) {
361
363
return {str, " " };
@@ -370,7 +372,7 @@ class OpenSSLCipherConfigurationParser {
370
372
return {left, str.substr (ix)};
371
373
}
372
374
373
- std::vector<std::string_view> splitCipherSuiteString (std::string_view string) {
375
+ std::vector<std::string_view> splitCipherSuiteString (std::string_view string) const {
374
376
std::vector<std::string_view> result;
375
377
376
378
while (!string.empty ()) {
@@ -531,7 +533,7 @@ class OpenSSLCipherConfigurationParser {
531
533
aliases.insert ({DEFAULT, this ->parse (" ALL:!COMPLEMENTOFDEFAULT:!eNULL" )});
532
534
}
533
535
534
- std::vector<Cipher> parse (std::string_view expression) {
536
+ std::vector<Cipher> parse (std::string_view expression) const {
535
537
/* *
536
538
* All ciphers by their openssl alias name.
537
539
*/
@@ -547,8 +549,10 @@ class OpenSSLCipherConfigurationParser {
547
549
}
548
550
} else if (element.rfind (EXCLUDE, 0 ) == 0 ) {
549
551
auto alias = element.substr (1 );
550
- if (aliases.find (alias) != aliases.end ()) {
551
- auto toAdd = aliases[alias];
552
+ auto found = aliases.find (alias);
553
+ if (found != aliases.end ()) {
554
+
555
+ auto toAdd = found.operator ->()->second ;
552
556
removedCiphers.insert (removedCiphers.end (), toAdd.begin (), toAdd.end ());
553
557
}
554
558
} else if (element.rfind (TO_END, 0 ) == 0 ) {
@@ -563,23 +567,26 @@ class OpenSSLCipherConfigurationParser {
563
567
this ->add (aliases, ciphers, element);
564
568
} else if (element.find (AND) != std::string::npos) {
565
569
auto intersections = this ->split (element, " +\\ " );
566
- if (intersections.size () > 0 && aliases.find (intersections[0 ]) != aliases.end ()) {
567
- auto result{aliases[intersections[0 ]]};
568
- for (int i = 1 ; i < intersections.size (); i++) {
569
- auto alias = aliases.find (intersections[i]);
570
- if (alias != aliases.end ()) {
571
- // make `result` only contain the aliases from `alias`
572
- result.erase (std::remove_if (result.begin (), result.end (),
573
- [&](auto x) {
574
- return std::find (alias->second .begin (),
575
- alias->second .end (),
576
- x) != alias->second .end ();
577
- }),
578
- result.end ());
570
+ if (intersections.size () > 0 ) {
571
+ auto found = aliases.find (intersections[0 ]);
572
+ if (found != aliases.end ()) {
573
+ auto result{found.operator ->()->second };
574
+ for (int i = 1 ; i < intersections.size (); i++) {
575
+ auto alias = aliases.find (intersections[i]);
576
+ if (alias != aliases.end ()) {
577
+ // make `result` only contain the aliases from `alias`
578
+ result.erase (std::remove_if (result.begin (), result.end (),
579
+ [&](auto x) {
580
+ return std::find (alias->second .begin (),
581
+ alias->second .end (),
582
+ x) != alias->second .end ();
583
+ }),
584
+ result.end ());
585
+ }
579
586
}
587
+ // Add all of `result` onto `ciphers`
588
+ ciphers.insert (ciphers.end (), result.begin (), result.end ());
580
589
}
581
- // Add all of `result` onto `ciphers`
582
- ciphers.insert (ciphers.end (), result.begin (), result.end ());
583
590
}
584
591
}
585
592
}
0 commit comments