diff options
| author | Arne Schwabe <arne@rfc2549.org> | 2015-03-16 12:55:41 +0100 | 
|---|---|---|
| committer | Arne Schwabe <arne@rfc2549.org> | 2015-03-16 12:55:41 +0100 | 
| commit | d98f6c6ba51ae8810bd2d035fa89f6ca24eba8fd (patch) | |
| tree | e2a263c9d409cead340a163230eb01f3bc62124c /remoteExample | |
| parent | d8a10a7d9f9de6dd86ed382c3eb7a22bbd8cd21e (diff) | |
Update/cleanup of external API, allow adding of non user editable profiles
--HG--
rename : remoteExample/src/main/assets/hd.conf => remoteExample/src/main/assets/test.conf
Diffstat (limited to 'remoteExample')
| -rw-r--r-- | remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl | 13 | ||||
| -rw-r--r-- | remoteExample/src/main/assets/test.conf (renamed from remoteExample/src/main/assets/hd.conf) | 0 | ||||
| -rw-r--r-- | remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java | 87 | ||||
| -rw-r--r-- | remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java | 30 | ||||
| -rw-r--r-- | remoteExample/src/main/res/layout/fragment_main.xml | 10 | ||||
| -rw-r--r-- | remoteExample/src/main/res/values/strings.xml | 1 | 
6 files changed, 90 insertions, 51 deletions
diff --git a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl index d0791a4a..273a0046 100644 --- a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl +++ b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl @@ -12,10 +12,14 @@ interface IOpenVPNAPIService {  	void startProfile (String profileUUID);
 -	/** Use a profile with all certificates etc. embedded */
 +	/** Use a profile with all certificates etc. embedded,
 +	 * old version which does not return the UUID of the addded profile, see
 +	 * below for a version that return the UUID on add */
  	boolean addVPNProfile (String name, String config);
 -	/** start a profile using an config */
 +	/** start a profile using a config as inline string. Make sure that all needed data is inlined,
 +	 * e.g., using <ca>...</ca> or <auth-user-data>...</auth-user-data>
 +	 * See the OpenVPN manual page for more on inlining files */
  	void startVPN (String inlineconfig);
  	/** This permission framework is used  to avoid confused deputy style attack to the VPN
 @@ -55,5 +59,8 @@ interface IOpenVPNAPIService {  	  * Before calling this function you should make sure OpenVPN for Android may actually
  	  * this function by checking if prepareVPNService returns null; */
  	boolean protectSocket(in ParcelFileDescriptor fd);
 -		
 +
 +
 +    /** Use a profile with all certificates etc. embedded */
 +    APIVpnProfile addNewVPNProfile (String name, boolean userEditable, String config);
  }
