简体   繁体   English

将pkcs12插入mobileconfig文件

[英]Insert pkcs12 to mobileconfig file

How do I insert a .p12 file in a .mobileconfig file ? 如何在.mobileconfig文件中插入.p12文件?

Apple configuration utility currently performs some unknown transformation/encoding on the .p12 file while inserting it in .mobileconfig (It is just an XML file). Apple配置实用程序当前在.p12文件中执行一些未知的转换/编码,同时将其插入.mobileconfig (它只是一个XML文件)。

I want to create this .mobileconfig file without using the Apple iPhone configuration utility by directly creating an XML file. 我想通过直接创建XML文件而不使用Apple iPhone配置实用程序来创建此.mobileconfig文件。

Thanks 谢谢

One way to accomplish this is base64 encoding the PKCS#12 file. 实现此目的的一种方法是base64编码PKCS#12文件。 This, for instance, works with PHP 例如,这适用于PHP

openssl_pkcs12_export( $strCertPEM, $strCertPkcs12, $resKey, $strCertPW );    
$arrCertBase64 = str_split( base64_encode($strCertPkcs12), 52);
$xmlUserCertPlist = plistVar('PayloadContent',$arrCertBase64,'data');

function plistVar($key,$var,$type)
{
  //...snip...
  if ( $type == 'data' ) return plistData($key,$var);
  //...snip...
}

function plistData($key,$arr)
{
  //...snip...
  $xml = "<key>". $key ."</key>\n";
  $xml .= "<data>\n";
  foreach ($arr as $val) { $xml .= $val."\n"; }
  $xml .= "</data>\n";
  return $xml;
}

If you want to insert the .p12 file inside the iphone configuration file you just have to select the credential tab on the iphone configuration utility of the selected configuration file. 如果要在iphone配置文件中插入.p12文件,只需在所选配置文件的iphone配置实用程序中选择凭据选项卡。 When you 当你 配置 it will 它会 请求.p12文件 to attach on the .mobileConfig File. 附加到.mobileConfig文件。

I have configuration file created using iphone configuration utility.Following will get changed when you attached the .p12 file into your configuration file. 我有使用iphone配置实用程序创建的配置文件。当您将.p12文件附加到配置文件中时,将会更改。

The following dictionary will get attached to the xml file after the creation of the .mobileconfig file 创建.mobileconfig文件后,以下字典将附加到xml文件

Password password_value PayloadCertificateFileName certificate_name.p12 PayloadContent //converted data from the certificate 密码password_value PayloadCertificateFileName certificate_name.p12 PayloadContent //来自证书的转换数据

        </data>
        <key>PayloadDescription</key>
        <string>Provides device authentication (certificate or identity).</string>
        <key>PayloadDisplayName</key>
        <string>Certificate_name.p12</string>
        <key>PayloadIdentifier</key>
        <string>company.Identifier</string>
        <key>PayloadOrganization</key>
        <string>Company name</string>
        <key>PayloadType</key>
        <string>com.apple.security.pkcs12</string>
        <key>PayloadUUID</key>
        <string>UUId of the device</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
    </dict>

In addition to steps mentioned by Anil, read binary data from pkcs12 certificate and then encode it using base64 encoding. 除了Anil提到的步骤之外,从pkcs12证书读取二进制数据,然后使用base64编码对其进行编码。 You can put that data in the xml mentioned by Anil. 您可以将该数据放在Anil提到的xml中。

<data>base64 encoded data
</data>

I happen to be working through this right now in my current position, deploying scripts to generate n.mobileconfig files for Mac OS workstations. 我正好在目前的位置正在解决这个问题,部署脚本为Mac OS工作站生成n.mobileconfig文件。

It helps to reference the official Apple documentation on 802.1X Authentcation , as they do provide an XML template and notes about it. 它有助于参考802.1X Authentcation上的官方Apple文档,因为它们提供了一个XML模板及其相关说明。 Also, referenced in many other places is mactls.sh . 此外,在许多其他地方引用的是mactls.sh I used that template to generate my mobileconfigs. 我使用该模板生成我的mobileconfigs。

To get the base64 content of the pkcs12 file, cat the existing pkcs12 file into openssl: 要获取pkcs12文件的base64内容,请将现有的pkcs12文件捕获到openssl:

B64PK12=$(cat ${PK12} | openssl enc -base64);

Use that variable to interpolate into your XML, provided you are using templates for your mobileconfig files. 如果您使用的是mobileconfig文件的模板,请使用该变量插入到XML中。

I was including both RADIUS CA and the decrypted PKCS12 file contents initially, with only the CA being imported, despite it not being base64 encoded. 我最初包括RADIUS CA和解密的PKCS12文件内容,只有CA被导入,尽管它不是base64编码的。 After base64 encoding both the CA and the pkcs12 contents, both were then added to the specified Keychain. 在base64编码CA和pkcs12内容之后,两者都被添加到指定的Keychain中。

Hope this helps. 希望这可以帮助。

You can use an apple script for creating a mobileconfig with the p12 inside. 您可以使用Apple脚本创建内置p12的mobileconfig。 I've been able to do it and it works great. 我已经能够做到这一点并且效果很好。 I'm afraid I can't share the code, but I can say it works. 我担心我无法分享代码,但我可以说它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM