Skip to content

Commit

Permalink
Continue signing as before; Potentially the previous logic was requir…
Browse files Browse the repository at this point in the history
…ed for Samba servers
  • Loading branch information
adfoster-r7 committed Aug 2, 2022
1 parent 46fcbdb commit 9e2be81
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/ruby_smb/signing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module Signing
# @param [RubySMB::GenericPacket] packet The packet to sign.
# @return [RubySMB::GenericPacket] the signed packet
def smb1_sign(packet)
packet = Signing::smb1_sign(packet, session_key, sequence_counter)
self.sequence_counter += 1
packet = Signing::smb1_sign(packet, @session_key, @sequence_counter)
@sequence_counter += 1

packet
end
Expand Down Expand Up @@ -41,7 +41,7 @@ def self.smb1_sign(packet, session_key, sequence_counter)
# @param [RubySMB::GenericPacket] packet The packet to sign.
# @return [RubySMB::GenericPacket] the signed packet
def smb2_sign(packet)
Signing::smb2_sign(packet, session_key)
Signing::smb2_sign(packet, @session_key)
end

# Take an SMB2 packet and sign it. This version is a module function that
Expand All @@ -51,10 +51,10 @@ def smb2_sign(packet)
# @param [String] session_key The key to use for signing.
# @return [RubySMB::GenericPacket] the signed packet
def self.smb2_sign(packet, session_key)
return packet if session_key.nil? || session_key == ''

packet.smb2_header.flags.signed = 1
packet.smb2_header.signature = "\x00" * 16
# OpenSSL 3 raises exceptions if the session key is an empty string
session_key = session_key == '' ? ("\x00" * 16).b : session_key
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), session_key, packet.to_binary_s)
packet.smb2_header.signature = hmac[0, 16]

Expand Down

0 comments on commit 9e2be81

Please sign in to comment.