NOTE: The secret_map_mutex should not be held by the caller of this function. The implementation of this function may call a plugin's TS_EVENT_SSL_SECRET handler which in turn may grab a lock for secret_map_mutex via a TSSslSecretSet call. These events will result in a deadlock.
| 56 | // secret_map_mutex via a TSSslSecretSet call. These events will result in a |
| 57 | // deadlock. |
| 58 | void |
| 59 | SSLSecret::loadSecret(const std::string &name1, const std::string &name2, std::string &data1, std::string &data2) |
| 60 | { |
| 61 | // Call the load secret hooks |
| 62 | // |
| 63 | class APIHook *curHook = g_lifecycle_hooks->get(TS_LIFECYCLE_SSL_SECRET_HOOK); |
| 64 | TSSecretID secret_name; |
| 65 | secret_name.cert_name = name1.data(); |
| 66 | secret_name.cert_name_len = name1.size(); |
| 67 | secret_name.key_name = name2.data(); |
| 68 | secret_name.key_name_len = name2.size(); |
| 69 | while (curHook) { |
| 70 | curHook->blocking_invoke(TS_EVENT_SSL_SECRET, &secret_name); |
| 71 | curHook = curHook->next(); |
| 72 | } |
| 73 | |
| 74 | data1 = this->getSecret(name1); |
| 75 | data2 = name2.empty() ? std::string{} : this->getSecret(name2); |
| 76 | if (data1.empty() || (!name2.empty() && data2.empty())) { |
| 77 | // If none of them loaded it, assume it is a file |
| 78 | data1 = loadFile(name1); |
| 79 | setSecret(name1, data1); |
| 80 | if (!name2.empty()) { |
| 81 | data2 = loadFile(name2); |
| 82 | setSecret(name2, data2); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | std::string |
| 88 | SSLSecret::loadFile(const std::string &name) |
no test coverage detected