Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported algorithm #25

Closed
Jornan opened this issue Mar 20, 2014 · 20 comments
Closed

Unsupported algorithm #25

Jornan opened this issue Mar 20, 2014 · 20 comments

Comments

@Jornan
Copy link

Jornan commented Mar 20, 2014

I have tried to implement this library and have used the following code (replacing "identifier", "thumbprint" and so on with my actual data):

        generator = new PassGenerator();
        request = new PassGeneratorRequest();
        request.PassTypeIdentifier = "identifier";
        request.TeamIdentifier = "myTeamIdentifier";
        request.SerialNumber = "serialNr";
        request.Description = "text";
        request.OrganizationName = "text";
        request.LogoText = "text";
        request.CertThumbprint = "thumbprint";
        request.CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser;

        request.BackgroundColor = "rgb(255,255,255)";
        request.ForegroundColor = "rgb(0,0,0)";

        request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\PassbookGenerator\Icons\Icon.png"));
        request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\PassbookGenerator\Icons\Icon@2x.png"));

        request.Style = PassStyle.Generic;

        request.AddPrimaryField(new StandardField("name", "", "Name"));

        request.AddSecondaryField(new StandardField("exercise", "Exercise", "Test"));

        request.AddAuxiliaryField(new StandardField("seat", "From date", "01-01-2014"));

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

When the last line of code is executed I get an ArgumentException saying "Unsupported algorithm specified". Any ida what I am doing wrong and how to fix it? The exception occurs in BountyCastle.Crypto.dll

@tomasmcguinness
Copy link
Owner

What sort of certificate are you using? Does it include the private key?

www.about.me/tomasmcguinness

On 20 Mar 2014, at 15:12, "Jornan" notifications@github.com wrote:

I have tried to implement this library and have used the following code (replacing "identifier", "thumbprint" and so on with my actual data):

    generator = new PassGenerator();
    request = new PassGeneratorRequest();
    request.PassTypeIdentifier = "identifier";
    request.TeamIdentifier = "myTeamIdentifier";
    request.SerialNumber = "serialNr";
    request.Description = "text";
    request.OrganizationName = "text";
    request.LogoText = "text";
    request.CertThumbprint = "thumbprint";
    request.CertLocation = System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser;

    request.BackgroundColor = "rgb(255,255,255)";
    request.ForegroundColor = "rgb(0,0,0)";

    request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\PassbookGenerator\Icons\Icon.png"));
    request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\PassbookGenerator\Icons\Icon@2x.png"));

    request.Style = PassStyle.Generic;

    request.AddPrimaryField(new StandardField("name", "", "Name"));

    request.AddSecondaryField(new StandardField("exercise", "Exercise", "Test"));

    request.AddAuxiliaryField(new StandardField("seat", "From date", "01-01-2014"));

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

When the last line of code is executed I get an ArgumentException saying "Unsupported algorithm specified". Any ida what I am doing wrong and how to fix it? The exception occurs in BountyCastle.Crypto.dll


Reply to this email directly or view it on GitHub.

@Jornan
Copy link
Author

Jornan commented Mar 22, 2014

Thanks for the reply. I am using the .cer certificate downloaded from the Apple Developer portal. I tried both using the certificate generated with my Mac and the one generated with Windows, following the guide you provided on your blog. Unfortunately, neither seems to work. The certificate on my Mac is tested using Apple's signpass command line tool and works problem free there.

Edit: I checked my certificate, it does not say that it has a private key. How do I obtain this?

@tomasmcguinness
Copy link
Owner

When you generate the certificate on a Mac, you need to export both the cert and key components. You do this by expanding the certificate row.

screen shot 2014-03-22 at 15 08 52

You much then select both the cert and key, before choosing Export. It should read "Export 2 items" You can then generate a p12 file. This will include both parts of the key.

If you've followed my guide about Windows certificates, you should end up with a PFX file containing both parts of the certificate. When performing the export it's important you choose to include the private key and to make the private key exportable. If you don't end up with a p12 or a pfx file, it won't include the private key.

@Jornan
Copy link
Author

Jornan commented Mar 24, 2014

That's the problem! Don't know what happened the last time, but I re-did the certificate process, and now it works. However, the same line of code still gives me an error message: "Object reference not set to an instance of an object". I wrapped the line of code in "if (request != null && generator != null)" to be sure that the request or generator actually is not null, but the code is still executed with the same error message.

@tomasmcguinness
Copy link
Owner

There is something missing then within the generation method. If you've generated a new certificate, did you make sure you updated the thumbprint value?

@Jornan
Copy link
Author

Jornan commented Mar 24, 2014

Yes, I checked the thumbprint value, I also checked that the new certificate in certmgr had the "This certificate has a private key ...". Do you have a list of everything that needs to be included in order for a proper pass to be generated? (for instance if some text fields are required, how many images and so on). Right now I have only included the Icon and IconRetina, but not thumbnail and other images. Are they required?

@tomasmcguinness
Copy link
Owner

No, the only image you need is the icon.

From your sample above, did you replace the "TeamIdentifier"?

@Jornan
Copy link
Author

Jornan commented Mar 24, 2014

Yep, the TeamIdentifier is replaced by a ten character string of numbers and letters. Is it possible to see exactly what it is expecting that is null?

