Testing with untrusted Https

本文介绍了解决在使用未签名HTTPS证书进行Web应用测试时遇到的信任问题的方法。主要分为两个步骤:首先捕获Web服务器的证书,然后使用Sun的keytool工具将其导入。通过这种方法,可以在开发环境中成功测试使用自签名证书的HTTPS网站。
 

Testing web applications in developmental environments that attempt to utilize Https through unsigned certificates can be challenging, especially if you’ve never had the pleasure of working with Sun’s keytool utility and X.509 security certificates.

This issue manifests itself as javax.net.ssl.SSLHandshakeExceptions and sun.security.validator.ValidatorExceptions. For example, attempting to access untrusted Https through Java may yield stack traces with these tidbits:

Javax.net.ssl.SSLHandshakeException: 
 sun.security.validator.ValidatorException: 
  PKIX path building failed: 
    sun.security.provider.certpath.SunCertPathBuilderException:
	 unable to find valid certification path to requested target
...
Caused by: sun.security.validator.ValidatorException: 
 PKIX path building failed: 
  sun.security.provider.certpath.SunCertPathBuilderException:
   unable to find valid certification path to requested target
...
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
 unable to find valid certification path to requested target

Solving this problem requires two steps. First, the web server’s certificate must be captured. Then, the certificate must be imported with Sun’s keytool utility (which comes with Java).

Obtaining a copy of the certificate in X.509 format requires Microsoft’s Internet Explorer. By placing the https URL into the browser window, a dialog will pop up requesting permission to accept the certificate. Click the View Certificate button and then the Details tab. In this tab, click the Copy to File button, then click Next and select the Base-64 encoded X.509 (.CER) option. After that, click Next to save the resulting file.

Importing the .cer file requires using the keytool utility, which can be found in bin directory of a Java installation. Via this tool, the .cer file is imported into a cacerts file, which is located in the lib/security directory of a Java installation. The easiest thing to do is to copy the .cer file obtained via Internet Explorer to my Java home dir/lib/security.

For example, if using the Java sdk for 1.4.2, the location on windows could be something like: C:/j2sdk1.4.2_05/jre/lib/security.

Once the .cer file has been copied to that directory, open a command prompt and either go to the security directory or use qualified paths. Type the following command:

$ ../../bin/keytool.exe -import -storepass changeit -file mycert.cer 
 -keystore cacerts -alias mycert

The only aspects requiring changes is the name of the certificate (in this case mycert.cer) and the alias (mycert).
The keytool will issue a series of statements describing the certificate and finally request whether or not to trust the certificate. Type yes and hit enter.

The problem should be solved. Verifying things is as easy as writing a test case. For instance, the following JUnit test verifies an untrusted Https site can be hit via Jakarta’s HttpClient.

package test.com.srv.rls.https.submit;

import junit.framework.TestCase;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public class HttpsSubmitTest extends TestCase {

 public void testHttpsConnection() throws Exception{
  HttpClient httpclient = new HttpClient();
  GetMethod httpget =
   new GetMethod("https://prf.acme.com:4175/invoke/ir/rve");
  try {
   httpclient.executeMethod(httpget);
   assertEquals("should have been 200",
      200, httpget.getStatusLine().getStatusCode());
  }finally {
   httpget.releaseConnection();
  }
 }
}

Now testing web applications via JUnit extensions like jWebUnit or HttpUnit is a breeze, so long as they run in the VM which contains the updated keystore.

Editable Email Notification ? Allows the user to disable the publisher, while maintaining the settings Disable Extended Email Publisher ? Project From 840293337@qq.com Project Recipient List ? Comma-separated list of email address that should receive notifications for this project. 1943564708@qq.com Project Reply-To List ? Comma-separated list of email address that should be in the Reply-To header for this project. $DEFAULT_REPLYTO Content Type ? HTML (text/html) Default Subject ? $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS Default Content ? $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results. Attachments ? Can use wildcards like 'module/dist/**/*.zip'. See the @includes of Ant fileset for the exact format. The base directory is the workspace. Attach Build Log ? Do Not Attach Build Log Content Token Reference ? Advanced Settings Pre-send Script ? $DEFAULT_PRESEND_SCRIPT Post-send Script ? $DEFAULT_POSTSEND_SCRIPT Additional groovy classpath ? 新增 Save to Workspace ? Triggers ? Always ? Send To Recipient List ? 新增 高级 Add TriggerDefault notification URL Notification URL ? Jenkins Classic GitHub GitHub 服务器 ? 添加 GitHub 服务器 高级 Edited GitHub API usage Github API usage rate limiting strategy ? Normalize API requests GitHub Enterprise Servers 新增 Global Trusted Pipeline Libraries Sharable libraries available to any Pipeline jobs running on this system. These libraries will be trusted, meaning they run without “sandbox” restrictions and may use @Grab. 新增 Global Untrusted Pipeline Libraries Sharable libraries available to any Pipeline jobs running on this system. These libraries will be untrusted, meaning they run with “sandbox” restrictions and cannot use @Grab. 新增 Build-timeout Plugin > BuildStep Action Enable BuildStep Action ? Git plugin Global Config user.name Value ? Global Config user.email Value ? Create new accounts based on author/committer's email ? Use existing account with same email if found ? Show the entire commit summary in changes ? Hide credential usage in job output ? Disable performance enhancements ? Preserve second fetch during checkout ? Add git tag action to jobs ? Shell Shell executable ? Extended E-mail Notification SMTP server smtp.qq.com SMTP Port 465 高级 Edited Default user e-mail suffix ? 高级 Edited Default Content Type ? HTML (text/html) List ID ? Add 'Precedence: bulk' E-mail Header ? Default Recipients ? $DEFAULT_RECIPIENTS Reply To List ? Emergency reroute ? Allowed Domains ? Excluded Recipients ? Default Subject ? $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS! Maximum Attachment Size ? -1 Default Content ? $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results. Default Pre-send Script ? Default Post-send Script ? Additional groovy classpath ? 新增 Enable Throttling ? Enable Debug Mode ? Require Administrator for Template Testing ? Enable watching for jobs ? Allow sending to unregistered users ? Default Triggers Content Token Reference ? 邮件通知 SMTP服务器 smtp.qq.com 用户默认邮件后缀 ? 高级 Edited 使用SMTP认证 ? 用户名 1943564708@qq.com 密码 已隐藏 修改密码 使用SSL协议 ? Use TLS SMTP端口 ? 465 Reply-To Address 字符集 UTF-8 通过发送测试邮件测试配置 Allure Report 帮我看看配置哪里出了问题,导致任务的地方发不出邮件,但是系统配置地方测试可以发
11-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值