| 199 | } |
| 200 | |
| 201 | std::string configureWireGuard(const std::string &pars) |
| 202 | { |
| 203 | std::string clientPrivateKey, clientIpAddress, clientDnsAddressList, peerPublicKey, |
| 204 | peerPresharedKey, peerEndpoint, allowedIps; |
| 205 | uint16_t listenPort; |
| 206 | CmdDnsManager dnsManager; |
| 207 | AmneziawgConfig amneziawgConfig; |
| 208 | deserializePars(pars, clientPrivateKey, clientIpAddress, clientDnsAddressList, peerPublicKey, |
| 209 | peerPresharedKey, peerEndpoint, allowedIps, listenPort, dnsManager, amneziawgConfig); |
| 210 | |
| 211 | bool success = false; |
| 212 | if (WireGuardController::instance().isInitialized()) { |
| 213 | do { |
| 214 | std::vector<std::string> allowed_ips_vector = WireGuardController::instance().splitAndDeduplicateAllowedIps(allowedIps); |
| 215 | if (allowed_ips_vector.size() < 1) { |
| 216 | spdlog::error("WireGuard: invalid AllowedIps \"{}\"", allowedIps); |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | if (!Validation::validateWireGuardConfig(clientIpAddress, clientDnsAddressList, allowed_ips_vector, peerEndpoint)) { |
| 221 | spdlog::error("WireGuard: IP validation failed, rejecting config"); |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if (!WireGuardController::instance().configureAdapter(clientIpAddress, |
| 226 | clientDnsAddressList, |
| 227 | MacUtils::resourcePath() + "/dns.sh", |
| 228 | allowed_ips_vector)) { |
| 229 | spdlog::error("WireGuard: configureAdapter() failed"); |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | if (!WireGuardController::instance().configureDefaultRouteMonitor(peerEndpoint)) { |
| 234 | spdlog::error("WireGuard: configureDefaultRouteMonitor() failed"); |
| 235 | break; |
| 236 | } |
| 237 | if (!WireGuardController::instance().configure(clientPrivateKey, |
| 238 | peerPublicKey, peerPresharedKey, |
| 239 | peerEndpoint, allowed_ips_vector, |
| 240 | listenPort, amneziawgConfig)) { |
| 241 | spdlog::error("WireGuard: configureDaemon() failed"); |
| 242 | break; |
| 243 | } |
| 244 | success = true; |
| 245 | } while (0); |
| 246 | } |
| 247 | return serializeResult(success); |
| 248 | } |
| 249 | |
| 250 | std::string getWireGuardStatus(const std::string &pars) |
| 251 | { |
nothing calls this directly
no test coverage detected