<commit_before>{-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable #-}

import Network.TLS.Internal
import Network.TLS.Cipher
import Network.TLS

import qualified Crypto.Random.AESCtr as RNG

import qualified Data.ByteString as B
import Data.Word
import Data.Char

import Network.Socket
import Network.BSD
import System.IO
import Control.Monad
import Control.Applicative ((<$>))
import Control.Concurrent
import Control.Exception (catch, SomeException(..))
import Prelude hiding (catch)

import Text.Printf

import System.Console.CmdArgs

tableCiphers =
	[ (0x0000, "NULL_WITH_NULL_NULL")
	, (0x0001, "RSA_WITH_NULL_MD5")
	, (0x0002, "RSA_WITH_NULL_SHA")
	, (0x003B, "RSA_WITH_NULL_SHA256")
	, (0x0004, "RSA_WITH_RC4_128_MD5")
	, (0x0005, "RSA_WITH_RC4_128_SHA")
	, (0x000A, "RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x002F, "RSA_WITH_AES_128_CBC_SHA")
	, (0x0035, "RSA_WITH_AES_256_CBC_SHA")
	, (0x003C, "RSA_WITH_AES_128_CBC_SHA256")
	, (0x003D, "RSA_WITH_AES_256_CBC_SHA256")
	, (0x000D, "DH_DSS_WITH_3DES_EDE_CBC_SHA")
	, (0x0010, "DH_RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x0013, "DHE_DSS_WITH_3DES_EDE_CBC_SHA")
	, (0x0016, "DHE_RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x0030, "DH_DSS_WITH_AES_128_CBC_SHA")
	, (0x0031, "DH_RSA_WITH_AES_128_CBC_SHA")
	, (0x0032, "DHE_DSS_WITH_AES_128_CBC_SHA")
	, (0x0033, "DHE_RSA_WITH_AES_128_CBC_SHA")
	, (0x0036, "DH_DSS_WITH_AES_256_CBC_SHA")
	, (0x0037, "DH_RSA_WITH_AES_256_CBC_SHA")
	, (0x0038, "DHE_DSS_WITH_AES_256_CBC_SHA")
	, (0x0039, "DHE_RSA_WITH_AES_256_CBC_SHA")
	, (0x003E, "DH_DSS_WITH_AES_128_CBC_SHA256")
	, (0x003F, "DH_RSA_WITH_AES_128_CBC_SHA256")
	, (0x0040, "DHE_DSS_WITH_AES_128_CBC_SHA256")
	, (0x0067, "DHE_RSA_WITH_AES_128_CBC_SHA256")
	, (0x0068, "DH_DSS_WITH_AES_256_CBC_SHA256")
	, (0x0069, "DH_RSA_WITH_AES_256_CBC_SHA256")
	, (0x006A, "DHE_DSS_WITH_AES_256_CBC_SHA256")
	, (0x006B, "DHE_RSA_WITH_AES_256_CBC_SHA256")
	, (0x0018, "DH_anon_WITH_RC4_128_MD5")
	, (0x001B, "DH_anon_WITH_3DES_EDE_CBC_SHA")
	, (0x0034, "DH_anon_WITH_AES_128_CBC_SHA")
	, (0x003A, "DH_anon_WITH_AES_256_CBC_SHA")
	, (0x006C, "DH_anon_WITH_AES_128_CBC_SHA256")
	, (0x006D, "DH_anon_WITH_AES_256_CBC_SHA256")
	]

fakeCipher cid = Cipher
	{ cipherID           = cid
	, cipherName         = "cipher-" ++ show cid
	, cipherDigestSize   = 0
	, cipherBulk         = Bulk
		{ bulkName         = "fake"
		, bulkKeySize      = 0
		, bulkIVSize       = 0
		, bulkBlockSize    = 0
		, bulkF            = undefined
		}
	, cipherKeyExchange  = CipherKeyExchange_RSA
	, cipherMACHash      = (\_ -> undefined)
	, cipherMinVer       = Nothing
	}

clienthello ciphers = ClientHello TLS10 (ClientRandom $ B.pack [0..31]) (Session Nothing) ciphers [0] []

openConnection :: String -> String -> [Word16] -> IO (Maybe Word16)
openConnection s p ciphers = do
	pn     <- if and $ map isDigit $ p
			then return $ fromIntegral $ (read p :: Int)
			else do
				service <- getServiceByName p "tcp"
				return $ servicePort service
        he     <- getHostByName s
	sock   <- socket AF_INET Stream defaultProtocol
	connect sock (SockAddrInet pn (head $ hostAddresses he))
	handle <- socketToHandle sock ReadWriteMode

	rng <- RNG.makeSystem
	let params = defaultParams { pCiphers = map fakeCipher ciphers }<commit_msg>fix structure for new api<commit_after>{-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable #-}

import Network.TLS.Internal
import Network.TLS.Cipher
import Network.TLS

import qualified Crypto.Random.AESCtr as RNG

import qualified Data.ByteString as B
import Data.Word
import Data.Char

import Network.Socket
import Network.BSD
import System.IO
import Control.Monad
import Control.Applicative ((<$>))
import Control.Concurrent
import Control.Exception (catch, SomeException(..))
import Prelude hiding (catch)

import Text.Printf

import System.Console.CmdArgs

tableCiphers =
	[ (0x0000, "NULL_WITH_NULL_NULL")
	, (0x0001, "RSA_WITH_NULL_MD5")
	, (0x0002, "RSA_WITH_NULL_SHA")
	, (0x003B, "RSA_WITH_NULL_SHA256")
	, (0x0004, "RSA_WITH_RC4_128_MD5")
	, (0x0005, "RSA_WITH_RC4_128_SHA")
	, (0x000A, "RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x002F, "RSA_WITH_AES_128_CBC_SHA")
	, (0x0035, "RSA_WITH_AES_256_CBC_SHA")
	, (0x003C, "RSA_WITH_AES_128_CBC_SHA256")
	, (0x003D, "RSA_WITH_AES_256_CBC_SHA256")
	, (0x000D, "DH_DSS_WITH_3DES_EDE_CBC_SHA")
	, (0x0010, "DH_RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x0013, "DHE_DSS_WITH_3DES_EDE_CBC_SHA")
	, (0x0016, "DHE_RSA_WITH_3DES_EDE_CBC_SHA")
	, (0x0030, "DH_DSS_WITH_AES_128_CBC_SHA")
	, (0x0031, "DH_RSA_WITH_AES_128_CBC_SHA")
	, (0x0032, "DHE_DSS_WITH_AES_128_CBC_SHA")
	, (0x0033, "DHE_RSA_WITH_AES_128_CBC_SHA")
	, (0x0036, "DH_DSS_WITH_AES_256_CBC_SHA")
	, (0x0037, "DH_RSA_WITH_AES_256_CBC_SHA")
	, (0x0038, "DHE_DSS_WITH_AES_256_CBC_SHA")
	, (0x0039, "DHE_RSA_WITH_AES_256_CBC_SHA")
	, (0x003E, "DH_DSS_WITH_AES_128_CBC_SHA256")
	, (0x003F, "DH_RSA_WITH_AES_128_CBC_SHA256")
	, (0x0040, "DHE_DSS_WITH_AES_128_CBC_SHA256")
	, (0x0067, "DHE_RSA_WITH_AES_128_CBC_SHA256")
	, (0x0068, "DH_DSS_WITH_AES_256_CBC_SHA256")
	, (0x0069, "DH_RSA_WITH_AES_256_CBC_SHA256")
	, (0x006A, "DHE_DSS_WITH_AES_256_CBC_SHA256")
	, (0x006B, "DHE_RSA_WITH_AES_256_CBC_SHA256")
	, (0x0018, "DH_anon_WITH_RC4_128_MD5")
	, (0x001B, "DH_anon_WITH_3DES_EDE_CBC_SHA")
	, (0x0034, "DH_anon_WITH_AES_128_CBC_SHA")
	, (0x003A, "DH_anon_WITH_AES_256_CBC_SHA")
	, (0x006C, "DH_anon_WITH_AES_128_CBC_SHA256")
	, (0x006D, "DH_anon_WITH_AES_256_CBC_SHA256")
	]

fakeCipher cid = Cipher
	{ cipherID           = cid
	, cipherName         = "cipher-" ++ show cid
	, cipherBulk         = Bulk
		{ bulkName         = "fake"
		, bulkKeySize      = 0
		, bulkIVSize       = 0
		, bulkBlockSize    = 0
		, bulkF            = undefined
		}
	, cipherKeyExchange  = CipherKeyExchange_RSA
	, cipherHash         = Hash
		{ hashName = "fake"
		, hashSize = 0
		, hashF    = undefined
		}
	, cipherMinVer       = Nothing
	}

clienthello ciphers = ClientHello TLS10 (ClientRandom $ B.pack [0..31]) (Session Nothing) ciphers [0] []

openConnection :: String -> String -> [Word16] -> IO (Maybe Word16)
openConnection s p ciphers = do
	pn     <- if and $ map isDigit $ p
			then return $ fromIntegral $ (read p :: Int)
			else do
				service <- getServiceByName p "tcp"
				return $ servicePort service
        he     <- getHostByName s
	sock   <- socket AF_INET Stream defaultProtocol
	connect sock (SockAddrInet pn (head $ hostAddresses he))
	handle <- socketToHandle sock ReadWriteMode

	rng <- RNG.makeSystem
	let params = defaultParams { pCiphers = map fakeCipher ciphers }
{'fraction_non_alphanumeric': 0.11448850486036105, 'fraction_numerical': 0.09782440981330041, 'mean_word_length': 4.898089171974522, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4788833', 'n_tokens_mistral': 3420, 'n_tokens_neox': 2791, 'n_words': 456}