B4J Question jShell parameter is ignored

avalle

Active Member
Licensed User
Longtime User
Hello!
I'm trying to use cURL via jShell to overcome the lack of support of mutual TLS authentication in jServer. See https://www.b4x.com/android/forum/t...s-client-authentication-in-b4j-server.116452/
It looks like some parameters of the curl.exe call are ignored.
I also tried to add the "-v" parameter to obtain a verbose log of the TLS handshaking, but it's also ignored.
jShell with cURL:
Sub AppStart (Args() As String)
    Dim shl As Shell
    
    shl.Initialize("shl", "C:\Program Files\cURL\bin\curl.exe", _
       Array As String("-i", "-v", "-L", "https://b4x.com"))
    shl.WorkingDirectory = File.DirApp
    
    shl.Run(10000) 'set a timeout of 10 seconds
    StartMessageLoop 'need to call this as this is a console app.
End Sub
Does anyone have an idea why this is happening?
My suspect is that also other parameters may be ignored, impacting the success of mTLS.

Thanks
Andrea
 

drgottjr

Expert
Licensed User
Longtime User
did you consume the shl's event?

output i got:
Success
HTTP/2 301
date: Sat, 13 Feb 2021 02:28:04 GMT
server: Apache/2.4.46 (cPanel) OpenSSL/1.1.1i mod_bwlimited/1.4
x-redirect-by: WordPress
location: https://www.b4x.com/
vary: User-Agent
content-length: 0
content-type: text/html; charset=UTF-8
HTTP/2 200
date: Sat, 13 Feb 2021 02:28:05 GMT
server: Apache/2.4.46 (cPanel) OpenSSL/1.1.1i mod_bwlimited/1.4
link: <https://www.b4x.com/wp-json/>; rel="https://api.w.org/", <https://www.b4x.com/>; rel=shortlink
vary: Accept-Encoding,User-Agent
content-type: text/html; charset=UTF-8
<!DOCTYPE html><html lang="en-US"><head itemscope itemtype="https://schema.org/WebSite"><meta charset="UTF-8" /><meta name="description" content="B4X is a programming language and a set of cross-platform RAD development tools that allow complete beginners, citizen developers, and professionals to build real-world Android, iOS and desktop solutions" /><meta name="keywords" content="development, programming, basic, ios, android, iot" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link media="all" href="https://www.b4x.com/wp/wp-content/c...optimize_fc4db59357d036c0abcc8b44a4311d7f.css" rel="stylesheet" /><title>Cross platform RAD development tools | B4X</title> <script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://www.b4x.com/",
"potentialAction": {
"@type": "SearchAction",
"target": "https://www.b4x.com/android/forum/pages/results/?query={search_term_string}",
"query-input": "required name=search_term_string"
}
}</script><link rel='dns-prefetch' href='//fonts.googleapis.com' /><link rel='dns-prefetch' href='//s.w.org' /><link href='https://cdn.shortpixel.ai' rel='preconnect' /><link rel="alternate" type="application/rss+xml" title="B4X &raquo; Feed" href="https://www.b4x.com/feed/" /><link rel="alternate" type="application/rss+xml" title="B4X &raquo; Comments Feed" href="https://www.b4x.com/comments/feed/" /><link rel="canonical" href="https://www.b4x.com/" /> <script>window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"https:\/\/www.b4x.com\/wp\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.3.2"}};
!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defe...
WP_VID_LIGHTBOX_URL="https://www.b4x.com/wp/wp-content/plugins/wp-video-lightbox";
function wpvl_paramReplace(name, string, value) {
// Find the param with regex
// Grab the first character in the returned string (should be ? or &)
// Replace our href string with our new value, passing on the name and delimeter
var re = new RegExp("[\?&]" + name + "=([^&#]*)");
var matches = re.exec(string);
var newString;
if (matches === null) {
// if there are no params, append the parameter
newString = string + '?' + name + '=' + value;
} else {
var delimeter = matches[0].charAt(0);
newString = string.replace(re, delimeter + name + "=" + value);
}
return newString;
}</script><link rel="icon" href="https://www.b4x.com/wp/wp-content/themes/altitude-pro/images/favicon.ico" /><link rel="pingback" href="https://www.b4x.com/wp/xmlrpc.php" /><meta itemprop="name" content="B4X" /><meta itemprop="url" content="https://www.b4x.com/" /><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=m2lLkKq9bl"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png?v=m2lLkKq9bl"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png?v=m2lLkKq9bl"><link rel="manifest" href="/manifest.json?v=m2lLkKq9bl"><link rel="mask-icon" href="/safari-pinned-tab.svg?v=m2lLkKq9bl" color="#5bbad5"><link rel="shortcut icon" href="/favicon.ico?v=m2lLkKq9bl"><meta name="theme-color" content="#ffffff"><link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400" rel="stylesheet"> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MZNZG44');</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1987329-1"></script> <script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-1987329-1', { 'anonymize_ip': true });</script> <style type="text/css">.site-title a { background: url(https://www.b4x.com/wp/wp-content/uploads/2016/07/Logo_white.png) no-repeat !important; }</style></head><body class="home page-template-default page page-id-268 wp-embed-responsive custom-header header-image header-full-width full-width-content genesis-breadcrumbs-hidden genesis-footer-widgets-visible front-page featured-section" itemscope itemtype="https://schema.org/WebPage"><div class="site-container"><ul class="genesis-skip-link"><li><a href="#genesis-content" class="screen-reader-shortcut"> Skip to main content</a></li><li><a href="#genesis-footer-widgets" class="screen-reader-shortcut"> Skip to footer</a></li></ul><header class="site-header" itemscope itemtype="https://schema.org/WPHeader"><div class="wrap"><div class="title-area"><h1 class="site-title" itemprop="headline"><a href="https://www.b4x.com/">B4X</a></h1><p class="site-description" itemprop="descr...


