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"
45
46# Constants for VPN connection status
47VPN_STATE_DISCONNECTED = 0
48VPN_STATE_INITIALIZING = 1
49VPN_STATE_CONNECTING = 2
50VPN_STATE_CONNECTED = 3
51VPN_STATE_TIMEOUT = 4
52VPN_STATE_FAILED = 5
53# TODO gmoturu: determine the exact timeout value
54# This is a random value as of now
55VPN_TIMEOUT = 30
56
57# Connectiivty Manager constants
58TYPE_MOBILE = 0
59TYPE_WIFI = 1
60
61# Multipath preference constants
62MULTIPATH_PREFERENCE_NONE = 0
63MULTIPATH_PREFERENCE_HANDOVER = 1 << 0
64MULTIPATH_PREFERENCE_RELIABILITY = 1 << 1
65MULTIPATH_PREFERENCE_PERFORMANCE = 1 << 2
66
67# Private DNS constants
68DNS_GOOGLE = "dns.google"
69DNS_QUAD9 = "dns.quad9.net"
70DNS_CLOUDFLARE = "1dot1dot1dot1.cloudflare-dns.com"
71PRIVATE_DNS_MODE_OFF = "off"
72PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic"
73PRIVATE_DNS_MODE_STRICT = "hostname"
74
75# IpSec constants
76SOCK_STREAM = 1
77SOCK_DGRAM = 2
78AF_INET = 2
79AF_INET6 = 10
80DIRECTION_IN = 0
81DIRECTION_OUT = 1
82MODE_TRANSPORT = 0
83MODE_TUNNEL = 1
84CRYPT_NULL = "ecb(cipher_null)"
85CRYPT_AES_CBC = "cbc(aes)"
86AUTH_HMAC_MD5 = "hmac(md5)"
87AUTH_HMAC_SHA1 = "hmac(sha1)"
88AUTH_HMAC_SHA256 = "hmac(sha256)"
89AUTH_HMAC_SHA384 = "hmac(sha384)"
90AUTH_HMAC_SHA512 = "hmac(sha512)"
91AUTH_CRYPT_AES_GCM = "rfc4106(gcm(aes))"
92
93
94# Constants for VpnProfile
95class VpnProfile(object):
96    """ This class contains all the possible
97        parameters required for VPN connection
98    """
99    NAME = "name"
100    TYPE = "type"
101    SERVER = "server"
102    USER = "username"
103    PWD = "password"
104    DNS = "dnsServers"
105    SEARCH_DOMAINS = "searchDomains"
106    ROUTES = "routes"
107    MPPE = "mppe"
108    L2TP_SECRET = "l2tpSecret"
109    IPSEC_ID = "ipsecIdentifier"
110    IPSEC_SECRET = "ipsecSecret"
111    IPSEC_USER_CERT = "ipsecUserCert"
112    IPSEC_CA_CERT = "ipsecCaCert"
113    IPSEC_SERVER_CERT = "ipsecServerCert"
114
115
116# Enums for VPN profile types
117class VpnProfileType(enum.Enum):
118    """ Integer constant for each type of VPN
119    """
120    PPTP = 0
121    L2TP_IPSEC_PSK = 1
122    L2TP_IPSEC_RSA = 2
123    IPSEC_XAUTH_PSK = 3
124    IPSEC_XAUTH_RSA = 4
125    IPSEC_HYBRID_RSA = 5
126
127
128# Constants for config file
129class VpnReqParams(object):
130    """ Config file parameters required for
131        VPN connection
132    """
133    vpn_server_addresses = "vpn_server_addresses"
134    vpn_verify_addresses = "vpn_verify_addresses"
135    vpn_username = "vpn_username"
136    vpn_password = "vpn_password"
137    psk_secret = "psk_secret"
138    client_pkcs_file_name = "client_pkcs_file_name"
139    cert_path_vpnserver = "cert_path_vpnserver"
140    cert_password = "cert_password"
141    pptp_mppe = "pptp_mppe"
142    ipsec_server_type = "ipsec_server_type"
143