【发布时间】:2014-06-23 18:02:00
【问题描述】:
我正在尝试从 Android 设备向服务器发送 证书签名请求。服务器在 iOS 设备上正常工作,并使用 OpenSSL 遵循SCEP procedure。
所以这是我的问题: 我可以发送已签名的封装 CSR,但服务器无法读取封装的 CSR。我从服务器收到以下错误:
pki.rb:26:in initialize: Could not parse the PKCS7: header too long (ArgumentError)
相关的ruby服务器代码:
#receive object and put it in object data
[...]
# Verify Input Data
p7sign = OpenSSL::PKCS7.new(data)
store = OpenSSL::X509::Store.new
p7sign.verify(nil, store, nil, OpenSSL::PKCS7::NOVERIFY)
signers = p7sign.signers
# Encrypted data (LINE 26 :)
p7enc = OpenSSL::PKCS7.new(p7sign.data)
# Certificate Signing Request
csr = p7enc.decrypt(ssl.key, ssl.certificate)
# Signed Certificate
request = OpenSSL::X509::Request.new(csr)
Java 代码(Android):
我正在使用 Bouncy Castle 生成 CSR,并使用 Volley (Google) 来发送它。
主要:
//Generate PEM formated CSR
byte[] pemCsr = getPemFromCsr(generateCSR());
//Envelop it in a PKCS#7 object
byte[] envelopedData = getDerFromCMSEnvelopedData(envelopData(pemCsr));
//Sign it in a PKCS#7 object
byte[] signedData = getDerFromCMSSignedData(signData(envelopedData));
sendCsrRequest(signedData);
企业社会责任:
//Generate the CSR
private static PKCS10CertificationRequest genrateCertificationRequest(){
// Build the CN for the cert we
X500NameBuilder nameBld = new X500NameBuilder(BCStyle.INSTANCE);
nameBld.addRDN(BCStyle.CN, "cn");
nameBld.addRDN(BCStyle.O, "o");
nameBld.addRDN(BCStyle.NAME, "name");
X500Name principal = nameBld.build();
// Generate the certificate signing request (csr = PKCS10)
String sigAlg = "SHA1withRSA";
JcaContentSignerBuilder csb = new JcaContentSignerBuilder(sigAlg);
ContentSigner cs = csb.build(privateKey);
DERPrintableString password = new DERPrintableString("mychallenge");
PKCS10CertificationRequestBuilder crb = new JcaPKCS10CertificationRequestBuilder(principal, publicKey);
crb.addAttribute((ASN1ObjectIdentifier) PKCSObjectIdentifiers.pkcs_9_at_challengePassword, password);
PKCS10CertificationRequest csr = crb.build(cs);
return csr;
}
//Envelop the CSR
private static CMSEnvelopedData envelopData(byte[] pemCsr) {
CMSTypedData msg = new CMSProcessableByteArray(pemCsr);
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(x509Certificate).setProvider("BC"));
CMSEnvelopedData ed = edGen.generate(msg,new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider("BC").build());
return ed;
}
//Sign the enveloped CSR
private static CMSSignedData signData(byte[] data){
ContentSigner signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
generator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()).build(signer, (X509Certificate) x509Certificate));
CMSTypedData cmsdata = new CMSProcessableByteArray(data);
CMSSignedData signedData = generator.generate(cmsdata, true);
return signedData;
}
我已经准备好粘贴其他代码(Volley 请求、utils 转换器),但目前可能已经足够了。
SCEP 已经在 iOS 设备上运行,所以服务器很干净。 Ruby 可以创建签名的 PKCS#7,所以我想我的签名步骤是可以的。 但是如果我发送一个空的签名 PKCS#7,我会惊讶地遇到同样的错误。
提前感谢您的帮助。
【问题讨论】:
-
只是自行车脱落,但 SCEP 在这种情况下可能并不安全。一旦扩展了安全边界,增加了用户控制下的移动设备,协议就崩溃了。见The Use of the Simple Certificate Enrollment Protocol (SCEP) and Untrusted Devices。
-
@jww 我已经隐藏了挑战密码是动态生成的,只有在向服务器提交代码后才能访问。它是 pdf 修复的一部分,所以唷,应该没问题 :)
标签: java android ruby openssl mdm