From 9e2be81b87f1cf93ac40f4c9b4cf7030abc6458e Mon Sep 17 00:00:00 2001 From: adfoster-r7 Date: Tue, 2 Aug 2022 20:42:09 +0100 Subject: [PATCH] Continue signing as before; Potentially the previous logic was required for Samba servers --- lib/ruby_smb/signing.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ruby_smb/signing.rb b/lib/ruby_smb/signing.rb index b46a8a302..176d1b2d3 100644 --- a/lib/ruby_smb/signing.rb +++ b/lib/ruby_smb/signing.rb @@ -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 @@ -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 @@ -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]