当前位置: 首页>>代码示例>>Java>>正文


Java KeyChainException类代码示例

本文整理汇总了Java中android.security.KeyChainException的典型用法代码示例。如果您正苦于以下问题:Java KeyChainException类的具体用法?Java KeyChainException怎么用?Java KeyChainException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyChainException类属于android.security包,在下文中一共展示了KeyChainException类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchCertificateChain

import android.security.KeyChainException; //导入依赖的package包/类
private X509Certificate[] fetchCertificateChain(Context context, String alias)
        throws KeyChainException, InterruptedException, MessagingException {

    X509Certificate[] chain = KeyChain.getCertificateChain(context, alias);
    if (chain == null || chain.length == 0) {
        throw new MessagingException("No certificate chain found for: " + alias);
    }
    try {
        for (X509Certificate certificate : chain) {
            certificate.checkValidity();
        }
    } catch (CertificateException e) {
        throw new CertificateValidationException(e.getMessage(), Reason.Expired, alias);
    }

    return chain;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:18,代码来源:KeyChainKeyManager.java

示例2: fetchPrivateKey

import android.security.KeyChainException; //导入依赖的package包/类
private PrivateKey fetchPrivateKey(Context context, String alias) throws KeyChainException,
        InterruptedException, MessagingException {

    PrivateKey privateKey = KeyChain.getPrivateKey(context, alias);
    if (privateKey == null) {
        throw new MessagingException("No private key found for: " + alias);
    }

    /*
     * We need to keep reference to the first private key retrieved so
     * it won't get garbage collected. If it will then the whole app
     * will crash on Android < 4.2 with "Fatal signal 11 code=1". See
     * https://code.google.com/p/android/issues/detail?id=62319
     */
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        savePrivateKeyReference(privateKey);
    }

    return privateKey;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:21,代码来源:KeyChainKeyManager.java

示例3: fetchCertificateChain

import android.security.KeyChainException; //导入依赖的package包/类
private X509Certificate[] fetchCertificateChain(Context context, String alias)
        throws KeyChainException, InterruptedException, MessagingException {

    X509Certificate[] chain = KeyChain.getCertificateChain(context, alias);
    if (chain == null || chain.length == 0) {
        throw new MessagingException("No certificate chain found for: " + alias);
    }
    try {
        for (X509Certificate certificate : chain) {
            certificate.checkValidity();
        }
    } catch (CertificateException e) {
        // Client certificate has expired or is not yet valid
        throw new CertificateValidationException(context.getString(R.string.client_certificate_expired, alias, e.toString()));
    }

    return chain;
}
 
开发者ID:daxslab,项目名称:daxSmail,代码行数:19,代码来源:KeyChainKeyManager.java

示例4: updateSslClientCertSummary

import android.security.KeyChainException; //导入依赖的package包/类
private void updateSslClientCertSummary(final Preference sslClientCert) {
    final String certAlias = getPreferenceString(sslClientCert, null);

    new AsyncTask<Preference, Void, X509Certificate>() {
        @Override
        protected X509Certificate doInBackground(Preference... preferences) {
            try {
                if (certAlias != null) {
                    X509Certificate[] certificates = KeyChain.getCertificateChain(
                            getActivity(), certAlias);
                    if (certificates != null && certificates.length > 0) {
                        return certificates[0];
                    }
                }
                return null;
            } catch (KeyChainException | InterruptedException e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        protected void onPostExecute(X509Certificate x509Certificate) {
            if (x509Certificate != null) {
                sslClientCert.setSummary(x509Certificate.getSubjectDN().toString());
            } else {
                sslClientCert.setSummary(getString(R.string.settings_openhab_none));
            }
        }
    }.execute(sslClientCert);
}
 
开发者ID:openhab,项目名称:openhab-android,代码行数:32,代码来源:OpenHABPreferencesActivity.java

示例5: MyKeyManager

import android.security.KeyChainException; //导入依赖的package包/类
private MyKeyManager(final Context ctx) {

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
        final String preferencesAlias = preferences.getString(Constants.PREFERENCE_SSLCLIENTCERT, null);

        if (preferencesAlias == null) {
            alias = null;
            certificateChain = null;
            privateKey = null;
            return;
        }

        if (!preferencesAlias.equals(alias) || certificateChain == null || privateKey == null) {

            // refresh cached certificate and  keys
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        certificateChain = KeyChain.getCertificateChain(ctx, preferencesAlias);
                        privateKey = KeyChain.getPrivateKey(ctx, preferencesAlias);
                        alias = preferencesAlias;
                    } catch (KeyChainException | InterruptedException e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }).start();
        }
    }
 
开发者ID:openhab,项目名称:openhab-android,代码行数:30,代码来源:MyKeyManager.java

示例6: scanForCause

import android.security.KeyChainException; //导入依赖的package包/类
private void scanForCause() {
    Throwable throwable = getCause();

    /*
     * User attention is required if the server certificate was deemed
     * invalid or if there was a problem with a client certificate.
     *
     * A CertificateException is known to be thrown by the default
     * X509TrustManager.checkServerTrusted() if the server certificate
     * doesn't validate. The cause of the CertificateException will be a
     * CertPathValidatorException. However, it's unlikely those exceptions
     * will be encountered here, because they are caught in
     * SecureX509TrustManager.checkServerTrusted(), which throws a
     * CertificateChainException instead (an extension of
     * CertificateException).
     *
     * A CertificateChainException will likely result in (or, be the cause
     * of) an SSLHandshakeException (an extension of SSLException).
     *
     * The various mail protocol handlers (IMAP, POP3, ...) will catch an
     * SSLException and throw a CertificateValidationException (this class)
     * with the SSLException as the cause. (They may also throw a
     * CertificateValidationException when STARTTLS is not available, just
     * for the purpose of triggering a user notification.)
     *
     * SSLHandshakeException is also known to occur if the *client*
     * certificate was not accepted by the server (unknown CA, certificate
     * expired, etc.). In this case, the SSLHandshakeException will not have
     * a CertificateChainException as a cause.
     *
     * KeyChainException is known to occur if the device has no client
     * certificate that's associated with the alias stored in the server
     * settings.
     */
    while (throwable != null
            && !(throwable instanceof CertPathValidatorException)
            && !(throwable instanceof CertificateException)
            && !(throwable instanceof KeyChainException)
            && !(throwable instanceof SSLHandshakeException)) {
        throwable = throwable.getCause();
    }

    if (throwable != null) {
        mNeedsUserAttention = true;

        // See if there is a server certificate chain attached to the SSLHandshakeException
        if (throwable instanceof SSLHandshakeException) {
            while (throwable != null && !(throwable instanceof CertificateChainException)) {
              throwable = throwable.getCause();
            }
        }

        if (throwable != null && throwable instanceof CertificateChainException) {
            mCertChain = ((CertificateChainException) throwable).getCertChain();
        }
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:58,代码来源:CertificateValidationException.java

示例7: signWithAlias

import android.security.KeyChainException; //导入依赖的package包/类
public void signWithAlias(final String path, 
    final String alias, 
    final String name, 
    final String location, 
    final String reason, 
    byte[] imageData,
    int page,
    float x,
    float y,
    float width,
    float height) throws IOException, InterruptedException, KeyChainException 
{
  byte[] buffer = new byte[BUFFER_SIZE];

  this.callbackContext = callbackContext;
  privKey = KeyChain.getPrivateKey(context, alias);
  Certificate[] chain = KeyChain.getCertificateChain(context, alias);
  File document = new File(path);

  if (!(document != null && document.exists()))
    new RuntimeException("");


  Signature signature = new Signature(chain, privKey);
  File outputPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
  outputPath.mkdirs();
  if (imageData.length > 0) {
    ByteArrayInputStream image = new ByteArrayInputStream(imageData);
    signature.setVisual(image, page, x, y, width, height);
    System.err.println("page " + page + ":" + x + "," + y + " " + width + "x" + height);
  }
  signature.sign(path, outputPath.getAbsolutePath(), name, location, reason);

  File outputDocument = new File(outputPath.getAbsolutePath() + "/" + document.getName() + ".signed.pdf");
  File resultDocument = new File(path);
  File removeDocument = new File(document.getPath() + ".unsigned.pdf");

  document.renameTo(removeDocument);
  outputDocument.renameTo(resultDocument);

  return;
}
 
开发者ID:KodeKreatif,项目名称:cordova-plugin-pdfdigisign,代码行数:43,代码来源:PDFDigiSign.java


注:本文中的android.security.KeyChainException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。