| 44 | } |
| 45 | |
| 46 | X509Credential::X509Credential(const std::vector<bytes>& der_chain_in) |
| 47 | : der_chain(bytes_to_x509_credential_data(der_chain_in)) |
| 48 | { |
| 49 | if (der_chain.empty()) { |
| 50 | throw std::invalid_argument("empty certificate chain"); |
| 51 | } |
| 52 | |
| 53 | // Parse the chain |
| 54 | auto parsed = std::vector<Certificate>(); |
| 55 | for (const auto& cert : der_chain) { |
| 56 | parsed.emplace_back(cert.data); |
| 57 | } |
| 58 | |
| 59 | // first element represents leaf cert |
| 60 | const auto& sig = find_signature(parsed[0].public_key_algorithm()); |
| 61 | const auto pub_data = sig.serialize(*parsed[0].public_key); |
| 62 | _signature_scheme = tls_signature_scheme(parsed[0].public_key_algorithm()); |
| 63 | _public_key = SignaturePublicKey{ pub_data }; |
| 64 | |
| 65 | // verify chain for valid signatures |
| 66 | for (size_t i = 0; i < der_chain.size() - 1; i++) { |
| 67 | if (!parsed[i].valid_from(parsed[i + 1])) { |
| 68 | throw std::runtime_error("Certificate Chain validation failure"); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | SignatureScheme |
| 74 | X509Credential::signature_scheme() const |
nothing calls this directly
no test coverage detected