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可以 ...
随机推荐
- 在docker中部署centos7镜像
本篇文章参考自: https://www.cnblogs.com/linjj/p/5606911.html https://blog.csdn.net/u012767761/article/detai ...
- javascript中的return、return true、return false、continue区别
1.语法为:return 表达式; 2.w3c中的解释: 语句结束函数执行,返回调用函数,而且把表达式的值作为函数的结果 也就是:当代码执行到return语句时,函数返回一个结果就结束运行了,ret ...
- JSON和JSONP详解
什么是JSON JSON是一种基于文本的数据交换方式,或者叫做数据描述格式,你是否该选用他首先肯定要关注它所拥有的优点. JSON的优点: 1.基于纯文本,跨平台传递极其简单: 2.Javascrip ...
- sqlserver服务启动后停止,传递给数据库 'master' 中的日志扫描操作的日志扫描号无效
电脑异常重启,导致SqlServer服务启动后,自动停止,在[计算机管理]-[事件查看器]-[windows日志]中进行查看系统错误日志,在[应用程序]下发现可能的错误信息有以下两条: 1.错误:传递 ...
- visual studio 2017 installer 安装包制作过程出现的问题---无法注册模块 HRESULT -2147024769 请与您的技术支持人员联系
使用visual studio 2017 installer制作打包程序时如果用到了外部控件需要按以下方式操作: 1.将应用程序及应用程序所用到的所有DLL拷贝到打包目录,加入打包程序之中. 2.将应 ...
- 前端工程化-webpack(babel编译ES6)
最新版安装与普通安装 使用babel-loader编译ES6,需要遵循规范,安装babel-presets 规范列表 对应babel-loader,babel-preset安装最新版和普通版: pre ...
- hdu4812 逆元+树分治
逆元链接:https://www.cnblogs.com/zzqc/p/7192436.html 经典的树分治题 #pragma comment("linker,"/STACK:1 ...
- CSS3:HSL和HSLA
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Ext.js入门:常用组件与综合案例(七)
一:datefield简单示例 二:timefield简单示例 三:numberfield简单示例 四:FormPanel提交 datefield简单示例: <html xmlns=&quo ...
- Python yaml模块
引用自:https://www.cnblogs.com/shaosks/p/7344771.html 一.简介 YAML 语言(发音 /ˈjæməl/ )的设计目标,就是方便人类读写.它实质上是一种通 ...