phax / as2-lib

A generic Java AS2 library, servlet and server
107 stars 43 forks source link

Proxy question #1

Closed patrickvanamstel closed 9 years ago

patrickvanamstel commented 9 years ago

How can i make connection to the endpoints using a proxy?

I cannot set the proxy at JVM level, because not all http connection must go through the same proxy.

After a little bot of digging in the classes i found in

AbstractHttpSenderModule.getConnection( ....)

the line

final HttpURLConnection aConn = (HttpURLConnection) aUrlObj.openConnection ();

I know i can add a proxy object to the openConnection method.

Is there an elegant way of overriding this method? Are there more places where this method is used (the openconnection) one?

phax commented 9 years ago

Well there is currently no nice way to do it. The question is, at what level do you want to specify the proxy. Is the AS2Session instance a suitable place?

phax commented 9 years ago

And should there be a difference between proxies for outbound messages and asynchronous MDNs (even if asyn MDNs are not used in PEPPOL)?

phax commented 9 years ago

I just added support for setting the HTTP proxy in the AS2Session. This proxy is than used for AS2 message sending as well as for async MDN sending. hth

patrickvanamstel commented 9 years ago

Philip,

I am investigating using this library instead of my customized Oxalis implementation.

At our company we connect to many different endpoints with a lot of different protocols. Furthermore we need to communicate in our DMZ and to the outside world.

So for each connection we must be able to set the proxy used.

I hope this answers your question.

Greatings from Holland, Patrick

On 06/10/2015 12:03 PM, Philip Helger wrote:

And should there be a difference between proxies for outbound messages and asynchronous MDNs (even if asyn MDNs are not used in PEPPOL)?

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-110678951.

patrickvanamstel commented 9 years ago

Thx

On 06/10/2015 12:23 PM, Philip Helger wrote:

I just added support for setting the HTTP proxy in the AS2Session. This proxy is than used for AS2 message sending as well as for async MDN sending. hth

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-110685787.

phax commented 9 years ago

If this works and you need a new release, just let me know!

patrickvanamstel commented 9 years ago

I will let you know.

I'm now going to test the implementation.

2 Tests:

Regards Patrick

On 06/10/2015 01:10 PM, Philip Helger wrote:

If this works and you need a new release, just let me know!

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-110701999.

patrickvanamstel commented 9 years ago

Maybe you know the answer to this question

For the Dutch Peppol implementation (SimplerInvoicing) i have tu used the ECryptoAlgorithm.DIGEST_SHA1 setting.

e.g. aSettings.setPartnershipName (aSettings.getSenderAS2ID () + "_" + aSettings.getReceiverAS2ID ()); aSettings.setMDNOptions (new DispositionOptions ().setMICAlg (ECryptoAlgorithm.DIGEST_SHA1)

.setMICAlgImportance (DispositionOptions.IMPORTANCE_REQUIRED) .setProtocol (DispositionOptions.PROTOCOL_PKCS7_SIGNATURE)

.setProtocolImportance (DispositionOptions.IMPORTANCE_REQUIRED));

Is there am elegant way of a fallback mechanism to a less secure SHA algoritm from the default SHA512.

P.S. I did not test the new proxy addition, but sending without a proxy does work to the Austrian Government and to the Oxalis implementation of the Dutch TestTool.

Regards, Patrick

On 06/10/2015 01:10 PM, Philip Helger wrote:

If this works and you need a new release, just let me know!

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-110701999.

phax commented 9 years ago

According to the AS2 RFC, only MD5 and SHA1 are the MUST supported ones. To use a fallback, use the DispositionOptions.setMICAlg with a String, where each element is separated by a comma (like "sha1,md5"). See the RFC at https://www.ietf.org/rfc/rfc4130.txt and start reading at page 21 (you can search for "Disposition-Notification-Options"):

      The "signed-receipt-micalg" parameter is a list of MIC algorithms
      preferred by the requester for use in signing the returned
      receipt.  The list of MIC algorithms SHOULD be honored by the
      recipient from left to right.

Unfortunately as2-lib does NOT yet honour the MIC algorithm list when receiving stuff.

phax commented 9 years ago

I just extended the DispositionOptions class so that it can handle multiple MIC algorithms. (Because of a certain incompatibility the version of the project was changed to 1.1.0-SNAPSHOT)

patrickvanamstel commented 9 years ago

Philip,

The solution of setting the proxy on the AS2Session works great for me.

Just a little feedback in making the proxy consitent.

The AS2session needs a java.net.Proxy. The SMPClientReadonly needs a org.apache.http.HttpHost

I would change the code to setting the proxy with the HttpHost object.

When you see a change of releasing the all the changes that would be great.

thanks a lot Patrick van Amstel

On 06/10/2015 01:10 PM, Philip Helger wrote:

If this works and you need a new release, just let me know!

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-110701999.

phax commented 9 years ago

Hi! As2-lib (unfortunately) still relies on the default Java HttpUrlConnection whereas smp-client already uses Apache http-client. It is on my agenda to switch as2-lib also to http-client. If I would do this know, would you be willing to test this directly? Than the proxy would also be consistent. Thanks, Philip

patrickvanamstel commented 9 years ago

That sounds like work.

I have a wrapper sender service that does the translation inside.

For me changing the Proxy to HttpHost is not important.

A release is ;)

Patrick

On 06/12/2015 08:52 AM, Philip Helger wrote:

Hi! As2-lib (unfortunately) still relies on the default Java HttpUrlConnection whereas smp-client already uses Apache http-client. It is on my agenda to switch as2-lib also to http-client. If I would do this know, would you be willing to test this directly? Than the proxy would also be consistent. Thanks, Philip

— Reply to this email directly or view it on GitHub https://github.com/phax/as2-lib/issues/1#issuecomment-111383160.

phax commented 9 years ago

Hi Patrick!

Version 1.1.0 is on its way to Maven central and should be visible there within the next half hour. Next steps will be to upgrade to http client in 1.2.0 :)

Have a nice WE!