NPE creating ssl-context in 0.1.10 #2

Closed
brunchboy opened this Issue Sep 26, 2012 · 6 comments

Comments

Projects
None yet
3 participants

After upgrading from the clojars 0.1.0 release to the recent 0.1.10, the following code, which used to work, now crashes with a NullPointerException during compilation:

(ns cirrus.apns
  (:use [clojure.tools.logging :only (debug info warn error)])
  (:require [herolabs.apns.ssl :as ssl]
            [herolabs.apns.push :as push]
            [herolabs.apns.message :as message]
            [herolabs.apns.feedback :as feedback]))

;; See https://github.com/HEROLABS/herolabs-apns#readme

(def key-store (clojure.java.io/resource "keystore-apns"))

(def silly-trust-managers (ssl/naive-trust-managers :trace true))

(def ctx (ssl/ssl-context
          :store-path key-store
          :store-pass "notActualPW"
          :cert-pass "norIsThis"
          :trust-managers silly-trust-managers))

It is the final def which crashes, as follows:

Exception in thread "main" java.lang.NullPointerException, compiling:(apns.clj:14)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3387)
    at clojure.lang.Compiler$DefExpr.eval(Compiler.java:398)
    at clojure.lang.Compiler.eval(Compiler.java:6516)
    at clojure.lang.Compiler.load(Compiler.java:6952)
    at clojure.lang.RT.loadResourceScript(RT.java:359)
    at clojure.lang.RT.loadResourceScript(RT.java:350)
    at clojure.lang.RT.load(RT.java:429)
    at clojure.lang.RT.load(RT.java:400)
    at clojure.core$load$fn__4890.invoke(core.clj:5415)
    at clojure.core$load.doInvoke(core.clj:5414)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5227)
    at clojure.core$load_lib.doInvoke(core.clj:5264)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_libs.doInvoke(core.clj:5298)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$require.doInvoke(core.clj:5381)
    at clojure.lang.RestFn.invoke(RestFn.java:3894)
    at cirrus.web$eval5469$loading__4784__auto____5470.invoke(web.clj:1)
    at cirrus.web$eval5469.invoke(web.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6511)
    at clojure.lang.Compiler.eval(Compiler.java:6501)
    at clojure.lang.Compiler.load(Compiler.java:6952)
    at clojure.lang.RT.loadResourceScript(RT.java:359)
    at clojure.lang.RT.loadResourceScript(RT.java:350)
    at clojure.lang.RT.load(RT.java:429)
    at clojure.lang.RT.load(RT.java:400)
    at clojure.core$load$fn__4890.invoke(core.clj:5415)
    at clojure.core$load.doInvoke(core.clj:5414)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5227)
    at clojure.core$load_lib.doInvoke(core.clj:5264)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_libs.doInvoke(core.clj:5298)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$require.doInvoke(core.clj:5381)
    at clojure.lang.RestFn.invoke(RestFn.java:551)
    at cirrus.test.shared$eval4251$loading__4784__auto____4252.invoke(shared.clj:1)
    at cirrus.test.shared$eval4251.invoke(shared.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6511)
    at clojure.lang.Compiler.eval(Compiler.java:6501)
    at clojure.lang.Compiler.load(Compiler.java:6952)
    at clojure.lang.RT.loadResourceScript(RT.java:359)
    at clojure.lang.RT.loadResourceScript(RT.java:350)
    at clojure.lang.RT.load(RT.java:429)
    at clojure.lang.RT.load(RT.java:400)
    at clojure.core$load$fn__4890.invoke(core.clj:5415)
    at clojure.core$load.doInvoke(core.clj:5414)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5227)
    at clojure.core$load_lib.doInvoke(core.clj:5264)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_libs.doInvoke(core.clj:5298)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$require.doInvoke(core.clj:5381)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at user$eval311.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:6511)
    at clojure.lang.Compiler.eval(Compiler.java:6500)
    at clojure.lang.Compiler.eval(Compiler.java:6501)
    at clojure.lang.Compiler.eval(Compiler.java:6477)
    at clojure.core$eval.invoke(core.clj:2797)
    at clojure.main$eval_opt.invoke(main.clj:297)
    at clojure.main$initialize.invoke(main.clj:316)
    at clojure.main$null_opt.invoke(main.clj:349)
    at clojure.main$main.doInvoke(main.clj:427)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
    at java.security.Provider$ServiceKey.(Provider.java:517)
    at java.security.Provider$ServiceKey.(Provider.java:510)
    at java.security.Provider.getService(Provider.java:684)
    at sun.security.jca.ProviderList.getService(ProviderList.java:331)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:157)
    at java.security.Security.getImpl(Security.java:696)
    at java.security.KeyStore.getInstance(KeyStore.java:600)
    at herolabs.apns.ssl$load_keystore.invoke(ssl.clj:15)
    at herolabs.apns.ssl$ssl_context.doInvoke(ssl.clj:25)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3382)
    ... 76 more

