tomasmcguinness / dotnet-passbook

A .Net Library for generating Apple Passbook (Wallet) files for iOS. Please get involved by creating pull requests and opening issues!
MIT License
319 stars 117 forks source link

Issue while Signing the Passbook certificate #178

Closed ahmadbjanthala closed 1 year ago

ahmadbjanthala commented 1 year ago

Hi, I can't get the pass to be signed by the certificates and I'm not sure what's wrong! I followed the instructions on README.md file and i got the two certificates: 1- Passbook certificate 2- Apple WWDR G4

I got error on this line:
generator.Generate(request); Passbook.Generator.Exceptions.ManifestSigningException: 'Failed to sign manifest'

I found out on the debug that the passbook certificate doesn't have a private key request.PassbookCertificate.PrivateKey is null

so i tried to sign that passbook certificate using openssl with new private key I created and i got error on this line: request.PassbookCertificate = new X509Certificate2(passCertbytes, "Password"); Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException: 'Cannot find the requested object.'

I'm using this code :

        PassGenerator generator = new PassGenerator();

        PassGeneratorRequest request = new PassGeneratorRequest();
        request.PassTypeIdentifier = "pass.com.varyan.0exqz";
        request.TeamIdentifier = "RW121242";
        request.SerialNumber = "121212";
        request.Description = "My first pass";
        request.OrganizationName = "0EXQ";
        request.LogoText = "0EXQZ Pass";

        request.BackgroundColor = "#FFFFFF";
        request.LabelColor = "#000000";
        request.ForegroundColor = "#000000";

        var fileName = _env.WebRootPath + "AppleWWDRCA.cer";
        var applecertbytes = await System.IO.File.ReadAllBytesAsync(fileName);
        request.AppleWWDRCACertificate = new X509Certificate2(applecertbytes);

        fileName = _env.WebRootPath + "pass_nocommon.p12";
        var passCertbytes = await System.IO.File.ReadAllBytesAsync(fileName);
        request.PassbookCertificate = new X509Certificate2(passCertbytes, "Test123!@#");

        request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(_env.WebRootPath + ("icon.png")));
        request.Images.Add(PassbookImage.Icon2X, System.IO.File.ReadAllBytes(_env.WebRootPath + ("icon@2x.png")));
        request.Images.Add(PassbookImage.Icon3X, System.IO.File.ReadAllBytes(_env.WebRootPath + ("icon@3x.png")));

        request.Style = PassStyle.Generic;
        request.AddPrimaryField(new StandardField("origin", "San Francisco", "SFO"));
        request.AddPrimaryField(new StandardField("destination", "London", "LDN"));

        request.AddSecondaryField(new StandardField("boarding-gate", "Gate", "A55"));

        request.AddAuxiliaryField(new StandardField("seat", "Seat", "G5"));
        request.AddAuxiliaryField(new StandardField("passenger-name", "Passenger", "Thomas Anderson"));
        request.AddBarcode(BarcodeType.PKBarcodeFormatPDF417, "01927847623423234234", "ISO-8859-1", "01927847623423234234");

        byte[] generatedPass = generator.Generate(request);

        Debug.WriteLine(generatedPass);

        var contentType = "APPLICATION/octet-stream";
        var rfileName = "vnd.apple.pkpass";
        return File(generatedPass, contentType, rfileName);
tomasmcguinness commented 1 year ago

Hi. You need to use the Passbook certificate to sign your pass. This should have the private key.