de.blinkt.openvpn.VpnProfile Java Examples

The following examples show how to use de.blinkt.openvpn.VpnProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProfileManager.java    From SimpleOpenVpn-Android with Apache License 2.0 6 votes vote down vote up
private void loadVPNList(Context context) {
    profiles = new HashMap<>();
    SharedPreferences listpref = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
    Set<String> vlist = listpref.getStringSet("vpnlist", null);
    if (vlist == null) {
        vlist = new HashSet<>();
    }

    for (String vpnentry : vlist) {
        try {
            ObjectInputStream vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
            VpnProfile vp = ((VpnProfile) vpnfile.readObject());

            // Sanity check
            if (vp == null || vp.mName == null || vp.getUUID() == null)
                continue;

            vp.upgradeProfile();
            profiles.put(vp.getUUID().toString(), vp);

        } catch (IOException | ClassNotFoundException e) {
            VpnStatus.logException("Loading VPN List", e);
        }
    }
}
 
Example #2
Source File: ConfigParser.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
private String getOptionStrings(Vector<Vector<String>> option) {
    String custom = "";
    for (Vector<String> optionsline : option) {
        if (!ignoreThisOption(optionsline)) {
            // Check if option had been inlined and inline again
            if (optionsline.size() == 2 && "extra-certs".equals(optionsline.get(0)) ) {
                custom += VpnProfile.insertFileData(optionsline.get(0), optionsline.get(1));


            } else {
                for (String arg : optionsline)
                    custom += VpnProfile.openVpnEscape(arg) + " ";
                custom += "\n";
            }
        }
    }
    return custom;
}
 
Example #3
Source File: ConfigParser.java    From SimpleOpenVpn-Android with Apache License 2.0 6 votes vote down vote up
private String getOptionStrings(Vector<Vector<String>> option) {
    String custom = "";
    for (Vector<String> optionsline : option) {
        if (!ignoreThisOption(optionsline)) {
            // Check if option had been inlined and inline again
            if (optionsline.size() == 2 && "extra-certs".equals(optionsline.get(0)) ) {
                custom += VpnProfile.insertFileData(optionsline.get(0), optionsline.get(1));


            } else {
                for (String arg : optionsline)
                    custom += VpnProfile.openVpnEscape(arg) + " ";
                custom += "\n";
            }
        }
    }
    return custom;
}
 
Example #4
Source File: ConfigParser.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private void checkRedirectParameters(VpnProfile np, Vector<Vector<String>> defgw, boolean defaultRoute) {

        boolean noIpv4 = false;
        if (defaultRoute)

            for (Vector<String> redirect : defgw)
                for (int i = 1; i < redirect.size(); i++) {
                    if (redirect.get(i).equals("block-local"))
                        np.mAllowLocalLAN = false;
                    else if (redirect.get(i).equals("unblock-local"))
                        np.mAllowLocalLAN = true;
                    else if (redirect.get(i).equals("!ipv4"))
                        noIpv4 = true;
                    else if (redirect.get(i).equals("ipv6"))
                        np.mUseDefaultRoutev6 = true;
                }
        if (defaultRoute && !noIpv4)
            np.mUseDefaultRoute = true;
    }
 
Example #5
Source File: EipSetupObserver.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private void handleGatewaySetupObserverEvent(Intent event) {
    if (observedProfileFromVpnStatus != null || setupVpnProfile != null) {
        //finish last setup observation
        Log.d(TAG, "finish last gateway setup");
        finishGatewaySetup(true);
    }

    VpnProfile vpnProfile = (VpnProfile) event.getSerializableExtra(PROVIDER_PROFILE);
    if (vpnProfile == null) {
        Log.e(TAG, "Tried to setup non existing vpn profile.");
        return;
    }
    setupVpnProfile = vpnProfile;
    setupNClosestGateway.set(event.getIntExtra(Gateway.KEY_N_CLOSEST_GATEWAY, 0));
    Log.d(TAG, "bitmaskapp add state listener");
    VpnStatus.addStateListener(this);

    launchVPN(setupVpnProfile);
}
 
