【问题标题】:https call working when called direct from java ,but not working from inside oracle 12chttps调用在直接从java调用时工作,但不能从oracle 12c内部工作
【发布时间】:2021-05-15 10:18:30
【问题描述】:

错误是: sun.security.validator.ValidatorException: PKIX 路径验证失败:java.security.cert.CertPathValidatorException:时间戳检查失败

使用的代码是:

create or replace and compile java source named sendsms as
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class HttpsCall {
public static void main(String[] args) throws Exception {
        
String httpsURL = "https://www.jawalbsms.ws/api.php/sendsms?user=abc&pass=xyz&to=9665555555555&message=good morning&sender=abc";
        
 URL myUrl = new URL(httpsURL);
 HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
 InputStream is = conn.getInputStream();
 InputStreamReader isr = new InputStreamReader(is);
 BufferedReader br = new BufferedReader(isr);

 String inputLine;

 while ((inputLine = br.readLine()) != null) {
       System.out.println(inputLine);
        }

    br.close();

} }

【问题讨论】:

    标签: java https oracle12c


    【解决方案1】:

    通过在代码中添加以下行来解决,现在可以在 oracle 12c 中正​​常工作

     SSLContext context = SSLContext.getInstance("TLSv1.2");
     TrustManager[] trustManager = new TrustManager[] {
     new X509TrustManager() {
     public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
          }
     public void checkClientTrusted(X509Certificate[] certificate, String str) {}
                 public void checkServerTrusted(X509Certificate[] certificate, String      str) {}
        }
      };
    context.init(null, trustManager, new SecureRandom());
    
    
    HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
    
    javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
    new HostnameVerifier(){
    public boolean verify(String hostname, SSLSession session) {   
           return true;   
      }
        });
    

    【讨论】:

    • 我认为这并没有像忽略问题那样真正“解决”。该端点由 Go Daddy 根证书颁发机构 G2 锚定。我相信这是大多数 Java 发行版的标准配置,但您的 Oracle 发行版似乎在其信任库中没有那个。
    猜你喜欢
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2018-04-12
    • 1970-01-01
    相关资源
    最近更新 更多