I am relatively new to socket programming so this may sound like a very lame question. I have to use authenticated TCP(MD5 as a TCP option to start with) as a transport for some application. I was wondering if this could be done using the sockets API or there is some other form of an existing TCP APIs that I could use to do the same. I would appreciate if I could get some help with this.
I'm a bit confused by your question. You can certainly set socket options on a socket using the setsockopt function, but by the sound of the rest of your question, this isn't quite what you mean. I've never heard of any transport protocol called Authenticated TCP and google throws up nothing useful. Is it a standard; is there an RFC?
If you're just wanting a secure, authenticated TCP transport layer, then you should look in to Secure Sockets Layer, or SSL for short, or its replacement, Transport Layer Security, or TLS for short. There will almost certainly be an implementation for whatever language you're using (you haven't specified).
- For C/C++, there's: OpenSSL
- For .Net, there's: SslStream
- For Java, there's the Secure Socket Extensions
Also, what do you mean by MD5 for authentication? MD5 is a hashing algorithm, however it's not collision resistant enough for use in communication that requires secure signatures.
Edit aha! You're talking about TCP options, I understand now. I haven't seen any implementations of that particular TCP option built in to any of the socket APIs, so you may be out of luck here. It depends on the implementation you use, but it might be especially rare given that this is a fairly obscure TCP option designed for enhancing the border gateway protocol, not something you would usually have use for outside of routing software. In case it is supported, you would set it something like this:
BOOL optVal = TRUE;
int optLen = sizeof(BOOL);
if (setsockopt(
socket,
IPPROTO_TCP,
TCP_WHATEVER,
optVal,
optLen) != SOCKET_ERROR) {
printf("Success\n");
}