HTTPS 통신 질문 입니다.

446 views
Skip to first unread message

GIL

unread,
Jul 22, 2012, 10:34:08 AM7/22/12
to ks...@googlegroups.com
안녕하세요. 
원격 서버의 XML을 참조 하기 위해서 URL Connection을 이용해서 Read 했습니다.
    ex> URL url = new URL(path);
 URLConnection conn = url.openConnection();
 is  = conn.getInputStream();
 
그런데, 원격 서버가 Https 인 곳에서는  하기와 같은 Exception이 발생 하네요.
 'javax.net.ssl.sslHandshake Exception: sun.security.validator.validationException: PKIK path building failed: sun.security.
provider.certPath.SuncertPathBuilderException: unable to find valid certification path to requested target. 

구글링 하여서 3가지 방법으로 해결을 시도는 해봤습니다. 
  • System.setProperty("java.protocal, "~~");    com.sun.net.ssl.internal.ssl.Provider provider = ~~~ ;  Security.addProvider(provider) ; 해당 코드 추가
  • HttpsURLConnection conn = (HttpsURLConnection)url.openConnection(); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, null, null);
         conn.setSSLSocketFactory(context.getSocketFactory()); 해당 방법으로 connection을 맺는 법
  • installcert.java 파일을 받아 jssercacers 파일 생성하역 java_home/jre/lib/security/ 폴더에 복사 함.

하지만 모두 실패하여 습니다. 어떻게 이 문제를 해결 할 수 있을까요? 
 
 

황용대

unread,
Jul 22, 2012, 11:21:29 AM7/22/12
to ks...@googlegroups.com
오픈jdk를 사용중이라면 오라클jdk로 바꾸세요

2012. 7. 22. 오후 11:34 GIL <jb9...@gmail.com> 작성:

--
Google 그룹스 'Korea Spring User Group' 그룹에 가입했으므로 본 메일이 전송되었습니다.
웹에서 이 토론을 보려면 https://groups.google.com/d/msg/ksug/-/DNNVDLNaDxMJ을(를) 방문하세요.
이 그룹에 게시하려면 ks...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 ksug+uns...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/ksug?hl=ko에서 그룹을 방문하세요.

YongHyuk Lee

unread,
Jul 22, 2012, 8:54:26 PM7/22/12
to ks...@googlegroups.com
전에.. 이렇게 한적 있는듯 한데.. 같은건지는..

vm 실행 옵션에..

-DUseSunHttpHandler=true

이런식으로 httpClient 사용시 Sun JDK 사용하라고 강제할 수 있다는...

2012년 7월 23일 오전 12:21, 황용대 <sta...@gmail.com>님의 말:



--
----------------------------------------
itemBay 개발실 개발2팀
과장 / 이용혁
Mobile: 010.8425.9004
서울시 양천구 목2동 524-1

고종봉

unread,
Jul 22, 2012, 9:04:17 PM7/22/12
to ks...@googlegroups.com
apache http client를 사용해도 마찬가지 일까요..??

2012년 7월 23일 오전 9:54, YongHyuk Lee <unlogi...@gmail.com>님의 말:

전성욱

unread,
Jul 22, 2012, 9:13:17 PM7/22/12
to ks...@googlegroups.com
저는 다른거 찾아보다가 apache http client 4.x버전 사용해서 https와 통신했습니다.

그때 만든 소스 입니다. 도움이 될려나 모르겠네요.

DefaultHttpClient httpclient = new DefaultHttpClient();

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File(this.getClass().getResource("").getPath()+"client.truststore")); 

try {
    trustStore.load(instream, "changeit".toCharArray());
} finally {
    instream.close();
}

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);

return httpclient;

2012년 7월 23일 오전 10:04, 고종봉 <mercu...@gmail.com>님의 말:

"신재근 <freepow@gmail.com>"

unread,
Jul 22, 2012, 9:25:15 PM7/22/12
to ks...@googlegroups.com

Ȥ�� �̰� ������ �ɷ�����? ������
��ۿ� �ҽ� �ֽ��ϴ�.

http://www.okjsp.pe.kr/seq/170298

�����ϼ���~


2012-07-23 ���� 10:13, ��� �� ��:
��� �ٸ��� ã�ƺ��ٰ� apache http client 4.x���� ����ؼ� https�� ����߽��ϴ�.

�׶� ���� �ҽ� �Դϴ�. ������ �ɷ��� �𸣰ڳ׿�.

DefaultHttpClient httpclient = new DefaultHttpClient();

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File(this.getClass().getResource("").getPath()+"client.truststore")); 

try {
    trustStore.load(instream, "changeit".toCharArray());
} finally {
    instream.close();
}

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);

return httpclient;

2012�� 7�� 23�� ���� 10:04, ������ <mercu...@gmail.com>���� ��:
apache http client�� ����ص� ������ �ϱ��..??

2012�� 7�� 23�� ���� 9:54, YongHyuk Lee <unlogi...@gmail.com>�� �� ��:

�� ��.. �̷��� ���� �ִµ� �ѵ�.. ����������..

vm ���� �ɼǿ�..