Hi,

sorry, I'm not really into this code, as my collegue is on vacation. First:
a) I could reproduce your error.
b) I found this "workaround":

(ns cirrus.apns
(:use [clojure.tools.logging :only (debug info warn error)])
(:require [herolabs.apns.ssl :as ssl]
[herolabs.apns.push :as push]
[herolabs.apns.message :as message]
[herolabs.apns.feedback :as feedback]))

;; See https://github.com/HEROLABS/herolabs-apns#readme

(def key-store-path (clojure.java.io/resource "keys/somerandomfilename.p12"))
(def cert-store-path (clojure.java.io/resource "keys/somerandomfilename.cer"))

(def silly-trust-managers (ssl/naive-trust-managers :trace true))

(def key-store (ssl/keystore :key-path key-store-path :key-pass "notActualPW" :cert-path cert-store-path))

(def ctx (ssl/ssl-context
:keystore key-store
:trust-managers silly-trust-managers))

c) I will have a closer look on it in the next days.

Cheers,

Chris

Am 26.09.2012 um 18:13 schrieb James Elliott:

After upgrading from the clojars 0.1.0 release to the recent 0.1.10, the following code, which used to work, now crashes with a NullPointerException during compilation:

(ns cirrus.apns
(:use [clojure.tools.logging :only (debug info warn error)])
(:require [herolabs.apns.ssl :as ssl]
[herolabs.apns.push :as push]
[herolabs.apns.message :as message]
[herolabs.apns.feedback :as feedback]))

;; See https://github.com/HEROLABS/herolabs-apns#readme

(def key-store (clojure.java.io/resource "keystore-apns"))

(def silly-trust-managers (ssl/naive-trust-managers :trace true))

(def ctx (ssl/ssl-context
:store-path key-store
:store-pass "notActualPW"
:cert-pass "norIsThis"
:trust-managers silly-trust-managers))
It is the final def which crashes, as follows:

