ryantenney / passkit4j

Java library for generating Apple Passbook (.pkpass) files

Home Page:http://www.ryantenney.com/passkit4j/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mutiple Aliases Problem

nitin-singh opened this issue · comments

Pass pass = new Pass()
            .teamIdentifier("asdfasdfasdf")
            .passTypeIdentifier("pass.com.bouldercoffeeco.storeCard")
            .organizationName("Boulder Coffee Co.")
            .description("Boulder Coffee Rewards Card")
            .serialNumber("p69f2J")
            .locations(
            new Location(43.145863, -77.602690).relevantText("South Wedge"),
            new Location(43.131063, -77.636425).relevantText("Brooks Landing"),
            new Location(43.147528, -77.576051).relevantText("Park Avenue"),
            new Location(43.155763, -77.612724).relevantText("State Street"),
            new Location(43.165389, -77.589655).relevantText("Public Market")
            )
            .barcode(new Barcode(BarcodeFormat.PDF417, "12345678"))
            .barcodes(
            new Barcode(BarcodeFormat.CODE128, "12345678"),
            new Barcode(BarcodeFormat.PDF417, "12345678"))
            .logoText("Boulder Coffee")
            .foregroundColor(Color.WHITE)
            .backgroundColor(new Color(118, 74, 50))
            .files(
            new PassResource("pkpass/pass.strings"),
            new PassResource("pkpass/icon.png"),
            new PassResource("pkpass/icon@2x.png"),
            new PassResource("pkpass/logo.png"),
            new PassResource("pkpass/logo@2x.png"),
            new PassResource("pkpass/strip.png"),
            new PassResource("pkpass/strip@2x.png")
             )
            .nfc(new NFC("test"))
            .passInformation(
            new StoreCard()
                    .headerFields(
                    new NumberField("balance", "balance_label", 25)
                            .textAlignment(TextAlignment.RIGHT)
                            .currencyCode("USD")
            )
                    .auxiliaryFields(
                    new TextField("level", "level_label", "level_gold"),
                    new TextField("usual", "usual_label", "Iced Mocha")
            )
                    .backFields(
                    new TextField("terms", "terms_label", "terms_value")
            )
    );

    PassSigner signer = PassSignerImpl.builder()
            .keystore(new   FileInputStream("pkpass/certificates/CertificatesD.p12"),"GD8R5W2JC7", "test")
            .intermediateCertificate(new    FileInputStream("pkpass/certificates/AppleWWDRCA.cer"))
            .build();
    PassSerializer.writePkPassArchive(pass, signer, new     FileOutputStream("passes/DemoCard.pkpass"));

I am using this code in my grails application.
I tried various scenarios like:

  • When i didnt pass the "GD8R5W2JC7" while creating pass signer it says: Provided KeyStore contains multiple aliases, please specify an alias
  • When i pass alias it says : KeyStore does not contain an X509Certificate with alias "The Alias i provided". I printed the alias for that certificate but no alias would work.

P.S I am using ubuntu 14.04.

Exact same issue, Any luck?

Hi,
I'm tryng to create a passbook and I had exact issue but I could to resolve it.

You should code:

