Commit 93e9e18

mo <mo.khan@gmail.com>
2017-11-26 17:44:30
remove extra characters from decryption.
1 parent 5f3de38
Changed files (3)
saml-kit/lib/saml/kit/cryptography.rb
@@ -39,10 +39,15 @@ module Saml
         end
 
         if cipher
+          iv = cipher_text[0..cipher.iv_len-1]
           data = cipher_text[cipher.iv_len..-1]
-          cipher.padding = 0
+          #cipher.padding = 0
           cipher.key = symmetric_key
-          cipher.iv = cipher_text[0..cipher.iv_len-1]
+          cipher.iv = iv
+
+          puts ['-key', symmetric_key].inspect
+          puts ['-iv', iv].inspect
+
           cipher.update(data) + cipher.final
         elsif rsa
           rsa.private_decrypt(cipher_text)
saml-kit/lib/saml/kit/response.rb
@@ -192,6 +192,9 @@ module Saml
             iv = cipher.random_iv
             encrypted = cipher.update(raw_xml_to_encrypt) + cipher.final
 
+            puts ['+iv', iv].inspect
+            puts ['+key', key].inspect
+
             xml.EncryptedAssertion xmlns: Namespaces::ASSERTION do
               xml.EncryptedData xmlns: Namespaces::XMLENC, TYPE: "http://www.w3.org/2001/04/xmlenc#Element" do
                 xml.EncryptionMethod Algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
saml-kit/spec/saml/response_spec.rb
@@ -423,9 +423,11 @@ RSpec.describe Saml::Kit::Response do
         subject.encrypt = true
         result = Hash.from_xml(subject.to_xml)
         expect(result['Response']['EncryptedAssertion']).to be_present
-        decrypted = Saml::Kit::Cryptography.new.decrypt(result['Response']['EncryptedAssertion'])
+        encrypted_assertion = result['Response']['EncryptedAssertion']
+        decrypted = Saml::Kit::Cryptography.new.decrypt(encrypted_assertion)
+        puts decrypted.inspect
         decrypted_hash = Hash.from_xml(decrypted)
-        #expect(decrypted_hash['Assertion']).to be_present
+        expect(decrypted_hash['Assertion']).to be_present
       end
     end
   end