Why do I encounter SSL certificate verification failed (result: 5) error for HTTP request?

30 views (last 30 days)
I am using the HTTP request function in MATLAB on macOS. However, I received the following error
Error using matlab.net.http.RequestMessage/sendOneRequest (line 1337) Secure connection to "https://some.website.url" not established because "SSL: certificate verification failed (result: 5)". Check your system certificates for expired, missing, or invalid certificates. Error in matlab.net.http.RequestMessage/sendAfterChallenge (line 1674) [response, request, history] = obj.sendOneRequest(connector, options, ... Error in matlab.net.http.RequestMessage/sendAndAuthenticate (line 1132) obj.sendAfterChallenge(response, connector, ... Error in matlab.net.http.RequestMessage/send (line 543) obj.sendAndAuthenticate([], completedURI, [], connector, options, ... Error in checkserver (line 7) resp = send(req, uri);
Why does this issue occur and how can I solve it?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Jan 2025
Edited: MathWorks Support Team on 3 Feb 2025
This issue was caused by expired certification as the error message suggests. It has been addressed in MATLAB R2021a and later releases. For earlier releases, here are a couple of workarounds for MATLAB R2020a as an example:
1) Force MATLAB to use the latest certificate file from the website
        In this case, you will need to download and use the certificate for the requested website/URL, and convert it into a Privacy-Enhanced Mail (PEM) file. Once you have the PEM file, you can then specify this certificate PEM file using "HTTPOptions.CertificateFilename".
        a. When using "request.send()" API for HTTP request in MATLAB
                Add the PEM file as follows:
options = matlab.net.http.HTTPOptions('CertificateFilename', <Path to POM File>); % Create Option
                For "CertificateFilename", you can access the documentation by executing the following command in the MATLAB R2020a command window:
               
>> web(fullfile(docroot, 'matlab/ref/matlab.net.http.httpoptions-class.html'))
                Then update the request using the option set:
response = request.send(url,options); % Send request by using the new option
        b. When using a higher level web access APIs
                Add the PEM file as follows:
options = weboptions(CertificateFilename, <Path to POM File>) 
                And refer to the following documentation pages:
                To access the documentation, execute the following command in the MATLAB R2020a command window:
               
>> web(fullfile(docroot, 'matlab/internet-file-access.html'))
                Additionally, for web options, use the command:
               
>> web(fullfile(docroot, 'matlab/ref/weboptions.html'))
                Then modify the HTTP request functions to take the new options.
        For obtaining the PEM file, you can refer to the following page as an example:
2) Alternatively, disable the verification of the certificates
        In this case, you will need to add the option to disable the verification. Do keep in mind that this workaround makes the connection less secure.
options = matlab.net.http.HTTPOptions('VerifyServerName', false); response = request.send(url,options);

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!