• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2016 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import enum
18
19######################################################
20# ConnectivityManager.NetworkCallback events
21######################################################
22EVENT_NETWORK_CALLBACK = "NetworkCallback"
23
24# event types
25NETWORK_CB_PRE_CHECK = "PreCheck"
26NETWORK_CB_AVAILABLE = "Available"
27NETWORK_CB_LOSING = "Losing"
28NETWORK_CB_LOST = "Lost"
29NETWORK_CB_UNAVAILABLE = "Unavailable"
30NETWORK_CB_CAPABILITIES_CHANGED = "CapabilitiesChanged"
31NETWORK_CB_SUSPENDED = "Suspended"
32NETWORK_CB_RESUMED = "Resumed"
33NETWORK_CB_LINK_PROPERTIES_CHANGED = "LinkPropertiesChanged"
34NETWORK_CB_INVALID = "Invalid"
35
36# event data keys
37NETWORK_CB_KEY_ID = "id"
38NETWORK_CB_KEY_EVENT = "networkCallbackEvent"
39NETWORK_CB_KEY_MAX_MS_TO_LIVE = "maxMsToLive"
40NETWORK_CB_KEY_RSSI = "rssi"
41NETWORK_CB_KEY_INTERFACE_NAME = "interfaceName"
42NETWORK_CB_KEY_CREATE_TS = "creation_timestamp"
43NETWORK_CB_KEY_CURRENT_TS = "current_timestamp"
44NETWORK_CB_KEY_NETWORK_SPECIFIER = "network_specifier"
45NETWORK_CB_KEY_TRANSPORT_INFO = "transport_info"
46
47# Constants for VPN connection status
48VPN_STATE_DISCONNECTED = 0
49VPN_STATE_INITIALIZING = 1
50VPN_STATE_CONNECTING = 2
51VPN_STATE_CONNECTED = 3
52VPN_STATE_TIMEOUT = 4
53VPN_STATE_FAILED = 5
54# TODO gmoturu: determine the exact timeout value
55# This is a random value as of now
56VPN_TIMEOUT = 30
57
58# Connectiivty Manager constants
59TYPE_MOBILE = 0
60TYPE_WIFI = 1
61
62# Network request related constants.
63NETWORK_CAP_TRANSPORT_WIFI = TYPE_WIFI
64NETWORK_CAP_CAPABILITY_INTERNET = 12
65
66# Network request related keys.
67NETWORK_CAP_TRANSPORT_TYPE_KEY = "TransportType"
68NETWORK_CAP_CAPABILITY_KEY = "Capability"
69
70# Multipath preference constants
71MULTIPATH_PREFERENCE_NONE = 0
72MULTIPATH_PREFERENCE_HANDOVER = 1 << 0
73MULTIPATH_PREFERENCE_RELIABILITY = 1 << 1
74MULTIPATH_PREFERENCE_PERFORMANCE = 1 << 2
75
76# Private DNS constants
77DNS_GOOGLE_HOSTNAME = "dns.google"
78DNS_QUAD9_HOSTNAME = "dns.quad9.net"
79DNS_CLOUDFLARE_HOSTNAME = "1dot1dot1dot1.cloudflare-dns.com"
80DOH_CLOUDFLARE_HOSTNAME = "cloudflare-dns.com"
81PRIVATE_DNS_MODE_OFF = "off"
82PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic"
83PRIVATE_DNS_MODE_STRICT = "hostname"
84
85DNS_SUPPORT_TYPE = {
86    DNS_GOOGLE_HOSTNAME: ["Do53", "DoT", "DoH"],
87    DNS_CLOUDFLARE_HOSTNAME: ["Do53","DoT"],
88    DOH_CLOUDFLARE_HOSTNAME: ["DoH"]
89}
90
91DNS_GOOGLE_ADDR_V4 = ["8.8.4.4", "8.8.8.8"]
92DNS_GOOGLE_ADDR_V6 = ["2001:4860:4860::8888",
93                      "2001:4860:4860::8844"]
94DNS_CLOUDFLARE_ADDR_V4 = ["1.1.1.1", "1.0.0.1"]
95DOH_CLOUDFLARE_ADDR_V4 = ["104.16.248.249", "104.16.249.249"]
96DOH_CLOUDFLARE_ADDR_V6 = ["2606:4700::6810:f8f9",
97                          "2606:4700::6810:f9f9"]
98
99
100# IpSec constants
101SOCK_STREAM = 1
102SOCK_DGRAM = 2
103AF_INET = 2
104AF_INET6 = 10
105DIRECTION_IN = 0
106DIRECTION_OUT = 1
107MODE_TRANSPORT = 0
108MODE_TUNNEL = 1
109CRYPT_NULL = "ecb(cipher_null)"
110CRYPT_AES_CBC = "cbc(aes)"
111AUTH_HMAC_MD5 = "hmac(md5)"
112AUTH_HMAC_SHA1 = "hmac(sha1)"
113AUTH_HMAC_SHA256 = "hmac(sha256)"
114AUTH_HMAC_SHA384 = "hmac(sha384)"
115AUTH_HMAC_SHA512 = "hmac(sha512)"
116AUTH_CRYPT_AES_GCM = "rfc4106(gcm(aes))"
117
118
119# Constants for VpnProfile
120class VpnProfile(object):
121    """ This class contains all the possible
122        parameters required for VPN connection
123    """
124    NAME = "name"
125    TYPE = "type"
126    SERVER = "server"
127    USER = "username"
128    PWD = "password"
129    DNS = "dnsServers"
130    SEARCH_DOMAINS = "searchDomains"
131    ROUTES = "routes"
132    MPPE = "mppe"
133    L2TP_SECRET = "l2tpSecret"
134    IPSEC_ID = "ipsecIdentifier"
135    IPSEC_SECRET = "ipsecSecret"
136    IPSEC_USER_CERT = "ipsecUserCert"
137    IPSEC_CA_CERT = "ipsecCaCert"
138    IPSEC_SERVER_CERT = "ipsecServerCert"
139
140
141# Enums for VPN profile types
142class VpnProfileType(enum.Enum):
143    """ Integer constant for each type of VPN
144    """
145    PPTP = 0
146    L2TP_IPSEC_PSK = 1
147    L2TP_IPSEC_RSA = 2
148    IPSEC_XAUTH_PSK = 3
149    IPSEC_XAUTH_RSA = 4
150    IPSEC_HYBRID_RSA = 5
151    IKEV2_IPSEC_USER_PASS = 6
152    IKEV2_IPSEC_PSK = 7
153    IKEV2_IPSEC_RSA = 8
154
155
156# Constants for config file
157class VpnReqParams(object):
158    """ Config file parameters required for
159        VPN connection
160    """
161    vpn_server_addresses = "vpn_server_addresses"
162    vpn_verify_addresses = "vpn_verify_addresses"
163    vpn_username = "vpn_username"
164    vpn_password = "vpn_password"
165    psk_secret = "psk_secret"
166    client_pkcs_file_name = "client_pkcs_file_name"
167    cert_path_vpnserver = "cert_path_vpnserver"
168    cert_password = "cert_password"
169    pptp_mppe = "pptp_mppe"
170    ipsec_server_type = "ipsec_server_type"
171    wifi_network = "wifi_network"
172    vpn_identity = "vpn_identity"
173    vpn_server_hostname = "vpn_server_hostname"
174