diff options
| author | Arne Schwabe <arne@rfc2549.org> | 2013-10-28 11:30:24 +0100 | 
|---|---|---|
| committer | Arne Schwabe <arne@rfc2549.org> | 2013-10-28 11:30:24 +0100 | 
| commit | 9652b48616789e1d8e3a4ebc4a6b63806cfdacb0 (patch) | |
| tree | db34996bbfb83e556b7d85d711b1f0e5afa0cc5a | |
| parent | fee992e1225e8a59f41327c06c8acc602447d674 (diff) | |
Fix NPE from market console
| -rwxr-xr-x | res/values/strings.xml | 1 | ||||
| -rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 40 | 
2 files changed, 30 insertions, 11 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index a7f0b07a..0a4c9509 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -298,4 +298,5 @@      <string name="thanks_for_donation">Thanks for donating %s!</string>      <string name="logCleared">Log cleared.</string>      <string name="show_password">Show password</string> +    <string name="keyChainAccessError">KeyChain Access error: %s</string>  </resources> diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index 05379b00..ce2aab37 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -553,9 +553,16 @@ public class VpnProfile implements Serializable {          return getKeyStoreCertificates(context, 5);      } +    class NoCertReturnedException extends Exception { +        public NoCertReturnedException (String msg) { +            super(msg); +        } +    } +      synchronized String[] getKeyStoreCertificates(Context context,int tries) {          PrivateKey privateKey = null;          X509Certificate[] cachain; +        Exception exp=null;          try {              privateKey = KeyChain.getPrivateKey(context, mAlias);              mPrivateKey = privateKey; @@ -564,6 +571,9 @@ public class VpnProfile implements Serializable {              cachain = KeyChain.getCertificateChain(context, mAlias); +            if(cachain == null) +                throw new NoCertReturnedException("No certificate returned from Keystore"); +              if (cachain.length <= 1 && !nonNull(mCaFilename)) {                  VpnStatus.logMessage(VpnStatus.LogLevel.ERROR, "", context.getString(R.string.keychain_nocacert));              } else { @@ -621,31 +631,39 @@ public class VpnProfile implements Serializable {              return new String[]{ca, extra, user};          } catch (InterruptedException e) { -            e.printStackTrace(); +            exp=e;          } catch (FileNotFoundException e) { -            e.printStackTrace(); +            exp=e;          } catch (CertificateException e) { -            e.printStackTrace(); +            exp=e;          } catch (IOException e) { -            e.printStackTrace(); +            exp=e;          } catch (KeyChainException e) { -            VpnStatus.logError(R.string.keychain_access); -            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { -                if (!mAlias.matches("^[a-zA-Z0-9]$")) { -                    VpnStatus.logError(R.string.jelly_keystore_alphanumeric_bug); -                } -            } +            exp=e; +        } catch (NoCertReturnedException e) { +            exp =e;          } catch (AssertionError e) {              if (tries ==0)                  return null;              Toast.makeText(context, String.format("Failure getting Keystore Keys (%s), retrying",e.getLocalizedMessage()),Toast.LENGTH_LONG).show();              try { -                Thread.sleep(300); +                Thread.sleep(3000);              } catch (InterruptedException e1) {                  e1.printStackTrace();              }              return getKeyStoreCertificates(context, tries-1);          } +        if (exp != null) { +            exp.printStackTrace(); +            VpnStatus.logError(R.string.keyChainAccessError, exp.getLocalizedMessage()); + +            VpnStatus.logError(R.string.keychain_access); +            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { +                if (!mAlias.matches("^[a-zA-Z0-9]$")) { +                    VpnStatus.logError(R.string.jelly_keystore_alphanumeric_bug); +                } +            } +        }          return null;      }  | 