Exception in thread "main" java.lang.NullPointerException, compiling:(apns.clj:14)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3387)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:398)
at clojure.lang.Compiler.eval(Compiler.java:6516)
at clojure.lang.Compiler.load(Compiler.java:6952)
at clojure.lang.RT.loadResourceScript(RT.java:359)
at clojure.lang.RT.loadResourceScript(RT.java:350)
at clojure.lang.RT.load(RT.java:429)
at clojure.lang.RT.load(RT.java:400)
at clojure.core$load$fn__4890.invoke(core.clj:5415)
at clojure.core$load.doInvoke(core.clj:5414)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5227)
at clojure.core$load_lib.doInvoke(core.clj:5264)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$require.doInvoke(core.clj:5381)
at clojure.lang.RestFn.invoke(RestFn.java:3894)
at cirrus.web$eval5469$loading__4784__auto____5470.invoke(web.clj:1)
at cirrus.web$eval5469.invoke(web.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.load(Compiler.java:6952)
at clojure.lang.RT.loadResourceScript(RT.java:359)
at clojure.lang.RT.loadResourceScript(RT.java:350)
at clojure.lang.RT.load(RT.java:429)
at clojure.lang.RT.load(RT.java:400)
at clojure.core$load$fn__4890.invoke(core.clj:5415)
at clojure.core$load.doInvoke(core.clj:5414)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5227)
at clojure.core$load_lib.doInvoke(core.clj:5264)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$require.doInvoke(core.clj:5381)
at clojure.lang.RestFn.invoke(RestFn.java:551)
at cirrus.test.shared$eval4251$loading__4784__auto____4252.invoke(shared.clj:1)
at cirrus.test.shared$eval4251.invoke(shared.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.load(Compiler.java:6952)
at clojure.lang.RT.loadResourceScript(RT.java:359)
at clojure.lang.RT.loadResourceScript(RT.java:350)
at clojure.lang.RT.load(RT.java:429)
at clojure.lang.RT.load(RT.java:400)
at clojure.core$load$fn__4890.invoke(core.clj:5415)
at clojure.core$load.doInvoke(core.clj:5414)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5227)
at clojure.core$load_lib.doInvoke(core.clj:5264)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$require.doInvoke(core.clj:5381)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at user$eval311.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6500)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.eval(Compiler.java:6477)
at clojure.core$eval.invoke(core.clj:2797)
at clojure.main$eval_opt.invoke(main.clj:297)
at clojure.main$initialize.invoke(main.clj:316)
at clojure.main$null_opt.invoke(main.clj:349)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at java.security.Provider$ServiceKey.(Provider.java:517)
at java.security.Provider$ServiceKey.(Provider.java:510)
at java.security.Provider.getService(Provider.java:684)
at sun.security.jca.ProviderList.getService(ProviderList.java:331)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:157)
at java.security.Security.getImpl(Security.java:696)
at java.security.KeyStore.getInstance(KeyStore.java:600)
at herolabs.apns.ssl$load_keystore.invoke(ssl.clj:15)
at herolabs.apns.ssl$ssl_context.doInvoke(ssl.clj:25)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3382)
... 76 more

Reply to this email directly or view it on GitHub.

Thanks, I am glad you were able to reproduce it. We have a workaround as well, so there is no rush, but it would be nice to know when it is fixed in the repository.

Contributor

niclasmeier commented Sep 30, 2012

First of all, thanks Chris!

I am back in the office on October 16th and I will have a look at it in that week.

@ghost ghost assigned niclasmeier Oct 22, 2012

niclasmeier added a commit that referenced this issue Oct 22, 2012

- fixed Issue #2 (NPE creating ssl-context in 0.1.10) by adding a def…
…ault value for newly introduced store-type parameter.

Hmm, I am having new problems now. I am stuck using older versions of the library, because I have not been able to get connections to the APNS servers using recent ones. I would really like to use the “workaround” approach above of using a dynamically-created keystore within the application, to save all the hassle of creating an actual Java keystore on disk every time the Apple certificates need updating. But with the following code, I inevitably end up with a connection that is nil, and no error message or explanation why:

(def key-store (ssl/keystore :key-path (clojure.java.io/resource "certs/CirrusPushKey.p12")
                             :key-pass (config/get :apns-keystore-pass)
                             :cert-path (clojure.java.io/resource "certs/CirrusPushCert.cer")))

(def silly-trust-managers (ssl/naive-trust-managers :trace true))

(def ctx (ssl/ssl-context :keystore key-store
                          :trust-managers silly-trust-managers))

(defn create-connection [] (push/create-connection (push/dev-address) ctx))

I know I must be close, because if I pass the wrong files, or the wrong key password, I do get exceptions. But not close enough, because calling create-connection always returns nil. Any ideas how I can debug this?

Contributor

niclasmeier commented Dec 6, 2012

Okay, supplying no message why the connection couldn't be established was some kind of mean of me. But I just uploaded the 0.1.13 fix version where a NullPointerException issue while creating a thread factory was fixed and A warning will be logged when the connection could not be established.

Unfortunately the code you supplied looks very similar to our own code I guess you already checked if any other value (like e.g. key-store, trust-manager, ctx, etc.) are nil

For whatever reason, the code that was not working yesterday with 0.1.12, is working just peachy fine today with 0.1.13. So this can stay happily closed. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment