| 537 | } |
| 538 | |
| 539 | TLSPolicy::Rule::Rule(std::string input) { |
| 540 | int s = 0; |
| 541 | |
| 542 | while (s < input.size()) { |
| 543 | int eq = input.find('=', s); |
| 544 | |
| 545 | if (eq == input.npos) |
| 546 | throw std::runtime_error("parse_verify"); |
| 547 | |
| 548 | MatchType mt = MatchType::EXACT; |
| 549 | if (input[eq - 1] == '>') |
| 550 | mt = MatchType::PREFIX; |
| 551 | if (input[eq - 1] == '<') |
| 552 | mt = MatchType::SUFFIX; |
| 553 | std::string term = input.substr(s, eq - s - (mt == MatchType::EXACT ? 0 : 1)); |
| 554 | |
| 555 | if (term.find("Check.") == 0) { |
| 556 | if (eq + 2 > input.size()) |
| 557 | throw std::runtime_error("parse_verify"); |
| 558 | if (eq + 2 != input.size() && input[eq + 2] != ',') |
| 559 | throw std::runtime_error("parse_verify"); |
| 560 | if (mt != MatchType::EXACT) |
| 561 | throw std::runtime_error("parse_verify: cannot prefix match Check"); |
| 562 | |
| 563 | bool* flag; |
| 564 | |
| 565 | if (term == "Check.Valid") |
| 566 | flag = &verify_cert; |
| 567 | else if (term == "Check.Unexpired") |
| 568 | flag = &verify_time; |
| 569 | else |
| 570 | throw std::runtime_error("parse_verify"); |
| 571 | |
| 572 | if (input[eq + 1] == '0') |
| 573 | *flag = false; |
| 574 | else if (input[eq + 1] == '1') |
| 575 | *flag = true; |
| 576 | else |
| 577 | throw std::runtime_error("parse_verify"); |
| 578 | |
| 579 | s = eq + 3; |
| 580 | } else { |
| 581 | std::map<int, Criteria>* criteria = &subject_criteria; |
| 582 | |
| 583 | if (term.find('.') != term.npos) { |
| 584 | auto scoped = splitPair(term, '.'); |
| 585 | |
| 586 | if (scoped.first == "S" || scoped.first == "Subject") |
| 587 | criteria = &subject_criteria; |
| 588 | else if (scoped.first == "I" || scoped.first == "Issuer") |
| 589 | criteria = &issuer_criteria; |
| 590 | else if (scoped.first == "R" || scoped.first == "Root") |
| 591 | criteria = &root_criteria; |
| 592 | else |
| 593 | throw std::runtime_error("parse_verify"); |
| 594 | |
| 595 | term = scoped.second; |
| 596 | } |
nothing calls this directly
no test coverage detected