Jelly Bean存在客户端证书错误问题

4

通过使用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)

我不知道如何解决这个bug。

你能帮我吗?

2个回答

2
我刚遇到了一个问题,还有一个错误信息如下: 致命信号11(SIGSEGV)在0x3f80005c处(代码=1),线程11709(FinalizerDaemon)
当我在Galaxy S3上升级到4.1.1并使用客户端SSL身份验证时,这些问题开始随机发生,通过使用KeyChain API从密钥中获取。
在4.0.4上它运行良好(幸运的是我成功降级)。
我不是100%确定,但4.1.1似乎有很多与SSL相关的bug - 可以检查这个: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证书。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接