de.blinkt.openvpn.core.VpnStatus Java Examples

The following examples show how to use de.blinkt.openvpn.core.VpnStatus. 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: LogListAdapter.java    From android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void newLog(VpnStatus.LogItem logItem) {
    if(mLogEntries.size() == MAX_LOG_ENTRIES) {
        mLevelLogEntries.remove(mLogEntries.get(0));
        mLogEntries.removeElementAt(0);
    }

    mLogEntries.add(logItem);
    mLevelLogEntries.add(logItem);

    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            notifyDataSetChanged();
            mRecyclerView.smoothScrollToPosition(getItemCount() - 1);
        }
    });
}
 
Example #2
Source File: ServerActivity.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
private void startVpn() {
    stopwatch = new Stopwatch();
    connectedServer = currentServer;
    hideCurrentConnection = true;
    adbBlockCheck.setEnabled(false);

    Intent intent = VpnService.prepare(this);

    if (intent != null) {
        VpnStatus.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_permission,
                VpnStatus.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
        // Start the query
        try {
            startActivityForResult(intent, START_VPN_PROFILE);
        } catch (ActivityNotFoundException ane) {
            // Shame on you Sony! At least one user reported that
            // an official Sony Xperia Arc S image triggers this exception
            VpnStatus.logError(R.string.no_vpn_support_image);
        }
    } else {
        onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null);
    }
}
 
Example #3
Source File: VoidVpnService.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private void establishBlockingVpn() {
    try {
        VpnStatus.logInfo(getProviderFormattedString(getResources(), R.string.void_vpn_establish));
        VpnStatus.updateStateString(STATE_ESTABLISH, "",
                R.string.void_vpn_establish, ConnectionStatus.LEVEL_BLOCKING);
        Builder builder = prepareBlockingVpnProfile();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)  {
            builder.addDisallowedApplication(getPackageName());
        }

        fd = builder.establish();
    } catch (Exception e) {
        // Catch any exception
        e.printStackTrace();
        VpnStatus.logError(R.string.void_vpn_error_establish);
    }
}
 
