Encountered InvalidSSLConfig

794 views
Skip to first unread message

delightwjk

unread,
Aug 29, 2011, 11:59:53 PM8/29/11
to Java client for Apple Push Notification service (APNs)
Hi,

First of all, thanks for this great library, which provides a simple
interface to use.

I encountered an issue which says "InvalidSSLConfig", and I searched
in internet and didn't get any luck. Here is the details of the
exception track.

Does anyone know what is wrong? Thanks in advance!

Exception in thread "main" com.notnoop.exceptions.InvalidSSLConfig:
java.io.IOException: failed to decrypt safe contents entry:
java.lang.ArithmeticException: / by zero
at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:
102)
at
com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:
139)
at
com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:
114)
at com.checkpoints.apns.App.main(App.java:11)
Caused by: java.io.IOException: failed to decrypt safe contents entry:
java.lang.ArithmeticException: / by zero
at
com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:
1277)
at java.security.KeyStore.load(KeyStore.java:1185)
at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:
87)
... 3 more
Caused by: java.lang.ArithmeticException: / by zero
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore
$PBEWithSHA1AndRC2_40.engineInit(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at
com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:
1273)
... 5 more


And here is my simple test code:


import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;

public class App {
public static void main(String[] args) {
ApnsService service =
APNS.newService().withCert("sb_cert_112711.p12",
"").withSandboxDestination().build();
String payload = APNS.newPayload().alertBody("Can't be simpler
than this!").build();
String token = "xxxxx....";
service.push(token, payload);

// Map<String, Date> inactiveDevices =
service.getInactiveDevices();
// for (String deviceToken : inactiveDevices.keySet()) {
// Date inactiveAsOf = inactiveDevices.get(deviceToken);
// }
}
}

Mahmood Ali

unread,
Aug 30, 2011, 12:25:51 AM8/30/11
to java-apn...@googlegroups.com
Greetings,

Sun/Oracle Java implementation doesn't handle password-less certificates, and it is a known SDK low-priority bug.

Please try exporting the certificate again with a valid password instead.

Hope this fixes the issue for you.

Regards,- Mahmood

Andrew Kinnie

unread,
Sep 20, 2011, 4:04:23 PM9/20/11
to java-apn...@googlegroups.com
I am getting an extremely weird problem using Java-APNS that I thought I'd ask about. I have a new development certificate, because they seem to expire in 90 days for some inexplicable reason. The new certificate runs fine when I run the server app on my machine in eclipse, and I can successfully push using it. However, after copying the certificate over to the server, then deploying the current version of the built app onto the server, then restarting the server, and the pushes always fail, with the error "expired cert."

Anyone have any insight on this? (I seriously doubt it, but I thought I would ask)

Andrew

Andrew Kinnie

unread,
Sep 20, 2011, 5:04:10 PM9/20/11
to java-apn...@googlegroups.com
For further information, we have multiple apps accepting pushes, and we can send the same notification contents to multiple apps.

I create a loop through the apps, then create a task for each app, and send the push to all the devices associated with that app.  The task is where the Java-APNS calls are made, by creating the payload, getting the certificate for the app, creating a new service building which has a singleton delegate.  I then build the service and push the payload to each device.  

Apparently, one of the apps in our database had an expired certificate.  If I push to a collection of apps including this one with the expired cert, it appears to stop the whole process.  I deleted the app from the db and now it works.  But I was wondering if anyone had insight on this.

Is the singleton delegate causing this process to fail somehow?

EOEditingContext ec = newEditingContext();
ec.lock();
// convert global ids back into eos in the new ec
notification = (Notification)ec.faultForGlobalID(notificationID, ec); 
devicesToNotify = ERXEOControlUtilities.faultsForGlobalIDs(ec, deviceIds);
String complex = APNS.newPayload()
    .actionKey("Details\u2026")
    .localizedKey(notification.notificationType().typeName())
    .localizedArguments(shortString(notification.textContents()))
    .badge(1)//.sound("default")
    .customField("id", notification.notificationIdentifier())
    .build();


String certificatePath = APNsUtilities.certBase + notification.application().certificateOrAndroidc2dmUser();
NSTimestamp notificationExpiry = notification.createDate().timestampByAddingGregorianUnits(
0, 
0, 
0, 
0, 
((notification.minutesToExpire() != null) ? notification.minutesToExpire() : notification.notificationType().defaultMinutesToExpire()), 
0);
System.out.println("\ncertificatePath is: " + certificatePath);


if (!(new File(certificatePath).exists())) {
System.out.println("Certificate not found at path: " + certificatePath);
// return false;
}
ApnsServiceBuilder sb = APNS.newService()
.withCert(certificatePath, notification.application().certificatePassword());
sb.withDelegate(APNsDelegate.getSingletonObject());
boolean sandbox = APNsUtilities.HOST.contains("sandbox");
if(sandbox) System.out.println("Sandbox host selected");
else {
System.out.println("Production host selected");
}
ApnsService service = APNsUtilities.HOST.contains("sandbox") ?
sb.withSandboxDestination().build() : 
sb.withProductionDestination().build();


System.out.println("push should be: " + complex);
System.out.println("Should push to: " + devicesToNotify.count() + " devices");


int deviceCount = devicesToNotify.count();
int receivers = 0;
try {
for(ApplicationDevice deviceToNotify : devicesToNotify){
try {
String client = deviceToNotify.deviceToken();

if(!(client == null || client.equals("") || client.equals("0"))) {
service.push(client, complex, notificationExpiry);//(client, complex); // can add additional argument here for expiry
if(sandbox) System.out.println("In sandbox, pushed to device with udid " + deviceToNotify.udid() + " and token " + deviceToNotify.deviceToken() + " pushed to Apple");
receivers++;
}
ApplicationDeviceNotification appDevNote
ApplicationDeviceNotification.createApplicationDeviceNotification(notification.editingContext(), deviceToNotify, notification);
} catch (Exception e) {
System.out.println("\nPush for Notification id " + notification.notificationIdentifier() + " failed for device with token " + deviceToNotify.deviceToken() + "\nand udid " + deviceToNotify.udid());
e.printStackTrace();
}
System.out.println("Device expecting push = " + deviceCount + " and devices receiving the push = " + receivers);
service.stop();
ec.saveChanges();
} catch (Exception e) {
e.printStackTrace();
} finally {
ec.unlock();

Santanu Chattopadhyay

unread,
Sep 21, 2011, 11:31:59 AM9/21/11
to java-apn...@googlegroups.com
Hi,
just import the cer file to server using keytool command.
Thanks,
santanu.

Andrew Kinnie

unread,
Sep 21, 2011, 11:33:36 AM9/21/11
to java-apn...@googlegroups.com
keytool command?  The server has the cert already.

Sent from my iPad
Reply all
Reply to author
Forward
0 new messages