`
Blackbaby
  • 浏览: 185037 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Disabling Certificate Validation in an HTTPS Connection

    博客分类:
  • java
 
阅读更多

final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
	public boolean verify(String hostname, SSLSession session) {
		return true;
	}
};

//Trust every server - dont check for any certificate 
private static void trustAllHosts() {
	// Create a trust manager that does not validate certificate chains
	TrustManager[] trustAllCerts = new TrustManager[] {
		new X509TrustManager() {
			public java.security.cert.X509Certificate[] getAcceptedIssuers() {
				return new java.security.cert.X509Certificate[] {};
			}
			public void checkClientTrusted(X509Certificate[] chain, String authType) {
			}
			public void checkServerTrusted(X509Certificate[] chain, String authType) {
			}
		}
	};
	// Install the all-trusting trust manager
	try {
		SSLContext sc = SSLContext.getInstance("TLS");
		sc.init(null, trustAllCerts, new java.security.SecureRandom());
		HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
URL url = new URL(effectiveUrl);
if (url.getProtocol().toLowerCase().equals("https")) {
	trustAllHosts();
	HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
	https.setHostnameVerifier(DO_NOT_VERIFY);
	connection = https;
} else {
	connection = (HttpURLConnection) url.openConnection();
URL url = new URL("http://haat.cn/DAQgE"); 
URLConnection conn = url.openConnection();
((HttpURLConnection) conn).setInstanceFollowRedirects(false);//Location header  302
String val = conn.getHeaderField("Location");
System.out.println(val);
分享到:
评论

相关推荐

    .NET mvc5 code first 教程

    A Visual Studio 2013 project which shows how to use the Entity Framework 6 in an ASP.NET MVC 5 web application project, using the Code First development approach. The previous version that uses EF 5 ...

    PLSQL.Developer v11.0.3.1770 主程序+ 中文包+keygen

    SQL Window could display an incorrect elapsed time Window List no longer brings window to front when closing a window with Shift-Click or Ctrl-Click Changing a window with Ctrl-Tab, Ctrl-Shift-Tab and...

    Improving the Performance of an IP-over-P2P

    Traffic is encrypted by default over all IPOP connections, with no granularity in enabling or disabling it. This research proposes and implements the feature of selective security, in which only a ...

    Bulletproof SSL and TLS,PDF , Ivan Ristic

    Backend Certificate and Hostname Validation 254 HTTP Strict Transport Security 254 Content Security Policy 255 Protocol Downgrade Protection 255 9. Performance Optimization . . . . . . . . . . . . . ....

    Odin – Inspector and Serializer v3.0.9

    With an effortless integration that deploys perfectly into pre-existing workflows, Odin allows you to serialize anything and enjoy Unity with 80+ new inspector attributes, no boilerplate code and so ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: In THistory.DeleteActions added validation of FActionIndex (FActionIndex could appear beyond the list boundaries). Thanks to Giedrius Matonis. - ADD: Added the method TCustomProp.Assign - a ...

    NIST SP800-98_RFID-2007.pdf

    approaches to privacy protection that involve the temporary or permanent disabling of RFID technology may introduce a security vulnerability because of the potential for these mechanisms to be used in...

    英文原版-Essentials of Schizophrenia 1st Edition

    Schizophrenia remains a common and frequently disabling illness that poses enormous challenges for affected individuals, their families, mental health care providers, healthcare systems, and society ...

    微软内部资料-SQL性能优化3

    In our example, if one transaction (T1) holds an exclusive lock at the table level, and another transaction (T2) holds an exclusive lock at the row level, each of the transactions believe they have ...

    Python Cookbook, 2nd Edition

    Reading an Unbuffered Character in a Cross-Platform Way Recipe 2.24. Counting Pages of PDF Documents on Mac OS X Recipe 2.25. Changing File Attributes on Windows Recipe 2.26. Extracting Text ...

    01450A (1).pdf

    Enabling/disabling of delays is configured in the code by commenting/uncommenting the following lines of code: ;; 2 lines below enable rising and falling edge delays #define RISING_EDGE_DELAY #define...

    logback.xml

    logback常用配置,包含debug、info、warn、error、界别的配置,输出到文件,按照日期建立文件夹

    TICQClient Version

    An option disabling direct connections, see property DisableDirectConnections[*] Direct connections are estabilished now through proxy (if any)[*] Removed thread layer while resolving IPs in SOCKS ...

    java7帮助文档

    see Appendix D: Disabling Cryptographic Algorithms in Java PKI Programmer's Guide and Disabled Cryptographic Algorithms in Java Secure Socket Extension (JSSE) Reference Guide. Various enhancements ...

    日志(logback)

    日志(logback)

    Build Report Tool 3.0.19.rar

    In case you get any build errors that you think might be caused by the Build Report Tool, try disabling the Build Report Window from showing automatically whenever you build. You can do this by ...

    Utilities for Windows NT 源码

    While lots of Windows NT settings can be changed through the registry, disabling the Lock Workstation button in the Windows NT Security (Ctrl-Alt-Del) dialog seems to be forgotten. This program ...

    Visual Assist X 2107官方原版 带破解补丁

    When Goto is invoked on an external type in XAML, VA prompts to open the Object Browser (instead of searching it without prompting). (case=96541) Find Symbol in Solution dialog lists symbols defined ...

    Spring.Boot.in.Action.2015.12.pdf

    ary 9Oish-character tweetable Boot application to an in-depth analysis of Boots Actuator in chapter 7, which enables a host of auto-magical operational features required for any production application...

    Odin2.0.15.rar

    With an effortless integration that deploys perfectly into pre-existing workflows, Odin allows you to serialize anything and enjoy Unity with 80+ new inspector attributes, no boilerplate code and so ...

Global site tag (gtag.js) - Google Analytics