Example #4
Source File: ServerActivity.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
private void receiveStatus(Context context, Intent intent) {
    if (checkStatus()) {
        changeServerStatus(VpnStatus.ConnectionStatus.valueOf(intent.getStringExtra("status")));
        lastLog.setText(VpnStatus.getLastCleanLogMessage(getApplicationContext()));
    }

    if (intent.getStringExtra("detailstatus").equals("NOPROCESS")) {
        try {
            TimeUnit.SECONDS.sleep(1);
            if (!VpnStatus.isVPNActive())
                prepareStopVPN();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
Example #5
Source File: BaseActivity.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    for (int i = 0; i < menu.size(); i++) {
        if (menu.getItem(i).getItemId() == R.id.actionCurrentServer
                && (connectedServer == null || hideCurrentConnection || !VpnStatus.isVPNActive()))
            menu.getItem(i).setVisible(false);

        if (premiumServers && menu.getItem(i).getItemId() == R.id.actionGetMoreServers)
            menu.getItem(i).setTitle(getString(R.string.current_servers_list));

        if (BuildConfig.FLAVOR == "underground" && menu.getItem(i).getItemId() == R.id.actionShare)
            menu.getItem(i).setVisible(false);
    }

    return useMenu();
}
 
Example #6
Source File: VpnProfile.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
private String processSignJellyBeans(PrivateKey privkey, byte[] data) {
    try {
        Method getKey = privkey.getClass().getSuperclass().getDeclaredMethod("getOpenSSLKey");
        getKey.setAccessible(true);

        // Real object type is OpenSSLKey
        Object opensslkey = getKey.invoke(privkey);

        getKey.setAccessible(false);

        Method getPkeyContext = opensslkey.getClass().getDeclaredMethod("getPkeyContext");

        // integer pointer to EVP_pkey
        getPkeyContext.setAccessible(true);
        int pkey = (Integer) getPkeyContext.invoke(opensslkey);
        getPkeyContext.setAccessible(false);

        // 112 with TLS 1.2 (172 back with 4.3), 36 with TLS 1.0
        byte[] signed_bytes = NativeUtils.rsasign(data, pkey);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);

    } catch (NoSuchMethodException | InvalidKeyException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example #7
Source File: LogFragment.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateState(final String status, final String logMessage, final int resId, final ConnectionStatus level) {
    if (isAdded()) {
        final String cleanLogMessage = VpnStatus.getLastCleanLogMessage(getActivity());

        getActivity().runOnUiThread(() -> {
            if (isAdded()) {
                if (mSpeedView != null) {
                    mSpeedView.setText(cleanLogMessage);
                }
                if (mConnectStatus != null)
                    mConnectStatus.setText(cleanLogMessage);
            }
        });
    }
}
 
Example #8
Source File: VpnProfile.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
private String processSignJellyBeans(PrivateKey privkey, byte[] data) {
    try {
        Method getKey = privkey.getClass().getSuperclass().getDeclaredMethod("getOpenSSLKey");
        getKey.setAccessible(true);
        // Real object type is OpenSSLKey
        Object opensslkey = getKey.invoke(privkey);
        getKey.setAccessible(false);
        Method getPkeyContext = opensslkey.getClass().getDeclaredMethod("getPkeyContext");
        // integer pointer to EVP_pkey
        getPkeyContext.setAccessible(true);
        int pkey = (Integer) getPkeyContext.invoke(opensslkey);
        getPkeyContext.setAccessible(false);
        // 112 with TLS 1.2 (172 back with 4.3), 36 with TLS 1.0
        byte[] signed_bytes = NativeUtils.rsasign(data, pkey);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);
    } catch (NoSuchMethodException | InvalidKeyException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example #9
Source File: VpnProfile.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
public String getSignedData(String b64data) {
    PrivateKey privkey = getKeystoreKey();
    byte[] data = Base64.decode(b64data, Base64.DEFAULT);
    // The Jelly Bean *evil* Hack
    // 4.2 implements the RSA/ECB/PKCS1PADDING in the OpenSSLprovider
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
        return processSignJellyBeans(privkey, data);
    }
    try {
        /* ECB is perfectly fine in this special case, since we are using it for
           the public/private part in the TLS exchange
         */
        @SuppressLint("GetInstance") Cipher rsaSigner = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
        rsaSigner.init(Cipher.ENCRYPT_MODE, privkey);
        byte[] signed_bytes = rsaSigner.doFinal(data);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);
    } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException
            | BadPaddingException | NoSuchPaddingException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example #10
Source File: NavigationDrawerFragment.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private void initUseBridgesEntry() {
    IconSwitchEntry useBridges = drawerView.findViewById(R.id.bridges_switch);
    if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) {
        useBridges.setVisibility(VISIBLE);
        useBridges.setChecked(getUsePluggableTransports(getContext()));
        useBridges.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (!buttonView.isPressed()) {
                return;
            }
            usePluggableTransports(getContext(), isChecked);
            if (VpnStatus.isVPNActive()) {
                EipCommand.startVPN(getContext(), false);
                closeDrawer();
            }
        });


    } else {
        useBridges.setVisibility(GONE);
    }
}
 
Example #11
Source File: VpnProfile.java    From SimpleOpenVpn-Android with Apache License 2.0 6 votes vote down vote up
private String processSignJellyBeans(PrivateKey privkey, byte[] data) {
    try {
        Method getKey = privkey.getClass().getSuperclass().getDeclaredMethod("getOpenSSLKey");
        getKey.setAccessible(true);

        // Real object type is OpenSSLKey
        Object opensslkey = getKey.invoke(privkey);
        getKey.setAccessible(false);
        Method getPkeyContext = opensslkey.getClass().getDeclaredMethod("getPkeyContext");

        // integer pointer to EVP_pkey
        getPkeyContext.setAccessible(true);
        int pkey = (Integer) getPkeyContext.invoke(opensslkey);
        getPkeyContext.setAccessible(false);

        // 112 with TLS 1.2 (172 back with 4.3), 36 with TLS 1.0
        byte[] signed_bytes = NativeUtils.rsasign(data, pkey);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);

    } catch (NoSuchMethodException | InvalidKeyException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example #12
Source File: NavigationDrawerFragment.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private void initFirewallEntry() {
    firewall = drawerView.findViewById(R.id.enableIPv6Firewall);
    boolean show = showExperimentalFeatures(getContext());
    firewall.setVisibility(show ? VISIBLE : GONE);
    firewall.setChecked(PreferenceHelper.useIpv6Firewall(getContext()));
    firewall.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (!buttonView.isPressed()) {
            return;
        }
        PreferenceHelper.setUseIPv6Firewall(getContext(), isChecked);
        if (VpnStatus.isVPNActive()) {
            if (isChecked) {
                firewallManager.startIPv6Firewall();
            } else {
                firewallManager.stopIPv6Firewall();
            }
        }
    });
}
 
