"ORA-29024: Certificate validation failure" - oracle

I am trying to consume Rest API in oracle procedure. I have created ACL entry as well as Added the SSL certificate to my oracle wallet manager. but when i am trying to execute the procedure i am getting the error as "ORA-29024: Certificate validation failure". Following is the code for my oracle procedure.
create or replace procedure TABADUL_TAS_AUTHENTICATION
is
req utl_http.req;
res utl_http.resp;
value VARCHAR2(1024);
value1 VARCHAR2(1024);
url varchar2(4000) := 'https://tapis.fasah.sa/tabadul/fasahqa/authorization/token';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) := '{"username":"ijsnj001","password":"P#ssw0rd"}';
begin
UTL_HTTP.set_wallet('file:d:\tabadul', 'tas123456');
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json;charset=utf-8');
utl_http.set_header(req,'X-IBM-Client-Id','00a2f36e933e2bb9edc76faaf26659eb');
utl_http.set_header(req,'X-IBM-Client-Secret','7c2829bd6b287b072ee269c9ad8f5ead');
utl_http.set_header(req,'Accept-Language','en');
utl_http.set_header(req,'Accept','application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
-- process the response from the HTTP call
DBMS_OUTPUT.PUT_LINE('HTTP response status code: ' || res.status_code);
--DBMS_OUTPUT.PUT_LINE('HTTP response reason phrase: ' || res.reason_phrase);
FOR i IN 1..UTL_HTTP.GET_HEADER_COUNT(res) LOOP
UTL_HTTP.GET_HEADER(res, i, name, value1);
--DBMS_OUTPUT.PUT_LINE(name || ': ' || value1);
END LOOP;
--dbms_output.put_line(content);
--dbms_output.put_line(utl_http.resp);
begin
loop
--dbms_output.put_line('A');
utl_http.read_line(res, value, true);
--dbms_output.put_line(length(value));
dbms_output.put_line(value);
--INSERT INTO A VALUES (VALUE);
--COMMIT;
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
--dbms_output.put_line(SQLCODE||','||SQLERRM);
utl_http.end_response(res);
when others then
--dbms_output.put_line(SQLCODE||','||SQLERRM);
utl_http.end_response(res);
end;
end TABADUL_TAS_AUTHENTICATION;

This issue has been resolved.I am writing the solution here, it might be helpful for others.
So instead of creating wallet for the actual website certificate, need to create wallet only for chain of certificate.

Related

Why am I getting this error in Oauth 2 access token code using PL/SQL?

I am able to get the access token using postman but I am not able to using the PL/SQL Block. I get unauthorized back as response even when I use the same client id and client secret. Please let me know what am I doing wrong. I am working on oracle 12c. Thank you.
DECLARE
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
l_ClientID varchar2(1000) := 'clientid';
l_ClientSecret varchar2(1000) := 'clientsecret';
l_AuthResponse UTL_HTTP.RESP;
l_AuthRaw VARCHAR2 (32767);
l_AuthReqBody varchar2(2000);
v_url varchar2(2000) := 'http://someurl/oauth/token';
l_ClientCredetial VARCHAR2(1000) := l_ClientID || ':' || l_ClientSecret;
BEGIN
l_AuthReqBody := 'grant_type=client_credentials'|| chr(38) || 'client_id=' || l_ClientID || chr(38) || 'client_secret=' || l_ClientSecret;
-- Set Oracle Wallet, which works fine
http_req := utl_http.begin_request(
v_url ,
'POST',
'HTTP/1.1');
utl_http.set_header (http_req, 'Content-Type','application/x-www-form-urlencoded');
utl_http.write_text (http_req, l_AuthReqBody);
l_AuthResponse := utl_http.get_response(http_req);
utl_http.read_text(l_AuthResponse, l_AuthRaw);
sp_memo_temp('1 l_AuthRaw: '||l_AuthRaw);
UTL_HTTP.end_response (l_AuthResponse);
UTL_HTTP.end_request (http_req);
END;
I just needed to access a REST webservice with OAuth and I just needed to set a header with my token, utl_http.set_header(l_http_request, 'Authorization', l_token).

Consuming rest API from Oracle PLSQL is returning ??? for arabic characters

I am trying to call a restful API from my Oracle procedure.
First, the API method is of type get and not post, so parameters are sent through header. the main purpose of the API is to send the received message as SMS to some providers and sometimes they are in Arabic format; We realized that Arabic received SMS are incomprehensible;
So I created a test procedure that takes a message and sends it to a test API method that returns the same message as response.
The API call succeeded but the response, only when arabic format is used, looks like ����. What should be added to my procedure so messages can be readable? I have tried to use escape for the message and to set the header format as you can see in below template, but unfortunately nothing succeeded:
PROCEDURE TEST(lang VARCHAR2,
message VARCHAR2,
P_RESPONSE OUT VARCHAR2) AS
v_request UTL_HTTP.req;
v_response UTL_HTTP.resp;
v_text VARCHAR2(1024);
v_url VARCHAR2(1024);
v_message VARCHAR2(1024);
l_webservice_link VARCHAR2(128);
BEGIN
BEGIN
P_RESPONSE := '';
v_message := utl_url.escape(message);
--v_message :=utl_url.escape(message,false,'UTF-8');
--v_message :=utl_url.escape(message,false,'windows-1256');
--v_message :=utl_url.escape(message,false,'AL32UTF8');
--v_message :=utl_url.escape(message,false,'AR8MSWIN1256');
l_webservice_link := GET_PARAM('REST_API_URL');
v_url := l_webservice_link ||
'Mytest?strMessage=' || v_message||
'&strLang=' || lang;
v_request := UTL_HTTP.begin_request(v_url);
--UTL_HTTP.set_header(v_request, 'Content-Type', 'charset=UTF-8');
--UTL_HTTP.set_header(v_request, 'Content-Type', 'windows-1256');
v_response := UTL_HTTP.get_response(v_request);
LOOP
BEGIN
UTL_HTTP.read_text(v_response, v_text);
DBMS_OUTPUT.put_line(v_text);
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
NULL;
END;
EXIT WHEN v_text IS NULL;
END LOOP;
UTL_HTTP.end_response(v_response);
IF v_response.status_code <> 200 THEN
P_RESPONSE := v_response.reason_phrase;
END IF;
EXCEPTION
WHEN OTHERS THEN
P_RESPONSE := 'An error has occured: ' || SQLERRM;
END;
END TEST;
Any help is more than appreciated.
Try to insert this code:
Charset VARCHAR2(20);
BEGIN
SELECT UTL_I18N.MAP_CHARSET(VALUE)
INTO Charset
FROM nls_database_parameters
WHERE parameter = 'NLS_CHARACTERSET';
UTL_HTTP.set_header(v_request, 'Content-Type', 'text/html; charset='||Charset);
I am not familiar with REST, I don't know wether text/html; is required and correct.
Update
I just see your database character set it AR8ASMO8X which does not have any IANA name (at least not according to Oracle UTL_I18N.MAP_CHARSET)
In this case try
UTL_HTTP.set_header(v_request, 'Content-Type', 'text/html; charset=UTF-8');
UTL_HTTP.begin_request(CONVERT(v_url,'AL32UTF8'));
Most likely the server returns response in UTF-8 - would be the most common one, otherwise check the header of the response.
Then try this:
UTL_HTTP.SET_BODY_CHARSET(v_response, 'AL32UTF8');
Apart from all above you may have also a display issue, i.e. inside Oracle everything would be fine, just your client is not able to display the characters properly, see OdbcConnection returning Chinese Characters as "?"

REST calls to a self-signed,not certified website using Oracle APEX

I'm trying to post some data to a website using APEX, by executing a PL/SQL code.
The problem is, the website's certificate is self-signed, so it's not properly certified, and I'm getting the below error:
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-28860: Fatal SSL error
I'm using the below code:
procedure publish_error_tickets
is
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'https://some_url';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) :=
'{
"issue": {
"project_id": 1,
"subject": "Example",
"priority_id": 4
}
}'; begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
utl_http.end_response(res);
end; end;
My question is, is it possible to somehow ignore the certificate validation process for the http message? There must be a way to reach a website without the need to buy a validated cert for the site.
Thanks in advance,
Tamas
For anyone having the same problem, I got it working with the solution Jeffrey Kemp posted( http://blog.rhjmartens.nl/2015/07/making-https-webservice-requests-from.html ), with a reverse proxy, it works like a charm!

ORA-28759: failure to open file

I have a problem.
When I use UTL_HTTP.SET_WALLET Oracle says me next errors:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-28759: failure to open file
Previously, I use Oracle Wallet Manager for setup the Sertificate from website "https://focus-api.kontur.ru/api3/". Cannot understand, what am I doing wrong.
DECLARE
HTTP_REQ UTL_HTTP.REQ;
HTTP_RESP UTL_HTTP.RESP;
URL_TEXT VARCHAR2(32767);
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
UTL_HTTP.SET_WALLET('file:d:\oracle\product\11.2.0\dbhome_1\NETWORK\wallet', 'password');
HTTP_REQ := UTL_HTTP.BEGIN_REQUEST('https://focus-api.kontur.ru/api3/req?inn=7714037390');
UTL_HTTP.SET_HEADER(HTTP_REQ, 'User-Agent', 'Mozilla/4.0');
HTTP_RESP := UTL_HTTP.GET_RESPONSE(HTTP_REQ);
LOOP
BEGIN
URL_TEXT := null;
UTL_HTTP.READ_LINE(HTTP_RESP, URL_TEXT, TRUE);
DBMS_OUTPUT.PUT_LINE(URL_TEXT);
EXCEPTION
WHEN OTHERS THEN EXIT;
END;
END LOOP;
UTL_HTTP.END_RESPONSE(HTTP_RESP);
END;
/

Accessing HTTP Header Info

I'm using Oracle 11g, together with F5 BIG-IP network and Glassfish app server and was wondering how, using pl/sql, access HTTP Header GET information, which should also include LDAP info from the F5?
Specifically, maybe this part will help:
--
Retrieving HTTP Response Headers
SET SERVEROUTPUT ON SIZE 40000
DECLARE
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
name VARCHAR2(256);
value VARCHAR2(1024);
BEGIN
UTL_HTTP.SET_PROXY('proxy.my-company.com', 'corp.my-company.com');
req := UTL_HTTP.BEGIN_REQUEST('http://www-hr.corp.my-company.com');
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
resp := UTL_HTTP.GET_RESPONSE(req);
DBMS_OUTPUT.PUT_LINE('HTTP response status code: ' || resp.status_code);
DBMS_OUTPUT.PUT_LINE('HTTP response reason phrase: ' || resp.reason_phrase);
FOR i IN 1..UTL_HTTP.GET_HEADER_COUNT(resp) LOOP
UTL_HTTP.GET_HEADER(resp, i, name, value);
DBMS_OUTPUT.PUT_LINE(name || ': ' || value);
END LOOP;
UTL_HTTP.END_RESPONSE(resp);
END;
Have you looked at the UTL_HTTP supplied package documentation? Not sure it has what you're looking for, but I'd start there.

Resources