使用Ruby on Rails签署iPhone配置XML配置文件

我正在生成一个有效的iPhone配置XML配置文件,并通过Rails页面提供它。

我试图弄清楚如何使用x509证书以编程方式对XML文件进行签名,以便iPhone将其识别为签名的配置文件

这是关于签署iPhone配置文件所涉及内容的一个很好的教程http://www.rootmanager.com/iphone-ota-configuration/iphone-ota-setup-with-signed-mobileconfig.html

具体来说,在命令行上执行此操作将对未签名文件company.mobileconfig进行签名

openssl smime -sign -in company.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key -certfile cert-chain.crt -outform der -nodetach

假设我在字符串中有XML文件,那么Ruby on Rails中的等效命令会是什么? 我可以找到很多关于通过带有rails的SSL连接提供内容的文档,但是在交付之前没有很多关于签署任意内容的文档。

下面的代码行将签署iPhone配置XML Profile。

 ssl_key_str = File.read("/path/to/private.key”) ssl_key = OpenSSL::PKey::RSA.new(ssl_key_str) ssl_cert_str = File.read("/path/to/certificate.crt”) ssl_cert = OpenSSL::X509::Certificate.new(ssl_cert_str) profile = File.read("/path/to/profile.mobileconfig") signed_profile = OpenSSL::PKCS7.sign(ssl_cert, ssl_key, profile, [], OpenSSL::PKCS7::BINARY) 

只是一个FYI – 我必须添加to_der到最后让我的工作:

 sign = OpenSSL::PKCS7.sign(cert, key, profile, [], OpenSSL::PKCS7::BINARY).to_der