I am trying to access an HTTPS server with a self-signed certificate from MATLAB. I have tried various methods in various MATLAB releases:
>> urlread('https://self-signed.badssl.com/')
In all MATLAB releases throws:
Error using urlreadwrite (line 98)
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.
Error in urlread (line 36)
[s,status] = urlreadwrite(mfilename,catchErrors,url,varargin{:});
And when trying to use pure Java:
>> u = java.net.URL('https://self-signed.badssl.com/');>> conn = u.openConnection;>> conn.connect
I receive:
Java exception occurred:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
(snip)
Further, webread:
>> webread('https://self-signed.badssl.com/')
In MATLAB releases prior to R2016b actually returns the data without any error or warning for this server:
ans =<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="shortcut icon" href="/icons/favicon-red.ico"/> <link rel="apple-touch-icon" href="/icons/icon-red.png"/> <title>self-signed.badssl.com</title> <link rel="stylesheet" href="/style.css"> <style>body { background: red; }</style></head><body><div id="content"> <h1 style="font-size: 12vw;"> self-signed.<br>badssl.com </h1></div></body></html>
But for another server:
>> webread('https://localhost/')
I receive:
Error using readContentFromWebService (line 45)
The server returned the message: "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target" for URL, 'https://localhost/' (with HTTP response code unknown).
Error in webread (line 122)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
And in MATLAB release R2016b:
>> webread('https://self-signed.badssl.com/')
Throws:
Error using webread (line 119)
Could not establish a secure connection to "self-signed.badssl.com". The reason is "error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed".
Check your certificate file (C:\MATLAB\R2016b\sys\certificates\ca\rootcerts.pem) for expired, missing or invalid certificates.
For both servers actually.
Best Answer