Java Code Examples for de.blinkt.openvpn.core.VpnStatus#logError()

The following examples show how to use de.blinkt.openvpn.core.VpnStatus#logError() . 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: VpnProfile.java    From Cake-VPN with GNU General Public License v2.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 2
Source File: VpnProfile.java    From SimpleOpenVpn-Android with Apache License 2.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 3
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 4
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 5
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 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: VpnProfile.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] 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
        return NativeUtils.rsasign(data, pkey);

    } catch (NoSuchMethodException | InvalidKeyException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
Example 8
Source File: Shapeshifter.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void reconnect() {
    try {
        shapeShifter.open();
        retry = 0;
        isErrorHandling = false;
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG, "SHAPESHIFTER RECONNECTION ERROR: " + e.getLocalizedMessage());
        VpnStatus.logError("Unable to reconnect shapeshifter: " + e.getLocalizedMessage());
    }
}
 
Example 9
Source File: FirewallManager.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTetheringStarted(boolean success) {
    if (success) {
        VpnStatus.logInfo("[FIREWALL] Rules for tethering enabled");
    } else {
        VpnStatus.logError("[FIREWALL] Could not enable rules for tethering.");
    }
}
 
Example 10
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 11
Source File: Shapeshifter.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void log(String s) {
    Log.e(TAG, "SHAPESHIFTER ERROR: " + s);
    VpnStatus.logError(s);
    isErrorHandling = true;
    close();

    if (retry < MAX_RETRY && !noNetwork) {
        retry++;
        reconnectHandler.postDelayed(Shapeshifter.this::reconnect, RETRY_TIME);
    } else {
        VpnStatus.logError(VpnStatus.ErrorType.SHAPESHIFTER);
    }
}
 
Example 12
Source File: EipSetupObserver.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level) {
    // VpnStatus.updateStateString("NOPROCESS", "No process running.", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED);

    Log.d(TAG, "vpn status: " + state + " - " + logmessage + " - " + level);
    if (observedProfileFromVpnStatus == null ||
            setupVpnProfile == null) {
        return;
    }
    if (!observedProfileFromVpnStatus.equals(setupVpnProfile.getUUIDString())) {
        Log.d(TAG, "vpn profile to setup and observed profile currently is used differ: " + setupVpnProfile.getUUIDString() + " vs. " + observedProfileFromVpnStatus);
        return;
    }

    if (ConnectionStatus.LEVEL_STOPPING == level) {
        finishGatewaySetup(false);
    } else if ("CONNECTRETRY".equals(state) && LEVEL_CONNECTING_NO_SERVER_REPLY_YET.equals(level)) {
        Log.d(TAG, "trying gateway: " + setupVpnProfile.getName());
        if (TIMEOUT.equals(logmessage)) {
            Log.e(TAG, "Timeout reached! Try next gateway!");
            VpnStatus.logError("Timeout reached! Try next gateway!");
            selectNextGateway();
            return;
        }
        int current = reconnectTry.get();
        reconnectTry.set(current + 1);
    } else if ("NOPROCESS".equals(state) && LEVEL_NOTCONNECTED == level) {
        //??
    } else if ("CONNECTED".equals(state)) {
        //saveLastProfile(context.getApplicationContext(), setupVpnProfile.getUUIDString());
        Provider provider = ProviderObservable.getInstance().getCurrentProvider();
        if (setupNClosestGateway.get() > 0 || provider.shouldUpdateEipServiceJson()) {
            //setupNClostestGateway > 0: at least one failed gateway -> did the provider change it's gateways?
            ProviderAPICommand.execute(context, ProviderAPI.DOWNLOAD_SERVICE_JSON, provider);
        }
        finishGatewaySetup(false);
    } else if ("TCP_CONNECT".equals(state)) {
        changingGateway.set(false);
    }
}
 
Example 13
Source File: LaunchVPN.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
protected void startVpnFromIntent() {
    // Resolve the intent

    final Intent intent = getIntent();
    final String action = intent.getAction();

    // If the intent is a request to create a shortcut, we'll do that and exit


    if (Intent.ACTION_MAIN.equals(action)) {
        // Check if we need to clear the log
        if (Preferences.getDefaultSharedPreferences(this).getBoolean(CLEARLOG, true))
            VpnStatus.clearLog();

        // we got called to be the starting point, most likely a shortcut
        mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);
        VpnProfile profileToConnect = (VpnProfile) intent.getExtras().getSerializable(PROVIDER_PROFILE);

        if (profileToConnect == null) {
            VpnStatus.logError(R.string.shortcut_profile_notfound);
            // show Log window to display error
            showLogWindow();
            finish();
        } else {
            mSelectedProfile = profileToConnect;
            launchVPN();
        }
    }
}
 
