Hi,I am writing an Android application which needs to Connect to OpenVpn
server using OpnVpn for Android.
I need to pass OVPN configuration to OpenVpn For Android app through my
application.
I can pass the Ovpn file path(Stored on SDcard) to
de.blinkt.openvpn.ConfigConverter.java class through Intent , but i need a
more secure way as i do not want to store the configuration file on SDcard.
I can create the OVPN file through my application and pass it to
ConfigConverter class as a String using Intent

I am inserting the code changes to onStart() method in ConfigConverter.java
class below as well as attaching the entire java file with this mail.

Please let me know the updates.

/**
     * Added code here to import and save vpn configuration file
     * which is passed through intent by external application. This
     * code can be moved to separate class if required. External
     * application will launch an intent for this class and will
     * pass configuration file as a string.
     * The caller application can use following code to pass ovpn
configuration as a String.
     *
     *         Intent i = new Intent();
            i.setData(Uri.parse(ovpnString));
            i.setComponent(new
ComponentName("de.blinkt.openvpn","de.blinkt.openvpn.ConfigConverter"));
            i.putExtra("IS_OVPN_STR_PRESENT", true);
            i.putExtra("PROFILE_NAME", profileName);
            startActivity(i);
     */
    @Override
    protected void onStart() {
        super.onStart();

        mArrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1);
        getListView().setAdapter(mArrayAdapter);
        final android.content.Intent intent = getIntent();

        if (intent != null) {

            final android.net.Uri data = intent.getData();
            if (data != null) {
                // log(R.string.import_experimental);
                log(R.string.importing_config, data.toString());

//Code modification start
                InputStream is = null;
                // check for configuration string parameter ovpnString
                if (intent.getBooleanExtra("IS_OVPN_STR_PRESENT", false)) {
                    is = new
ByteArrayInputStream(data.toString().getBytes());
                    mPossibleName = intent.getStringExtra("PROFILE_NAME");
                    doImport(is);
                } else {
//Code modification end

                    try {
                        if (data.getScheme().equals("file")) {
                            mPossibleName = data.getLastPathSegment();
                            if (mPossibleName != null) {
                                mPossibleName =
mPossibleName.replace(".ovpn","");
                                mPossibleName =
mPossibleName.replace(".conf","");
                            }
                        }
                        is = getContentResolver().openInputStream(data);
                        mPathsegments = data.getPathSegments();

                        doImport(is);
                    } catch (FileNotFoundException e) {
                        log(R.string.import_content_resolve_error);
                    }
                }
            }
        }
        return;
    }

/////////////////////////

Thanks,
Alok

Attachment: ConfigConverter.java
Description: Binary data

Reply via email to