Skip to content

Commit

Permalink
Merge pull request #84 from getyoti/Release161
Browse files Browse the repository at this point in the history
Release 1.6.1
  • Loading branch information
emmas-yoti authored Jan 23, 2020
2 parents ad18e8c + 8c56613 commit 6ba09c0
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 20 deletions.
5 changes: 4 additions & 1 deletion lib/yoti/activity_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lib/yoti/protobuf/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/yoti/share/attribute_issuance_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/yoti/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Yoti
# @return [String] the gem's current version
VERSION = '1.6.0'.freeze
VERSION = '1.6.1'.freeze
end
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/yoti/activity_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions spec/yoti/protobuf/protobuf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { '' }

Expand Down
2 changes: 1 addition & 1 deletion spec/yoti/share/attribute_issuance_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions spec/yoti/share/extra_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6ba09c0

Please sign in to comment.