| 205 | } |
| 206 | |
| 207 | std::string configureWireGuard(const std::string &pars) |
| 208 | { |
| 209 | std::string clientPrivateKey, clientIpAddress, clientDnsAddressList, peerPublicKey, |
| 210 | peerPresharedKey, peerEndpoint, allowedIps; |
| 211 | uint16_t listenPort; |
| 212 | CmdDnsManager dnsManager; |
| 213 | AmneziawgConfig amneziawgConfig; |
| 214 | deserializePars(pars, clientPrivateKey, clientIpAddress, clientDnsAddressList, peerPublicKey, |
| 215 | peerPresharedKey, peerEndpoint, allowedIps, listenPort, dnsManager, amneziawgConfig); |
| 216 | |
| 217 | bool success = false; |
| 218 | if (WireGuardController::instance().isInitialized()) { |
| 219 | do { |
| 220 | std::vector<std::string> allowed_ips_vector = WireGuardController::instance().splitAndDeduplicateAllowedIps(allowedIps); |
| 221 | if (allowed_ips_vector.size() < 1) { |
| 222 | spdlog::error("WireGuard: invalid AllowedIps \"{}\"", allowedIps); |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | if (!Validation::validateWireGuardConfig(clientIpAddress, clientDnsAddressList, allowed_ips_vector, peerEndpoint)) { |
| 227 | spdlog::error("WireGuard: IP validation failed, rejecting config"); |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | uint32_t fwmark = WireGuardController::instance().getFwmark(); |
| 232 | spdlog::info("Fwmark = {}", fwmark); |
| 233 | |
| 234 | if (!WireGuardController::instance().configure(clientPrivateKey, |
| 235 | peerPublicKey, peerPresharedKey, |
| 236 | peerEndpoint, allowed_ips_vector, |
| 237 | fwmark, listenPort, amneziawgConfig)) { |
| 238 | spdlog::error("WireGuard: configure() failed"); |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | if (!WireGuardController::instance().configureDefaultRouteMonitor(peerEndpoint)) { |
| 243 | spdlog::error("WireGuard: configureDefaultRouteMonitor() failed"); |
| 244 | break; |
| 245 | } |
| 246 | std::string script = Utils::getDnsScript(dnsManager); |
| 247 | if (script.empty()) { |
| 248 | spdlog::error("WireGuard: could not find appropriate dns manager script"); |
| 249 | break; |
| 250 | } |
| 251 | if (!WireGuardController::instance().configureAdapter(clientIpAddress, |
| 252 | clientDnsAddressList, |
| 253 | script, |
| 254 | allowed_ips_vector, fwmark)) { |
| 255 | spdlog::error("WireGuard: configureAdapter() failed"); |
| 256 | break; |
| 257 | } |
| 258 | success = true; |
| 259 | } while (0); |
| 260 | } |
| 261 | return serializeResult(success); |
| 262 | } |
| 263 | |
| 264 | std::string getWireGuardStatus(const std::string &pars) |
nothing calls this directly
no test coverage detected