Example #13
Source File: FirewallManager.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSuRequested(boolean success) {
    if (!success) {
        VpnStatus.logError("[FIREWALL] Root permission needed to execute custom firewall rules.");
        new Handler(Looper.getMainLooper()).post(() -> {
            Toast.makeText(context.getApplicationContext(), context.getString(R.string.root_permission_error, context.getString(R.string.app_name)), Toast.LENGTH_LONG).show();
        });
        TetheringObservable.allowVpnWifiTethering(false);
        TetheringObservable.allowVpnUsbTethering(false);
        TetheringObservable.allowVpnBluetoothTethering(false);
        PreferenceHelper.allowWifiTethering(context, false);
        PreferenceHelper.allowUsbTethering(context, false);
        PreferenceHelper.allowBluetoothTethering(context, false);
        PreferenceHelper.setUseIPv6Firewall(context, false);
    }
}
 
Example #14
Source File: ProviderApiManager.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Downloads the eip-service.json from a given URL, and saves eip service capabilities including the offered gateways
 * @return a bundle with a boolean value mapped to a key named BROADCAST_RESULT_KEY, and which is true if the download was successful.
 */
@Override
protected Bundle getAndSetEipServiceJson(Provider provider) {
    Bundle result = new Bundle();
    String eipServiceJsonString = "";
    try {
        String eipServiceUrl = provider.getApiUrlWithVersion() + "/" + EIP.SERVICE_API_PATH;
        eipServiceJsonString = downloadWithProviderCA(provider.getCaCert(), eipServiceUrl);
        JSONObject eipServiceJson = new JSONObject(eipServiceJsonString);
        if (BuildConfig.DEBUG) {
            VpnStatus.logDebug("EIP SERVICE JSON: " + eipServiceJsonString);
        }
        if (eipServiceJson.has(ERRORS)) {
            setErrorResult(result, eipServiceJsonString);
        } else {
            provider.setEipServiceJson(eipServiceJson);
            provider.setLastEipServiceUpdate(System.currentTimeMillis());
            result.putBoolean(BROADCAST_RESULT_KEY, true);
        }
    } catch (NullPointerException | JSONException e) {
        setErrorResult(result, eipServiceJsonString);
    }
    return result;
}
 
Example #15
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 #16
Source File: VpnProfile.java    From android with GNU General Public License v3.0 6 votes vote down vote up
public Intent prepareStartService(Context context) {
    Intent intent = getStartServiceIntent(context);


    if (mAuthenticationType == VpnProfile.TYPE_KEYSTORE || mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE) {
        if (getKeyStoreCertificates(context) == null)
            return null;
    }


    try {
        FileWriter cfg = new FileWriter(VPNLaunchHelper.getConfigFilePath(context));
        cfg.write(getConfigFile(context, false));
        cfg.flush();
        cfg.close();
    } catch (IOException e) {
        VpnStatus.logException(e);
    }

    return intent;
}
 
Example #17
Source File: Shapeshifter.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public boolean stop() {
    try {
        shapeShifter.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        VpnStatus.logError(e.getLocalizedMessage());
    }
    EipStatus.getInstance().deleteObserver(this);
    return false;
}
 
Example #18
Source File: EipStatus.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void setEipLevel(ConnectionStatus level) {
    switch (level) {
        case LEVEL_CONNECTED:
            currentEipLevel = EipLevel.CONNECTED;
            break;
        case LEVEL_VPNPAUSED:
            if (VpnStatus.getLastConnectedVpnProfile() != null && VpnStatus.getLastConnectedVpnProfile().mPersistTun) {
                //if persistTun is enabled, treat EipLevel as connecting as it *shouldn't* allow passing traffic in the clear...
                currentEipLevel = EipLevel.CONNECTING;
            } else {
                //... if persistTun is not enabled, background network traffic will pass in the clear
                currentEipLevel = EipLevel.DISCONNECTED;
            }
            break;
        case LEVEL_CONNECTING_SERVER_REPLIED:
        case LEVEL_CONNECTING_NO_SERVER_REPLY_YET:
        case LEVEL_WAITING_FOR_USER_INPUT:
        case LEVEL_START:
            currentEipLevel = EipLevel.CONNECTING;
            break;
        case LEVEL_AUTH_FAILED:
        case LEVEL_NOTCONNECTED:
            currentEipLevel = EipLevel.DISCONNECTED;
            break;
        case LEVEL_STOPPING:
            currentEipLevel = EipLevel.DISCONNECTING;
            break;
        case LEVEL_NONETWORK:
        case LEVEL_BLOCKING:
            setEipLevelWithDelay(level);
            break;
        case UNKNOWN_LEVEL:
            currentEipLevel = EipLevel.UNKNOWN; //??
            break;
    }
}
 