Example 14
Source File: FirewallManager.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFirewallStopped(boolean success) {
    if (success) {
        VpnStatus.logInfo("[FIREWALL] Custom rules deleted");
    } else {
        VpnStatus.logError("[FIREWALL] Could not delete custom rules");
    }
}
 
Example 15
Source File: LaunchVPN.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    // Resolve the intent

    final Intent intent = getIntent();
    final String action = intent.getAction();

    // If the intent is a request to create a shortcut, we'll do that and exit


    if (Intent.ACTION_MAIN.equals(action)) {
        // we got called to be the starting point, most likely a shortcut
        String shortcutUUID = intent.getStringExtra(EXTRA_KEY);
        String shortcutName = intent.getStringExtra(EXTRA_NAME);
        mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);

        VpnProfile profileToConnect = ProfileManager.get(this, shortcutUUID);
        if (shortcutName != null && profileToConnect == null)
            profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName);

        if (profileToConnect == null) {
            VpnStatus.logError(R.string.shortcut_profile_notfound);
            // show Log window to display error
            finish();
            return;
        }

        mSelectedProfile = profileToConnect;
        launchVPN();

    }
}
 
Example 16
Source File: GrantPermissionsActivity.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    Intent i = VpnService.prepare(this);
    if (i == null) {
        onActivityResult(VPN_PREPARE, RESULT_OK, null);
    } else {
        try {
            startActivityForResult(i, VPN_PREPARE);
        } catch (ActivityNotFoundException e) {
            VpnStatus.logError(R.string.no_vpn_support_image);
            finish();
        }
    }
}
 
Example 17
Source File: FirewallManager.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTetheringStopped(boolean success) {
    if (success) {
        VpnStatus.logInfo("[FIREWALL] Rules for tethering successfully disabled");
    } else {
        VpnStatus.logError("[FIREWALL] Could not disable rules for tethering.");
    }
}
 
Example 18
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 19
Source File: LaunchVPN.java    From bitmask_android with GNU General Public License v3.0 4 votes vote down vote up
void launchVPN() {
    int vpnok = mSelectedProfile.checkProfile(this);
    if (vpnok != R.string.no_error_found) {
        showConfigErrorDialog(vpnok);
        return;
    }

    Intent intent = null;
    try {
        intent = VpnService.prepare(this.getApplicationContext());
    } catch (NullPointerException npe) {
        tellToReceiverOrBroadcast(this.getApplicationContext(), EIP_ACTION_PREPARE_VPN, RESULT_CANCELED);
        finish();
        return;
    }

    // Check if we want to fix /dev/tun
    SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this);
    boolean usecm9fix = prefs.getBoolean("useCM9Fix", false);
    boolean loadTunModule = prefs.getBoolean("loadTunModule", false);

    if (loadTunModule)
        execeuteSUcmd("insmod /system/lib/modules/tun.ko");

    if (usecm9fix && !mCmfixed) {
        execeuteSUcmd("chown system /dev/tun");
    }

    if (intent != null) {
        VpnStatus.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_permission,
                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);
            showLogWindow();
        }
    } else {
        onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null);
    }

}
 
Example 20
Source File: EipSetupObserver.java    From bitmask_android with GNU General Public License v3.0 4 votes vote down vote up
private void handleEipEvent(Intent intent) {
    int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED);
    Bundle result = intent.getBundleExtra(BROADCAST_RESULT_KEY);
    String eipRequest = result.getString(EIP_REQUEST);
    EIP.EIPErrors error = EIP.EIPErrors.UNKNOWN;
    try {
        JSONObject jsonObject = new JSONObject(result.getString(EIP.ERRORS));
        error = EIP.EIPErrors.valueOf(jsonObject.getString(EIP.ERRORID));
    } catch (Exception e) {
        //ignore
    }
    if (eipRequest == null) {
        return;
    }
    switch (eipRequest) {
        case EIP_ACTION_START:
        case EIP_ACTION_START_ALWAYS_ON_VPN:
            if (resultCode == RESULT_CANCELED) {
                //setup failed
                if (error == EIP.EIPErrors.NO_MORE_GATEWAYS) {
                    finishGatewaySetup(false);
                    EipCommand.startBlockingVPN(context.getApplicationContext());
                } else {
                    finishGatewaySetup(false);
                    EipCommand.stopVPN(context);
                    EipStatus.refresh();
                }
            }
            break;
        case EIP_ACTION_PREPARE_VPN:
            if (resultCode == RESULT_CANCELED) {
                VpnStatus.logError("Error preparing VpnService.");
                finishGatewaySetup(false);
                EipStatus.refresh();
            }
            break;
        default:
            break;
    }

    for (EipSetupListener listener : listeners) {
        listener.handleEipEvent(intent);
    }
}