From e31af4bead2a59dcbcfda1d339effac58e544407 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Fri, 19 Mar 2010 22:56:50 -0400 Subject: [PATCH] SSL enabled or disabled per presence of OpenSSL. --- History.txt | 4 ++++ lib/net/ldap.rb | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/History.txt b/History.txt index 8cc3481..4b014b8 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,7 @@ +=== Net::LDAP NEXT / 2010-__-__ +* SSL capabilities will be enabled or disabled based on whether we can load + OpenSSL successfully or not. + === Net::LDAP 0.1.1 / 2010-03-18 * Fixing a critical problem with sockets. diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index 13657a9..e114cfb 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -1,5 +1,15 @@ -require 'openssl' require 'ostruct' + +module Net + class LDAP + begin + require 'openssl' + HasOpenSSL = true + rescue LoadError + HasOpenSSL = false + end + end +end require 'socket' require 'net/ber' @@ -1141,6 +1151,7 @@ module Net end def self.wrap_with_ssl(io) + raise Net::LDAP::LdapError, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL ctx = OpenSSL::SSL::SSLContext.new conn = OpenSSL::SSL::SSLSocket.new(io, ctx) conn.connect