1 module DDNS.Client.MakeReq
7 import Control.Monad.Trans
11 import OpenSSL.X509.Request
12 import System.Console.Haskeline
14 import System.Posix.Files
15 import System.Posix.Uname
19 = do fqdn <- runInputT defaultSettings $
20 do defaultFqdn <- liftM uNodeName $ liftIO uname
21 fqdn <- getInputLine ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ")
24 _ -> return defaultFqdn
26 putStrLn "Generating RSA keypair..."
27 key <- generateRSAKey 1024 3 Nothing
29 let pubFile = fqdn ++ ".pub"
30 withFile pubFile WriteMode $ \ h ->
31 writePublicKey key >>= hPutStr h
32 putStrLn ("Wrote " ++ pubFile)
34 let keyFile = fqdn ++ ".key"
35 withFile keyFile WriteMode $ \ h ->
36 writePKCS8PrivateKey key Nothing >>= hPutStr h
37 setFileMode keyFile ownerReadMode
38 putStrLn ("Wrote " ++ keyFile ++ " (with no encryption)")
42 setSubjectName req [("CN", fqdn)]
44 signX509Req req key Nothing
45 let reqFile = fqdn ++ ".req"
46 withFile reqFile WriteMode $ \ h ->
47 writeX509Req req ReqNewFormat >>= hPutStr h
48 putStrLn ("Wrote " ++ reqFile)
49 putStrLn ("Now send " ++ reqFile ++ " to the server operator and tell him/her to sign it.")