Home | History | Annotate | Download | only in net
      1 #!/usr/bin/env python3.4
      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 
     17 import enum
     18 
     19 ######################################################
     20 # ConnectivityManager.NetworkCallback events
     21 ######################################################
     22 EVENT_NETWORK_CALLBACK = "NetworkCallback"
     23 
     24 # event types
     25 NETWORK_CB_PRE_CHECK = "PreCheck"
     26 NETWORK_CB_AVAILABLE = "Available"
     27 NETWORK_CB_LOSING = "Losing"
     28 NETWORK_CB_LOST = "Lost"
     29 NETWORK_CB_UNAVAILABLE = "Unavailable"
     30 NETWORK_CB_CAPABILITIES_CHANGED = "CapabilitiesChanged"
     31 NETWORK_CB_SUSPENDED = "Suspended"
     32 NETWORK_CB_RESUMED = "Resumed"
     33 NETWORK_CB_LINK_PROPERTIES_CHANGED = "LinkPropertiesChanged"
     34 NETWORK_CB_INVALID = "Invalid"
     35 
     36 # event data keys
     37 NETWORK_CB_KEY_ID = "id"
     38 NETWORK_CB_KEY_EVENT = "networkCallbackEvent"
     39 NETWORK_CB_KEY_MAX_MS_TO_LIVE = "maxMsToLive"
     40 NETWORK_CB_KEY_RSSI = "rssi"
     41 NETWORK_CB_KEY_INTERFACE_NAME = "interfaceName"
     42 NETWORK_CB_KEY_CREATE_TS = "creation_timestamp"
     43 NETWORK_CB_KEY_CURRENT_TS = "current_timestamp"
     44 
     45 # Constants for VPN connection status
     46 VPN_STATE_DISCONNECTED = 0
     47 VPN_STATE_INITIALIZING = 1
     48 VPN_STATE_CONNECTING = 2
     49 VPN_STATE_CONNECTED = 3
     50 VPN_STATE_TIMEOUT = 4
     51 VPN_STATE_FAILED = 5
     52 # TODO gmoturu: determine the exact timeout value
     53 # This is a random value as of now
     54 VPN_TIMEOUT = 15
     55 
     56 # Connectiivty Manager constants
     57 TYPE_MOBILE = 0
     58 TYPE_WIFI = 1
     59 
     60 # Multipath preference constants
     61 MULTIPATH_PREFERENCE_NONE = 0
     62 MULTIPATH_PREFERENCE_HANDOVER = 1 << 0
     63 MULTIPATH_PREFERENCE_RELIABILITY = 1 << 1
     64 MULTIPATH_PREFERENCE_PERFORMANCE = 1 << 2
     65 
     66 # IpSec constants
     67 SOCK_STREAM = 1
     68 SOCK_DGRAM = 2
     69 AF_INET = 2
     70 AF_INET6 = 10
     71 DIRECTION_IN = 0
     72 DIRECTION_OUT = 1
     73 MODE_TRANSPORT = 0
     74 MODE_TUNNEL = 1
     75 CRYPT_NULL = "ecb(cipher_null)"
     76 CRYPT_AES_CBC = "cbc(aes)"
     77 AUTH_HMAC_MD5 = "hmac(md5)"
     78 AUTH_HMAC_SHA1 = "hmac(sha1)"
     79 AUTH_HMAC_SHA256 = "hmac(sha256)"
     80 AUTH_HMAC_SHA384 = "hmac(sha384)"
     81 AUTH_HMAC_SHA512 = "hmac(sha512)"
     82 AUTH_CRYPT_AES_GCM = "rfc4106(gcm(aes))"
     83 
     84 # Constants for VpnProfile
     85 class VpnProfile(object):
     86     """ This class contains all the possible
     87         parameters required for VPN connection
     88     """
     89     NAME = "name"
     90     TYPE = "type"
     91     SERVER = "server"
     92     USER = "username"
     93     PWD = "password"
     94     DNS = "dnsServers"
     95     SEARCH_DOMAINS = "searchDomains"
     96     ROUTES = "routes"
     97     MPPE = "mppe"
     98     L2TP_SECRET = "l2tpSecret"
     99     IPSEC_ID = "ipsecIdentifier"
    100     IPSEC_SECRET = "ipsecSecret"
    101     IPSEC_USER_CERT = "ipsecUserCert"
    102     IPSEC_CA_CERT = "ipsecCaCert"
    103     IPSEC_SERVER_CERT = "ipsecServerCert"
    104 
    105 # Enums for VPN profile types
    106 class VpnProfileType(enum.Enum):
    107     """ Integer constant for each type of VPN
    108     """
    109     PPTP = 0
    110     L2TP_IPSEC_PSK = 1
    111     L2TP_IPSEC_RSA = 2
    112     IPSEC_XAUTH_PSK = 3
    113     IPSEC_XAUTH_RSA = 4
    114     IPSEC_HYBRID_RSA = 5
    115 
    116 # Constants for config file
    117 class VpnReqParams(object):
    118     """ Config file parameters required for
    119         VPN connection
    120     """
    121     wifi_network = "wifi_network"
    122     vpn_server_addresses = "vpn_server_addresses"
    123     vpn_verify_address = "vpn_verify_address"
    124     vpn_username = "vpn_username"
    125     vpn_password = "vpn_password"
    126     psk_secret = "psk_secret"
    127     client_pkcs_file_name = "client_pkcs_file_name"
    128     cert_path_vpnserver = "cert_path_vpnserver"
    129     cert_password = "cert_password"
    130     pptp_mppe = "pptp_mppe"
    131     ipsec_server_type = "ipsec_server_type"
    132