PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/runtime/esb-security/src/com/sun/jbi/internal/security/https/DefaultHostnameVerifier.java

https://bitbucket.org/openesb/openesb-core
Java | 121 lines | 47 code | 14 blank | 60 comment | 3 complexity | 4cfb31eed386007d00bbb484381508d6 MD5 | raw file
  1. /*
  2. * BEGIN_HEADER - DO NOT EDIT
  3. *
  4. * The contents of this file are subject to the terms
  5. * of the Common Development and Distribution License
  6. * (the "License"). You may not use this file except
  7. * in compliance with the License.
  8. *
  9. * You can obtain a copy of the license at
  10. * https://open-esb.dev.java.net/public/CDDLv1.0.html.
  11. * See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. *
  14. * When distributing Covered Code, include this CDDL
  15. * HEADER in each file and include the License file at
  16. * https://open-esb.dev.java.net/public/CDDLv1.0.html.
  17. * If applicable add the following below this CDDL HEADER,
  18. * with the fields enclosed by brackets "[]" replaced with
  19. * your own identifying information: Portions Copyright
  20. * [year] [name of copyright owner]
  21. */
  22. /*
  23. * @(#)DefaultHostnameVerifier.java
  24. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
  25. *
  26. * END_HEADER - DO NOT EDIT
  27. */
  28. /**
  29. * DefaultHostnameVerifier.java
  30. *
  31. * SUN PROPRIETARY/CONFIDENTIAL.
  32. * This software is the proprietary information of Sun Microsystems, Inc.
  33. * Use is subject to license terms.
  34. *
  35. * Created on October 20, 2004, 5:33 PM
  36. */
  37. package com.sun.jbi.internal.security.https;
  38. import com.sun.jbi.StringTranslator;
  39. import java.net.InetAddress;
  40. import java.net.UnknownHostException;
  41. import java.util.logging.Logger;
  42. import javax.net.ssl.SSLSession;
  43. /**
  44. * The default hostname verifier is throwing a java.io.IOException:
  45. * HTTPS hostname wrong: should be [hostname] ( this was probably due
  46. * to a failure to map the IP to the hostname.
  47. *
  48. * @author Sun Microsystems, Inc.
  49. */
  50. public class DefaultHostnameVerifier
  51. implements javax.net.ssl.HostnameVerifier
  52. {
  53. /** The Logger */
  54. private Logger mLogger = null;
  55. /** The String Translator. */
  56. private StringTranslator mTranslator;
  57. /**
  58. * Creates a new instance of DefaultHostnameVerifier.
  59. *
  60. * @param translator is the StringTranslator
  61. */
  62. public DefaultHostnameVerifier(StringTranslator translator)
  63. {
  64. mLogger = Logger.getLogger(
  65. com.sun.jbi.internal.security.Constants.PACKAGE);
  66. mTranslator = translator;
  67. }
  68. /**
  69. *
  70. * @param urlHostName is the Hostname from the Service URL
  71. * @param session is the SSL Session
  72. * @return true if verified.
  73. */
  74. public boolean verify(String urlHostName, SSLSession session)
  75. {
  76. InetAddress[] urlHostAddresses = null;
  77. InetAddress[] peerHostAddresses = null;
  78. try
  79. {
  80. urlHostAddresses = InetAddress.getAllByName(urlHostName);
  81. peerHostAddresses = InetAddress.getAllByName(session.getPeerHost());
  82. }
  83. catch (UnknownHostException uhex)
  84. {
  85. // -- Log the exception
  86. mLogger.warning(uhex.toString());
  87. return false;
  88. }
  89. // -- Maybe there is a better way of doing this comparison,
  90. // -- but the list of ip addresses on a multihomed schemaorg_apache_xmlbeans.system should be small.
  91. for ( int i = 0; i < urlHostAddresses.length; i++)
  92. {
  93. // -- Compare each urlHostIP to each peerHostIP
  94. for ( int j = 0; j < peerHostAddresses.length; j++)
  95. {
  96. if ( urlHostAddresses[i].equals(peerHostAddresses[j]))
  97. {
  98. return true;
  99. }
  100. }
  101. }
  102. mLogger.severe(mTranslator.getString(
  103. HttpConstants.BC_ERR_HOSTNAME_VERIFICATION_FAILED,
  104. urlHostName, session.getPeerHost()));
  105. return false;
  106. }
  107. }