blackberry - 使用 BlackBerry App 安装 SSL 证书

标签 blackberry ssl ssl-certificate

我们有一个 BlackBerry 应用程序可以访问使用 SSL 证书的安全 Web 服务,但某些 BlackBerry OS5 设备上并未安装该证书。这会给看到此消息的我们应用程序的用户带来问题。

“您正在尝试打开安全连接,但服务器的证书不受信任。”

我们可以通过这种方式手动安装证书

https://search.thawte.com/support/ssl-digital-certificates/index?page=content&id=SO4477&actp=search&viewlocale=en_US&searchid=1328216150785

但这对我们的客户来说显然不是一个好的解决方案。

有没有办法用应用程序打包和安装所需的证书?此证书适用于 iOS、Android、IE、Firefox 和 Chrome。

最佳答案

您可以将证书 X509 作为资源包含在代码包中,并将其放入 keystore 中。但是用户将不得不手动进入他们的证书存储并信任它。如果用户之前没有使用过证书存储,这将产生不幸的副作用,即迫使他们在此时选择密码。

以下代码将从 PEM 格式的资源文件中读取证书,但删除了 -----BEGIN/END CERTIFICATE----- 行。我已经使用了这段代码的所有元素,但不是在这个确切的配置中。如果有任何问题,我很乐意尝试解决。

证书将不受信任,因此用户必须手动进入设备选项下的证书存储应用程序并“信任”证书。确保他们了解他们无法撤销证书。如果不删除并重新安装操作系统,则无法在设备上撤消该操作。唯一的其他选择是重新颁发新证书。

如果有人知道如何解决这些挑剔的问题,请告诉我,我会将解决方案包含在此代码中,或链接到现在存在的任何地方。

X509Certificate _x509;

try {
    // Get an input stream for the certificate in a resource file
    InputStream rs = getClass().getResourceAsStream("/certificate.pem");

    // PEM format is Base64 encoded
    Base64InputStream b64is = new Base64InputStream(rs);

    // Create the X509 certificate
    _x509 = new X509Certificate(b64is);

    // Clean up.
    b64is.close();
    rs.close();

    // if the certificate is self signed this will perform a 
    // verfication check. For non-self signed certificates
    // one could provide the signer's certificate in another
    // resource file and validate it with that public key. Other
    // versions of verify will verify it with a certificate in
    // a keystore, but then we wouldn't need to do all this.
    _x509.verify(_x509.getPublicKey());
    System.out.println(_x509.getSubjectFriendlyName());
    System.out.println(Integer.toHexString(_x509.hashCode()));

    // Add the certificate to the DeviceKeyStore
    KeyStore ks = DeviceKeyStore.getInstance();

    // Associated data is set to null, but can be used if there is associated
    // data known. You can use _x509.getStatus() instead of encoding the GOOD
    // constant, but if the device can not find a revokation or validation list
    // it will set the status to UNKNOWN which will confuse users. ks.getTicket()
    // will prompt the user for permission for the program to access the key store.
    // This may also cause the system to ask the user to set a password, unfortunately
    // I can't remember, but I don't think it will if there is no private key in the
    // certificate.
    ks.set(null, _x509.getSubjectFriendlyName(), _x509, CertificateStatus.GOOD, 
       ks.getTicket() );
} catch (CertificateException ce) {
    System.out.println(ce.toString());
} catch (CryptoException crypt) {
    System.out.println(crypt);
} catch (IOException ioe) {
    System.out.println(ioe.toString());
}

关于blackberry - 使用 BlackBerry App 安装 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9132234/

相关文章:

php - Azure 上的 Drupal update.php 抛出错误 "Could not connect to server"

wordpress - 在 wordpress 站点上使用共享 SSL

java - 我如何在 Blackberry 中执行 http get 请求

deployment - 如何使用 Loader.exe 正确强制安装 Blackberry Java 应用程序

blackberry - 如何在 Blackberry MapField 中显示多个位置?

security - 使用 WSS 进行身份验证然后使用 WS 进行数据有意义吗?

azure - 动态访问从云服务上传到Azure门户的证书

certificate - 邮件服务器上的 SSL 证书是否会降低电子邮件被分类为垃圾邮件的可能性?

ssl - 如何将 Cpanel 自动生成的 SSL 下载为(key.pem 和 cert.pem)

java - 在 J2ME/BlackBerry 应用程序中解析 cookie header