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

Mutiple Aliases Problem #37

Open
nitin-singh opened this issue Apr 25, 2016 · 9 comments
Open

Mutiple Aliases Problem #37

nitin-singh opened this issue Apr 25, 2016 · 9 comments

Comments

@nitin-singh
Copy link

nitin-singh commented Apr 25, 2016

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/[email protected]"),
            new PassResource("pkpass/logo.png"),
            new PassResource("pkpass/[email protected]"),
            new PassResource("pkpass/strip.png"),
            new PassResource("pkpass/[email protected]")
             )
            .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.

@krisboud
Copy link

krisboud commented Jun 9, 2016

Exact same issue, Any luck?

@Waxampu
Copy link

Waxampu commented Jul 6, 2016

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!

@martinreichart
Copy link

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();

@ychoudhary
Copy link

ychoudhary commented Mar 16, 2017

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.

@ychoudhary
Copy link

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();

}`

@vamshisomanchi
Copy link

@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

@ryantenney
Copy link
Owner

ryantenney commented May 9, 2018

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

@ZooMMX
Copy link

ZooMMX commented May 27, 2020

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.

@JakobStadlhuber
Copy link

JakobStadlhuber commented Jun 13, 2021

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

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

9 participants