Well, trying to use a custom pfx already converted in bks using keytool...
With the help of forum until now... and some knowledge have from b4j i am at this point:
my main code:
with the help of AI - found that must pass the ssl to client somehow like that - but this is my problem - i think (may be not easy to use httpjob) - or need a special setup ??
but in httpjob... there is no hc - any idea how i will pass my ssl / cert?
With the help of forum until now... and some knowledge have from b4j i am at this point:
my main code:
B4X:
#AdditionalJar: bcprov-jdk15to18-1.81
.....
Sub GetCustomSSLSocketFactory As Object
Try
Dim keystore As JavaObject
keystore.InitializeNewInstance("java.security.KeyStore", Array("BKS"))
Dim inp As InputStream = File.OpenInput(File.DirAssets, "mykeystore.bks")
Dim pw As String = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ' your keystore password
Dim charArray As Object = StringToCharArray(pw)
keystore.RunMethod("load", Array(inp, charArray))
inp.Close
Dim tmf As JavaObject
tmf.InitializeNewInstance("javax.net.ssl.TrustManagerFactory", Array("X509"))
tmf.RunMethod("init", Array(keystore))
Dim context As JavaObject
context.InitializeStatic("javax.net.ssl.SSLContext")
Dim sslcontext As JavaObject = context.RunMethod("getInstance", Array("TLS"))
sslcontext.RunMethod("init", Array(Null, tmf.RunMethod("getTrustManagers", Null), Null))
Return sslcontext.RunMethod("getSocketFactory", Null)
Catch
Log("Error creating SSL context: " & LastException)
Return Null
End Try
End Sub
Sub InitSecureHttpClient
Try
' Step 1: Create Java OkHttpClient
Dim builder As JavaObject
builder.InitializeNewInstance("okhttp3.OkHttpClient$Builder", Null)
Dim sslFactory As Object = GetCustomSSLSocketFactory
If sslFactory = Null Then
Log("Failed to build SSL Factory")
Return
End If
builder.RunMethod("sslSocketFactory", Array(sslFactory, Null))
Dim javaClient As Object = builder.RunMethod("build", Null)
' Step 2: Assign it to a B4A OkHttpClient
GlobalSecureClient.Initialize("secure")
Dim joSecure As JavaObject = GlobalSecureClient
joSecure.SetField("client", javaClient)
Catch
Log("InitSecureHttpClient error: " & LastException)
End Try
End Sub
Sub StringToCharArray(pw As String) As Object
Dim jo As JavaObject
Return jo.InitializeStatic("java.lang.String").RunMethod("toCharArray", Null).As(Object)
End Sub
with the help of AI - found that must pass the ssl to client somehow like that - but this is my problem - i think (may be not easy to use httpjob) - or need a special setup ??
B4X:
Dim j As HttpJob
j.Initialize("job111", Me)
Dim m As Map
m.Initialize
m.Put("mything",mystring)
Dim json1 As JSONGenerator
json1.Initialize(m)
j.PostString(Main.urllic & "/getpin",json1.ToString) ',Array(json1.ToString)
J.GetRequest.SetContentType("application/json")
'custom ssl here... hmmm (ofcourse there is no hc...)
Dim joReq As JavaObject = j.GetRequest
joReq.SetField("hc", Main.GlobalSecureClient)
'-----------
wait for (j) JobDone(j As HttpJob)
Log(j.GetString)
If j.Success Then
Dim json2 As JSONParser
json2.Initialize(j.GetString)
Dim m2 As Map = json2.NextObject
If m2.ContainsKey("error") Then
If m2.Get("error")=True Then
....
End If
Else
...
End If
Else
Log("Unknown Error")
End If
Catch
Log(LastException)
End Try
but in httpjob... there is no hc - any idea how i will pass my ssl / cert?