Access To HTTPS Via Utl
Access To HTTPS Via Utl
Access To HTTPS Via Utl
Go to URL of website
Certificate chain
Certificate details
Export it to a [Base-64 encoded X.509 (.CER)] file.
Exporting the complete chain in Firefox does not work when importing to the wallet. Im
not sure if this is a limitation of Firefox or the Wallet software.
Export certificate
Next certificate
Add certificates
$> orapki wallet add -wallet /home/oracle/wallet -trusted_cert -cert
verisignclass3.cer -pwd password123
$> orapki wallet add -wallet /home/oracle/wallet -trusted_cert -cert
www.verisign.com.cer -pwd password123
$> orapki wallet add -wallet /home/oracle/wallet -trusted_cert -cert
oracle.com.cer -pwd password123
(You will get an error when importing the first certificate, it is already present by default
PKI-04003: The trusted certificate is already present in the wallet.)
View contents
$> orapki wallet display -wallet /home/oracle
A working example
For more information about the ACL, have a look at my blog about the Access Control List.
Connect!
If all went well, you can now connect to the https site:
select utl_http.request('https://support.oracle.com',
NULL,'file:/home/oracle/wallet','password123') from dual;
Point to the location of the wallet, do not include the wallet file name! Otherwise you
will get ORA-28759 failure to open file.
Result:
UTL_HTTP.REQUEST('HTTPS://SUPPORT.ORACLE.COM',NULL,'FILE:/HOME/ORACLE/WAL
LET','P
------------------------------------------------------------------------------<HTML>
<HEAD>
<title>Oracle Configuration Support Manager</title>
<meta http-equiv="REFRESH" content="0;url=/CSP/ui/flash.html"></HEAD>
<BODY>
</BODY>
</HTML>
In PL/SQL
create or replace package whitehorses as
procedure connect_to_oracle;
end whitehorses;
create or replace package body whitehorses as
procedure connect_to_oracle is
req utl_http.req;
resp utl_http.resp;
data varchar2(32767);
begin
utl_http.set_wallet('file:' || '/home/oracle/wallet', 'password123');
req := utl_http.begin_request('https://support.oracle.com');
utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
resp := utl_http.get_response(req);
loop
begin
data := null;
utl_http.read_line(resp, data, TRUE);
-- process your data here
exception when others then exit;
end;
end loop;
utl_http.end_response(resp);
end connect_to_oracle;
end whitehorses;
Conclusion
The solution is not that hard to implement. You need to:
1. Get the certificates
2. Create a wallet
3. Add certificates to wallet
4. Create ACL and open access to site and port
5. Connect to HTTPS!
I hope this blog post will help and good luck!