Created
August 3, 2018 10:46
-
-
Save naz013/074022388efe48e174bca7c2b73139ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getCustomConfigFile(Context context) { | |
boolean isDebug = BuildConfig.DEBUG && PrefUtils.getBoolean(context, PrefUtils.USE_CUSTOM, false); | |
File cacheDir = context.getCacheDir(); | |
String cfg = ""; | |
// Enable management interface | |
cfg += "# Enables connection to GUI\n"; | |
cfg += "management "; | |
cfg += cacheDir.getAbsolutePath() + "/" + "mgmtsocket"; | |
cfg += " unix\n"; | |
cfg += "management-client\n"; | |
cfg += "management-query-passwords\n"; | |
cfg += "management-hold\n"; | |
cfg += "machine-readable-output\n"; | |
// Users are confused by warnings that are misleading... | |
cfg += "ifconfig-nowarn\n\n"; | |
// set dev | |
cfg += "# Network Driver Section\n"; | |
if (isDebug) cfg += "dev " + PrefUtils.getString(context, PrefUtils.DEV, "tun") + "\n\n"; | |
else cfg += "dev " + mDriver + "\n\n"; | |
// set remote section | |
cfg += "# Remote Section\n"; | |
if (isDebug) { | |
cfg += "remote " + PrefUtils.getString(context, PrefUtils.REMOTE_IP, "127.0.0.1") | |
+ " " + PrefUtils.getString(context, PrefUtils.REMOTE_PORT, "4987"); | |
} else { | |
cfg += "remote " + mServerName + " " + mServerPort; | |
} | |
if (mUseUdp) { | |
cfg += " udp\n\n"; | |
} else { | |
cfg += " tcp\n\n"; | |
} | |
// set base section | |
cfg += "# Base Section\n"; | |
cfg += "client\n"; | |
if (isDebug) { | |
cfg += "resolv-retry " + PrefUtils.getString(context, PrefUtils.RESOLVE_RETRY, "infinite") + "\n"; | |
if (PrefUtils.getBoolean(context, PrefUtils.TLS_EXIT, true)) { | |
cfg += "tls-exit\n"; | |
} | |
if (PrefUtils.getBoolean(context, PrefUtils.NOBIND, true)) { | |
cfg += "nobind\n"; | |
} | |
if (PrefUtils.getBoolean(context, PrefUtils.PERSIST_KEY, true)) { | |
cfg += "persist-key\n"; | |
} | |
} else { | |
cfg += "resolv-retry infinite\n"; | |
cfg += "tls-exit\n"; | |
cfg += "nobind\n"; | |
cfg += "persist-key\n"; | |
} | |
cfg += "ns-cert-type server\n"; | |
cfg += "comp-lzo\n"; | |
cfg += "verb 103\n"; | |
cfg += "reneg-sec 0\n"; | |
cfg += "mssfix 1400\n"; | |
if (isDebug) { | |
cfg += "route-delay " + PrefUtils.getString(context, PrefUtils.ROUTE_DELAY, "2") + "\n"; | |
if (PrefUtils.getBoolean(context, PrefUtils.REDIRECT_GATEWAY, true)) { | |
cfg += "redirect-gateway\n"; | |
} | |
} else { | |
cfg += "route-delay 2\n"; | |
cfg += "redirect-gateway\n"; | |
} | |
if (PrefUtils.isFreeVersion(context)) { | |
cfg += "auth-user-pass " + context.getFilesDir() + "/" + ApplicationConstants.VPN_AUTH_FILE + "\n"; | |
} else { | |
cfg += "auth-user-pass\n\n"; | |
} | |
// set route if use ssh | |
if (mUseCustomConfig) { | |
cfg += "# Routing\n"; | |
cfg += mCustomConfigOptions; | |
cfg += "\n\n"; | |
} | |
// set encryption section | |
cfg += "# Encryption Section\n"; | |
if (mUseStrongSecurity) { | |
cfg += "auth SHA256\n"; | |
cfg += "cipher AES-256-CBC\n"; | |
cfg += "keysize 256\n"; | |
cfg += "keysize 256\n"; | |
cfg += "tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA\n\n"; | |
} else { | |
cfg += "# Empty\n\n"; | |
} | |
cfg += "# Explicit exit notify option\n"; | |
if (mUseUdp) { | |
cfg += "explicit-exit-notify 10\n\n"; | |
} else { | |
cfg += "# Empty\n\n"; | |
} | |
// set server certificate <ca> | |
cfg += "# Server certificate\n"; | |
cfg += "<ca>\n"; | |
cfg += mCaFilename + "\n"; | |
cfg += "</ca>"; | |
// need to use for smoke test server | |
// if (PrefUtils.isUseSmoke(context)) { | |
// cfg += "cipher AES-256-CBC\n"; | |
// cfg += "fast-io\n"; | |
// cfg += "script-security 2\n"; | |
// cfg += "ping 5\n"; | |
// cfg += "ping-exit 120\n"; | |
// } | |
Log.i("VPNProfile CONFIG", cfg); | |
return cfg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment