Coder Social home page Coder Social logo

Comments (31)

libetl avatar libetl commented on June 8, 2024 1

Hi.
Ok, looks like your ca cert was filtered.
You should make sure that the certificate chain is fully given in pem format, or der, or p12 or jks.
I am not sure if .crt format is supported by curl java.
Give me some time to understand the trouble.

from curl.

libetl avatar libetl commented on June 8, 2024 1

databinary does not support <<<EOF bash notation

from curl.

libetl avatar libetl commented on June 8, 2024 1

leave a white space between the url and --data-binary

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

My request look like:
HttpResponse response = curl()
.key("./my.key")
.cert("./mycert.pem")
.cacert("./ca-chain.crt")
.xUpperCase("POST")
.hUpperCase("accept: application/xml")
.hUpperCase("Content-Type: application/xml")
.databinary("@- <<EOFSOMEDATAEOF")
.run("https://url:port/");

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

I lost 2 days and I can't find solution make request with provide the rsa key to a server.
I'm ashamed, but it's true.
Usual curl or "Postman" works fine with this request.
And I decided to use your library for that.
Sorry for my bad English)

from curl.

libetl avatar libetl commented on June 8, 2024

.pem is just a key pair (crt + key)

If you lost your key, maybe curl java will not be able to work on your request

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

No, I have the key. And how I said above, curl from terminal or through postman works well.

from curl.

libetl avatar libetl commented on June 8, 2024

What about converting your ca-chain certificate from crt format to pem format ?

https://stackoverflow.com/questions/991758/how-to-get-pem-file-from-key-and-crt-files

then

HttpResponse response = curl()
.key("./my.key")
.cert("./mycert.pem")
.cacert("./ca-chain.pem")
.xUpperCase("POST")
.hUpperCase("accept: application/xml")
.hUpperCase("Content-Type: application/xml")
.databinary("@- <<EOFSOMEDATAEOF")
.run("https://url:port/");

The ca cert will not be filtered and you will be able to move forward

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

Ok I will try. But im not sure that will help, because in postman I set only "mycert.pem", "my.key" and password for key, that is working without ca-cert.pem.

from curl.

libetl avatar libetl commented on June 8, 2024

hmm... "password for key" that is disturbing,

you should stip off the password from the key before using curl for java.

from curl.

libetl avatar libetl commented on June 8, 2024

https://futurestud.io/tutorials/how-to-remove-pem-password-from-ssl-certificate

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

And Im just tried curl from terminal without ca-chain and that also work
look like:
curl -v \ --key ./my.key \ --cert ./mycert.pem \ -X POST \ -H "accept: application/xml" \ -H "Content-Type: application/xml" \ "https://....:..../" \ --data-binary @- <<EOF ........ EOF

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

do you think remove password from the key may will help?

from curl.

libetl avatar libetl commented on June 8, 2024

true.

And once done, just remove the ca chain certificate, because I think that the mycert.pem already contains the CA cert.

from curl.

libetl avatar libetl commented on June 8, 2024
HttpResponse response = curl()
.key("./my.unprotected.key")
.cert("./mycert.pem")
.xUpperCase("POST")
.hUpperCase("accept: application/xml")
.hUpperCase("Content-Type: application/xml")
.databinary("@- <<EOFSOMEDATAEOF")
.run("https://url:port/");

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

hmm
now I received:
Exception in thread "main" org.toilelibre.libe.curl.Curl$CurlException: java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.getDefaultHostnameVerifier()Ljavax/net/ssl/HostnameVerifier; at org.toilelibre.libe.curl.Curl.$(Curl.java:21) at safeApi.utils.Pinning.main(Pinning.java:53) Caused by: java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.getDefaultHostnameVerifier()Ljavax/net/ssl/HostnameVerifier; at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) at org.toilelibre.libe.curl.Curl.$(Curl.java:19) ... 1 more Caused by: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.getDefaultHostnameVerifier()Ljavax/net/ssl/HostnameVerifier; at org.toilelibre.libe.curl.HttpClientProvider.handleSSLParams(HttpClientProvider.java:139) at org.toilelibre.libe.curl.HttpClientProvider.prepareHttpClient(HttpClientProvider.java:62) at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:46) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

But im use so request:
String response = $("curl " +
"--key ./new.key \\n" +
"--cert ./mycert.pem \\n" +
"-X POST \\n" +
"-H "accept: application/xml" \\n" +
"-H "Content-Type: application/xml" \\n" +
"https://....:..../" +
"--data-binary @- <<EOFsomedataEOF");

Because builder throw exception. Sorry I forgot tell about:
" Unrecognized option: --databinary"

from curl.

libetl avatar libetl commented on June 8, 2024

