X509Credentials(const std::string& certstr, const std::string& keystr) : key(keystr) , certs(certstr) { // Verify that one of the certs match the private key bool found = false; for (mbedtls_x509_crt* cert = certs.get(); cert; cert = cert->next) { if (mbedtls_pk_check_pair(&cert->pk, key.get()) == 0) { found = true; break; } } if (!found) throw Exception("Public/private key pair does not match"); }
bool check_pair(const context& pub, const context& priv) { int ret = mbedtls_pk_check_pair(&pub.pk_, &priv.pk_); switch (ret) { case 0: return true; case MBEDTLS_ERR_PK_BAD_INPUT_DATA: case MBEDTLS_ERR_PK_TYPE_MISMATCH: throw exception{ret, __FUNCTION__}; break; default: return false; break; } }