Skip to content

Instantly share code, notes, and snippets.

View kazu-yamamoto's full-sized avatar
💭
QUIC and TLS 1.3

Kazu Yamamoto kazu-yamamoto

💭
QUIC and TLS 1.3
View GitHub Profile
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
-- |
-- To reproduce with curl, run mainTls (from ghci) and use
--
-- @
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.IORef
import Data.Default
import qualified Network.HTTP.Types as Http
import qualified Network.Wai as Wai
import Network.Wai.Handler.Warp as Warp
@kazu-yamamoto
kazu-yamamoto / quic-tls.hs
Last active November 1, 2019 05:27
Using QUIC APIs in Haskell TLS
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Concurrent
import Control.Monad
import Data.ByteString hiding (putStrLn)
import Data.Default.Class
import Network.TLS
import Network.TLS.Extra.Cipher
@kazu-yamamoto
kazu-yamamoto / gist:cde22cf569e7e78a179d30a9982b1433
Last active October 7, 2017 11:30
Concurrent hello world in Haskell
module Main (main) where
import Control.Concurrent
main :: IO ()
main = do
codechan <- newEmptyMVar
wait <- newEmptyMVar
myid <- myThreadId
putStrLn $ "I'm " ++ show myid
{-# LANGUAGE BangPatterns #-}
-- % ghc -Wall -threaded -O A.hs
-- % ./A +RTS -N2
--
-- illegal hardware instruction
-- segmentation fault
module Main where
import Control.Concurrent
@kazu-yamamoto
kazu-yamamoto / gist:4a647ffc38adf0ab56f26165a2a9c02b
Last active January 31, 2017 00:31
TLS 1.3 PSK failure from Haskell to NSS
Trying full handshake:
ClientHello -->
"010000e80303b90e92607bd3688f93ca0c05bc45253801a70c1b7d4d15e0919583594b3665b400003cc02bc02cc02fc030009e009fc023c024c027c0280067006bc009c00ac013c01400330039009c009d003d003c0035002f1301130200380032000a0005010000830000001d001b000018746c7331332e63727970746f2e6d6f7a696c6c612e6f7267ff01000100000a00060004001d0017000b00020100000d0012001008040805080604020503060304010201002b0003027f12002800260024001d0020252d54f0a5a7bfa3d61b904a616e2eed9dd091a0be6359ff44889610ddf49b44002d00020101"
"0200004e7f12e25d168388d7f371b510af05f0f1c55882cc14ef1e68fb97845b34271623ad991301002800280024001d00200b0870a2a19d080eaa56b5eda30e6e5978cffd5cd59afffa1bd6ea1cb6e66e26"
<-- ServerHello
"08000010000e000a00060004001d0017000000000b0009bc000009b800051830820514308203fca0030201020212031b91d311dd34af1b39e8a55d6f28eb45fb300d06092a864886f70d01010b0500304a310b300906035504061302555331163014060355040a130d4c6574277320456e6372797074312330210603550403131a4c6574277320456e637279707420417574686f72697479205833301e170d3137303
@kazu-yamamoto
kazu-yamamoto / gist:9428e2512fb91f06010ad0f0f36def27
Last active June 24, 2016 23:21
concurrent hello world in Haskell
module Main where
import Control.Concurrent
main :: IO ()
main = do
mvar <- newEmptyMVar
_ <- forkIO $ child mvar
action <- takeMVar mvar
action
% ghc hello-world.hs -L/usr/lib -L/opt/local/lib
Linking hello-world ...
Undefined symbols for architecture x86_64:
"_PaUtil_AllocateMemory", referenced from:
_Pa_Initialize in libHSbindings-portaudio-0.0.1.a(pa_front.o)
"_PaUtil_FreeMemory", referenced from:
_Pa_Initialize in libHSbindings-portaudio-0.0.1.a(pa_front.o)
_Pa_Terminate in libHSbindings-portaudio-0.0.1.a(pa_front.o)
"_PaUtil_InitializeClock", referenced from:
_Pa_Initialize in libHSbindings-portaudio-0.0.1.a(pa_front.o)
import java.util.*;
class Person {
String name;
int age;
Person (String n, int a) {
name = n;
age = a;
}
}
(defun which (file path)
(catch 'loop
(while path
(if (file-exists-p (expand-file-name file (car path)))
(throw 'loop (message "%s" (expand-file-name file (car path))))
(setq path (cdr path))))))