Different S/MIME signature between OpenSSL and C#

后端 未结 1 513
南笙
南笙 2020-12-11 23:29

I\'m trying to use an OpenSSL code in my .Net program. Here\'s the code:

openssl pkcs12 -in \"My PassKit Cert.p12\"          


        
相关标签:
1条回答
  • 2020-12-12 00:11

    I got this working in the end!

    First, you must go here, and install the apple ROOT cert:

    http://www.apple.com/certificateauthority/

    (it's the first one). Install it into your trusted root authority. A Mac already has this.

    Second, install the developer cert as a trusted root authority, which is in the developer portal, where you go to add devices, make passkit keys, all that

    https://developer.apple.com/ios/manage/certificates/team/index.action

    (you need a login for that)

    then you need to generate your passkit key in the dev portal, download it, install it on your mac, then export it WITH the private key as a .p12 file.

    you can then move this file to the windows machine and use it. I used this code, after generating the manifest:

    var cert = new X509Certificate2(@"path-to-your.p12", "password");
    
    var buffer = File.ReadAllBytes(Path.Combine(basePath, "manifest.json"));
    
    ContentInfo cont = new ContentInfo(buffer);
    var cms = new SignedCms(cont, true);
    var signer = new CmsSigner(SubjectIdentifierType.SubjectKeyIdentifier, cert);
    
    signer.IncludeOption = X509IncludeOption.ExcludeRoot;
    
    cms.ComputeSignature(signer);
    
    var myCmsMessage = cms.Encode();
    
    
    File.WriteAllBytes(Path.Combine(basePath, "signature"), myCmsMessage);
    

    Sorry, this is rather messy code, but it works :)

    Don't forget to set

    "passTypeIdentifier" : "pass.com.yourcompany.NameOfYourPass", "teamIdentifier" : "YOUR TEAM ID",

    in the pass.json!

    0 讨论(0)
提交回复
热议问题