Remove trailing whitespaces and tabs

master
Guillaume DOTT 2013-06-05 10:28:56 +02:00
parent 442be992a0
commit 16a5ad5930
2 changed files with 41 additions and 41 deletions

View File

@ -21,16 +21,16 @@ class PaiementCic
@@hmac_key = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" # clé extraite grâce à extract2HmacSha1.html fourni par le Crédit Mutuel @@hmac_key = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" # clé extraite grâce à extract2HmacSha1.html fourni par le Crédit Mutuel
cattr_accessor :hmac_key cattr_accessor :hmac_key
@@target_url = "https://paiement.creditmutuel.fr/test/paiement.cgi" # "https://ssl.paiement.cic-banques.fr/paiement.cgi" @@target_url = "https://paiement.creditmutuel.fr/test/paiement.cgi" # "https://ssl.paiement.cic-banques.fr/paiement.cgi"
cattr_accessor :target_url cattr_accessor :target_url
@@tpe = "123456" @@tpe = "123456"
cattr_accessor :tpe cattr_accessor :tpe
@@societe = "masociete" @@societe = "masociete"
cattr_accessor :societe cattr_accessor :societe
@@url_ok = "" @@url_ok = ""
cattr_accessor :url_ok cattr_accessor :url_ok
@ -63,52 +63,52 @@ class PaiementCic
hmac_key.valid_hmac?(mac_string, params['MAC']) hmac_key.valid_hmac?(mac_string, params['MAC'])
end end
# Check if the HMAC matches the HMAC of the data string # Check if the HMAC matches the HMAC of the data string
def valid_hmac?(mac_string, sent_mac) def valid_hmac?(mac_string, sent_mac)
computeHMACSHA1(mac_string) == sent_mac.downcase computeHMACSHA1(mac_string) == sent_mac.downcase
end end
# Return the HMAC for a data string # Return the HMAC for a data string
def computeHMACSHA1(data) def computeHMACSHA1(data)
hmac_sha1(usable_key(self), data).downcase hmac_sha1(usable_key(self), data).downcase
end end
def hmac_sha1(key, data) def hmac_sha1(key, data)
length = 64 length = 64
if (key.length > length) if (key.length > length)
key = [Digest::SHA1.hexdigest(key)].pack("H*") key = [Digest::SHA1.hexdigest(key)].pack("H*")
end end
key = key.ljust(length, 0.chr) key = key.ljust(length, 0.chr)
ipad = ''.ljust(length, 54.chr) ipad = ''.ljust(length, 54.chr)
opad = ''.ljust(length, 92.chr) opad = ''.ljust(length, 92.chr)
k_ipad = key ^ ipad k_ipad = key ^ ipad
k_opad = key ^ opad k_opad = key ^ opad
#Digest::SHA1.hexdigest(k_opad + [Digest::SHA1.hexdigest(k_ipad + sData)].pack("H*")) #Digest::SHA1.hexdigest(k_opad + [Digest::SHA1.hexdigest(k_ipad + sData)].pack("H*"))
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), key, data) OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), key, data)
end end
private private
# Return the key to be used in the hmac function # Return the key to be used in the hmac function
def usable_key(payement) def usable_key(payement)
hex_string_key = payement.hmac_key[0..37] hex_string_key = payement.hmac_key[0..37]
hex_final = payement.hmac_key[38..40] + "00"; hex_final = payement.hmac_key[38..40] + "00";
cca0 = hex_final[0].ord cca0 = hex_final[0].ord
if cca0 > 70 && cca0 < 97 if cca0 > 70 && cca0 < 97
hex_string_key += (cca0 - 23).chr + hex_final[1..2] hex_string_key += (cca0 - 23).chr + hex_final[1..2]
elsif hex_final[1..2] == "M" elsif hex_final[1..2] == "M"
hex_string_key += hex_final[0..1] + "0" hex_string_key += hex_final[0..1] + "0"
else else
hex_string_key += hex_final[0..2] hex_string_key += hex_final[0..2]
end end
[hex_string_key].pack("H*") [hex_string_key].pack("H*")
end end
end end

View File

@ -7,11 +7,11 @@ module PaiementCic::FormHelper
sDate = Time.now.strftime("%d/%m/%Y:%H:%M:%S") sDate = Time.now.strftime("%d/%m/%Y:%H:%M:%S")
chaine = [oMac.tpe, sDate, oa["montant"], oa["reference"].to_s, oa["texte-libre"], oMac.version, "FR", oMac.societe, "", "", "", "", "", "", "", "", "", "", ""].join("*") chaine = [oMac.tpe, sDate, oa["montant"], oa["reference"].to_s, oa["texte-libre"], oMac.version, "FR", oMac.societe, "", "", "", "", "", "", "", "", "", "", ""].join("*")
chaineMAC = oMac.computeHMACSHA1(chaine) chaineMAC = oMac.computeHMACSHA1(chaine)
url_retour = options[:url_retour] || bank_callback_order_transactions_url url_retour = options[:url_retour] || bank_callback_order_transactions_url
url_retour_ok = options[:url_retour_ok] || bank_callback_order_transactions_url(order) url_retour_ok = options[:url_retour_ok] || bank_callback_order_transactions_url(order)
url_retour_err = options[:url_retour_err] || bank_err_order_transaction_url(order) url_retour_err = options[:url_retour_err] || bank_err_order_transaction_url(order)
html = ' html = '
<input type="hidden" name="version" id="version" value="' + oa["version"] + '" /> <input type="hidden" name="version" id="version" value="' + oa["version"] + '" />
<input type="hidden" name="TPE" id="TPE" value="' + oa["TPE"] + '" /> <input type="hidden" name="TPE" id="TPE" value="' + oa["TPE"] + '" />