@tomasmcguinness
Copy link
Owner

The easiest way is to connect it to a Mac and view the console for the phone. If you don't have a Mac, send me your PKPass file and I'll have a look.

@Jornan
Copy link
Author

Jornan commented Mar 24, 2014

Thanks for all the support. However, since this error message is occurring when I try to generate the pass I never get to the point where I have a pass to investigate ...

@tomasmcguinness
Copy link
Owner

Ah, of course.

There is nothing considered mandatory in the generator as it doesn't validate the request.

Have you tried to debug it?

On 24 Mar 2014, at 08:30, "Jornan" notifications@github.com wrote:

Thanks for all the support. However, since this error message is occurring when I try to generate the pass I never get to the point where I have a pass to investigate ...


Reply to this email directly or view it on GitHub.

@Jornan
Copy link
Author

Jornan commented Mar 24, 2014

After a little bit of help from a more experienced Visual Studio user, I managed to find this:

'generator.Generate(request)' threw an exception of type 'Passbook.Generator.Exceptions.ManifestSigningException' byte[]

Looks like something is still wrong with the signing process. Any idea what this can be caused by?

Edit: Based on the Tracing in VS, it looks like the problem occurs when getting the Apple public certificate. That one should just be to add to the Windows Certificate store, right?

@tomasmcguinness
Copy link
Owner

Yes, you should be able to see where it's loading the Apple certificates and either load using the Thumbprint or load directly from the disk

@Jornan
Copy link
Author

Jornan commented Mar 25, 2014

Loaded directly from disk, now it works! Thank you for all the help and support :-)

@tomasmcguinness
Copy link
Owner

Great. If you need any more help, please ask.

@VyasRR
Copy link

VyasRR commented Feb 29, 2016

Hi,

I am able to generate a .pkpass file using C# code (thanks to the tutorials available). The pass which I generated works correct on Android device(installed an application Pass2U Wallet to open the pass) and MAC OS (through mail). But, the same pass does not open on an iOS device. Kindly help me.

I have also attached the generated pkpass file for reference.

Regards,
Vyas

IndyCar.zip

@tomasmcguinness
Copy link
Owner

The best thing to do is look at the log files produced by your device when you try to open the pass. Once you have the error message, please open a new issue and I'll review it.

T

@VyasRR
Copy link

VyasRR commented Feb 29, 2016

Thank you. I opened a new issue for the same.

"Unable to open pkpass on an iOS device #41"

@mohmedmajid
Copy link

mohmedmajid commented Apr 7, 2021

Hi Tomas
First, thank you for this great work
when i try to use this project it threw exception with this message
"Key does not exist.\r\n"
this is thrown when call method ComputeSignature

@singhdilip1007
Copy link

Hi @tomasmcguinness I want to set 2 fields in a row and 3 rows with 2 fields and one last row with 3 fields. Below is my code snippet but it seems all fields are generating in one line. Please help me.

PassGenerator generator = new PassGenerator();
            PassGeneratorRequest request = new PassGeneratorRequest();

            request.PassTypeIdentifier = "xxxxxxxxxxxxxxxx";
            request.TeamIdentifier = "xxxxxxxxxxxxxxxxxxxx";
            request.SerialNumber = Guid.NewGuid().ToString("N"); ;
            request.Description = "My test pass";
            request.OrganizationName = "Test";
            request.LogoText = "My Logo Text";
            request.BackgroundColor = "#19342f";
            request.LabelColor = "#19342f";
            request.ForegroundColor = "#FFFFFF";

            request.AppleWWDRCACertificate = new X509Certificate2(Server.MapPath("~/Certificate/xxxxxxxxxxxx.cer"));
            request.PassbookCertificate = new X509Certificate2(Server.MapPath("~/Certificate/xxxxxx.pfx"), "xxxxxxxx");

            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
            request.Images.Add(PassbookImage.Icon2X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon@2x.png")));
            request.Images.Add(PassbookImage.Icon3X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon@2x.png")));

            request.Images.Add(PassbookImage.Logo, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/logo.png")));
            request.Images.Add(PassbookImage.Logo2X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/logo@2x.png")));
            request.Images.Add(PassbookImage.Logo3X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/logo@2x.png")));

            request.Style = PassStyle.Generic;

            request.AddPrimaryField(new StandardField("PharmacyName", "1991 Mountain Boulevard Oakland, Ca", "Walmart Pharmacy","TestAttr",DataDetectorTypes.PKDataDetectorTypeAddress));
            
            request.AddSecondaryField(new StandardField("first", "First", "Test1"));
            request.AddSecondaryField(new StandardField("second", "Second", "Test11"));
            request.AddSecondaryField(new StandardField("third", "Third", "Test111"));

            request.AddSecondaryField(new StandardField
            {
                Key = "field3",
                Label = "Field 3",
                Value = "Value 3",
            });
            request.AddSecondaryField(new StandardField
            {
                Key = "field32",
                Label = "Field2",
                Value = "Value 2",
            });
            request.LogoText = "Prescription Discount card";
            

            byte[] generatedPass = generator.Generate(request);
            return File(generatedPass, "application/vnd.apple.pkpass", request.SerialNumber+".pkpass");
            ```
            
            Your small help will make my day
     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants