diff --git a/lib/yoti/activity_details.rb b/lib/yoti/activity_details.rb index e8e879ad..740c970d 100644 --- a/lib/yoti/activity_details.rb +++ b/lib/yoti/activity_details.rb @@ -93,6 +93,9 @@ class ActivityDetails # # @param receipt [Hash] the receipt from the API request # @param decrypted_profile [Object] Protobuf AttributeList decrypted object containing the profile attributes + # @param decrypted_application_profile [Object] Protobuf AttributeList decrypted object containing profile attributes for the application profile + # @param extra_data [Yoti::Share::ExtraData|nil] Processed extra data object or nil + # if absent from the receipt # def initialize(receipt, decrypted_profile = nil, decrypted_application_profile = nil, extra_data = nil) @remember_me_id = receipt['remember_me_id'] @@ -103,7 +106,7 @@ def initialize(receipt, decrypted_profile = nil, decrypted_application_profile = @timestamp = receipt['timestamp'] ? Time.parse(receipt['timestamp']) : nil @extended_user_profile = process_decrypted_profile(decrypted_profile) @extended_application_profile = process_decrypted_profile(decrypted_application_profile) - @extra_data = Share::ExtraData.new(extra_data) if extra_data + @extra_data = extra_data @user_profile = @extended_user_profile.map do |name, attribute| [name, attribute.value] end.to_h diff --git a/lib/yoti/dynamic_share_service/extension/thirdparty_attribute_extension.rb b/lib/yoti/dynamic_share_service/extension/thirdparty_attribute_extension.rb index 62baad6a..4060eb8b 100644 --- a/lib/yoti/dynamic_share_service/extension/thirdparty_attribute_extension.rb +++ b/lib/yoti/dynamic_share_service/extension/thirdparty_attribute_extension.rb @@ -2,6 +2,16 @@ module Yoti module DynamicSharingService + class ThirdPartyAttributeDefinition + def initialize(name) + @name = name + end + + def to_json(*_args) + { name: @name }.to_json + end + end + class ThirdPartyAttributeExtensionBuilder def initialize @expiry_date = nil @@ -14,8 +24,8 @@ def with_expiry_date(expiry_date) end def with_definitions(*names) - names.each do |s| - @definitions += [{ name: s }] + @definitions += names.map do |name| + ThirdPartyAttributeDefinition.new(name) end self end diff --git a/lib/yoti/protobuf/main.rb b/lib/yoti/protobuf/main.rb index 38e773ea..ade28dfd 100644 --- a/lib/yoti/protobuf/main.rb +++ b/lib/yoti/protobuf/main.rb @@ -44,9 +44,9 @@ def application_profile(receipt) end def extra_data(receipt) - return nil unless valid_receipt?(receipt) + return nil if receipt['extra_data_content'].nil? || receipt['extra_data_content'] == '' - decipher_profile(receipt['extra_data'], receipt['wrapped_receipt_key']) if receipt['extra_data'] + decipher_extra_data(receipt['extra_data_content'], receipt['wrapped_receipt_key']) end def attribute_list(data) @@ -111,11 +111,21 @@ def decode_profile(profile_content) end def decipher_profile(profile_content, wrapped_key) - encrypted_data = decode_profile(profile_content) - unwrapped_key = Yoti::SSL.decrypt_token(wrapped_key) - decrypted_data = Yoti::SSL.decipher(unwrapped_key, encrypted_data.iv, encrypted_data.cipher_text) + decrypted_data = decipher_data(profile_content, wrapped_key) Protobuf.attribute_list(decrypted_data) end + + def decipher_extra_data(extra_data_content, wrapped_key) + decrypted_data = decipher_data(extra_data_content, wrapped_key) + proto = Yoti::Protobuf::Sharepubapi::ExtraData.decode(decrypted_data) + Share::ExtraData.new(proto) + end + + def decipher_data(encrypted_content, wrapped_key) + encrypted_data = decode_profile(encrypted_content) + unwrapped_key = Yoti::SSL.decrypt_token(wrapped_key) + Yoti::SSL.decipher(unwrapped_key, encrypted_data.iv, encrypted_data.cipher_text) + end end end end diff --git a/lib/yoti/share/attribute_issuance_details.rb b/lib/yoti/share/attribute_issuance_details.rb index d0e4d0a3..8b183ddb 100644 --- a/lib/yoti/share/attribute_issuance_details.rb +++ b/lib/yoti/share/attribute_issuance_details.rb @@ -28,7 +28,7 @@ class AttributeIssuanceDetails # @param [Yoti::Protobuf::Sharepubapi::ThirdPartyAttribute] data_entry # def initialize(data_entry) - @token = Base64.encode64(data_entry.issuance_token) + @token = Base64.strict_encode64(data_entry.issuance_token) begin @expiry_date = DateTime.parse(data_entry.issuing_attributes.expiry_date) rescue ArgumentError diff --git a/lib/yoti/version.rb b/lib/yoti/version.rb index 9b46c765..b10ec208 100644 --- a/lib/yoti/version.rb +++ b/lib/yoti/version.rb @@ -1,4 +1,4 @@ module Yoti # @return [String] the gem's current version - VERSION = '1.6.0'.freeze + VERSION = '1.6.1'.freeze end diff --git a/sonar-project.properties b/sonar-project.properties index af41373c..b5efb7b6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,6 @@ sonar.projectKey = yoti-web-sdk:ruby sonar.projectName = ruby-sdk -sonar.projectVersion = 1.6.0 +sonar.projectVersion = 1.6.1 sonar.language=ruby sonar.exclusions = **/protobuf/**.rb, coverage/**, spec/sample-data/** sonar.links.scm = https://github.com/getyoti/yoti-ruby-sdk diff --git a/spec/yoti/activity_details_spec.rb b/spec/yoti/activity_details_spec.rb index 3167558c..642cae61 100644 --- a/spec/yoti/activity_details_spec.rb +++ b/spec/yoti/activity_details_spec.rb @@ -74,7 +74,7 @@ def proto_attr(name, value, content_type) }, nil, nil, extra_data) end it 'returns the extra data' do - expect(activity_details.extra_data).to be_kind_of(Yoti::Share::ExtraData) + expect(activity_details.extra_data).to eql extra_data end end end diff --git a/spec/yoti/dynamic_share_service/extension/thirdparty_attribute_extension_spec.rb b/spec/yoti/dynamic_share_service/extension/thirdparty_attribute_extension_spec.rb index 2d17d5f9..569337d5 100644 --- a/spec/yoti/dynamic_share_service/extension/thirdparty_attribute_extension_spec.rb +++ b/spec/yoti/dynamic_share_service/extension/thirdparty_attribute_extension_spec.rb @@ -2,6 +2,21 @@ require 'spec_helper' +describe 'ThirdPartyAttributeDefinition' do + describe 'to_json' do + let :name do + 'AttributeName' + end + let :defn do + Yoti::DynamicSharingService::ThirdPartyAttributeDefinition.new(name) + end + it 'marshals into json' do + expected = '{"name":"AttributeName"}' + expect(defn.to_json).to eql expected + end + end +end + describe 'Yoti::DynamicSharingService::ThirdPartyAttributeExtension' do describe '.to_json' do let :expiry_date do diff --git a/spec/yoti/protobuf/protobuf_spec.rb b/spec/yoti/protobuf/protobuf_spec.rb index 1cf6206e..6bc5c545 100644 --- a/spec/yoti/protobuf/protobuf_spec.rb +++ b/spec/yoti/protobuf/protobuf_spec.rb @@ -42,6 +42,27 @@ def assert_expected_image(image, mime_type, base64_last_ten) end end + describe '.extra_data' do + context 'when the receipt has extra_data_content' do + let :extra_data_content do + 'ChCZK1k2WpNVdi58yu9MvXz5EnDxrDl1CUfUBDCSy/u6uI2+X7/tTrosHXWxu4ksN8qfVU2zdPE9FrEVNYKs7bbwdf3oOQ81q8+yF9Zv7szCUrYflY6WCwKBRJluYEApxXdjcHdvlhmzCXrgMeAV6qHj0n9qWrWXZytx+LT0mLHQPxeU' + end + let :wrapped_receipt_key do + 'UqAI7cCcSFZ3NHWqEoXW3YfCXMxmvUBeN+JC2mQ/EVFvCjJ1DUVSzDP87bKtbZqKLqkj8oD0rQvMkS7VcYrUZ8aW6cTh+anX11LJLrP3ZYjr5QRQc5RHkOa+c3cFJV8ZwXzwJPkZny3BlHpEuAUhjcxywAcOPX4PULzO4zPrrkWq0cOtASVRqT+6CpR03RItL3yEY0CFa3RoYgrfkMsE8f8glft0GVVleVs85bAhiPmkfNQY0YZ/Ba12Ofph/S+4qB8ydfk96gpp+amb/Wfbd4gvs2DUCVpHu7U+937JEcEi6NJ08A5ufuWXoBxVKwVN1Tz7PNYDeSLhko77AIrJhg==' + end + let :receipt do + { + 'extra_data_content' => extra_data_content, + 'wrapped_receipt_key' => wrapped_receipt_key + } + end + + it 'returns extra data' do + expect(Yoti::Protobuf.extra_data(receipt)).to be_a Yoti::Share::ExtraData + end + end + end + describe '.attribute_list' do let(:data) { '' } diff --git a/spec/yoti/share/attribute_issuance_details_spec.rb b/spec/yoti/share/attribute_issuance_details_spec.rb index 0be43c09..799f7ed4 100644 --- a/spec/yoti/share/attribute_issuance_details_spec.rb +++ b/spec/yoti/share/attribute_issuance_details_spec.rb @@ -29,7 +29,7 @@ def create_thirdparty_attribute_proto(token, expiry_date, *definitions) 'tokenValue' end let :b64token do - Base64.encode64 token + Base64.strict_encode64 token end let :now do DateTime.now diff --git a/spec/yoti/share/extra_data_spec.rb b/spec/yoti/share/extra_data_spec.rb index 04a9eb8d..80485e6e 100644 --- a/spec/yoti/share/extra_data_spec.rb +++ b/spec/yoti/share/extra_data_spec.rb @@ -38,7 +38,7 @@ def create_extra_data_proto(*rows) 'tokenValue1' end let :b64token do - Base64.encode64 token_value + Base64.strict_encode64 token_value end let :attribute_name do 'attributeName1' @@ -71,7 +71,7 @@ def create_extra_data_proto(*rows) 'tokenValue' end let :b64token do - Base64.encode64 token_value + Base64.strict_encode64 token_value end let :attribute1 do 'attribute1' @@ -107,7 +107,7 @@ def create_extra_data_proto(*rows) 'tokenValue' end let :b64token do - Base64.encode64 token + Base64.strict_encode64 token end let :attribute do 'attributeName' @@ -139,10 +139,7 @@ def create_extra_data_proto(*rows) 'tokenValue' end let :b64token do - Base64.encode64 token - end - let :attribute do - 'attributeName' + Base64.strict_encode64 token end let :proto do create_extra_data_proto(