Example #6
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
private void checkinlinefile(Vector<String> args, BufferedReader br) throws IOException, ConfigParseError {
    String arg0 = args.get(0).trim();
    // CHeck for <foo>
    if (arg0.startsWith("<") && arg0.endsWith(">")) {
        String argname = arg0.substring(1, arg0.length() - 1);
        String inlinefile = VpnProfile.INLINE_TAG;
        String endtag = String.format("</%s>", argname);
        do {
            String line = br.readLine();
            if (line == null) {
                throw new ConfigParseError(String.format("No endtag </%s> for starttag <%s> found", argname, argname));
            }
            if (line.trim().equals(endtag)) break;
            else {
                inlinefile += line;
                inlinefile += "\n";
            }
        } while (true);
        if (inlinefile.endsWith("\n")) inlinefile = inlinefile.substring(0, inlinefile.length() - 1);
        args.clear();
        args.add(argname);
        args.add(inlinefile);
    }
}
 
Example #7
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
private String getOptionStrings(Vector<Vector<String>> option) {
    String custom = "";
    for (Vector<String> optionsline : option) {
        if (!ignoreThisOption(optionsline)) {
            // Check if option had been inlined and inline again
            if (optionsline.size() == 2 && ("extra-certs".equals(optionsline.get(0)) || "http-proxy-user-pass".equals(optionsline.get(0)))) {
                custom += VpnProfile.insertFileData(optionsline.get(0), optionsline.get(1));
            } else {
                for (String arg : optionsline)
                    custom += VpnProfile.openVpnEscape(arg) + " ";
                custom += "\n";
            }
        }
    }
    return custom;
}
 
Example #8
Source File: ConfigParser.java    From Cake-VPN with GNU General Public License v2.0 6 votes vote down vote up
private void checkinlinefile(Vector<String> args, BufferedReader br) throws IOException, ConfigParseError {
    String arg0 = args.get(0).trim();
    // CHeck for <foo>
    if (arg0.startsWith("<") && arg0.endsWith(">")) {
        String argname = arg0.substring(1, arg0.length() - 1);
        String inlinefile = VpnProfile.INLINE_TAG;
        String endtag = String.format("</%s>", argname);
        do {
            String line = br.readLine();
            if (line == null) {
                throw new ConfigParseError(String.format("No endtag </%s> for starttag <%s> found", argname, argname));
            }
            if (line.trim().equals(endtag)) break;
            else {
                inlinefile += line;
                inlinefile += "\n";
            }
        } while (true);
        if (inlinefile.endsWith("\n")) inlinefile = inlinefile.substring(0, inlinefile.length() - 1);
        args.clear();
        args.add(argname);
        args.add(inlinefile);
    }
}
 
Example #9
Source File: ProfileManager.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
private void loadVPNList(Context context) {
    profiles = new HashMap<>();
    SharedPreferences listpref = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
    Set<String> vlist = listpref.getStringSet("vpnlist", null);
    if (vlist == null) {
        vlist = new HashSet<>();
    }

    for (String vpnentry : vlist) {
        try {
            ObjectInputStream vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
            VpnProfile vp = ((VpnProfile) vpnfile.readObject());

            // Sanity check
            if (vp == null || vp.mName == null || vp.getUUID() == null)
                continue;

            vp.upgradeProfile();
            profiles.put(vp.getUUID().toString(), vp);

        } catch (IOException | ClassNotFoundException e) {
            VpnStatus.logException("Loading VPN List", e);
        }
    }
}
 
Example #10
Source File: ConfigParser.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private String getOptionStrings(Vector<Vector<String>> option) {
    String custom = "";
    for (Vector<String> optionsline : option) {
        if (!ignoreThisOption(optionsline)) {
            // Check if option had been inlined and inline again
            if (optionsline.size() == 2 &&
                    "extra-certs".equals(optionsline.get(0))) {
                custom += VpnProfile.insertFileData(optionsline.get(0), optionsline.get(1));
            } else {
                for (String arg : optionsline)
                    custom += VpnProfile.openVpnEscape(arg) + " ";
                custom += "\n";
            }
        }
    }
    return custom;
}
 
Example #11
Source File: VpnConfigGeneratorTest.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGenerateVpnProfile_v3_ovpn_tcp_udp() throws Exception {
    gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_tcp_udp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
    vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
    HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
    assertTrue(vpnProfiles.containsKey(OBFS4));
    assertTrue(vpnProfiles.containsKey(OPENVPN));
    System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
    assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_ovpn_tcp_udp.trim()));
}
 
