blob: e4161e211c3f8a4fcb5b267c3e9400a5d151bd46 [file] [log] [blame]
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.android_scripting.facade;
import android.app.Service;
import android.net.VpnManager;
import android.os.RemoteException;
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile;
import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
import org.json.JSONObject;
/**
* Access VPN functions.
*/
public class VpnFacade extends RpcReceiver {
private final Service mService;
private final VpnManager mVpnManager;
private CertInstallerHelper mCertHelper;
public VpnFacade(FacadeManager manager) {
super(manager);
mService = manager.getService();
mCertHelper = new CertInstallerHelper();
mVpnManager = mService.getSystemService(VpnManager.class);
}
private VpnProfile genLegacyVpnProfile(JSONObject vpnProfileJson) {
VpnProfile vp = new VpnProfile(vpnProfileJson.optString("key", ""));
vp.name = vpnProfileJson.optString("name", "");
vp.type = vpnProfileJson.optInt("type", VpnProfile.TYPE_PPTP);
vp.server = vpnProfileJson.optString("server", "");
vp.username = vpnProfileJson.optString("username", "");
vp.password = vpnProfileJson.optString("password", "");
vp.dnsServers = vpnProfileJson.optString("dnsServers", "");
vp.searchDomains = vpnProfileJson.optString("searchDomains", "");
vp.routes = vpnProfileJson.optString("routes", "");
vp.mppe = vpnProfileJson.optBoolean("mppe", true);
vp.l2tpSecret = vpnProfileJson.optString("l2tpSecret", "");
vp.ipsecIdentifier = vpnProfileJson.optString("ipsecIdentifier", "");
vp.ipsecSecret = vpnProfileJson.optString("ipsecSecret", "");
vp.ipsecUserCert = vpnProfileJson.optString("ipsecUserCert", "");
vp.ipsecCaCert = vpnProfileJson.optString("ipsecCaCert", "");
vp.ipsecServerCert = vpnProfileJson.optString("ipsecServerCert", "");
vp.saveLogin = vpnProfileJson.optBoolean("saveLogin", false);
return vp;
}
@Rpc(description = "Start legacy VPN with a profile.")
public void vpnStartLegacyVpn(@RpcParameter(name = "vpnProfile") JSONObject vpnProfile)
throws RemoteException {
VpnProfile profile = genLegacyVpnProfile(vpnProfile);
mVpnManager.startLegacyVpn(profile);
}
@Rpc(description = "Stop the current legacy VPN connection.")
public void vpnStopLegacyVpn() throws RemoteException {
mVpnManager.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN, mService.getUserId());
}
@Rpc(description = "Get the info object of the currently active legacy VPN connection.")
public LegacyVpnInfo vpnGetLegacyVpnInfo() throws RemoteException {
return mVpnManager.getLegacyVpnInfo(mService.getUserId());
}
@Override
public void shutdown() {
}
@Rpc(description = "Install certificate for RSA VPNs.")
public void installCertificate(@RpcParameter(name = "vpnProfile") JSONObject vpnProfile,
@RpcParameter(name = "certFile") String certFile,
@RpcParameter(name = "password") String password)
throws RemoteException {
VpnProfile profile = genLegacyVpnProfile(vpnProfile);
mCertHelper.installCertificate(profile, certFile, password);
}
}