i don't use curl, but i think the -i and -v arguments give the response headers and verbose output. i seem to have gotten them. and, of course, the -L was not ignored. you didn't say what you got when you ran shl, so i can't comment further.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The handshake information is piped to STDERR, not STDOUT.
B4X:
'Non-UI application (console / server application)
#Region Project Attributes 
    #CommandLineArgs:
    #MergeLibraries: True 
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    doCurl
    StartMessageLoop
End Sub

Sub doCurl
    Dim shl As Shell
    shl.Initialize("shl", "C:\B4X\curl-7.75.0-win64-mingw\bin\curl.exe", Array As String("-i", "-v", "-L", "https://b4x.com"))    'Perform an ImageMagic Conversion.
    shl.WorkingDirectory = File.DirApp
    shl.Run(10000) 'set a timeout of 10 seconds
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
        'Log(StdOut)
        Log(StdErr) 'Log TLS handshaking information
    Else
        Log("Error: " & StdErr)
    End If
    StopMessageLoop
End Sub
 
Upvote 0

avalle

Active Member
Licensed User
Longtime User
That's it Oliver! Thanks!
I didn't know that the handshaking info goes to STDERR.
Clearly when using the console everything goes there...

With that now I'll figure out why mTLS does not work as expected within the jShell call.
Will update you shortly...
 
Upvote 0

avalle

Active Member
Licensed User
Longtime User
Ok so the problem I'm facing is with the encoding of the data parameter for Curl on Windows:
cURL sample:
"C:\Program Files\cURL\bin\curl.exe" https://postman-echo.com/post -H "Accept: application/json" -H "Content-Type: application/json; charset=UTF-8" -d "{\"token\":\"test123ABC\"}"
The "-d" parameter is not properly encoded when using the following code in B4J:
doCurl:
shl.Initialize("shl", "C:\Program Files\cURL\bin\curl.exe", _
    Array As String("-H", $""Accept: application/json""$, "-H", $""Content-Type: application/json; charset=UTF-8""$, _
    "-d", $""{\"token\":\"test123ABC\"}""$, "https://postman-echo.com/post"))
Looking at the response from Postman:
Postman Echo:
{"args":{},"data":"'{\"client_notification_token\":\"test123ABC\"}'","files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-60282d6b-2e1bea5024b36e486199858f","content-length":"44","user-agent":"curl/7.75.0","accept":"application/json","content-type":"application/json; charset=UTF-8"},"json":null,"url":"https://postman-echo.com/post"}
"data" contains the value that is transmitted, which is an invalid JSON, and in fact the "json" field in the response is null.

I've tried other combinations of single quotes and double quotes, but still I can't understand how to fix it...
Your help is welcome!

Andrea
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Use InitializeDoNotHandleQuotes instead of Initialize
 
Upvote 0

Similar Threads

Top