Example #12
Source File: ProfileManager.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
private static VpnProfile get(String key) {
    if (tmpprofile != null && tmpprofile.getUUIDString().equals(key))
        return tmpprofile;

    if (instance == null)
        return null;
    return instance.profiles.get(key);

}
 
Example #13
Source File: ProfileManager.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the profile that is connected (to connect if the service restarts)
 */
public static void setConnectedVpnProfile(Context c, VpnProfile connectedProfile) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    Editor prefsedit = prefs.edit();
    prefsedit.putString(LAST_CONNECTED_PROFILE, connectedProfile.getUUIDString());
    prefsedit.apply();
    mLastConnectedVpn = connectedProfile;
}
 
Example #14
Source File: ExcludeAppsFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
PackageAdapter(Context c, VpnProfile vp) {
    mPm = c.getPackageManager();
    mProfile = vp;
    mInflater = LayoutInflater.from(c);

    mPackages = new Vector<>();
    mFilteredData = mPackages;
}
 
Example #15
Source File: VpnConfigGenerator.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public HashMap<Connection.TransportType, VpnProfile> generateVpnProfiles() throws
        ConfigParser.ConfigParseError,
        NumberFormatException,
        JSONException,
        IOException {
    HashMap<Connection.TransportType, VpnProfile> profiles = new HashMap<>();
    profiles.put(OPENVPN, createProfile(OPENVPN));
    if (supportsObfs4()) {
        profiles.put(OBFS4, createProfile(OBFS4));
    }
    return profiles;
}
 
Example #16
Source File: X509Utils.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
public static PemObject readPemObjectFromFile (String keyfilename) throws IOException {

		Reader inStream;

		if(VpnProfile.isEmbedded(keyfilename))
			inStream = new StringReader(VpnProfile.getEmbeddedContent(keyfilename));
		else 
			inStream = new FileReader(new File(keyfilename));

		PemReader pr = new PemReader(inStream);
		PemObject r = pr.readPemObject();
		pr.close();
		return r;
	}
 
Example #17
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
private void checkRedirectParameters(VpnProfile np, Vector<Vector<String>> defgw) {
    for (Vector<String> redirect : defgw)
        for (int i = 1; i < redirect.size(); i++) {
            if (redirect.get(i).equals("block-local")) np.mAllowLocalLAN = false;
            else if (redirect.get(i).equals("unblock-local")) np.mAllowLocalLAN = true;
        }
}
 
Example #18
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
private Pair<Connection, Connection[]> parseConnection(String connection, Connection defaultValues) throws IOException, ConfigParseError {
    // Parse a connection Block as a new configuration file
    ConfigParser connectionParser = new ConfigParser();
    StringReader reader = new StringReader(connection.substring(VpnProfile.INLINE_TAG.length()));
    connectionParser.parseConfig(reader);
    return connectionParser.parseConnectionOptions(defaultValues);
}
 
Example #19
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
private static void useEmbbedUserAuth(VpnProfile np, String inlinedata) {
    String data = VpnProfile.getEmbeddedContent(inlinedata);
    String[] parts = data.split("\n");
    if (parts.length >= 2) {
        np.mUsername = parts[0];
        np.mPassword = parts[1];
    }
}
 
Example #20
Source File: ProfileManager.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
public void removeProfile(Context context, VpnProfile profile) {
    String vpnentry = profile.getUUID().toString();
    profiles.remove(vpnentry);
    saveProfileList(context);
    context.deleteFile(vpnentry + ".vp");
    if (mLastConnectedVpn == profile) mLastConnectedVpn = null;
}
 
