2016-02-23 32 views
3

好吧,我們都知道,即​​將發生的情況是,根據news release,情人節當天(即我稱之爲「開發者之愛」)的Apple WWDR證書已過期來自Apple。Safari Push Package:如何修復Apple過期的WWDR證書

我使用C#爲Safari生成推送包,並且,意外,這不起作用。這是我在我的記錄終點得到,而不是消息:

{「日誌」:「推包的簽名驗證失敗」]}

這是怎麼了我的老PKCS#7簽名代碼如下所示:

// Sign the message with the private key of the signer. 
static byte[] PKCS7SignMessage(byte[] message, X509Certificate2 signerCertificate) 
{ 
    // Place message in a ContentInfo object. 
    // This is required to build a SignedCms object. 
    ContentInfo contentInfo = new ContentInfo(message); 

    // Instantiate SignedCms object with the ContentInfo above. 
    // Has default SubjectIdentifierType IssuerAndSerialNumber. 
    // Has default Detached property value false, so message is 
    // included in the encoded SignedCms. 
    SignedCms signedCms = new SignedCms(contentInfo, true); 

    // Formulate a CmsSigner object for the signer. 
    CmsSigner cmsSigner = new CmsSigner(signerCertificate); 
    cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;   

    // Sign the CMS/PKCS #7 message. 
    signedCms.ComputeSignature(cmsSigner); 

    // Encode the CMS/PKCS #7 message. 
    return signedCms.Encode(); 
} 

Apple要求還「將路徑傳遞給更新的中間體以用於額外的證書參數」。

所以,我想這一點:

X509Certificate2 appleIntermediate = new X509Certificate2(); 
appleIntermediate.Import(@"Path-to-new-WWRD.cer"); 
cmsSigner.Certificates.Add(appleIntermediate); 

它沒有工作。(推包的簽名驗證失敗)

後來我試圖改變這一行:

cmsSigner.IncludeOption = X509IncludeOption.WholeChain; 

它沒有工作。我有一個例外說:

「一個證書鏈不能建立到信任的根權威」。

好吧,現在我決定:

  • 所有蘋果CA根證書添加到本地計算機的受信任的證書存儲區。
  • 將更新的WWRD證書添加到本地計算機的中間證書存儲區。
  • 重新啓動過程並再次嘗試代碼。好消息是,它現在正在重新簽名,理論上包括整個證書鏈。

但它沒有工作。(推包的簽名驗證失敗)

據蘋果公司稱,固定這本是小菜一碟:

Safari瀏覽器推送通知

更新您的通知包簽名服務器,包括您的網站推送證書和更新後的中間證書。在此日期之後,新用戶將無法註冊您的網站的推送通知,直到您的服務器更新完畢。如果您使用openssl_pkcs7_sign函數僅使用Web推送證書對推送包進行簽名,則應該將路徑傳遞給更新的中間體以獲取額外的證書參數。

現在,在計劃英語中意味着什麼? 我該如何將它應用到C#上下文中?

+0

你是否設法找到解決方案? – JonSquared

+1

@JonSquared還沒有。我決定不給這個優先考慮,因爲Safari沒有很大的市場份額。只要Firefox和Chrome繼續爲我提供良好的Push消息支持,我可以對蘋果說f *這個詞。 –

回答

0

蘋果不希望整個鏈。他們只期望你的證書,以及他們的中間證書被包括在內。所以你的代碼應該看起來像這樣:

static public byte[] PKCS7SignMessage(byte[] manifest_data, X509Certificate2 signerCertificate) { 
     X509Certificate2Collection ca_chain; 
     ContentInfo content; 
     SignedCms signed_cms; 
     CmsSigner signer; 

     signed_cms = new SignedCms(); 

     ca_chain = new X509Certificate2Collection(new X509Certificate2(@"Path-to-new-intermediate-WWRD.cer")); 

     content = new ContentInfo(manifest_data); 

     signed_cms = new SignedCms(content, true); 

     signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signerCertificate); 
     signer.IncludeOption = X509IncludeOption.ExcludeRoot; 
     signer.Certificates.AddRange(ca_chain); 

     signed_cms.ComputeSignature(signer); 

     return signed_cms.Encode(); 
    }