Files
amnezia-client/client/protocols/protocols_defs.h
T

233 lines
6.5 KiB
C++
Raw Normal View History

2021-04-04 23:12:36 +03:00
#ifndef PROTOCOLS_DEFS_H
#define PROTOCOLS_DEFS_H
#include <QObject>
2021-05-10 02:33:31 +03:00
#include <QDebug>
2021-09-16 19:49:50 +03:00
#include <QQmlEngine>
2021-04-04 23:12:36 +03:00
namespace amnezia {
2021-04-26 22:54:31 +03:00
namespace config_key {
// Json config strings
2021-05-07 23:28:37 +03:00
constexpr char hostName[] = "hostName";
constexpr char userName[] = "userName";
constexpr char password[] = "password";
constexpr char port[] = "port";
constexpr char local_port[] = "local_port";
2022-02-01 19:48:59 +03:00
constexpr char dns1[] = "dns1";
constexpr char dns2[] = "dns2";
2021-05-07 23:28:37 +03:00
constexpr char description[] = "description";
2021-10-04 19:07:49 +03:00
constexpr char cert[] = "cert";
2021-10-05 12:22:13 +03:00
constexpr char config[] = "config";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char containers[] = "containers";
constexpr char container[] = "container";
constexpr char defaultContainer[] = "defaultContainer";
2021-04-26 22:54:31 +03:00
constexpr char vpnproto[] = "protocol";
2021-05-07 23:28:37 +03:00
constexpr char protocols[] = "protocols";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char remote[] = "remote";
constexpr char transport_proto[] = "transport_proto";
constexpr char cipher[] = "cipher";
constexpr char hash[] = "hash";
constexpr char ncp_disable[] = "ncp_disable";
2021-05-18 15:50:52 +03:00
constexpr char tls_auth[] = "tls_auth";
2021-04-26 22:54:31 +03:00
2021-10-20 18:43:51 +03:00
constexpr char client_priv_key[] = "client_priv_key";
constexpr char client_pub_key[] = "client_pub_key";
constexpr char server_priv_key[] = "server_priv_key";
constexpr char server_pub_key[] = "server_pub_key";
constexpr char psk_key[] = "psk_key";
2021-12-25 21:14:55 +03:00
constexpr char client_ip[] = "client_ip"; // internal ip address
2021-10-20 18:43:51 +03:00
2021-05-07 23:28:37 +03:00
constexpr char site[] = "site";
constexpr char block_outside_dns[] = "block_outside_dns";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char subnet_address[] = "subnet_address";
constexpr char subnet_mask[] = "subnet_mask";
2021-06-12 11:59:36 +03:00
constexpr char subnet_cidr[] = "subnet_cidr";
2021-04-26 22:54:31 +03:00
constexpr char additional_client_config[] = "additional_client_config";
constexpr char additional_server_config[] = "additional_server_config";
2021-05-07 23:28:37 +03:00
// proto config keys
constexpr char last_config[] = "last_config";
2022-11-01 23:24:58 +03:00
constexpr char isThirdPartyConfig[] = "isThirdPartyConfig";
2022-11-01 23:24:58 +03:00
constexpr char openvpn[] = "openvpn";
2022-11-03 23:39:58 +03:00
constexpr char wireguard[] = "wireguard";
2022-11-01 23:24:58 +03:00
2021-04-26 22:54:31 +03:00
}
2021-04-04 23:12:36 +03:00
namespace protocols {
2022-02-01 19:48:59 +03:00
namespace dns {
constexpr char amneziaDnsIp[] = "172.29.172.254";
}
2021-06-12 11:59:36 +03:00
2021-04-26 22:54:31 +03:00
namespace openvpn {
2021-06-12 11:59:36 +03:00
constexpr char defaultSubnetAddress[] = "10.8.0.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
2023-01-15 17:32:11 +03:00
constexpr char serverConfigPath[] = "/opt/amnezia/openvpn/server.conf";
2021-05-07 23:28:37 +03:00
constexpr char caCertPath[] = "/opt/amnezia/openvpn/pki/ca.crt";
constexpr char clientCertPath[] = "/opt/amnezia/openvpn/pki/issued";
constexpr char taKeyPath[] = "/opt/amnezia/openvpn/ta.key";
constexpr char clientsDirPath[] = "/opt/amnezia/openvpn/clients";
constexpr char defaultPort[] = "1194";
2021-05-10 05:25:20 -07:00
constexpr char defaultTransportProto[] = "udp";
2021-05-07 23:28:37 +03:00
constexpr char defaultCipher[] = "AES-256-GCM";
constexpr char defaultHash[] = "SHA512";
constexpr bool defaultBlockOutsideDns = true;
constexpr bool defaultNcpDisable = false;
2021-05-18 15:50:52 +03:00
constexpr bool defaultTlsAuth = true;
2021-05-07 23:28:37 +03:00
constexpr char ncpDisableString[] = "ncp-disable";
2021-05-18 15:50:52 +03:00
constexpr char tlsAuthString[] = "tls-auth /opt/amnezia/openvpn/ta.key 0";
2021-05-07 23:28:37 +03:00
constexpr char defaultAdditionalClientConfig[] = "";
constexpr char defaultAdditionalServerConfig[] = "";
2021-04-04 23:12:36 +03:00
}
namespace shadowsocks {
2021-05-07 23:28:37 +03:00
constexpr char ssKeyPath[] = "/opt/amnezia/shadowsocks/shadowsocks.key";
constexpr char defaultPort[] = "6789";
constexpr char defaultLocalProxyPort[] = "8585";
constexpr char defaultCipher[] = "chacha20-ietf-poly1305";
2021-04-04 23:12:36 +03:00
}
namespace cloak {
2021-05-07 23:28:37 +03:00
constexpr char ckPublicKeyPath[] = "/opt/amnezia/cloak/cloak_public.key";
constexpr char ckBypassUidKeyPath[] = "/opt/amnezia/cloak/cloak_bypass_uid.key";
constexpr char ckAdminKeyPath[] = "/opt/amnezia/cloak/cloak_admin_uid.key";
constexpr char defaultPort[] = "443";
2021-06-19 16:38:35 +03:00
constexpr char defaultRedirSite[] = "tile.openstreetmap.org";
constexpr char defaultCipher[] = "chacha20-poly1305";
2021-05-10 02:33:31 +03:00
2021-04-04 23:12:36 +03:00
}
2021-06-12 11:59:36 +03:00
namespace wireguard {
constexpr char defaultSubnetAddress[] = "10.8.1.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
constexpr char defaultPort[] = "51820";
constexpr char serverConfigPath[] = "/opt/amnezia/wireguard/wg0.conf";
constexpr char serverPublicKeyPath[] = "/opt/amnezia/wireguard/wireguard_server_public_key.key";
constexpr char serverPskKeyPath[] = "/opt/amnezia/wireguard/wireguard_psk.key";
}
2021-04-04 23:12:36 +03:00
namespace sftp {
constexpr char defaultUserName[] = "sftp_user";
} // namespace sftp
2021-04-04 23:12:36 +03:00
} // namespace protocols
2021-05-07 23:28:37 +03:00
2021-09-16 19:49:50 +03:00
namespace ProtocolEnumNS {
2021-09-16 16:19:14 +03:00
Q_NAMESPACE
2021-09-20 21:51:28 +03:00
enum TransportProto {
Udp,
Tcp
};
Q_ENUM_NS(TransportProto)
enum Proto {
2021-09-20 21:51:28 +03:00
Any = 0,
2021-05-07 23:28:37 +03:00
OpenVpn,
ShadowSocks,
Cloak,
2021-09-20 21:51:28 +03:00
WireGuard,
2021-10-02 21:56:47 +03:00
Ikev2,
L2tp,
// non-vpn
TorWebSite,
2021-09-20 21:51:28 +03:00
Dns,
FileShare,
Sftp
2021-05-07 23:28:37 +03:00
};
Q_ENUM_NS(Proto)
2021-09-20 21:51:28 +03:00
enum ServiceType {
None = 0,
Vpn,
Other
};
Q_ENUM_NS(ServiceType)
2021-09-16 19:49:50 +03:00
} // namespace ProtocolEnumNS
using namespace ProtocolEnumNS;
2021-09-16 16:19:14 +03:00
2021-09-20 21:51:28 +03:00
class ProtocolProps : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE static QList<Proto> allProtocols();
2021-09-20 21:51:28 +03:00
// spelling may differ for various protocols - TCP for OpenVPN, tcp for others
Q_INVOKABLE static TransportProto transportProtoFromString(QString p);
Q_INVOKABLE static QString transportProtoToString(TransportProto proto, Proto p = Proto::Any);
2021-09-20 21:51:28 +03:00
Q_INVOKABLE static Proto protoFromString(QString p);
Q_INVOKABLE static QString protoToString(Proto p);
2021-09-20 21:51:28 +03:00
Q_INVOKABLE static QMap<Proto, QString> protocolHumanNames();
Q_INVOKABLE static QMap<Proto, QString> protocolDescriptions();
2021-05-07 23:28:37 +03:00
Q_INVOKABLE static ServiceType protocolService(Proto p);
2021-05-07 23:28:37 +03:00
Q_INVOKABLE static int defaultPort(Proto p);
Q_INVOKABLE static bool defaultPortChangeable(Proto p);
2021-09-20 21:51:28 +03:00
Q_INVOKABLE static TransportProto defaultTransportProto(Proto p);
Q_INVOKABLE static bool defaultTransportProtoChangeable(Proto p);
2021-09-20 21:51:28 +03:00
2021-10-04 21:13:07 +03:00
Q_INVOKABLE static QString key_proto_config_data(Proto p);
Q_INVOKABLE static QString key_proto_config_path(Proto p);
2021-10-04 21:13:07 +03:00
2021-09-20 21:51:28 +03:00
};
2021-05-07 23:28:37 +03:00
2021-09-16 16:19:14 +03:00
static void declareQmlProtocolEnum() {
qmlRegisterUncreatableMetaObject(
2021-09-16 19:49:50 +03:00
ProtocolEnumNS::staticMetaObject,
2021-09-16 16:19:14 +03:00
"ProtocolEnum",
1, 0,
"ProtocolEnum",
"Error: only enums"
);
2021-09-20 21:51:28 +03:00
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"TransportProto",
"Error: only enums"
);
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"ServiceType",
"Error: only enums"
);
2021-09-16 16:19:14 +03:00
}
2021-04-04 23:12:36 +03:00
} // namespace amnezia
QDebug operator<<(QDebug debug, const amnezia::Proto &p);
2021-05-10 02:33:31 +03:00
2021-04-04 23:12:36 +03:00
#endif // PROTOCOLS_DEFS_H