| 2068 | } |
| 2069 | |
| 2070 | int Server::RemoveCertificate(const CertInfo& cert) { |
| 2071 | if (!_options.has_ssl_options()) { |
| 2072 | LOG(ERROR) << "ServerOptions.ssl_options is not configured yet"; |
| 2073 | return -1; |
| 2074 | } |
| 2075 | std::string cert_key(cert.certificate); |
| 2076 | cert_key.append(cert.private_key); |
| 2077 | SSLContext* ssl_ctx = _ssl_ctx_map.seek(cert_key); |
| 2078 | if (ssl_ctx == NULL) { |
| 2079 | LOG(WARNING) << cert << " doesn't exist"; |
| 2080 | return 0; |
| 2081 | } |
| 2082 | if (ssl_ctx->ctx == _default_ssl_ctx) { |
| 2083 | LOG(WARNING) << "Cannot remove: " << cert |
| 2084 | << " since it's the default certificate"; |
| 2085 | return -1; |
| 2086 | } |
| 2087 | |
| 2088 | if (!_reload_cert_maps.Modify(RemoveCertMapping, *ssl_ctx)) { |
| 2089 | LOG(ERROR) << "Fail to remove mappings from _reload_cert_maps"; |
| 2090 | return -1; |
| 2091 | } |
| 2092 | |
| 2093 | _ssl_ctx_map.erase(cert_key); |
| 2094 | return 0; |
| 2095 | } |
| 2096 | |
| 2097 | bool Server::RemoveCertMapping(CertMaps& bg, const SSLContext& ssl_ctx) { |
| 2098 | for (size_t i = 0; i < ssl_ctx.filters.size(); ++i) { |