Example #21
Source File: OpenVPNService.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
private OpenVPNManagement instantiateOpenVPN3Core() {
    try {
        Class cl = Class.forName("de.blinkt.openvpn.core.OpenVPNThreadv3");
        return (OpenVPNManagement) cl.getConstructor(OpenVPNService.class, VpnProfile.class).newInstance(this, mProfile);
    } catch (IllegalArgumentException | InstantiationException | InvocationTargetException |
            NoSuchMethodException | ClassNotFoundException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #22
Source File: ProfileManager.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the profile that was last connected (to connect if the service restarts)
 */
public static VpnProfile getLastConnectedProfile(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);

    String lastConnectedProfile = prefs.getString(LAST_CONNECTED_PROFILE, null);
    if (lastConnectedProfile != null)
        return get(c, lastConnectedProfile);
    else
        return null;
}
 
Example #23
Source File: ConfigParser.java    From SimpleOpenVpn-Android with Apache License 2.0 5 votes vote down vote up
static public void useEmbbedUserAuth(VpnProfile np, String inlinedata) {
    String data = VpnProfile.getEmbeddedContent(inlinedata);
    String[] parts = data.split("\n");
    if (parts.length >= 2) {
        np.mUsername = parts[0];
        np.mPassword = parts[1];
    }
}
 
Example #24
Source File: ConfigParser.java    From SimpleOpenVpn-Android with Apache License 2.0 5 votes vote down vote up
private void checkRedirectParameters(VpnProfile np, Vector<Vector<String>> defgw) {
    for (Vector<String> redirect : defgw)
        for (int i = 1; i < redirect.size(); i++) {
            if (redirect.get(i).equals("block-local"))
                np.mAllowLocalLAN = false;
            else if (redirect.get(i).equals("unblock-local"))
                np.mAllowLocalLAN = true;
        }
}
 
Example #25
Source File: OpenVPNService.java    From Cake-VPN with GNU General Public License v2.0 5 votes vote down vote up
private OpenVPNManagement instantiateOpenVPN3Core() {
    try {
        Class cl = Class.forName("de.blinkt.openvpn.core.OpenVPNThreadv3");
        return (OpenVPNManagement) cl.getConstructor(OpenVPNService.class, VpnProfile.class).newInstance(this, mProfile);
    } catch (IllegalArgumentException | InstantiationException | InvocationTargetException |
            NoSuchMethodException | ClassNotFoundException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #26
Source File: ConfigParser.java    From SimpleOpenVpn-Android with Apache License 2.0 5 votes vote down vote up
private void checkinlinefile(Vector<String> args, BufferedReader br) throws IOException, ConfigParseError {
    String arg0 = args.get(0).trim();
    // CHeck for <foo>
    if (arg0.startsWith("<") && arg0.endsWith(">")) {
        String argname = arg0.substring(1, arg0.length() - 1);
        String inlinefile = VpnProfile.INLINE_TAG;

        String endtag = String.format("</%s>", argname);
        do {
            String line = br.readLine();
            if (line == null) {
                throw new ConfigParseError(String.format("No endtag </%s> for starttag <%s> found", argname, argname));
            }
            if (line.trim().equals(endtag))
                break;
            else {
                inlinefile += line;
                inlinefile += "\n";
            }
        } while (true);

        args.clear();
        args.add(argname);
        args.add(inlinefile);
    }

}
 
Example #27
Source File: OpenVPNService.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private OpenVPNManagement instantiateOpenVPN3Core() {
    try {
        Class cl = Class.forName("de.blinkt.openvpn.core.OpenVPNThreadv3");
        return (OpenVPNManagement) cl.getConstructor(OpenVPNService.class, VpnProfile.class).newInstance(this, mProfile);
    } catch (IllegalArgumentException | InstantiationException | InvocationTargetException |
            NoSuchMethodException | ClassNotFoundException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #28
Source File: VPNLaunchHelper.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public static void startOpenVpn(VpnProfile startprofile, Context context) {
    Intent startVPN = startprofile.prepareStartService(context);
    if (startVPN != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
            //noinspection NewApi
            context.startForegroundService(startVPN);
        else
            context.startService(startVPN);

    }
}
 
Example #29
Source File: ProfileManager.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
public VpnProfile getProfileByName(String name) {
    for (VpnProfile vpnp : profiles.values()) {
        if (vpnp.getName().equals(name)) {
            return vpnp;
        }
    }
    return null;
}
 
Example #30
Source File: ProfileManager.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
public static VpnProfile getAlwaysOnVPN(Context context) {
    checkInstance(context);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    String uuid = prefs.getString("alwaysOnVpn", null);
    return get(uuid);

}