User: Password:
|
|
Subscribe / Log in / New account

A longstanding GnuTLS certificate validation botch

A longstanding GnuTLS certificate validation botch

Posted Mar 6, 2014 0:59 UTC (Thu) by mathstuf (subscriber, #69389)
In reply to: A longstanding GnuTLS certificate validation botch by Karellen
Parent article: A longstanding GnuTLS certificate validation botch

If I were to write it in a safer language (say…Haskell), I'd have something like:

sslChecks :: [CertChain -> Cert -> Reader SslContext (Maybe String)]
sslChecks = [validCert, acceptableAlgorithm, trustedChain, ...]

sslCheck :: CertChain -> Cert -> Reader SslContext (Maybe String)
sslCheck chain cert = (liftM mconcat . sequence) . map ($ cert) . map ($ chain) $ sslChecks

where a failure just bails out of the code at the end (the Reader monad stores the options any checks might care about). No style, error checking, boilerplate, or whatever to worry about. Just write a check, put it in the right place in the lift of checks to make and return an error string if necessary.


(Log in to post comments)

A longstanding GnuTLS certificate validation botch

Posted Mar 6, 2014 1:08 UTC (Thu) by mathstuf (subscriber, #69389) [Link]

Bleh…and that's wrong since mconcat isn't set up for "Nothing" to be the success :/ . I guess adding an Monoid instance for Either a () would work better.

A longstanding GnuTLS certificate validation botch

Posted Mar 6, 2014 1:49 UTC (Thu) by nybble41 (subscriber, #55106) [Link]

That version of sslCheck will concatenate the error strings together end-to-end if multiple checks fail (Just "First ErrorSecond Error"). Did you intend something like this, which returns a list of errors?

sslCheck :: CertChain -> Cert -> Reader SslContext [String]
sslCheck chain cert = liftM catMaybes $ sequence $ sslChecks <*> pure chain <*> pure cert

A longstanding GnuTLS certificate validation botch

Posted Mar 6, 2014 2:00 UTC (Thu) by mathstuf (subscriber, #69389) [Link]

That looks much better. I haven't done much Applicative work (which is how I tried it first) and missed the 'pure'. The original idea was to get just the first error message, but why not all :) .


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds