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可以 ...
随机推荐
- unbuntu中如何像Windows一样顺畅的切换中英文输入法
1.首先在unbuntu安装搜狗拼音输入法(这个不用教了) 2.点击右上角的搜狗拼音的图标点击设置进入设置页面 3.选择高级 4.选择Fcitx设置 5.添加输入法英语(美国) 6.在设置中选择按键, ...
- python 语言特性
动态强类型: 动态类型语言:在运行期进行类型检查的语言,也就是在编写代码的时候可以不指定变量的数据类型,比如Python和Ruby 静态类型语言:它的数据类型是在编译期进行检查的,也就是说变量在使用前 ...
- 16-client、offset、scroll系列
1.client系列 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...
- wordpress更换主题未能连接到FTP服务器
报错原因:由于你的 WordPress 所在的目录没有写入权限,而wordpress安装主题或者更新时,企图通过ftp帐号进行更新,所以无法完成安装或更新 解决办法: 找到wp-config.php文 ...
- Deep Learning系统实训之三:卷积神经网络
边界填充(padding):卷积过程中,越靠近图片中间位置的像素点越容易被卷积计算多次,越靠近边缘的像素点被卷积计算的次数越少,填充就是为了使原来边缘像素点的位置变得相对靠近中部,而我们又不想让填充的 ...
- AlexNet
AlexNet学习笔记 目录 AlexNet整体结构 CNN 全连接 TensorFlow实现 AlexNet是2012年ImageNet竞赛冠军获得者Hinton和他的学生Alex Krizhevs ...
- web----粘包
一.什么是粘包 所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 须知:只有TCP有粘包现象,UDP永远不会粘包 粘包不一定会发生 如果发生了:1.可能是在 ...
- jsp统计页面访问量和刷访问量的简单使用
~Jsp可以进行简单的页面访问量统计,当然也可以使用Jsp刷访问量. 1:第一种使用全局变量<%! int i=0;%>进行页面的访问量统计,只有新打开一个浏览器才可以进行统计. 2:第二 ...
- c++ primer 笔记 (三)
标准库类型string 和 vector ,分别定义了大小可变的字符串和集合. bitset,提供了一个抽象方法来操作位的集合.提供更方便的处理位的方式(相对于整型值上 ...
- Jmeter如何提取响应头部的JSESSIONID
近期有柠檬班的学生找到华华,问了一个问题,就是利用Jmeter做接口测试的时候,如何提取头部的JSESSIONID然后传递到下一个请求,继续完成当前用户的请求. 其实,关于这个问题有三种种解决方法: ...