-DUseSunHttpHandler=true

�̷������� httpClient ���� Sun JDK ����϶�� ������ �� �ִٴ�...

2012�� 7�� 23�� ���� 12:21, Ȳ��� <sta...@gmail.com>�� �� ��:

����jdk�� ������̶�� ����Ŭjdk�� �ٲټ���

2012. 7. 22. ���� 11:34 GIL <jb9...@gmail.com> �ۼ�:

�ȳ��ϼ���. 
��� ������ XML�� ���� �ϱ� ���ؼ� URL Connection�� �̿��ؼ� Read �߽��ϴ�.
    ex> URL url = new URL(path);
 URLConnection conn = url.openConnection();
 is  = conn.getInputStream();
 
�׷���, ��� ������ Https �� ��������  �ϱ�� ���� Exception�� �߻� �ϳ׿�.
 'javax.net.ssl.sslHandshake Exception: sun.security.validator.validationException: PKIK path building failed: sun.security.
provider.certPath.SuncertPathBuilderException: unable to find valid certification path to requested target. 

���۸� �Ͽ��� 3���� ������� �ذ��� �õ��� �غý��ϴ�. 
  • System.setProperty("java.protocal, "~~");    com.sun.net.ssl.internal.ssl.Provider provider = ~~~ ;  Security.addProvider(provider) ; �ش� �ڵ� �߰�
  • HttpsURLConnection conn = (HttpsURLConnection)url.openConnection(); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, null, null);
         conn.setSSLSocketFactory(context.getSocketFactory()); �ش� ������� connection�� �δ� ��
  • installcert.java ������ �޾� jssercacers ���� ���Ͽ� java_home/jre/lib/security/ ����� ���� ��.

������ ��� �����Ͽ� ���ϴ�. ��� �� ������ �ذ� �� �� �������? 
 
 

--
Google �׷콺 'Korea Spring User Group' �׷쿡 ���������Ƿ� �� ������ ��۵Ǿ���ϴ�.
������ �� ����� ������ https://groups.google.com/d/msg/ksug/-/DNNVDLNaDxMJ�� (��) �湮�ϼ���.
�� �׷쿡 �Խ��Ϸ��� ks...@googlegroups.com(��) �� �̸����� ��������.
�׷쿡�� Ż���Ϸ��� ksug+uns...@googlegroups.com �� �̸����� �����ּ���.
�� ���� �ɼ��� ������ http://groups.google.com /group/ksug?hl=ko���� �׷��� �湮�ϼ���.
--
Google �׷콺 'Korea Spring User Group' �׷쿡 ���������Ƿ� �� ������ ��۵Ǿ���ϴ�.
�� �׷쿡 �Խ��Ϸ��� ks...@googlegroups.com(��) �� �̸����� ��������.
�׷쿡�� Ż���Ϸ��� ksug+uns...@googlegroups.com�� �̸����� �����ּ���.
�� ���� �ɼ��� ������ http://groups.google.com/group/ksug?hl=ko�� �� �׷��� �湮�ϼ���.



--
----------------------------------------
itemBay ���߽� ����2��
���� / �̿���
Mobile: 010.8425.9004
����� ��õ�� ��2�� 524-1

--
Google �׷콺 'Korea Spring User Group' �׷쿡 ���������Ƿ� �� ������ ��۵Ǿ���ϴ�.
�� �׷쿡 �Խ��Ϸ��� ks...@googlegroups.com(��)�� �̸����� ��������.
�׷쿡�� Ż���Ϸ��� ksug+uns...@googlegroups.com�� �̸����� �����ּ���.
�� ���� �ɼ��� ������ http://groups.google.com/group/ksug?hl=ko�� �� �׷��� �湮�ϼ���.

--
Google �׷콺 'Korea Spring User Group' �׷쿡 ���������Ƿ� �� ������ ��۵Ǿ���ϴ�.
�� �׷쿡 �Խ��Ϸ��� ks...@googlegroups.com(��) �� �̸����� ��������.
�׷쿡�� Ż���Ϸ��� ksug+uns...@googlegroups.com�� �̸����� �����ּ���.
�� ���� �ɼ��� ������ http://groups.google.com/group/ksug?hl=ko�� �� �׷��� �湮�ϼ���.

--
Google �׷콺 'Korea Spring User Group' �׷쿡 ���������Ƿ� �� ������ ��۵Ǿ���ϴ�.
�� �׷쿡 �Խ��Ϸ��� ks...@googlegroups.com(��)�� �̸����� ��������.
�׷쿡�� Ż���Ϸ��� ksug+uns...@googlegroups.com�� �̸����� �����ּ���.
�� ���� �ɼ��� ������ http://groups.google.com/group/ksug?hl=ko���� �׷��� �湮�ϼ���.

GIL

unread,
Aug 6, 2012, 9:42:58 AM8/6/12
to ks...@googlegroups.com
jeager 님이 올리신
요기 소스보고 해결 했습니다. 감사합니다.

2012년 7월 22일 일요일 오후 11시 34분 8초 UTC+9, GIL 님의 말:
Reply all
Reply to author
Forward
0 new messages