PassSigner signer = PassSignerImpl.builder()
            .keystore(new   FileInputStream("pkpass/certificates/CertificatesD.p12", **"PASS_CERTIFICATE"**)
            .alias(**"NAME_ALIAS"**)
            .intermediateCertificate(new    FileInputStream("pkpass/certificates/AppleWWDRCA.cer"))
            .build();
    PassSerializer.writePkPassArchive(pass, signer, new     FileOutputStream("passes/DemoCard.pkpass"));

Let me know how you go!

I had the same issue and found a solution. Instead of passing the certificate and an alias you need to create your own keystore and load the certificate and then pass that keystore to the PassSigner.

First create the keystore
KeyStore keystore = KeyStore.getInstance("PKCS12");

Load your certificate/keypair
keystore.load(inputStreamForP12, "passwordForP12".toCharArray());

Create the PassSigner
PassSigner signer = PassSignerImpl.builder().keystore(keystore, "passwordForP123").intermediateCertificate(inputStreamForWWDRCA).build();

Hi @martinreichart / @ryantenney ,

The solution given above by @martinreichart worked for me, while executing it on Windows machine with Oracle JDK 1.6.045.
But when I deployed the same code on our linux server (WAS8) IBM JDK 1.6, its giving me below error.

.PassbookServiceImpl - Create Sign-In Request for com.dataobjects.v2.reservation.passbook.SignPassRequest@cde4fa73 .PassbookServiceImpl - Validate Signin Request .PassbookServiceImpl - Valid Signin Request .PassbookBOImpl - Inside PassbookBOImpl class - createSignPass method started .PassbookBOImpl - Inside PassbookBOImpl method - getPassSigner method started .PassbookBOImpl - Inside PassbookBOImpl method - getPassSignerForRitzCarlton method started .PassbookBOImpl - Initializing the Pass Signer for : ritz.carlton.passbook.rewards.pass.file .PassbookBOImpl - ######################## Aliases are :[jean mountford, pass type id: pass.com.ritzcarlton.dev.reservationpass] .PassbookBOImpl - Problem generating signer for passbook com.ryantenney.passkit4j.sign.PassSigningException: Provided KeyStore contains multiple aliases, please specify an alias at com.ryantenney.passkit4j.sign.PassSigningUtil.firstAlias(PassSigningUtil.java:136) ~[passkit4j-2.0.4.jar:na] at com.ryantenney.passkit4j.sign.PassSigningUtil.getCertificate(PassSigningUtil.java:100) ~[passkit4j-2.0.4.jar:na] at com.ryantenney.passkit4j.sign.PassSignerImpl$Builder.build(PassSignerImpl.java:111) ~[passkit4j-2.0.4.jar:na] at com.reservation.v2.business.impl.PassbookBOImpl.initializeSigner(PassbookBOImpl.java:303) [classes/:na] at com.reservation.v2.business.impl.PassbookBOImpl.getRitzCarltonRewardsPassSigner(PassbookBOImpl.java:513) [classes/:na] at com.reservation.v2.business.impl.PassbookBOImpl.getPassSignerForRitzCarlton(PassbookBOImpl.java:217) [classes/:na] at com.reservation.v2.business.impl.PassbookBOImpl.getPassSigner(PassbookBOImpl.java:195) [classes/:na] at com.reservation.v2.business.impl.PassbookBOImpl.createSignPass(PassbookBOImpl.java:115) [classes/:na] at com.reservation.v2.services.impl.PassbookServiceImpl.createSignPass(PassbookServiceImpl.java:57) [classes/:na]

Here is the code snippet:
`
try {
// Create Keystore
KeyStore keystore = KeyStore.getInstance("PKCS12");
// Load Cert Pass (.p12 file)
certPassIS = new FileInputStream(ResourceUtils.getFile(passFileName));
// Load the Apple cert
appleCertIS = new FileInputStream(ResourceUtils.getFile(appleCertPass));
/* Create the PassSigner */
keystore.load(certPassIS, certPass.toCharArray());
passSigner = PassSignerImpl.builder().keystore(keystore, certPass).intermediateCertificate(appleCertIS).build();
} catch (Exception e) {
e.printStackTrace();

}
`
Could you please help.

We have found the solution for this. Here is the fix. We need to pass the provider for the underlying keystore, i.e. SunJSSE or IBMJCE

`try {
// Create Keystore
KeyStore keystore = KeyStore.getInstance("PKCS12","IBMJCE");
// Load Cert Pass (.p12 file)
certPassIS = new FileInputStream(ResourceUtils.getFile(passFileName));
// Load the Apple cert
appleCertIS = new FileInputStream(ResourceUtils.getFile(appleCertPass));
/* Create the PassSigner */
keystore.load(certPassIS, certPass.toCharArray());
passSigner = PassSignerImpl.builder().keystore(keystore, certPass).intermediateCertificate(appleCertIS).build();
} catch (Exception e) {
e.printStackTrace();

}`

@ychoudhary/ @martinreichart / @ryantenney
I was trying to use the solution which worked for you when i run the class i get following error , I guess it because i imported my keystore from import java.security.KeyStore;
Is there any alternative solution for my problem.
StoreCardExample.txt

java.lang.SecurityException: class "org.bouncycastle.asn1.DEREncodable"'s signer information does not match signer information of other classes in the same package

@vamshisomanchi in your case the problem seems to be that you have multiple versions of BouncyCastle on your classpath.

Just had this issue, and I had it every year since 2017. In my case the solution is to remove whitespaces from the alias name, my alias was "my name lastname" and changing to "mnl" or "my_name_lastname" fixed this issue.

openssl pkcs12 -in cert.p12 and then search for friendlyName use it the PassSignerImpl.bulder()
.alias("aliasFound")