Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sha512 doodles #1

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b1372f1
try printing out some backend message stuff
Aug 16, 2019
99efb99
print out received codes
Aug 16, 2019
c2e4a1b
bump protocol version
Aug 26, 2019
cb4e507
bump version
Aug 26, 2019
ca2d496
ok some cargo culting
Aug 26, 2019
60a977a
ruby doesn't like addition there?
Aug 26, 2019
eb321f2
start to bring the front end into line
Aug 26, 2019
ae9d478
bump version
Aug 26, 2019
1622c3b
teach password.rb to use sha512
Aug 26, 2019
7de2023
lost a comma
Aug 26, 2019
157fde3
pass the user salt along
Aug 26, 2019
0800ecd
try just requiring digest
Aug 26, 2019
7d28e47
maybe ruby and python agree?
Aug 27, 2019
2897eda
add the pw configuration?
Aug 27, 2019
3f2d242
i didn't use the right names
Aug 27, 2019
bc24f8f
check the user salt length
Aug 27, 2019
c8242cf
apparently we use different packing symbols
Aug 27, 2019
4971e09
try and unpack the second place with stuff
Aug 27, 2019
89f8a23
try ranges?
Aug 27, 2019
4528717
some brute forcing
Aug 28, 2019
2f3971f
don't think i know much about ruby string substitution
Aug 28, 2019
809da49
try just hardcoding the encoding
Aug 28, 2019
7d792b6
try adding some more transparency
Aug 28, 2019
c9d32b3
try printing more out
Aug 28, 2019
6bb1acc
print out manual hash
Aug 28, 2019
b4cc4e9
ok....
Aug 28, 2019
97b0c3b
encode the prefix as bytes
Aug 28, 2019
8313313
try some inspection
Aug 29, 2019
eeb31cb
am i unpacking right?
Aug 29, 2019
636b8d4
maybe this for the salt?
Aug 29, 2019
02db95c
print out hashes for comparison
Aug 29, 2019
f9aef86
try concating the strings
Aug 29, 2019
7d01d76
use byte concat instead of array
Aug 29, 2019
2525b02
regular string
Aug 29, 2019
ffa2f79
remove unneded print statements
Aug 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vertica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Vertica

# The protocol version (3.0.0) implemented in this library.
PROTOCOL_VERSION = 3 << 16
PROTOCOL_VERSION = 3 << 16 | 5

# Opens a new connection to a Vertica database.
# @param (see Vertica::Connection#initialize)
Expand Down
2 changes: 1 addition & 1 deletion lib/vertica/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def startup_connection
case message = read_message
when Vertica::Protocol::Authentication
if message.code != Vertica::Protocol::Authentication::OK
write_message(Vertica::Protocol::Password.new(@options[:password], auth_method: message.code, user: @options[:username], salt: message.salt))
write_message(Vertica::Protocol::Password.new(@options[:password], auth_method: message.code, user: @options[:username], salt: message.salt, userSalt: message.userSalt))
end
else
process_message(message)
Expand Down
20 changes: 18 additions & 2 deletions lib/vertica/protocol/backend/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@ class Authentication < BackendMessage
message_id 'R'

OK = 0
KERBEROS_V4 = 1
KERBEROS_V5 = 2
CLEARTEXT_PASSWORD = 3
CRYPT_PASSWORD = 4
MD5_PASSWORD = 5
SCM_CREDENTIAL = 6
GSS = 7
GSS_CONTINUE = 8
SSPI = 9
CHANGE_PASSWORD = 9
PASSWORD_CHANGED = 10
PASSWORD_GRACE = 11
HASH = 65536
HASH_MD5 = 65536+5
HASH_SHA512 = 65536+512

attr_reader :code
attr_reader :salt
attr_reader :userSalt
attr_reader :auth_data

def initialize(data)
@code, other = data.unpack('Na*')
case @code
when CRYPT_PASSWORD, MD5_PASSWORD then @salt = other
when CRYPT_PASSWORD then @salt = other
when MD5_PASSWORD, HASH_MD5 then @salt = other[0...4]
when GSS_CONTINUE then @auth_data = other
when HASH, HASH_SHA512
@salt = other[0...4]
@userSaltLen = other[4...8].unpack('I>').first
if @userSaltLen != 16
puts "user salt length isn't 16, raise error"
end
userSaltArray = other[8...other.size].unpack('a*')
@userSalt = userSaltArray.first
end
end
end
Expand Down
17 changes: 13 additions & 4 deletions lib/vertica/protocol/frontend/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Protocol
class Password < FrontendMessage
message_id 'p'

def initialize(password, auth_method: Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD, salt: nil, user: nil)
def initialize(password, auth_method: Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD, salt: nil, user: nil, userSalt: nil)
@password = password
@auth_method, @salt, @user = auth_method, salt, user
@auth_method, @salt, @user, @userSalt = auth_method, salt, user, userSalt
end

def encoded_password
Expand All @@ -14,11 +14,20 @@ def encoded_password
@password
when Vertica::Protocol::Authentication::CRYPT_PASSWORD
@password.crypt(@salt)
when Vertica::Protocol::Authentication::MD5_PASSWORD
when Vertica::Protocol::Authentication::MD5_PASSWORD, \
Vertica::Protocol::Authentication::HASH_MD5
require 'digest/md5'
@password = Digest::MD5.hexdigest("#{@password}#{@user}")
@password = Digest::MD5.hexdigest("#{@password}#{@salt}")
@password = "md5#{@password}"
prefix = "md5".bytes
@password = "#{prefix}#{@password}"
when Vertica::Protocol::Authentication::HASH, \
Vertica::Protocol::Authentication::HASH_SHA512
require 'digest'
@password = Digest::SHA512.hexdigest("#{@password}#{@userSalt}")
@password = Digest::SHA512.hexdigest("#{@password}#{@salt}")
prefix = "sha512"
@password = "#{prefix}#{@password}"
else
raise ArgumentError.new("unsupported authentication method: #{@auth_method}")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vertica/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Vertica
# The version of the package. We adhere to semantic versioning.
# To release a new version, update this constant, commit to master, and run `rake release`
VERSION = "1.0.3"
VERSION = "1.0.34"
end
5 changes: 5 additions & 0 deletions vagrant/configure_vertica_passwords.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select SET_CONFIG_PARAMETER('SecurityAlgorithm', 'SHA512');
CREATE AUTHENTICATION default_network METHOD 'hash' HOST '0.0.0.0/0';
CREATE AUTHENTICATION default_local METHOD 'hash' LOCAL;
GRANT AUTHENTICATION default_network to public;
GRANT AUTHENTICATION default_local to public;