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可以 ...
随机推荐
- 006_nginx动态upstream和安全检查模块
一.参考Tengine http://tengine.taobao.org/document_cn/http_dyups_cn.html ngx_http_dyups_module Descrip ...
- 路由器中继(repeater)模式 和 AP+WDS模式区别?
理论上的 中继(repeater)模式, 只有连接的最后一个才会有信号发出,中间的连接节点是没有信号发出的. AP+WDS模式:就是每一个路由都有信号发出,可以进行信号的全方位覆盖.
- 调试Windows Service
调试Windows Service 使用一般的调试方法调试不了Windows Servers,所以参考了一些调试方法 我服务源码中使用了Timer,注意不能使用工具箱内的Timer,用System.T ...
- keras2.0的一些变化
keras 变化太快了https://github.com/fchollet/keras/wiki/Keras-2.0-release-notes
- Jmeter接口测试实例图文示例
以getObjectByCode接口为例,用jmeter2.13来进行接口测试. 测试前准备: 测试工具及版本:jmeter 2.13 r1665067(须包含__MD5函数) 示例接口:8.1根据单 ...
- python----多继承C3算法
https://blog.csdn.net/fmblzf/article/details/52512145
- SPOJ-SERVICE 线性dp+维度压缩
还是线性dp,有点感觉了,另外这个问题也可以用滚动数组 /* 依然是先按照阶段i划分, dp[i][j][k]表示完成第i个请求时,两个员工分别在j位置和k位置的费用(还有一个员工一定在位置p) dp ...
- [转] python安装numpy和pandas
最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了.首要条件,python版本必须 ...
- noip2016 天天爱跑步
没看过正解..应该是些乱七八糟想不出来的东西 解法1: 首先,必须要做的是将每条路径拆成2个直的路径 那么对于那条从深度大的到深度小的路径 dep[x]-dep[y]应该等于观察时间 那么就可以在这些 ...
- web扫描工具-Nikto介绍与使用
Nikto Perl语言开发的开源Web安全扫描器 web扫描模式:截断代理主动扫描 可以扫描的方面:软件版本搜索存在安全隐患的文件服务器配置漏洞WEB Application层面的安全隐患避免404 ...