Need urgent help with Network.tls

Hi, I am trying to use Haskell to download email/attachments from gmail. For which I am exploring Network.TLS. I got this sample from the net that connects to gmail smtp and works just fine - http://hpaste.org/82890 However, when I modify it a bit to try to connect to imap, it simply does not work. To debug, I tried to connect to a webserver, even that seems to not work. I modified the function as follows. emailGmail2 = do let host = "localhost" let port = 443 let params = defaultParamsClient{pCiphers = ciphers} g <- RNG.makeSystem h <- connectTo host (PortNumber (fromIntegral port)) hSetBuffering h LineBuffering cWrite h "GET / HTTP/1.0" cWrite h "" cWaitFor h "ABCD" con <- contextNewOnHandle h params g handshake con bye con And I get a "BAD request" response from the server - Can some please give me a sample code that uses Network.TLS to connect to a imap.google.com (or even a webserver for that matter)? Regards, Kashyap

You can use HaskellNet http://hackage.haskell.org/package/HaskellNet or
imapget http://hackage.haskell.org/package/imapget directly or look into
their source code for connecting to imap manually.
-Satvik
On Sat, Feb 23, 2013 at 8:58 PM, C K Kashyap
Hi,
I am trying to use Haskell to download email/attachments from gmail. For which I am exploring Network.TLS. I got this sample from the net that connects to gmail smtp and works just fine - http://hpaste.org/82890
However, when I modify it a bit to try to connect to imap, it simply does not work. To debug, I tried to connect to a webserver, even that seems to not work. I modified the function as follows.
emailGmail2 = do let host = "localhost" let port = 443 let params = defaultParamsClient{pCiphers = ciphers} g <- RNG.makeSystem h <- connectTo host (PortNumber (fromIntegral port)) hSetBuffering h LineBuffering cWrite h "GET / HTTP/1.0" cWrite h "" cWaitFor h "ABCD" con <- contextNewOnHandle h params g handshake con bye con
And I get a "BAD request" response from the server - Can some please give me a sample code that uses Network.TLS to connect to a imap.google.com(or even a webserver for that matter)?
Regards, Kashyap
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

The reason I want to use TLS is that I'd want to pack the whole thing in a
DLL and give it off to a friend for use.
What I am really looking for is a small sample code that demonstrates how
TLS package can be used to connect to a webserver or imapserver.
Regards,
Kashyap
On Sat, Feb 23, 2013 at 10:46 PM, satvik chauhan
You can use HaskellNet http://hackage.haskell.org/package/HaskellNet or imapget http://hackage.haskell.org/package/imapget directly or look into their source code for connecting to imap manually.
-Satvik
On Sat, Feb 23, 2013 at 8:58 PM, C K Kashyap
wrote: Hi,
I am trying to use Haskell to download email/attachments from gmail. For which I am exploring Network.TLS. I got this sample from the net that connects to gmail smtp and works just fine - http://hpaste.org/82890
However, when I modify it a bit to try to connect to imap, it simply does not work. To debug, I tried to connect to a webserver, even that seems to not work. I modified the function as follows.
emailGmail2 = do let host = "localhost" let port = 443 let params = defaultParamsClient{pCiphers = ciphers} g <- RNG.makeSystem h <- connectTo host (PortNumber (fromIntegral port)) hSetBuffering h LineBuffering cWrite h "GET / HTTP/1.0" cWrite h "" cWaitFor h "ABCD" con <- contextNewOnHandle h params g handshake con bye con
And I get a "BAD request" response from the server - Can some please give me a sample code that uses Network.TLS to connect to a imap.google.com(or even a webserver for that matter)?
Regards, Kashyap
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sat, Feb 23, 2013 at 1:58 PM, C K Kashyap
What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
TLS isn't actually SSL, despite SSL getting blessed as "TLS 0.9". Various attempts at TLS-enabled web protocols have foundered, so you won't find much code to speak TLS to web servers. (SSL is negotiated at socket connect time and involves no protocol commands.) In short, sample code that can do https would be completely useless for comparing to TLS-enabled code. IMAP is somewhat harder than SMTP; I suggest you read up on the protocol. I've done a fair amount of work with it, and still would have to refer to the RFC to establish a connection without the help of an existing IMAP library. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On 02/23/2013 09:05 PM, Brandon Allbery wrote:
On Sat, Feb 23, 2013 at 1:58 PM, C K Kashyap
wrote: What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
TLS isn't actually SSL, despite SSL getting blessed as "TLS 0.9". Various attempts at TLS-enabled web protocols have foundered, so you won't find much code to speak TLS to web servers. (SSL is negotiated at socket connect time and involves no protocol commands.) In short, sample code that can do https would be completely useless for comparing to TLS-enabled code.
SSL and TLS can be negociated at socket connect. TLS is just the standard name of SSL. at the wire level, TLS1.x is SSL 3.(1+x). What you're refering to is the STARTTLS style protocol command which work independently of the version of TLS (include SSL2, SSL3). Many programs have abused "SSL" and "TLS" different name to differentiate how TLS is negociated (straight away, or with a protocol command). Fortunately more and more programs do the right thing and differentiate the two types with the following two options: "SSL/TLS" or "STARTTLS". -- Vincent

