The apache-md5 package

[Tags: bsd3, library]

Haskell implementation of Apache HTTP server specific MD5 digest algorithm that uses OpenSSL MD5() function.

README and ChangeLog can be found in source code package and on GitHub:


[Skip to ReadMe]

Properties

Versions0.5.0.0, 0.5.0.1, 0.6.0.0, 0.6.1.0, 0.6.1.1, 0.6.1.2, 0.6.1.4
Change logChangeLog.md
Dependenciesbase (==4.*), bytestring (==0.10.*) [details]
LicenseBSD3
Copyright(c) 2009, 2010, 2012, 2013 Peter Trško
AuthorPeter Trško <peter.trsko@gmail.com>
Maintainerpeter.trsko@gmail.com
CategoryData, Cryptography
Source repositoryhead: git clone git://github.com/trskop/apache-md5.git
this: git clone git://github.com/trskop/apache-md5.git(tag v0.5.0.1)
UploadedSat Jul 27 08:56:31 UTC 2013 by PeterTrsko
DistributionsNixOS:0.6.1.4
Downloads831 total (55 in last 30 days)
Votes
1 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Flags

NameDescriptionDefault
pedanticPass additional warning flags including -Werror to GHC during compilation.Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for apache-md5-0.5.0.1

Apache MD5

Description

Haskell implementation of Apache specific MD5 digest algorithm that uses OpenSSL MD5.

Documentation

Stable releases with API documentation are available on Hackage.

Installation

Requires OpenSSL library with header files. On Debian and Ubuntu Linux it's provided by libssl-dev package that can be installed using apt-get:

$ apt-get install libssl-dev

For more see apt-get(8) manual page or e.g. Ubuntu Documentation: AptGet Howto.

After that just use cabal-install as you would normally do. For details see HaskellWiki: How to install a Cabal package.

Example

Create htpasswd like entry and print it to stdout:

module Main (main)
    where

import Control.Applicative ((<$>))
import System.Environment (getArgs, getProgName)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)

import Control.Monad.Random (evalRandIO, getRandomRs)
    -- MonadRandom package http://hackage.haskell.org/package/MonadRandom/
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS (index, pack)
import qualified Data.ByteString.Char8 as C8 (concat, pack, putStrLn, singleton)
    -- bytestring package http://hackage.haskell.org/package/bytestring
import Data.Digest.ApacheMD5 (alpha64, apacheMD5)


htpasswdEntry :: String -> String -> ByteString -> ByteString
htpasswdEntry username password salt = C8.concat
    [ C8.pack username
    , C8.pack ":$apr1$"
    , salt
    , C8.singleton '$'
    , apacheMD5 (C8.pack password) salt
    ]

genSalt :: IO ByteString
genSalt = evalRandIO
    $ BS.pack . map (BS.index alpha64) . take 8 <$> getRandomRs (0, 63)

main :: IO ()
main = do
    args <- getArgs
    progName <- getProgName
    case args of
        [userName, password] ->
            genSalt >>= C8.putStrLn . htpasswdEntry userName password
        _ -> do
            hPutStrLn stderr $ "Usage: " ++ progName ++ " USER_NAME PASSWORD"
            exitFailure

Compiling and running above example:

$ ghc -Wall example.hs
[1 of 1] Compiling Main             ( example.hs, example.o )
Linking example ...
$ ./example
Usage: example USER_NAME PASSWORD
$ ./example foo 123456
foo:$apr1$yM9AMlr2$EHssuHrqSAe8HPrAdN7HC/

Unit Tests

Requires htpasswd command line utility installed. On Debian and Ubuntu Linux it is provided by apache2-utils package that can be installed using apt-get:

$ apt-get install apache2-utils

For more see apt-get(8) manual page or e.g. Ubuntu Documentation: AptGet Howto.

To run tests use command similar to this:

$ cabal configure --enable-tests && cabal build && cabal test

Contributions

Contributions, pull requests and bug reports are welcome! Please don't be afraid to contact author using GitHub or by e-mail (see .cabal file for that).