【问题标题】:Encrypting mdm profile加密 mdm 配置文件
【发布时间】:2013-08-23 14:49:29
【问题描述】:

我在这里看到了有关签署和加密最终 mdm 配置文件的问题: iOS MDM profile signing, which certificate to use?

我正在使用 Bouncy Castle 库进行加密。目前我在使用 scep 身份证书加密最终配置文件时卡住了。

我面临以下问题。

  1. 使用 scep 响应证书检索的公钥不是 16 字节(128 位),因此加密失败,消息密钥应为 128 位。

  2. 如果我可以使用以下代码将公钥更改为 16 字节,则设备会抛出无效的配置文件 dailog。

    public static string getKeyMessageDigest(string key)
         {
             byte[] ByteData = Encoding.UTF8.GetBytes(key);
             //MD5 creating MD5 object.
             MD5 oMd5 = MD5.Create();
             byte[] HashData = oMd5.ComputeHash(ByteData);
    
             //convert byte array to hex format
             StringBuilder oSb = new StringBuilder();
             for (int x = 0; x < HashData.Length; x++)
             {
                 //hexadecimal string value
                 oSb.Append(HashData[x].ToString("x2"));
             }
             return Convert.ToString(oSb);
         }
    

有人可以帮我写一些博客或示例代码来加密配置文件吗?感谢您的帮助。

【问题讨论】:

    标签: c# ios certificate mdm


    【解决方案1】:

    我遇到了类似的问题。 PFB 我现在用来加密的工作代码。我正在从设备响应中检索签名证书,从中检索公钥并使用它进行加密。

    byte[] request = StreamToByte(ResponseFromDevice);
    var signer = new SignedCms();
    signer.Decode(request);
    X509Certificate2 certificate = signer.Certificates[0];
    string xmlData = "payload string to encrypt";
    
    Byte[] cleartextsbyte = UTF8Encoding.UTF8.GetBytes(xmlData);
    ContentInfo contentinfo = new ContentInfo(cleartextsbyte);
    EnvelopedCms envelopedCms = new EnvelopedCms(contentinfo);
    CmsRecipient recipient = new CmsRecipient(certificate);
    envelopedCms.Encrypt(recipient);
    string data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>EncryptedPayloadContent</key><data>[ENCRYPTEDDATA]</data><key>PayloadDescription</key><string>For profile enrollment</string><key>PayloadDisplayName</key><string>ProfileName</string><key>PayloadIdentifier</key><string>YourIdentifier</string><key>PayloadOrganization</key><string>YourOrg</string><key>PayloadRemovalDisallowed</key><false/><key>PayloadType</key><string>Configuration</string><key>PayloadUUID</key><string>YourUDID/string><key>PayloadVersion</key><integer>1</integer></dict></plist>";
    data = data.Replace("[ENCRYPTEDDATA]", Convert.ToBase64String(envelopedCms.Encode()));
    HttpContext.Current.Response.Write(data);
    WebOperationContext.Current.OutgoingResponse.ContentType = "application/x-apple-aspen-config";
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
    

    【讨论】:

    • +1 你是超级明星!我已经为此苦苦挣扎了一段时间。我有完全相同的解决方案,但错过了来自EncryptedPayloadContentEncrypted。这到底是在哪里记录的?!无论如何,感谢您的帮助!
    【解决方案2】:

    我在 cmets 中回答了你之前的问题:

    “我建议看看 OS X Server MDM 实现。

    一般来说加密配置文件,我记得你应该使用 PKCS7 包装。所以,你应该看看这个:http://www.cs.berkeley.edu/~jonah/bc/org/bouncycastle/jce/PKCS7SignedData.html

    顺便说一句。如果您想大致了解一下,我建议您阅读一点密码学知识。您的问题的非常高级的概述:您正在尝试直接使用 RSA 密钥来加密数据。但是,它应该用于加密对称密钥,而对称密钥又用于加密数据。”

    你也可以看看这里: PKCS#7 Encryption

    您的代码不起作用,因为它是 - 不是 PKCS7 - 您正在尝试使用没有任何意义的 MD5(公共证书密钥)

    我真的-真的建议再次阅读 MDM 文档和一些关于密码学的东西。很容易出错(无论是非工作还是不安全的实现)。

    【讨论】:

      【解决方案3】:

      在 bouncycastle 中,您必须使用 CMSAlgorithm.DES_EDE3_CBC 对其进行加密。然后像您在上一步中所做的那样对数据进行签名。确保在签名之前对加密的有效负载进行 Base64 编码。

      【讨论】:

        猜你喜欢
        • 2014-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多