In the last blog post I wrote about how to access an HTTP-resource and the ACL needed for it. That works great for HTTP, but as the world is turning to HTTPS it is not enough in most cases.
In this post I will look at how to set up the trust store in a database to allow access to an HTTPS-based access. I will use the same simple select grabbing the html for a webpage to show how it works.
Where we left off
The last blog post ended with showing how access on HTTPS to the same website we got to work with HTTP gave us a certificate error. You may want to review that post to see the ACL-setup for HTTP.
This is the error we get now.
select utl_http.request('https://example.com') from dual;
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1530 ORA-29024: Certificate validation failure ORA-06512: at "SYS.UTL_HTTP", line 380 ORA-06512: at "SYS.UTL_HTTP", line 1470 ORA-06512: at line 1 29273. 00000 - "HTTP request failed" *Cause: The UTL_HTTP package failed to execute the HTTP request. *Action: Use get_detailed_sqlerrm to check the detailed error message. Fix the error and retry the HTTP request.
Thus, we have the ACL to allow a call to be made, but the certificate of that website cannot be trusted.
What is a trust store
What we need is to set up our trust store. This is a mechanism showing that you want to trust certain certificates. The ones we want to trust are the ones used by the vendors giving out certificates.
We do not need the certificate for a certain website, but the ones that is in the chain of certificates used to create it. There will be at least one more than the certificate for the site you are accessing.
We see this work every day when we browse the internet. Almost every site you visit these days is redirected to https. My blog is served over both. I just noticed that the function for forwarding HTTP to HTTPS is not active so either works right now. I will have to look at that, but I only noticed due to writing this post.
Back to web browsers, they come with a trust store filled with the most common ones so you get to every site without warnings. Occasionally you get to one that is not there or where the certificate has expired. The database comes with an empty trust store, forcing you to explicitly trust every certificate you want to use.
How to download a certificate
When you look around at all the blogs that talks about HTTPS for Oracle DB the instructions I found were all focused on how you click down a certificate via a web browser. Most showing it in IE. The problem is that those instructions are pretty much out of date as soon as the web browser releases a new version. I know of few things that moves around so much in the user interface. It seems no vendor has yet found a place in their GUI where they are happy with it.
While I like a GUI to do ad hoc things, I am not at al happy with a reliance on it to download things needed for an installation. If there is a new certificate, I want to just grab it via script rather than clicking down it in a GUI.
After a lot of reading, testing and playing around I have found this to work for all cases I’ve tried.
openssl s_client -connect example.com:443 -showcerts
Basic explanation follows, for full understanding, dive head first into the world of openssl.
s_client is running this as a client connecting to a remote server using SSL/TLS. Meaning, connecting as a web browser or any other (such as a database) client program would.
-connect identifies the host:port to connect to.
-showcerts displays the whole certificate chain.
For example.com it will return something like this:
CONNECTED(00000008) depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA verify return:1 depth=0 C = US, ST = California, L = Los Angeles, O = Internet Corporation for Assigned Names and Numbers, OU = Technology, CN = www.example.org verify return:1 --- Certificate chain 0 s:/C=US/ST=California/L=Los Angeles/O=Internet Corporation for Assigned Names and Numbers/OU=Technology/CN=www.example.org i:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA -----BEGIN CERTIFICATE----- MIIHQDCCBiigAwIBAgIQD9B43Ujxor1NDyupa2A4/jANBgkqhkiG9w0BAQsFADBN MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E aWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTgxMTI4MDAwMDAwWhcN MjAxMjAyMTIwMDAwWjCBpTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3Ju aWExFDASBgNVBAcTC0xvcyBBbmdlbGVzMTwwOgYDVQQKEzNJbnRlcm5ldCBDb3Jw b3JhdGlvbiBmb3IgQXNzaWduZWQgTmFtZXMgYW5kIE51bWJlcnMxEzARBgNVBAsT ClRlY2hub2xvZ3kxGDAWBgNVBAMTD3d3dy5leGFtcGxlLm9yZzCCASIwDQYJKoZI hvcNAQEBBQADggEPADCCAQoCggEBANDwEnSgliByCGUZElpdStA6jGaPoCkrp9vV rAzPpXGSFUIVsAeSdjF11yeOTVBqddF7U14nqu3rpGA68o5FGGtFM1yFEaogEv5g rJ1MRY/d0w4+dw8JwoVlNMci+3QTuUKf9yH28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37jjd80OyA3cEAAAAWdcMZVGAAAEAwBIMEYCIQCEZIG3IR36Gkj1dq5L6EaGVycX sHvpO7dKV0JsooTEbAIhALuTtf4wxGTkFkx8blhTV+7sf6pFT78ORo7+cP39jkJC AHYAh3W/51l8+IxDmV+9827/Vo1HVjb/SrVgwbTq/16ggw8AAAFnXDGWFQAABAMA RzBFAiBvqnfSHKeUwGMtLrOG3UGLQIoaL3+uZsGTX3MfSJNQEQIhANL5nUiGBR6g l0QlCzzqzvorGXyB/yd7nttYttzo8EpOAHYAb1N2rDHwMRnYmQCkURX/dxUcEdkC wQApBo2yCJo32RMAAAFnXDGWnAAABAMARzBFAiEA5Hn7Q4SOyqHkT+kDsHq7ku7z RDuM7P4UDX2ft2Mpny0CIE13WtxJAUr0aASFYZ/XjSAMMfrB0/RxClvWVss9LHKM MA0GCSqGSIb3DQEBCwUAA4IBAQBzcIXvQEGnakPVeJx7VUjmvGuZhrr7DQOLeP4R 8CmgDM1pFAvGBHiyzvCH1QGdxFl6cf7wbp7BoLCRLR/qPVXFMwUMzcE1GLBqaGZM v1Yh2lvZSLmMNSGRXdx113pGLCInpm/TOhfrvr0TxRImc8BdozWJavsn1N2qdHQu N+UBO6bQMLCD0KHEdSGFsuX6ZwAworxTg02/1qiDu7zW7RyzHvFYA4IAjpzvkPIa X6KjBtpdvp/aXabmL95YgBjT8WJ7pqOfrqhpcmOBZa6Cg6O1l4qbIFH/Gj9hQB5I 0Gs4+eH6F9h3SojmPTYkT+8KuZ9w84Mn+M8qBXUQoYoKgIjN -----END CERTIFICATE----- 1 s:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA -----BEGIN CERTIFICATE----- MIIElDCCA3ygAwIBAgIQAf2j627KdciIQ4tyS8+8kTANBgkqhkiG9w0BAQsFADBh MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3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UDVW0Uy7ZvCj4hsbw5eyPdFVMA0GCSqGSIb3DQEB CwUAA4IBAQAjPt9L0jFCpbZ+QlwaRMxp0Wi0XUvgBCFsS+JtzLHgl4+mUwnNqipl 5TlPHoOlblyYoiQm5vuh7ZPHLgLGTUq/sELfeNqzqPlt/yGFUzZgTHbO7Djc1lGA 8MXW5dRNJ2Srm8c+cftIl7gzbckTB+6WohsYFfZcTEDts8Ls/3HB40f/1LkAtDdC 2iDJ6m6K7hQGrn2iWZiIqBtvLfTyyRRfJs8sjX7tN8Cp1Tm5gr8ZDOo0rwAhaPit c+LJMto4JQtV05od8GiG7S5BNO98pVAdvzr508EIDObtHopYJeS4d60tbvVS3bR0 j6tJLp07kzQoH3jOlOrHvdPJbRzeXDLz -----END CERTIFICATE----- 2 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA -----BEGIN CERTIFICATE----- MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97 nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4 gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= -----END CERTIFICATE----- --- Server certificate subject=/C=US/ST=California/L=Los Angeles/O=Internet Corporation for Assigned Names and Numbers/OU=Technology/CN=www.example.org issuer=/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA --- No client certificate CA names sent Server Temp Key: ECDH, P-256, 256 bits --- SSL handshake has read 4643 bytes and written 322 bytes --- New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256 Server public key is 2048 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session: Protocol : TLSv1.2 Cipher : ECDHE-RSA-AES128-GCM-SHA256 Session-ID: 9EABB694EB9920D06E661977AB2BA1C57C5E6BF8EAEE7D3CD96A5A853956E63F Session-ID-ctx: Master-Key: 42BDA71815735B41A0BBD512D84DB1B71B092C896CA498098D523B3A618809DD8926AFAD86F819003562ACFB12E5ECA1 TLS session ticket lifetime hint: 7200 (seconds) TLS session ticket: 0000 - 57 22 f3 96 0c 39 7a 40-ec 8d ce a4 1b 04 67 f1 W"...9z@......g. 0010 - 54 bd 5e ce 77 69 5e 46-b0 b1 d7 9a 1f f8 db d7 T.^.wi^F........ 0020 - c9 c7 ce a6 97 5a 6f 0f-50 32 b6 6b d5 1c c2 12 .....Zo.P2.k.... 0030 - 4f b3 41 00 1e a2 2a 57-b2 f8 a5 b7 cc d0 fa 86 O.A...*W........ 0040 - a8 66 78 c4 bb 0d ce fd-ca 6a 94 c8 cf c2 e0 44 .fx......j.....D 0050 - f3 2f 13 7b 81 52 ef 8f-64 22 1e 81 24 3f fc 50 ./.{.R..d"..$?.P 0060 - 02 56 a2 11 9f 20 cb bf-5b ee ed 8b 0b e0 0d 28 .V... ..[......( 0070 - 7a de 49 c0 c9 99 10 12-1b ea b5 38 da 57 42 6c z.I........8.WBl 0080 - f4 df ae 0f f2 65 0e d0-72 29 af 11 61 af 8e c0 .....e..r)..a... 0090 - 20 be 28 c9 4f 9a cf 5f-be 48 13 fd d7 e8 69 69 .(.O.._.H....ii Start Time: 1587290660 Timeout : 7200 (sec) Verify return code: 0 (ok) --- closed
That is a quite a file to read and interpret, fortunately we only need to grab some parts and save to a file or two.
The sections we want are the ones like this:
-----BEGIN CERTIFICATE----- <... snip ... > -----END CERTIFICATE-----
You will find three such sections, only copy the last two to new files. I’ll use the names cert1.txt and cert2.txt in the examples below.
Creating the Wallet
We’re now ready to set up the wallet for example.com http-access.
For all of this we will use the “orapki” program installed together with the database.
Let’s first create an empty wallet we can add the certificates to.
orapki wallet create -wallet blogwallet -auto_login -pwd BlogWallet1
This creates a wallet with the name “blogwallet”, using it is logged in automatically while modifications requires providing the password “BlogWallet”. The name of the file can be provided using a path if needed.
Now that we have the wallet we can add our two certificates from the certificate chain we found for example.com.
orapki wallet add -wallet blogwallet -trusted_cert -pwd BlogWallet1 -cert cert1.txt
orapki wallet add -wallet blogwallet -trusted_cert -pwd BlogWallet1 -cert cert2.txt
Take a look at the wallet, it is actually a directory with files in it.
Testing that it works
With that we now have a wallet that should allow us to pass the certificate validation for example.com. Make sure the wallet file is readable by the user running the database, typically “oracle”.
select utl_http.request('https://example.com'
, null
, 'file:/opt/oracle/oradata/XE/XEPDB1/blogwallet/')
from dual;
"<!doctype html>
<html>
<head>
<title>Example Domain</title>
Again the rest of the output was cut off for brevity.
There it is, we now have https connectivity set up. A little bit of ACL and a little bit of adding certificates to a trust store served by a wallet in Oracle.
With that any kind of URI using HTTPS can be set up, such as REST-calls or authentication using to cloud services. But that is something for another time and another blog post.
Pingback: Update on creating wallet – Oracle DB Development
Pingback: Scripting the Oracle Wallet truststore – Oracle DB Development
Hi Mathias. Very good blog.
I was following step by step but the error persist. The DB version is 12.1.0.2
SQL> select UTL_HTTP.request(‘https://api.twilio.com’,null,’file:/opt/oracle/oracle12/admin/WFTP12D/testTwi/’,’TestWili1′) from dual;
select UTL_HTTP.request(‘https://api.twilio.com’,null,’file:/opt/oracle/oracle12/admin/WFTP12D/testTwi/’,’TestWili1′) from dual
*
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-29024: Certificate validation failure
ORA-06512: at “SYS.UTL_HTTP”, line 1491
ORA-06512: at line 1
Also I tested with openssl and received the certificate… I’m not sure about what is my error
openssl s_client -showcerts -connect api.twilio.com:443
CONNECTED(00000003)
depth=2 C = US, O = DigiCert Inc, OU = http://www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = http://www.digicert.com, CN = Thawte RSA CA 2018
verify return:1
depth=0 C = US, ST = California, L = San Francisco, O = “Twilio, Inc.”, CN = *.twilio.com
verify return:1
To me it looks like the wallet either does not have the correct certs or the path to it is wrong (though I think that results in a wallet not found). Did you get it to work with example.com and oracle.com like I used?
It helped. Thank you
Hi Mathias,
Thank you for your Blog – really interesting.
This is how my certificate looks like:
CN = DigiCert Global Root CA
CN = Thawte RSA CA 2018
CN = *.
I am getting the same error as Jenny…
I have tried only with ROOT (without Thawte & *.) and with whole chain but the result is the same ORA-29024.
With other certificates it is functioning, but with this not. 🙁
I am wondering is there any step that I should do for those kind of certificates? (DigiCert Global Root CA with domain and wildcard)
Thank you in advance!
Felix
It was helpful…. Thanks!
Hi Mathias,
I have followed the steps exactly as you have mentioned in the blog, but still, I am getting the below error.
orapki wallet add -wallet wallet -trusted_cert -cert example.crt -pwd WalletPasswd123
Oracle PKI Tool Release 19.0.0.0.0 – Production
Version 19.3.0.0.0
Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
Operation is successfully completed.
[oracle@pwcdb u01]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 – Production on Fri Mar 19 20:47:53 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0
SQL> select utl_http.request(‘https://example.com’,null, ‘file:/u01/wallet’, null) from dual;
select utl_http.request(‘https://example.com’,null, ‘file:/u01/wallet’, null) from dual
*
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at “SYS.UTL_HTTP”, line 1530
ORA-29024: Certificate validation failure
ORA-06512: at “SYS.UTL_HTTP”, line 380
ORA-06512: at “SYS.UTL_HTTP”, line 1470
ORA-06512: at line 1