Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Forked from nullren/ssltest.hs
Last active December 23, 2015 09:49
Show Gist options
  • Save cosmo0920/6617434 to your computer and use it in GitHub Desktop.
Save cosmo0920/6617434 to your computer and use it in GitHub Desktop.
-- Initial hs-IRC.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: test
version: 0.1.0.0
-- synopsis:
description:
test SSL
license: MIT
-- license-file: LICENSE
author: cosmo0920
-- maintainer:
-- copyright:
category: Network
build-type: Simple
cabal-version: >=1.10
executable testSSL
main-is: test.hs
other-modules:
ghc-options: -Wall -O2 -fno-warn-type-defaults -fno-warn-unused-do-bind
default-extensions: ExtendedDefaultRules
NoImplicitPrelude
CPP
GADTs
build-depends: base >= 4.5 && < 5
, network >= 2.3
, tls >= 1.1 && < 1.2
, tls-extra >= 0.6
, crypto-api >= 0.12
, random >= 1.0
, cprng-aes >= 0.5
, mtl >= 2.0
, process >= 1.1
, regex-posix >= 0.94
, text >= 0.11
, bytestring >= 0.9
default-language: Haskell2010
import System.IO
import Network.TLS
import Network.TLS.Extra
import Crypto.Random.AESCtr
-- import qualified Control.Exception as E
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Prelude
host :: String
host = "irc.oftc.net"
port :: String
port = "6697"
params :: Params
params = defaultParamsClient {pCiphers = ciphersuite_all}
-- | Makes a SSL connection to the server.
connect_ssl :: IO ()
connect_ssl = do
gen <- makeSystem
ctx <- connectionClient host port params gen
handshake ctx
let setnick = L.pack "NICK testssl\r\nUSER testssl 0 * :Testing the IRCssl\r\n"
sendData ctx setnick
listen ctx
listen :: TLSCtx -> IO ()
listen ctx = forever $ do
out <- recvData ctx
B.putStr out
main :: IO ()
main = connect_ssl
{-
$ runhaskell ssltest.hs
ssltest.hs: HandshakeFailed (Error_Packet_Parsing "Failed reading: certrequest distinguishname not of the correct size\nFrom:\thandshake\n\n")
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment