开发者

Please recommend a way of authorizing a plain text transaction over HTTP in Java?

I have a web service on an insecure network that needs authorization.

I wish to implement it over HTTP, instead of HTTPS, at the same time evading man-in-the-middle and sniffing attacks. I need only one key for the client and the server.

The client calls a server function, and the server can authenticate whether this client is right, and can give back a response, which needs to be signed not encrypted.

I have a crude idea how this could be implemented, and will give it as an exa开发者_StackOverflowmple:

Pseudocode
Web service and client has already shared PASSCODE1 and PASSCODE2

First Handshake:
Client pings web service
Web service sends random string A with length 
Client checks A is nonnull, and sends Hash X=(md5(A XOR PASSCODE1) XOR 
    concat("RIGHT",random string B) XOR PASSCODE2)
Web service receives Hash X, checks if "RIGHT" is there, saves  key B, sends 
    Hash Y=(md5(B XOR PASSCODE1) XOR concat ("RIGHT", random string C) 
        XOR PASSCODE2)
Client checks if this value is right, and they are authenticated
At this point, if everything goes right, have keys B and C for this 
    particular transaction

Sample Transaction:
Client calls function(args, md5(args, C) XOR PASSCODE2)
Server returns (object(), md5(args, B) XOR PASSCODE2)

keys expire after a few minutes, and a new key pair needs to be requested

I know this method is really crude, are there any other ways to do so?

Specifically, I am looking to do this in Java.


Generally speaking, you shouldn't be doing this yourself. Depending on the platform you are using, there is more than likely a framework available which implements the WS-Security specification.

This specification covers message integrity as well as message encryption using plain text (in other words, over HTTP) using X.509 certificates.

However, what becomes important is that you protect the certificates that are being used for the signing, as you can't avoid man-in-the-middle attacks if the certificate is out in the open.

A Google search for the terms "java WS-security" reveals a few resources on how to implement the WS-Security specification in Java.

However, you might want to look at the Web Services Developers Pack, as it appears to be a little more standardized in the framework.


As others have commented, SSL is the way to do it. Rolling your own is a recipe for getting it wrong.

If you design your own combination of hash and encryption algorithms, and you're not a hotshot cryptographer, you're pretty much guaranteed to come up with something exploitable. Whether you care enough, of course, is another matter. Perhaps you're only trying to defend against casual attackers who wouldn't put the effort into exploit weaknesses in your approach.

One approach might be to exchange S/MIME content over plain HTTP. At least then you're sticking with an established mechanism.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