On 02/23/2013 06:58 PM, C K Kashyap wrote:
The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
Regards, Kashyap
Kashyap, I suggest you look at the connection package [1] which is made for this specific purpose, and comes with examples on how to use it [2]. If you want to only use tls, i suggest to look at connection's code [3], or the tls-debug [4] package, which got many small utils that use tls. [1] http://hackage.haskell.org/package/connection [2] https://github.com/vincenthz/hs-connectionhttps://github.com/vincenthz/hs-connection/tree/master/examples [3] https://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs [4] https://github.com/vincenthz/hs-tls/tree/master/debug/src -- Vincent

Thank you so much Vincent,
I think this is what I need ... I tried to use it to connect to a local web
server running in 443 - http://hpaste.org/82943 however, I get the
following error -
ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))
Am I missing something?
Regards,
Kashyap
On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez
On 02/23/2013 06:58 PM, C K Kashyap wrote:
The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
Regards, Kashyap
Kashyap,
I suggest you look at the connection package [1] which is made for this specific purpose, and comes with examples on how to use it [2].
If you want to only use tls, i suggest to look at connection's code [3], or the tls-debug [4] package, which got many small utils that use tls.
[1] http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection [2] <https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples [3] https://github.com/vincenthz/**hs-connection/blob/master/** Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs [4] https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src
-- Vincent

Okay ... looks like connection is exactly what I want .... The examples
work just fine on Linux .. however, on Windows, I continue to get the
WSACONNECTIONREFUSED eror.
Even adding a "withSocketsDo" does not seem to help.
Regards,
Kashyap
On Sun, Feb 24, 2013 at 8:58 AM, C K Kashyap
Thank you so much Vincent,
I think this is what I need ... I tried to use it to connect to a local web server running in 443 - http://hpaste.org/82943 however, I get the following error -
ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))
Am I missing something?
Regards, Kashyap
On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez
wrote: On 02/23/2013 06:58 PM, C K Kashyap wrote:
The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
Regards, Kashyap
Kashyap,
I suggest you look at the connection package [1] which is made for this specific purpose, and comes with examples on how to use it [2].
If you want to only use tls, i suggest to look at connection's code [3], or the tls-debug [4] package, which got many small utils that use tls.
[1] http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection [2] <https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples [3] https://github.com/vincenthz/**hs-connection/blob/master/** Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs [4] https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src
-- Vincent

Okay ... now magically, I stopped seeing the "WSACONNECTIONREFUSED"
error!!! ..
Regards,
Kashyap
On Sun, Feb 24, 2013 at 10:03 AM, C K Kashyap
Okay ... looks like connection is exactly what I want .... The examples work just fine on Linux .. however, on Windows, I continue to get the WSACONNECTIONREFUSED eror.
Even adding a "withSocketsDo" does not seem to help.
Regards, Kashyap
On Sun, Feb 24, 2013 at 8:58 AM, C K Kashyap
wrote: Thank you so much Vincent,
I think this is what I need ... I tried to use it to connect to a local web server running in 443 - http://hpaste.org/82943 however, I get the following error -
ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))
Am I missing something?
Regards, Kashyap
On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez
wrote: On 02/23/2013 06:58 PM, C K Kashyap wrote:
The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
What I am really looking for is a small sample code that demonstrates how TLS package can be used to connect to a webserver or imapserver.
Regards, Kashyap
Kashyap,
I suggest you look at the connection package [1] which is made for this specific purpose, and comes with examples on how to use it [2].
If you want to only use tls, i suggest to look at connection's code [3], or the tls-debug [4] package, which got many small utils that use tls.
[1] http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection [2] <https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples [3] https://github.com/vincenthz/**hs-connection/blob/master/** Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs [4] https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src
-- Vincent

2013/2/23 C K Kashyap
The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
Why does this requirement compel you to forego the imapget or HaskellNet packages? -- Jason Dusek pgp // solidsnack // C1EBC57DC55144F35460C8DF1FD4C6C1FED18A2B

What I am looking to achieve is - create a DLL that would do the complete
gmail thing that could be linked to a standard C program (on windows) and
could be used to download emails from gmail.
What I gathered from HsOpenSSL (which is required for HaskellNet) depends
on some native ssl dll .... That is the reason I wanted to get a standalone
library ... again, I might have got the whole thing wrong.
Regards,
Kashyap
On Sun, Feb 24, 2013 at 3:54 AM, Jason Dusek
2013/2/23 C K Kashyap
: The reason I want to use TLS is that I'd want to pack the whole thing in a DLL and give it off to a friend for use.
Why does this requirement compel you to forego the imapget or HaskellNet packages?
-- Jason Dusek pgp // solidsnack // C1EBC57DC55144F35460C8DF1FD4C6C1FED18A2B

On 02/23/2013 03:28 PM, C K Kashyap wrote:
Hi,
I am trying to use Haskell to download email/attachments from gmail. For which I am exploring Network.TLS. I got this sample from the net that connects to gmail smtp and works just fine - http://hpaste.org/82890 Your example look odd,
Typically you would either: * connect directly using tls (usually using the standard "secure" service port) * or connect to the normal service port, do a basic handshake with the server, tell that you're going to switch the connection with STARTTLS, and use tls. but you will not use both methods in the same connection. Hope that helps, -- Vincent
participants (5)
-
Brandon Allbery
-
C K Kashyap
-
Jason Dusek
-
satvik chauhan
-
Vincent Hanquez