import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
public class Main {
public static void main(String[] args) {
BufferedInputStream bis = null;
SSLSocket feedSock = null;
try {
KeyStore ks = null;
ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream("path.."), "password".toCharArray());
System.out.println("key size:" + ks.size() + "/key type:" + ks.getType());
/// SUNX 509 or PKIX
// 인증서 인코딩 알고리즘
KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(ks, "password..".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
tmf.init((KeyStore) null);
// TLS or SSL protocol get
SSLContext sc = SSLContext.getInstance("TLS");
// SSLContext sc = SSLContext.getInstance("SSL");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory ssf = sc.getSocketFactory();
feedSock = (SSLSocket) ssf.createSocket("feedback.sandbox.push.apple.com", 2196);
String[] cipherSuites = feedSock.getSupportedCipherSuites();
feedSock.setEnabledCipherSuites(cipherSuites);
// TLS HandShake
feedSock.startHandshake();
;
System.out.println("피드백 서비스 연결:" + feedSock.isConnected());
int a = 0;
bis = new BufferedInputStream(feedSock.getInputStream());
while (true) {
byte[] tuple = new byte[38];
a = bis.read(tuple, 0, tuple.length);
System.out.println(a);
byte[] time_t = Arrays.copyOfRange(tuple, 0, 4);
byte[] token_length = Arrays.copyOfRange(tuple, 4, 6);
byte[] token = Arrays.copyOfRange(tuple, 6, tuple.length);
if (a > 0) {
// System.out.println("time_t:" + byteArrayToInt(time_t));
// System.out.println("token_length:" + byteArrayToInt(token_length));
// System.out.println("token:" + byteArrayToHex(token));
} else {
break;
}
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CertificateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
bis.close();
feedSock.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}