Permalink
Browse files

- updated version number

- added documentation how to use the files provided by Apple directly and not creating a JKS keystone.
  • Loading branch information...
1 parent 8feaeb2 commit cc380415bbfcee64138ffd7fc9c22313ae982f82 @niclasmeier niclasmeier committed Oct 22, 2012
Showing with 41 additions and 17 deletions.
  1. +40 −16 README.md
  2. +1 −1 project.clj
View
@@ -38,38 +38,39 @@ The next important step is to create a connecion. The connection will act as pro
to the Apple service. You don't need to open, close or maintain it. The underlying connection management
is handeled by the library and netty.
+## Creating a connection
To create a connection we will need a `ssl-context` and an `address` of the Apple servers. The `address` is the easy part.
You may need the `dev-address` or the `prod-address` to obtain the addresses used by Apple.
-To create the `ssl-context` you may use the functions in `herolabs.apns.ssl`. First create a File or URL to your
-keystore. How you create this, I'll explain later.
+To create the `ssl-context` you may use the functions in `herolabs.apns.ssl`. First create a Files or URLs to your
+certificate and key files. Then you can use the `keystore` function to create a transient keystore containing the key and the certificate.
- (def key-store (clojure.java.io/resource "keys/my-keystore"))
+ (let [key-file (resource "files/my-project.p12")
+ cert-file (resource "files/my-project.cer")
+ store (ssl/keystore :key-path key-
+ :key-pass "verysecretkeypass"
+ :cert-path cert-file)]
+ …
+ )
+
Unfortunately the certificates used by Apple are not signed by a major (known by the JRE) authority. So the connection
would not be established by the JRE. You have to choices: a) import the Apple certificates into the JRE keystores (secure)
b) override the trust manager so that he accepts the certificate (not so secure). In this example I chose b.
- (def silly-trust-managers (naive-trust-managers :trace true)))
+Now lets have a look how to create the context and connection:
-Now we have everything in place to create the SSLContext to user for the connection.
+ (let [silly-trust-managers (naive-trust-managers :trace true)
+ ctx (ssl/ssl-context :keystore store :trust-managers silly-trust-managers)
+ connection (push/create-connection (dev-address) ctx)]
+ …
+ )
- (def ctx (ssl-context
- :store-path keystore
- :store-pass "averysecretpassword"
- :cert-pass "anevenbetterpassword"
- :trust-managers silly-trust-managers)
-
-So let's create the connection:
-
- (def connection (push/create-connection (dev-address) ctx))
Now lets send a message:
(send-message connection "--the-device-token--" message)
-a vóila! The message is sent!
-
Due to the nature of the protocol the feedback is very "limitied". This means, if an error occurs Apple simply closes
the underlying connection. So you don't get any feedback if the message will reach the sender, but that is exactly
the terms Apple supplies. Event the so calles "enhanced" message format delivers some errors about the message format,
@@ -88,6 +89,29 @@ The `feedback` function returns a lazy collection that reads the data from the s
also contain the `dev-address` or the `prod-address` functions to contain the addresses. Be aware that they differ from
the ones used by the push service.
+## Creating a ssl-context using a JKS keystore
+This is the old and less elegant easy way.
+
+To create the `ssl-context` you may use the functions in `herolabs.apns.ssl`. First create a File or URL to your
+keystore. How you create this, I'll explain later.
+
+ (def key-store (clojure.java.io/resource "keys/my-keystore"))
+
+As trust manager just use the same brainded version like in the last example. Now we have everything in place to create the SSLContext to user for the connection.
+
+ (def ctx (ssl-context
+ :store-path keystore
+ :store-pass "averysecretpassword"
+ :cert-pass "anevenbetterpassword"
+ :trust-managers silly-trust-managers)
+
+So let's create the connection:
+
+ (def connection (push/create-connection (dev-address) ctx))
+
+
+a vóila! The message is sent!
+
## Creating a JKS keystore
Personally I used this [guide](http://www.agentbob.info/agentbob/79-AB.html). Basically you convert the .P12 certificate
View
@@ -1,4 +1,4 @@
-(defproject herolabs/apns "0.1.10"
+(defproject herolabs/apns "0.1.11"
:description "A simple lightweight library to use with the Apple push notification service."
:url "https://github.com/HEROLABS/herolabs-apns"
:dependencies [[org.clojure/clojure "1.4.0"]

0 comments on commit cc38041

Please sign in to comment.