Apache HttpComponents from the curl lib is offending provided Apache HttpComponents from your server.

Can you try in an unit test ?

from curl.

libetl avatar libetl commented on June 8, 2024

data binary is quite new in 0.0.14, may not be working as expected in full text command mode.

from curl.

libetl avatar libetl commented on June 8, 2024

curl lib uses apache httpcomponents 4.5.2

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

What test can I do? :)

from curl.

libetl avatar libetl commented on June 8, 2024

you can create a standalone project or test that uses curl lib, so you don't have to cope with offending classes (yet)

from curl.

libetl avatar libetl commented on June 8, 2024

because your jetty seems to be conflicting with curl (I don't know which version of apache hc your server relies on, but it seems to be incompatible : java.lang.NoSuchMethodError)

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

Hmm..
In clean project I also received
java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 1 at org.toilelibre.libe.curl.Curl.$(Curl.java:21) at Main.main(Main.java:19)

from curl.

libetl avatar libetl commented on June 8, 2024

I mean, even after omitting the cacert ?

HttpResponse response = curl()
.key("./my.unprotected.key")
.cert("./mycert.pem")
.xUpperCase("POST")
.hUpperCase("accept: application/xml")
.hUpperCase("Content-Type: application/xml")
.databinary("@- <<EOFSOMEDATAEOF")
.run("https://url:port/");

Can you give me the full stacktrace ?

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

Yes, even so. :(
Stacktrace from raw curl:
Exception in thread "main" org.toilelibre.libe.curl.Curl$CurlException: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 1 at org.toilelibre.libe.curl.Curl.$(Curl.java:21) at Main.main(Main.java:22) Caused by: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 1 at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) at org.toilelibre.libe.curl.Curl.$(Curl.java:19) ... 1 more Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 at org.toilelibre.libe.curl.HttpRequestProvider.lambda$setHeaders$7(HttpRequestProvider.java:180) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at org.toilelibre.libe.curl.HttpRequestProvider.setHeaders(HttpRequestProvider.java:180) at org.toilelibre.libe.curl.HttpRequestProvider.prepareRequest(HttpRequestProvider.java:48) at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:46) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

And from builder
Exception in thread "main" org.toilelibre.libe.curl.Curl$CurlException: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 1 at org.toilelibre.libe.curl.Curl.curl(Curl.java:37) at org.toilelibre.libe.curl.Curl$CurlArgumentsBuilder.run(Curl.java:74) at Main.main(Main.java:20) Caused by: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 1 at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) at org.toilelibre.libe.curl.Curl.curl(Curl.java:35) ... 2 more Caused by: java.lang.ArrayIndexOutOfBoundsException: 1 at org.toilelibre.libe.curl.HttpRequestProvider.lambda$setHeaders$7(HttpRequestProvider.java:180) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at org.toilelibre.libe.curl.HttpRequestProvider.setHeaders(HttpRequestProvider.java:180) at org.toilelibre.libe.curl.HttpRequestProvider.prepareRequest(HttpRequestProvider.java:48) at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:46) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

from curl.

libetl avatar libetl commented on June 8, 2024

It does not fail at the same place.
Give me some time.

from curl.

libetl avatar libetl commented on June 8, 2024

I have written an unit test in my project, and it works fine :

    @Test
    public void complexOne() {
         $("curl -k " +
                "--cert src/test/resources/clients/libe/libe.pem \n" +
                "--key src/test/resources/clients/libe/libe.key \n" +
                "-X POST \n" +
                "-H \"accept: application/xml\" \n" +
                "-H \"Content-Type: application/xml\" \n" +
                "https://localhost:%d/ " +
                "--data-binary @src/test/resources/form.sh");
         }

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

it's really funny, I did it!!! I rewrote ssl socket factory for working with my jks and it works fine. :)
But I could not understand why curl lib is not working with my key. Also now I receive the same I received while using sslSocketFactory before...

Exception in thread "main" org.toilelibre.libe.curl.Curl$CurlException: java.util.concurrent.ExecutionException: org.toilelibre.libe.curl.Curl$CurlException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at org.toilelibre.libe.curl.Curl.$(Curl.java:21) at Main.main(Main.java:19) Caused by: java.util.concurrent.ExecutionException: org.toilelibre.libe.curl.Curl$CurlException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) at org.toilelibre.libe.curl.Curl.$(Curl.java:19) ... 1 more Caused by: org.toilelibre.libe.curl.Curl$CurlException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:50) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2033) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1135) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:46)

from curl.

OneXeor avatar OneXeor commented on June 8, 2024

Sorry for the time spent and thank you very much.

from curl.

libetl avatar libetl commented on June 8, 2024

handshake failure : https over http ?

Good luck, sorry for the loss of time.

from curl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.