\ No newline at end of file diff --git a/remoteExample/src/main/assets/hd.conf b/remoteExample/src/main/assets/test.conf index 3dc917aa..3dc917aa 100644 --- a/remoteExample/src/main/assets/hd.conf +++ b/remoteExample/src/main/assets/test.conf diff --git a/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java b/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java index f5591764..9d7e3b8e 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/api/APIVpnProfile.java @@ -1,3 +1,8 @@ +/*
 + * Copyright (c) 2012-2015 Arne Schwabe
 + * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
 + */
 +
  package de.blinkt.openvpn.api;
  import android.os.Parcel;
 @@ -5,47 +10,51 @@ import android.os.Parcelable;  public class APIVpnProfile implements Parcelable {
 -	public final String mUUID;
 -	public final String mName;
 -	public final boolean mUserEditable;
 +    public final String mUUID;
 +    public final String mName;
 +    public final boolean mUserEditable;
 +    public final String mProfileCreator;
 -	public APIVpnProfile(Parcel in) {
 -		mUUID = in.readString();
 -		mName = in.readString();
 +    public APIVpnProfile(Parcel in) {
 +        mUUID = in.readString();
 +        mName = in.readString();
          mUserEditable = in.readInt() != 0;
 -	}
 -
 -	public APIVpnProfile(String uuidString, String name, boolean userEditable) {
 -		mUUID=uuidString;
 -		mName = name;
 -		mUserEditable=userEditable;
 -	}
 -
 -	@Override
 -	public int describeContents() {
 -		return 0;
 -	}
 -
 -	@Override
 -	public void writeToParcel(Parcel dest, int flags) {
 -		dest.writeString(mUUID);
 -		dest.writeString(mName);
 -		if(mUserEditable)
 -			dest.writeInt(0);
 -		else
 -			dest.writeInt(1);
 -	}
 -
 -	public static final Parcelable.Creator<APIVpnProfile> CREATOR
 -	= new Parcelable.Creator<APIVpnProfile>() {
 -		public APIVpnProfile createFromParcel(Parcel in) {
 -			return new APIVpnProfile(in);
 -		}
 -
 -		public APIVpnProfile[] newArray(int size) {
 -			return new APIVpnProfile[size];
 -		}
 -	};
 +        mProfileCreator = in.readString();
 +    }
 +
 +    public APIVpnProfile(String uuidString, String name, boolean userEditable, String profileCreator) {
 +        mUUID = uuidString;
 +        mName = name;
 +        mUserEditable = userEditable;
 +        mProfileCreator = profileCreator;
 +    }
 +
 +    @Override
 +    public int describeContents() {
 +        return 0;
 +    }
 +
 +    @Override
 +    public void writeToParcel(Parcel dest, int flags) {
 +        dest.writeString(mUUID);
 +        dest.writeString(mName);
 +        if (mUserEditable)
 +            dest.writeInt(0);
 +        else
 +            dest.writeInt(1);
 +        dest.writeString(mProfileCreator);
 +    }
 +
 +    public static final Creator<APIVpnProfile> CREATOR
 +            = new Creator<APIVpnProfile>() {
 +        public APIVpnProfile createFromParcel(Parcel in) {
 +            return new APIVpnProfile(in);
 +        }
 +
 +        public APIVpnProfile[] newArray(int size) {
 +            return new APIVpnProfile[size];
 +        }
 +    };
  }
 diff --git a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java index 4f6481b0..a6d2baf5 100644 --- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java +++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java @@ -44,6 +44,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand          v.findViewById(R.id.disconnect).setOnClickListener(this);          v.findViewById(R.id.getMyIP).setOnClickListener(this);          v.findViewById(R.id.startembedded).setOnClickListener(this); +        v.findViewById(R.id.addNewProfile).setOnClickListener(this);          mHelloWorld = (TextView) v.findViewById(R.id.helloworld);          mStartVpn = (Button) v.findViewById(R.id.startVPN);          mStatus = (TextView) v.findViewById(R.id.status); @@ -59,6 +60,8 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand      private static final int START_PROFILE_EMBEDDED = 2;      private static final int START_PROFILE_BYUUID = 3;      private static final int ICS_OPENVPN_PERMISSION = 7; +    private static final int PROFILE_ADD_NEW = 8; +      protected IOpenVPNAPIService mService=null;      private Handler mHandler; @@ -66,7 +69,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand -    private void startEmbeddedProfile() +    private void startEmbeddedProfile(boolean addNew)      {          try {              InputStream conf = getActivity().getAssets().open("test.conf"); @@ -82,12 +85,11 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand              }              br.readLine(); -            //			mService.addVPNProfile("test", config); -            mService.startVPN(config); -        } catch (IOException e) { -            e.printStackTrace(); -        } catch (RemoteException e) { -            // TODO Auto-generated catch block +            if (addNew) +                mService.addNewVPNProfile("nonEditable", false, config); +            else +                mService.startVPN(config); +        } catch (IOException | RemoteException e) {              e.printStackTrace();          }      } @@ -252,6 +254,14 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand                      e.printStackTrace();                  }                  break; + +            case R.id.addNewProfile: +                try { +                    prepareStartProfile(PROFILE_ADD_NEW); +                } catch (RemoteException e) { +                    // TODO Auto-generated catch block +                    e.printStackTrace(); +                }              default:                  break;          } @@ -271,12 +281,11 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand      public void onActivityResult(int requestCode, int resultCode, Intent data) {          if (resultCode == Activity.RESULT_OK) {              if(requestCode==START_PROFILE_EMBEDDED) -                startEmbeddedProfile(); +                startEmbeddedProfile(false);              if(requestCode==START_PROFILE_BYUUID)                  try {                      mService.startProfile(mStartUUID);                  } catch (RemoteException e) { -                    // TODO Auto-generated catch block                      e.printStackTrace();                  }              if (requestCode == ICS_OPENVPN_PERMISSION) { @@ -288,6 +297,9 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand                  }              } +            if (requestCode == PROFILE_ADD_NEW) { +                startEmbeddedProfile(true); +            }          }      }; diff --git a/remoteExample/src/main/res/layout/fragment_main.xml b/remoteExample/src/main/res/layout/fragment_main.xml index e4fa019d..9279bd69 100644 --- a/remoteExample/src/main/res/layout/fragment_main.xml +++ b/remoteExample/src/main/res/layout/fragment_main.xml @@ -67,4 +67,14 @@              android:layout_below="@+id/getMyIP"              android:text="@string/start_embedded" /> +    <Button +        android:id="@+id/addNewProfile" +        style="?android:attr/buttonStyleSmall" +        android:layout_width="wrap_content" +        android:layout_height="wrap_content" +        android:text="@string/addNew" +        android:layout_alignTop="@+id/startembedded" +        android:layout_toRightOf="@+id/startembedded" +        android:layout_toEndOf="@+id/startembedded" /> +  </RelativeLayout> diff --git a/remoteExample/src/main/res/values/strings.xml b/remoteExample/src/main/res/values/strings.xml index bbaee226..49d4978d 100644 --- a/remoteExample/src/main/res/values/strings.xml +++ b/remoteExample/src/main/res/values/strings.xml @@ -10,6 +10,7 @@      <string name="show_my_ip">Show my IP</string>      <string name="disconnect">Disconnect</string>      <string name="start_embedded">Start embedded profile</string> +    <string name="addNew">Add new Profile</string>  </resources>  | 
