From 489d06e15e64ba145c2f85310f9a44a290c33b8d Mon Sep 17 00:00:00 2001 From: Alex Chaplianka Date: Thu, 14 Jun 2018 10:16:53 +0300 Subject: [PATCH 1/5] Upgrading OkHttp to 3.10, --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e9a0c78..611b75b 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.squareup.okhttp3 okhttp - 3.2.0 + 3.10.0 From 2896926b345b29e1e76a5c2b5f56c8fe1bf7ad41 Mon Sep 17 00:00:00 2001 From: Alex Chaplianka Date: Thu, 14 Jun 2018 10:17:43 +0300 Subject: [PATCH 2/5] #44 Adding trust manager to support JDK9+ --- .../apns/clients/SyncOkHttpApnsClient.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java b/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java index 3ba261c..0d41f24 100644 --- a/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java +++ b/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java @@ -43,6 +43,7 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.security.spec.InvalidKeySpecException; +import java.util.Arrays; import java.util.UUID; /** @@ -181,8 +182,16 @@ public SyncOkHttpApnsClient(InputStream certificate, String password, boolean pr sslContext.init(keyManagers, tmf.getTrustManagers(), null); final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); - - builder.sslSocketFactory(sslSocketFactory); + TrustManagerFactory trustManagerFactory = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + trustManagerFactory.init((KeyStore) null); + TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); + if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) { + throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers)); + } + X509TrustManager trustManager = (X509TrustManager) trustManagers[0]; + sslContext.init(null, new TrustManager[]{trustManager}, null); + builder.sslSocketFactory(sslSocketFactory, trustManager); client = builder.build(); From d1b8b87f594e6a6d13db3b1e54dc18035655fa13 Mon Sep 17 00:00:00 2001 From: Alex Chaplianka Date: Thu, 14 Jun 2018 10:18:05 +0300 Subject: [PATCH 3/5] bump to 1.0.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 611b75b..795aa72 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.clevertap.apns apns-http2 - 1.0.3 + 1.0.4 apns-http2 A library for communicating with the Apple Push Gateway in HTTP/2. From cefebd97deef40806f7d95980d15a84bcc8e487b Mon Sep 17 00:00:00 2001 From: Alex Chaplianka Date: Fri, 15 Jun 2018 23:14:27 +0300 Subject: [PATCH 4/5] FIX: Initializing with the keystore --- .../java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java b/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java index 0d41f24..591d9b1 100644 --- a/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java +++ b/src/main/java/com/clevertap/apns/clients/SyncOkHttpApnsClient.java @@ -178,7 +178,7 @@ public SyncOkHttpApnsClient(InputStream certificate, String password, boolean pr SSLContext sslContext = SSLContext.getInstance("TLS"); final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - tmf.init((KeyStore) null); + tmf.init(ks); sslContext.init(keyManagers, tmf.getTrustManagers(), null); final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); From 5de928782bb051d81e03d16c6e829a747b2da5bd Mon Sep 17 00:00:00 2001 From: Alex Chaplianka Date: Sun, 17 Jun 2018 16:41:36 +0300 Subject: [PATCH 5/5] CHORE:Adding simple test for APN notification --- .../apns/integration/NotificationTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/com/clevertap/apns/integration/NotificationTest.java diff --git a/src/test/com/clevertap/apns/integration/NotificationTest.java b/src/test/com/clevertap/apns/integration/NotificationTest.java new file mode 100644 index 0000000..e2cf22e --- /dev/null +++ b/src/test/com/clevertap/apns/integration/NotificationTest.java @@ -0,0 +1,60 @@ +package com.clevertap.apns.integration; + +import com.clevertap.apns.ApnsClient; +import com.clevertap.apns.Notification; +import com.clevertap.apns.NotificationResponse; +import com.clevertap.apns.NotificationResponseListener; +import com.clevertap.apns.clients.ApnsClientBuilder; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; + +public class NotificationTest { + private static String APN_AUTH_KEY; + private static String TOKEN; + private static String TEAM_ID; + private static String KEY_ID; + + ApnsClient asyncClient; + @BeforeClass + public static void init(){ + APN_AUTH_KEY = System.getProperty("com.clevertap.auth_key"); + TOKEN = System.getProperty("com.clevertap.token"); + TEAM_ID = System.getProperty("com.clevertap.team_id"); + KEY_ID = System.getProperty("com.clevertap.key_id"); + } + @Before + public void setUp() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException { + asyncClient = new ApnsClientBuilder(). + inAsynchronousMode(). + withApnsAuthKey(APN_AUTH_KEY). + withTeamID(TEAM_ID). + withKeyID(KEY_ID). + build(); + } + @Test + public void sendNotification(){ + Notification notification = new Notification.Builder(TOKEN).alertBody("Hello").build(); + + asyncClient.push(notification, new NotificationResponseListener() { + @Override + public void onSuccess(Notification notification) { + + } + + @Override + public void onFailure(Notification notification, NotificationResponse response) { + Assert.fail("Failed to send notification: "+response.getResponseBody()); + } + }); + } + +}