【问题标题】:Client certificat bug with Jelly beans果冻豆的客户端证书错误
【发布时间】:2012-08-22 16:18:52
【问题描述】:

在 Android 中,我使用具有相互身份验证的 TLS 连接和使用此代码创建的客户端证书。

private static X509Certificate generateX509V1Certificate(KeyPair pair, SecureRandom sr)
{
  String dn="CN="+sUuid.toString();
  final Calendar calendar = Calendar.getInstance();
  calendar.add(Calendar.HOUR, -1);
  final Date startDate = new Date(calendar.getTimeInMillis());
  calendar.add(Calendar.YEAR, 1);
  final Date expiryDate = new Date(calendar.getTimeInMillis());
  final BigInteger serialNumber =   
    BigInteger.valueOf(Math.abs(System.currentTimeMillis()));
  X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
  X500Principal dnName = new X500Principal(dn);
  certGen.setSerialNumber(serialNumber);
  certGen.setIssuerDN(dnName);
  certGen.setNotBefore(startDate);
  certGen.setNotAfter(expiryDate);
  certGen.setSubjectDN(dnName); // note: same as issuer
  certGen.setPublicKey(pair.getPublic());
  certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
  if (VERSION.SDK_INT<VERSION_CODES.GINGERBREAD)
    return certGen.generateX509Certificate(pair.getPrivate(), "BC");
  else
    return  certGen.generate(pair.getPrivate(), sr);
}

密钥对算法是“RSA”。 密码算法是“RSA/ECB/PKCS1Padding”。

在Jelly Bean版本之前可以正常使用。

使用 Jelly bean,我在调用时收到错误

socket.getSession().getPeerCertificates()

进程在日志中被杀死:

E/NativeCrypto(1133): error:140C10F7:SSL routines:SSL_SET_PKEY:unknown certificate type
A/libc(1133): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1233 (AsyncTask #1)

我不知道如何解决这个错误。

你能帮帮我吗?

【问题讨论】:

    标签: android certificate ssl


    【解决方案1】:

    我刚刚遇到了这个问题,还有一个出现以下错误: 致命信号 11 (SIGSEGV) 位于 0x3f80005c (code=1),线程 11709 (FinalizerDaemon)

    当我在 Galaxy S3 上升级到 4.1.1 时,它们开始随机发生,该应用程序通过使用来自 KeyChain API 的密钥来使用客户端 SSL 身份验证。

    它在 4.0.4 上运行良好(幸运的是我设法降级了)。

    我不是 100% 确定,但 4.1.1 似乎有很多与 SSL 相关的错误 - 请检查这个:http://code.google.com/p/android/issues/detail?id=35141 还有这个:http://code.google.com/p/android/issues/detail?id=34577(可能与当前案例无关) 同样在这个论坛帖子中:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/Lj2iHX4prds 在对从 KeyChain API 返回的 PrivateKey 对象执行 GC 时,提到了 SEGFAULT。

    因此,作为最后的建议 - 尽可能长时间使用 4.0.4 或转到 4.1.2 - 似乎修复了一些错误。

    我还可以确认,我遇到的两个问题在 4.1.2 模拟器上不存在。 Galaxy S3 没有 4.1.2 图像,因此我无法确认它们是针对真实设备修复的(没有其他设备)。

    希望可以。

    【讨论】:

      【解决方案2】:

      将生成的证书转储到文件中并尝试在 OpenSSL 1.0 中解析它。这与 Android 用于解析证书的代码相同,因此它应该可以帮助您找到错误。也许他们根本不再支持 v1 证书,您可以尝试生成 v3 证书。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-12
        • 2011-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-29
        相关资源
        最近更新 更多