Index: scripts/mysql-brute.nse
===================================================================
--- scripts/mysql-brute.nse	(revision 16950)
+++ scripts/mysql-brute.nse	(arbetskopia)
@@ -23,6 +23,15 @@
 -- Revised 01/23/2010 - v0.2 - revised by Patrik Karlsson, changed username, password loop, added credential storage for other mysql scripts, added timelimit
 -- Revised 01/23/2010 - v0.3 - revised by Patrik Karlsson, fixed bug showing account passwords detected twice
 
+-- ripped from ssh-hostkey.nse
+-- openssl is required for this script
+if not pcall(require,"openssl") then
+	portrule = function() return false end
+  	action = function() end
+  	stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.", filename )
+  	return;
+end
+
 portrule = shortport.port_or_service(3306, "mysql")
 
 action = function( host, port )
Index: scripts/mysql-databases.nse
===================================================================
--- scripts/mysql-databases.nse	(revision 16950)
+++ scripts/mysql-databases.nse	(arbetskopia)
@@ -26,6 +26,16 @@
 
 dependencies = {"mysql-brute", "mysql-empty-password"}
 
+-- ripped from ssh-hostkey.nse
+-- openssl is required for this script
+if not pcall(require,"openssl") then
+	portrule = function() return false end
+  	action = function() end
+  	stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.", filename )
+  	return;
+end
+
+
 -- Version 0.1
 -- Created 01/23/2010 - v0.1 - created by Patrik Karlsson
 
Index: scripts/mysql-users.nse
===================================================================
--- scripts/mysql-users.nse	(revision 16950)
+++ scripts/mysql-users.nse	(arbetskopia)
@@ -32,6 +32,15 @@
 -- Version 0.1
 -- Created 01/23/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
 
+-- ripped from ssh-hostkey.nse
+-- openssl is required for this script
+if not pcall(require,"openssl") then
+	portrule = function() return false end
+  	action = function() end
+  	stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.", filename )
+  	return;
+end
+
 portrule = shortport.port_or_service(3306, "mysql")
 
 action = function( host, port )
Index: scripts/mysql-variables.nse
===================================================================
--- scripts/mysql-variables.nse	(revision 16950)
+++ scripts/mysql-variables.nse	(arbetskopia)
@@ -40,6 +40,16 @@
 -- Version 0.1
 -- Created 01/23/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
 
+-- ripped from ssh-hostkey.nse
+-- openssl is required for this script
+if not pcall(require,"openssl") then
+	portrule = function() return false end
+  	action = function() end
+  	stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.", filename )
+  	return;
+end
+
+
 portrule = shortport.port_or_service(3306, "mysql")
 
 action = function( host, port )
Index: nselib/mysql.lua
===================================================================
--- nselib/mysql.lua	(revision 16950)
+++ nselib/mysql.lua	(arbetskopia)
@@ -13,8 +13,12 @@
 
 module(... or "mysql", package.seeall)
 
-require 'openssl'
+local HAVE_SSL = false
 
+if pcall(require,'openssl') then
+  HAVE_SSL = true
+end
+
 Capabilities = 
 {
 	LongPassword = 0x1,
@@ -121,31 +125,41 @@
 	
 end
 
---- Creates a hashed value of the password and salt according to MySQL authentication post version 4.1
---
--- @param pass string containing the users password
--- @param salt string containing the servers salt as obtained from <code>receiveGreeting</code>
--- @return reply string containing the raw hashed value
-local function createLoginHash(pass, salt)
 
-	local hash_stage1 = openssl.sha1( pass )
-	local hash_stage2 = openssl.sha1( hash_stage1 )
-	local hash_stage3 = openssl.sha1( salt .. hash_stage2 )
-	local reply = ""
+if HAVE_SSL then
 
-	local pos, b1, b2, b3, _ = 1, 0, 0, 0
-	
-	for pos=1, hash_stage1:len() do
-		_, b1 = bin.unpack( "C", hash_stage1, pos )
-		_, b2 = bin.unpack( "C", hash_stage3, pos )
-	
-		reply = reply .. string.char( bit.bxor( b2, b1 ) )
+	--- Creates a hashed value of the password and salt according to MySQL authentication post version 4.1
+	--
+	-- @param pass string containing the users password
+	-- @param salt string containing the servers salt as obtained from <code>receiveGreeting</code>
+	-- @return reply string containing the raw hashed value
+	local function createLoginHash(pass, salt)
+
+		local hash_stage1 = openssl.sha1( pass )
+		local hash_stage2 = openssl.sha1( hash_stage1 )
+		local hash_stage3 = openssl.sha1( salt .. hash_stage2 )
+		local reply = ""
+
+		local pos, b1, b2, b3, _ = 1, 0, 0, 0
+
+		for pos=1, hash_stage1:len() do
+			_, b1 = bin.unpack( "C", hash_stage1, pos )
+			_, b2 = bin.unpack( "C", hash_stage3, pos )
+
+			reply = reply .. string.char( bit.bxor( b2, b1 ) )
+		end
+
+		return reply
+
 	end
-	
-	return reply
-	
+
+else
+	local function createLoginHash(pass, salt)
+		return nil
+	end
 end
 
+
 --- Attempts to Login to the remote mysql server
 --
 -- @param socket already connected to the remote server
@@ -166,6 +180,10 @@
 	local authversion = params.authversion or "post41"
 	local username = username or ""
 
+	if not(HAVE_SSL) then
+		return false, "No OpenSSL"
+	end	
+
 	if authversion ~= "post41" then
 		return false, "Unsupported authentication version: " .. authversion
 	end