Example #19
Source File: Shapeshifter.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public void start() {
    try {
        shapeShifter.open();
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG, "SHAPESHIFTER ERROR: " + e.getLocalizedMessage());
        VpnStatus.logError(VpnStatus.ErrorType.SHAPESHIFTER);
        VpnStatus.logError(e.getLocalizedMessage());
    }
}
 
Example #20
Source File: LogFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStop() {
    super.onStop();
    VpnStatus.removeStateListener(this);
    VpnStatus.removeByteCountListener(this);

    getActivity().getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat)
            .putInt(VERBOSITYLEVEL, ladapter.mLogLevel).apply();

}
 
Example #21
Source File: FirewallManager.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFirewallStarted(boolean success) {
    if (success) {
        VpnStatus.logInfo("[FIREWALL] Custom rules established");
    } else {
        VpnStatus.logError("[FIREWALL] Could not establish custom rules.");
    }
}
 
Example #22
Source File: EipSetupObserver.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void finishGatewaySetup(boolean changingGateway) {
    VpnStatus.removeStateListener(this);
    setupVpnProfile = null;
    setupNClosestGateway.set(0);
    observedProfileFromVpnStatus = null;
    this.changingGateway.set(changingGateway);
    this.reconnectTry.set(0);
}
 
Example #23
Source File: VpnProfile.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] getExtAppSignedData(Context c, byte[] data) {
    if (TextUtils.isEmpty(mExternalAuthenticator))
        return null;
    try {
        return ExtAuthHelper.signData(c, mExternalAuthenticator, mAlias, data);
    } catch (KeyChainException | InterruptedException e) {
        VpnStatus.logError(R.string.error_extapp_sign, mExternalAuthenticator, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example #24
Source File: LogListAdapter.java    From android with GNU General Public License v3.0 5 votes vote down vote up
private void initLevelEntries() {
    mLevelLogEntries.clear();
    for(VpnStatus.LogItem li: mLogEntries) {
        if (li.getVerbosityLevel() <= mLogLevel || mLogLevel == VpnProfile.MAXLOGLEVEL)
            mLevelLogEntries.add(li);
    }
}
 
Example #25
Source File: LogListAdapter.java    From android with GNU General Public License v3.0 5 votes vote down vote up
public String getLogAsString() {
    StringBuilder stringBuilder = new StringBuilder();
    for (VpnStatus.LogItem entry : mLogEntries) {
        stringBuilder.append(getTime(entry));
        stringBuilder.append(' ');
        stringBuilder.append(entry.getString(mContext));
        stringBuilder.append('\n');
    }
    return stringBuilder.toString();
}
 
Example #26
Source File: VpnProfile.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public String getVersionEnvString(Context c) {
    String version = "unknown";
    try {
        PackageInfo packageinfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        version = packageinfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        VpnStatus.logException(e);
    }
    return String.format(Locale.US, "%s %s", c.getPackageName(), version);

}
 
Example #27
Source File: EipStatus.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
public static EipStatus getInstance() {
    if (currentStatus == null) {
        currentStatus = new EipStatus();
        VpnStatus.addStateListener(currentStatus);
    }
    return currentStatus;
}
 
Example #28
Source File: VPNhtApplication.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    PRNGFixes.apply();
    Fabric.with(this, new Crashlytics());
    sThis = this;

    if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
    }

    VpnStatus.addStateListener(this);
}
 
Example #29
Source File: VPNhtApplication.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateState(String state, String logmessage, int localizedResId, VpnStatus.ConnectionStatus level) {
    if(!mCreated) {
        mCreated = true;
        return;
    }

    if(level.equals(VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED)) {
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_HOSTNAME);
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_FIREWALL);
        PrefUtils.remove(this, Preferences.LAST_CONNECTED_COUNTRY);
    }
}
 
Example #30
Source File: EipStatusTest.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpdateState_LEVEL_VPNPAUSED_hasNotPersistentTun() throws Exception {

    mockStatic(PreferenceHelper.class);
    VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OPENVPN);
    mockVpnProfile.mPersistTun = false;
    doNothing().when(PreferenceHelper.class);
    VpnStatus.setLastConnectedVpnProfile(null, mockVpnProfile);
    VpnStatus.updateStateString("SCREENOFF", "", R.string.state_screenoff, LEVEL_VPNPAUSED);
    assertTrue("LEVEL_VPN_PAUSED eipLevel", eipStatus.getEipLevel() == DISCONNECTED);
    assertTrue("LEVEL_VPN_PAUSED level", eipStatus.getLevel() == LEVEL_VPNPAUSED);
}