Skip to content

Commit

Permalink
Support "insecure" TLS.
Browse files Browse the repository at this point in the history
In addition to the plaintext and "secure" TLS modes. It's useful
when one authenticates against a LDAP server with a self-signed
certificate, for example.
  • Loading branch information
supki committed Apr 1, 2015
1 parent e56c2b4 commit c65895b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Ldap/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ with host port f = do
params = Conn.ConnectionParams
{ Conn.connectionHostname =
case host of
Plain h -> h
Secure h -> h
Plain h -> h
Secure h -> h
Insecure h -> h
, Conn.connectionPort = port
, Conn.connectionUseSecure =
case host of
Expand All @@ -133,6 +134,11 @@ with host port f = do
, Conn.settingDisableSession = False
, Conn.settingUseServerName = False
}
Insecure _ -> Just Conn.TLSSettingsSimple
{ Conn.settingDisableCertificateValidation = True
, Conn.settingDisableSession = False
, Conn.settingUseServerName = False
}
, Conn.connectionUseSocks = Nothing
}

Expand Down
1 change: 1 addition & 0 deletions src/Ldap/Client/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import qualified Ldap.Asn1.Type as Type
data Host =
Plain String
| Secure String
| Insecure String
deriving (Show, Eq, Ord)

data Ldap = Ldap
Expand Down
18 changes: 18 additions & 0 deletions ssl/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC+zCCAeOgAwIBAgIJAL+SevcUdGeVMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV
BAMMCWxvY2FsaG9zdDAeFw0xNTA0MDEyMjA2NTZaFw00MjA4MTcyMjA2NTZaMBQx
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAMq+GXKsMouYN7wpvSlBz4/BY4A/uQ19sP9LQId8VVrHZxUbt4QP5m+uFkYw
qCznxHeXunDruidrJiCsJ5TfPqXZ9E+/hO0ewzpxiTGyycgxgippBJXcEIYRvHPD
J/BtnNwsQD1vJExq7vJg2ItvZYPVyu/rCevTqsr12nJ+iZ/zx8+PsgRFqSJ9iuQa
PiejWEQNqNirMHclgvpYNSarEcqyu2U6j+jJtre8NIguzx0ErLYoJxfjznoPoBzG
4n/S9gJljX1/DcCKCZmMRTpxSy6UPLuS5BIWVhXrbTRP3QUm5qWQdcpOgCH8WGK1
EDk5E8qzzSg/e+cDv9etz+4jUScCAwEAAaNQME4wHQYDVR0OBBYEFL3gfN6W366G
XF6/UN8HXnHyVepYMB8GA1UdIwQYMBaAFL3gfN6W366GXF6/UN8HXnHyVepYMAwG
A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBADDaU8lRRUMIVYNl51Dnow9g
I2CgTLuTE+ftj27NSzURKCPy9QOPQ2FIFAoL57lAKlyds/tWx5zk4GoVUlIlFb+O
43uJ0NKrT5tXDsu68d3wfgwna+kpPFib3n8G1GQWI9DoaBoNOcbl2f11Tu2kujIh
LPk75BQnBLxRZRE0VSeLHE4ncy8HPZeqoDdrpjLn92aNLlojK0GfgjimkvR/trCd
doQuooLYwyFGQRd6HcrqWqoIuDKimBgnu9lcF7GEsks2f4fxtqewqrYvAzZ+Olkv
MUMU6xdL5/6ai/xqcOza3cJoR84obIHWzzzDe8BZpD1/TfPQJiCLVqmslQiR+Fc=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions ssl/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDKvhlyrDKLmDe8
Kb0pQc+PwWOAP7kNfbD/S0CHfFVax2cVG7eED+ZvrhZGMKgs58R3l7pw67onayYg
rCeU3z6l2fRPv4TtHsM6cYkxssnIMYIqaQSV3BCGEbxzwyfwbZzcLEA9byRMau7y
YNiLb2WD1crv6wnr06rK9dpyfomf88fPj7IERakifYrkGj4no1hEDaj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4XAKQu5wXPWM8mrehOwlBxA+Gt
70Xe2/yM9h1PFizlkh1G+jBz3Nk1KxaPZNstu4lsfc0VMeEv+91cHMj4PJIflDBj
PIlG0jY38Lr30KfZiILUtcrCjw0dFv98a3pccWx7AoGBAPIxhVChDoThlxIXwznq
MT1dHx8mqDmBGHACPrg4wAEs8xZbXLyokny/2n6YWIX0dGj9WIwQjMRrRK9b2JE5
VmCNcq3ZXXshrP2+p0l9CPdNHubGvYy3LK+n3nwUuIkIHfdT/21DOFizMVzxhLDy
/s+4Xn40x7nuJMSyfmvN1EKY
-----END PRIVATE KEY-----
6 changes: 5 additions & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import SpecHelper (port)

main :: IO ()
main =
bracket (do (_, out, _, h) <- runInteractiveProcess "./test/ldap.js" [] Nothing (Just [("PORT", show port)])
bracket (do (_, out, _, h) <- runInteractiveProcess "./test/ldap.js" [] Nothing
(Just [ ("PORT", show port)
, ("SSL_CERT", "./ssl/cert.pem")
, ("SSL_KEY", "./ssl/key.pem")
])
hGetLine out
return h)
(\h -> do terminateProcess h
Expand Down
2 changes: 1 addition & 1 deletion test/SpecHelper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ locally :: (Ldap -> IO a) -> IO (Either LdapError a)
locally = Ldap.with localhost port

localhost :: Host
localhost = Plain "localhost"
localhost = Insecure "localhost"

port :: Num a => a
port = 24620
Expand Down
10 changes: 7 additions & 3 deletions test/ldap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env nodejs

var fs = require('fs');
var ldapjs = require('ldapjs');
var server = ldapjs.createServer();
var port = process.env.PORT

var port = process.env.PORT;
var certificate = fs.readFileSync(process.env.SSL_CERT, "utf-8");
var key = fs.readFileSync(process.env.SSL_KEY, "utf-8");
var server = ldapjs.createServer({certificate: certificate, key: key});

// <http://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_National_Pok%C3%A9dex_number>
var pokemon = [
Expand Down Expand Up @@ -105,5 +109,5 @@ server.del('o=localhost', [], function(req, res, next) {
});

server.listen(port, function() {
console.log("ldap://localhost:%d", port);
console.log("ldaps://localhost:%d", port);
});

0 comments on commit c65895b

Please sign in to comment.