svnkit https 忽略证书认证
直接上代码
解决jdk版本问题:Security.setProperty("jdk.tls.disabledAlgorithms", "");
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import org.apache.log4j.Logger;
import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil; import cn.internetware.yanphone.genplatform.constants.ServerConstants;
import cn.internetware.yanphone.genplatform.model.ApiInfo;
import cn.internetware.yanphone.genplatform.model.Commit;
import cn.internetware.yanphone.genplatform.model.Group;
import cn.internetware.yanphone.genplatform.model.SVNProjectLog; public class SVNUtils { private static final Logger LOGGER = Logger.getLogger(SVNUtils.class); static {
Security.setProperty("jdk.tls.disabledAlgorithms", "");
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
} public static boolean deleteFile(String url, String username, String password, String message) {
try { SVNURL svnUrl = SVNURL.parseURIEncoded(url); ISVNAuthenticationManager authManager = new BasicWithCertificateTrustedAuthenticationManager(username,
password);
SVNClientManager clientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),
authManager);
SVNCommitClient commitClient = clientManager.getCommitClient();
commitClient.doDelete(new SVNURL[] { svnUrl }, "delete project " + message);
} catch (SVNException e) {
LOGGER.error("Delete svn error", e);
return false;
}
return true;
} public static long checkout(String url, File destPath) {
ISVNAuthenticationManager authManager = new BasicWithCertificateTrustedAuthenticationManager(
ServerConstants.SVN_ADMIN_USERNAME, ServerConstants.SVN_ADMIN_PASSWORD);
SVNClientManager clientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),
authManager);
SVNUpdateClient updateClient = clientManager.getUpdateClient();
try {
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
return updateClient.doCheckout(svnUrl, destPath, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false);
} catch (SVNException e) {
LOGGER.error("svn checkout error ...... ", e);
}
return 0;
} }
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; /**
* TrustManager utilities for generating TrustManagers.
*
* @since 3.0
*/
public final class TrustManagerUtils
{
private static final X509Certificate[] EMPTY_X509CERTIFICATE_ARRAY = new X509Certificate[]{}; private static class TrustManager implements X509TrustManager { private final boolean checkServerValidity; TrustManager(boolean checkServerValidity) {
this.checkServerValidity = checkServerValidity;
} /**
* Never generates a CertificateException.
*/
public void checkClientTrusted(X509Certificate[] certificates, String authType)
{
return;
} public void checkServerTrusted(X509Certificate[] certificates, String authType)
throws CertificateException
{
if (checkServerValidity) {
for (int i = 0; i < certificates.length; ++i)
{
certificates[i].checkValidity();
}
}
} /**
* @return an empty array of certificates
*/
public X509Certificate[] getAcceptedIssuers()
{
return EMPTY_X509CERTIFICATE_ARRAY;
}
} private static final X509TrustManager ACCEPT_ALL=new TrustManager(false); private static final X509TrustManager CHECK_SERVER_VALIDITY=new TrustManager(true); /**
* Generate a TrustManager that performs no checks.
*
* @return the TrustManager
*/
public static X509TrustManager getAcceptAllTrustManager(){
return ACCEPT_ALL;
} /**
* Generate a TrustManager that checks server certificates for validity,
* but otherwise performs no checks.
*
* @return the validating TrustManager
*/
public static X509TrustManager getValidateServerCertificateTrustManager(){
return CHECK_SERVER_VALIDITY;
} /**
* Return the default TrustManager provided by the JVM.
* <p>
* This should be the same as the default used by {@link javax.net.ssl.SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)
* SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
* when the TrustManager parameter is set to {@code null}
* @param keyStore the KeyStore to use, may be {@code null}
* @return the default TrustManager
* @throws GeneralSecurityException
*/
public static X509TrustManager getDefaultTrustManager(KeyStore keyStore) throws GeneralSecurityException {
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory instance = TrustManagerFactory.getInstance(defaultAlgorithm);
instance.init(keyStore);
return (X509TrustManager) instance.getTrustManagers()[0];
} }
import java.security.cert.X509Certificate; import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager; public class BasicWithCertificateTrustedAuthenticationManager extends BasicAuthenticationManager { public BasicWithCertificateTrustedAuthenticationManager(String userName, String password) { super(userName, password); } @Override public TrustManager getTrustManager(SVNURL url) throws SVNException { try { // HTTPS URL requires certificate trust process // if (url != null && url.getProtocol() != null &&
// url.getProtocol().startsWith("https")) { // TrustManagerUtils comes from commons-net:commons-net:3.3 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) { }
} };
return trustAllCerts[0]; // } } catch (Exception e) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getMessage()), e); } } }
svnkit https 忽略证书认证的更多相关文章
- RestTemplate请求https忽略证书认证
RestTemplate是Spring提供的用于访问Rest服务的客户端,提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率.RestTemplate 默认使用J2SE提供的方式( ...
- SSL通信-忽略证书认证错误
.NET的SSL通信过程中,使用的证书可能存在各种问题,某种情况下可以忽略证书的错误继续访问.可以用下面的方式跳过服务器证书验证,完成正常通信. 1.设置回调属性ServicePointManager ...
- java实现https免证书认证
java实现https免证书认证 解决方法: 1.下载两个包,httpclient-4.2.jar和httpcore-4.2.jar,复制以下代码就可使用. 2.调用类代码: String htt ...
- https绕过证书认证请求 Get或Post请求(证书过期,忽略证书)
报错信息 解决: postman方式 java请求 报错信息 javax.net.ssl.SSLHandshakeException: sun.security.validator.Validator ...
- https的证书认证 iOS版
一.证书链 SecTrustRef: SecTrustRef trust = challenge.protectionSpace.serverTrust; 需要先拿出一个 SecTrustRef 对象 ...
- Https 忽略证书\使用自定义证书的java代码实现
public SSLContext createIgnoreVerifySSL() throws KeyManagementException, NoSuchAlgorithmException, K ...
- 各种编程语言忽略http的SSL证书认证
目录 前言 代码 go语言 Python语言 Ruby语言 Java语言 PHP语言 C#语言 前言 我们内部测试的http服务器很多时候证书都是没有经过第三方认证的,我们发送http请求基本上都是忽 ...
- QT https post请求(QNetworkRequest要设置SSL证书,而SSL证书认证有三种,实测成功)
以VS开发为例.因为https访问需要用到SSL认证,而QT默认是不支持SSL认证,所以在使用之前必须先做一些准备工作: 需要安装OpenSSL库: 1.首先打开http://slproweb.com ...
- Https握手协议以及证书认证
1. 什么是https Https = http + 加密 + 认证 https是对http的安全强化,在http的基础上引入了加密和认证过程.通过加密和认证构建一条安全的传输通道.所以https可以 ...
随机推荐
- Python-百度经纬度转高德经纬度
import math def bdToGaoDe(lon,lat): """ 百度坐标转高德坐标 :param lon: :param lat: :return: &q ...
- git 使用https 和SSH 提交远程库小总结
一.使用https提交远程库 首先已经git commit -m “注释” 本地仓库关联远程github服务器:git remote add origin “https://XXXX.git” 提交 ...
- 使用rpm包安装lamp环境
前提: 是你的centos能联网,或者有本地的yum仓库 或者配置通过代理上网 vim /etc/yum.conf 加入如下内容 proxy=http://192.168.11.82:808 1.通过 ...
- php中常用的正则表达式函数
php中常用的正则表达式函数 * preg_match() * preg_match_all() * preg_replace() * preg_filter() * preg_grep() * pr ...
- 性能测试二十二:环境部署之Nginx
由于单纯用tomcat只能通过ip+端口号的形式访问,这样只能访问一个tomcat,而真实项目中又不可能只用一两个tomcat,所以就需要Nginx来进行分配访问请求, Nginx本身性能非常好,据官 ...
- Fiddler抓包5-接口测试(Composer)
前言 Fiddler最大的优势在于抓包,我们大部分使用的功能也在抓包的功能上,fiddler做接口测试也是非常方便的. 对应没有接口测试文档的时候,可以直接抓完包后,copy请求参数,修改下就可以了. ...
- java远程工具类
package com.zdz.httpclient; import java.io.BufferedReader; import java.io.IOException; import java.i ...
- Django 关闭Debug后使用Nginx做静态文件的访问
Django 关闭Debug后使用Nginx做静态文件的访问 关闭Django 的Debug参数 1 . 修改settings.py配置文件 DEBUG = False 2 . settings.py ...
- 【C语言】 二叉树的基本运算
• 二叉树节点类型BTNode: typedef struct node { char data; struct node *lchild, *rchild; } BTNode; 创建二叉树 void ...
- 转 关于Https协议中的ssl加密解密流程
关于Https协议中的ssl加密解密流程 2016年09月28日 09:51:15 阅读数:14809 转载自:http://www.cnblogs.com/P_Chou/archive/2010/1 ...