-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Implement basic support for distributed signatures #39
Open
namxam
wants to merge
6
commits into
master
Choose a base branch
from
distributed-signature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f86044d
Add support for HVU and HVZ order types
namxam b9d3ba0
Implement fetching of transaction details via HVD
namxam d5b92ec
Add support for signing and rejecting ebics orders
namxam e9778ac
Set file encoding for older ruby versions
namxam 92dfc19
Update list of supported ruby versions / platforms
namxam dc8e4ba
Merge branch 'master' into distributed-signature
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,16 @@ class Epics::GenericUploadRequest < Epics::GenericRequest | |
attr_accessor :key | ||
attr_accessor :document | ||
|
||
def initialize(client, document) | ||
def initialize(client, document = nil) | ||
super(client) | ||
self.document = document | ||
self.key ||= cipher.random_key | ||
end | ||
|
||
def segmented? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you choose |
||
true | ||
end | ||
|
||
def cipher | ||
@cipher ||= OpenSSL::Cipher.new("aes-128-cbc") | ||
end | ||
|
@@ -83,4 +87,4 @@ def pad(d) | |
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'nokogiri' | ||
|
||
require_relative './h004/hvu' | ||
require_relative './h004/hvz' | ||
require_relative './h004/hvd' | ||
|
||
module Epics | ||
module H004 | ||
UnknownInput = Class.new(ArgumentError) | ||
|
||
def self.from_xml(raw_xml) | ||
doc = Nokogiri::XML(raw_xml).at_xpath('/*') | ||
|
||
unless doc.namespace.href == "urn:org:ebics:H004" | ||
fail UnknownInput, "Unknown xml file contents" | ||
end | ||
|
||
case doc.name | ||
when "HVZResponseOrderData" | ||
Epics::H004::HVZ.new(doc) | ||
when "HVUResponseOrderData" | ||
Epics::H004::HVU.new(doc) | ||
when "HVDResponseOrderData" | ||
Epics::H004::HVD.new(doc) | ||
end | ||
rescue Nokogiri::XML::XPath::SyntaxError => ex | ||
fail UnknownInput, "Invalid XML input data: #{ex.message}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Epics | ||
module H004 | ||
class HVD | ||
attr_accessor :doc | ||
|
||
def initialize(xml_doc) | ||
self.doc = xml_doc | ||
end | ||
|
||
def to_h | ||
order = doc.at_xpath("/h004:HVDResponseOrderData") | ||
{ | ||
signers: signers(order.xpath('./h004:SignerInfo')), | ||
order_details_available: order.at_xpath('./h004:OrderDetailsAvailable').content == 'true', | ||
order_data_available: order.at_xpath('./h004:OrderDataAvailable').content == 'true', | ||
digest: order.at_xpath('./h004:DataDigest').content, | ||
digest_signature_version: order.at_xpath('./h004:DataDigest')['SignatureVersion'], | ||
display_file: Base64.decode64(order.at_xpath('./h004:DisplayFile').content).encode("UTF-8", "ISO-8859-15"), | ||
} | ||
end | ||
|
||
private | ||
|
||
def originator(node) | ||
{ | ||
name: node.at_xpath('./h004:Name').content.strip, | ||
partner_id: node.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: node.at_xpath('./h004:UserID').content.strip, | ||
timestamp: Time.parse(node.at_xpath('./h004:Timestamp').content), | ||
} | ||
end | ||
|
||
def signers(nodes) | ||
nodes.map do |signer| | ||
{ | ||
name: signer.at_xpath('./h004:Name').content.strip, | ||
partner_id: signer.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: signer.at_xpath('./h004:UserID').content.strip, | ||
signature_class: signer.at_xpath('./h004:Permission')['AuthorisationLevel'] | ||
} | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Epics | ||
module H004 | ||
class HVU | ||
attr_accessor :doc | ||
|
||
def initialize(xml_doc) | ||
self.doc = xml_doc | ||
end | ||
|
||
def to_h | ||
doc.xpath("/h004:HVUResponseOrderData/h004:OrderDetails").map do |order| | ||
{ | ||
order_id: order.at_xpath('./h004:OrderID').content, | ||
order_type: order.at_xpath('./h004:OrderType').content, | ||
originator: originator(order.at_xpath('./h004:OriginatorInfo')), | ||
signers: signers(order.xpath('./h004:SignerInfo')), | ||
required_signatures: order.at_xpath('./h004:SigningInfo')['NumSigRequired'].to_i, | ||
applied_signatures: order.at_xpath('./h004:SigningInfo')['NumSigDone'].to_i, | ||
ready_for_signature: order.at_xpath('./h004:SigningInfo')['readyToBeSigned'].to_s.downcase == 'true', | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def originator(node) | ||
{ | ||
name: node.at_xpath('./h004:Name').content.strip, | ||
partner_id: node.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: node.at_xpath('./h004:UserID').content.strip, | ||
timestamp: Time.parse(node.at_xpath('./h004:Timestamp').content), | ||
} | ||
end | ||
|
||
def signers(nodes) | ||
nodes.map do |signer| | ||
{ | ||
name: signer.at_xpath('./h004:Name').content.strip, | ||
partner_id: signer.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: signer.at_xpath('./h004:UserID').content.strip, | ||
signature_class: signer.at_xpath('./h004:Permission')['AuthorisationLevel'] | ||
} | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'bigdecimal' | ||
|
||
module Epics | ||
module H004 | ||
class HVZ | ||
attr_accessor :doc | ||
|
||
def initialize(xml_doc) | ||
self.doc = xml_doc | ||
end | ||
|
||
def to_h | ||
doc.xpath("/h004:HVZResponseOrderData/h004:OrderDetails").map do |order| | ||
{ | ||
order_id: order.at_xpath('./h004:OrderID').content, | ||
order_type: order.at_xpath('./h004:OrderType').content, | ||
originator: originator(order.at_xpath('./h004:OriginatorInfo')), | ||
signers: signers(order.xpath('./h004:SignerInfo')), | ||
required_signatures: order.at_xpath('./h004:SigningInfo')['NumSigRequired'].to_i, | ||
applied_signatures: order.at_xpath('./h004:SigningInfo')['NumSigDone'].to_i, | ||
ready_for_signature: as_boolean(order.at_xpath('./h004:SigningInfo')['readyToBeSigned']), | ||
total_amount: BigDecimal.new(order.at_xpath('./h004:TotalAmount').content), | ||
total_amount_type: as_boolean(order.at_xpath('./h004:TotalAmount')['isCredit']) ? 'credit' : 'debit', | ||
total_orders: order.at_xpath('./h004:TotalOrders').content.to_i, | ||
digest: order.at_xpath('./h004:DataDigest').content, | ||
digest_signature_version: order.at_xpath('./h004:DataDigest')['SignatureVersion'], | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def originator(node) | ||
{ | ||
name: node.at_xpath('./h004:Name').content.strip, | ||
partner_id: node.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: node.at_xpath('./h004:UserID').content.strip, | ||
timestamp: Time.parse(node.at_xpath('./h004:Timestamp').content), | ||
} | ||
end | ||
|
||
def signers(nodes) | ||
nodes.map do |signer| | ||
{ | ||
name: signer.at_xpath('./h004:Name').content.strip, | ||
partner_id: signer.at_xpath('./h004:PartnerID').content.strip, | ||
user_id: signer.at_xpath('./h004:UserID').content.strip, | ||
signature_class: signer.at_xpath('./h004:Permission')['AuthorisationLevel'] | ||
} | ||
end | ||
end | ||
|
||
def as_boolean(input) | ||
input.to_s.downcase == 'true' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Epics | ||
class HVD < Epics::GenericRequest | ||
attr_accessor :order_id, :order_type | ||
|
||
def initialize(client, order_id, order_type) | ||
super(client) | ||
self.order_id = order_id | ||
self.order_type = order_type | ||
end | ||
|
||
def header | ||
{ | ||
:@authenticate => true, | ||
static: { | ||
"HostID" => host_id, | ||
"Nonce" => nonce, | ||
"Timestamp" => timestamp, | ||
"PartnerID" => partner_id, | ||
"UserID" => user_id, | ||
"Product" => { | ||
:@Language => "de", | ||
:content! => "EPICS - a ruby ebics kernel" | ||
}, | ||
"OrderDetails" => { | ||
"OrderType" => "HVD", | ||
"OrderAttribute" => "DZHNN", | ||
"HVDOrderParams" => { | ||
"PartnerID" => partner_id, | ||
"OrderType" => order_type, | ||
"OrderID" => order_id, | ||
} | ||
}, | ||
"BankPubKeyDigests" => { | ||
"Authentication" => { | ||
:@Version => "X002", | ||
:@Algorithm => "http://www.w3.org/2001/04/xmlenc#sha256", | ||
:content! => client.bank_x.public_digest | ||
}, | ||
"Encryption" => { | ||
:@Version => "E002", | ||
:@Algorithm => "http://www.w3.org/2001/04/xmlenc#sha256", | ||
:content! => client.bank_e.public_digest | ||
} | ||
}, | ||
"SecurityMedium" => "0000" | ||
}, | ||
"mutable" => { | ||
"TransactionPhase" => "Initialisation" | ||
} | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this intermediate class
Epics::H004
which determines the type and reacts accordingly? I mean in this method we already know that the result will beHVU
anyways.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could refactor it to something like: