X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=blackboard-dns.git;a=blobdiff_plain;f=DDNS%2FClient%2FMakeReq.hs;fp=DDNS%2FClient%2FMakeReq.hs;h=b9baa49c5b7eb31e99fd0cc5fb4a31c1f3b64a6c;hp=0000000000000000000000000000000000000000;hb=20021ec127c5574db472d88ff47cbf7e656969f4;hpb=3674500cd498050a48d69d1d30a6139ba3ba88f5 diff --git a/DDNS/Client/MakeReq.hs b/DDNS/Client/MakeReq.hs new file mode 100644 index 0000000..b9baa49 --- /dev/null +++ b/DDNS/Client/MakeReq.hs @@ -0,0 +1,49 @@ +module DDNS.Client.MakeReq + ( makeReq + ) + where + +import Control.Monad +import Control.Monad.Trans +import DDNS.Utils +import OpenSSL.PEM +import OpenSSL.RSA +import OpenSSL.X509.Request +import System.Console.Haskeline +import System.IO +import System.Posix.Files +import System.Posix.Uname + +makeReq :: IO () +makeReq + = do fqdn <- runInputT defaultSettings $ + do defaultFqdn <- liftM uNodeName $ liftIO uname + fqdn <- getInputLine ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ") + case trim fqdn of + Just s -> return s + _ -> return defaultFqdn + + putStrLn "Generating RSA keypair..." + key <- generateRSAKey 1024 3 Nothing + + let pubFile = fqdn ++ ".pub" + withFile pubFile WriteMode $ \ h -> + writePublicKey key >>= hPutStr h + putStrLn ("Wrote " ++ pubFile) + + let keyFile = fqdn ++ ".key" + withFile keyFile WriteMode $ \ h -> + writePKCS8PrivateKey key Nothing >>= hPutStr h + setFileMode keyFile ownerReadMode + putStrLn ("Wrote " ++ keyFile ++ " (with no encryption)") + + req <- newX509Req + setVersion req 2 + setSubjectName req [("CN", fqdn)] + setPublicKey req key + signX509Req req key Nothing + let reqFile = fqdn ++ ".req" + withFile reqFile WriteMode $ \ h -> + writeX509Req req ReqNewFormat >>= hPutStr h + putStrLn ("Wrote " ++ reqFile) + putStrLn ("Now send " ++ reqFile ++ " to the server operator and tell him/her to sign it.")