as2 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40b3957adcdaa34f7df9fe0ee83966f7076e80bc9dc9c02b8f27a4fb22395fda
4
- data.tar.gz: 1d8002959f6b4afa70c94fd363c9d97c15b2f20a82ee96b1bc39ebba8a55972e
3
+ metadata.gz: 2cc88a7c3befd19715a142f886fcac0429911b1b2c6d4df8e5c6f6797c6469c2
4
+ data.tar.gz: ba6943a989242be148d7e39c896f61747b8455888883b60ff179d6bf53e25309
5
5
  SHA512:
6
- metadata.gz: bb04b23ab84f14e131e74e3a213e71ae5f3009f805af08b7cc1c88dc3798745639e4cffea1a85811df51a522776797f236da98c82ab84863dd5891c0b37fc243
7
- data.tar.gz: a71c9ea6c4c82637103ae1353e5b54cee88ad4f52b388883b0b409c24722247bbd0ead903ca5ef00ba1df41403ab11f1d6b4b03f9d03f58af39ccb399848adf0
6
+ metadata.gz: 14dc1ecb69d8678db913d9ee2425ae35f3e2e1b9a927a3a573e36e9a704dd4a7ab994d7c98182bf0053f40520040f0001fbc8b1390c82ebd57aa7e5c3495e99c
7
+ data.tar.gz: e43327ebbeac9bd46a2ccc4e3cd13f6354de46a3507fe01b134ecf33feef6643555c63e2ad2310debf8b3a23ec88c985d869087bf4cce29a2c54d8d06cfa753a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.1, August 10, 2022
2
+
3
+ * Any HTTP 2xx status received from a partner should be considered successful. [#12](https://github.com/andjosh/as2/pull/12)
4
+
1
5
  ## 0.5.0, March 21, 2022
2
6
 
3
7
  * improvements to `As2::Client`. improve compatibility with non-Mendelson AS2 servers. [#8](https://github.com/andjosh/as2/pull/8)
data/README.md CHANGED
@@ -30,12 +30,10 @@ along.
30
30
  will see a MIC verification failure. AS2 RFC specifically prefers sha1 and
31
31
  mentions md5. Mendelson AS2 server supports a number of other algorithms.
32
32
  (sha256, sha512, etc)
33
- 2. Payload bodies (typically EDI files) can be binary or base64 encoded. We
34
- error if the body is not base64-encoded.
35
- 3. Payload bodies can have a few different mime types. We expect only
36
- `application/EDI-Consent`. We're unable to receive content that has any other
33
+ 2. Payload bodies can have a few different mime types. We expect a type that
34
+ matches `application/EDI-*`. We're unable to receive content that has any other
37
35
  mime type. https://datatracker.ietf.org/doc/html/rfc1767#section-1
38
- 4. AS2 partners may agree to use separate certificates for data encryption and data signing.
36
+ 3. AS2 partners may agree to use separate certificates for data encryption and data signing.
39
37
  We do not support separate certificates for these purposes.
40
38
 
41
39
  ## Installation
data/as2.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Simple AS2 server and client implementation}
13
13
  spec.description = %q{Simple AS2 server and client implementation. Follows the AS2 implementation from http://as2.mendelson-e-c.com}
14
- spec.homepage = "https://github.com/andjosh/as2"
14
+ spec.homepage = "https://github.com/alexdean/as2"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
data/lib/as2/client.rb CHANGED
@@ -95,7 +95,7 @@ module As2
95
95
  resp = http.request(req)
96
96
  end
97
97
 
98
- if resp.code == '200'
98
+ if resp && resp.code.start_with?('2')
99
99
  mdn_report = evaluate_mdn(
100
100
  mdn_content_type: resp['Content-Type'],
101
101
  mdn_body: resp.body,
data/lib/as2/message.rb CHANGED
@@ -2,6 +2,28 @@ module As2
2
2
  class Message
3
3
  attr_reader :verification_error
4
4
 
5
+ # given multiple parts of a message, choose the one most likely to be the actual content we care about
6
+ #
7
+ # @param [Array<Mail::Part>]
8
+ # @return [Mail::Part, nil]
9
+ def self.choose_attachment(mail_parts)
10
+ return nil if mail_parts.nil?
11
+
12
+ # if there are multiple content parts, try to prefer the EDI content.
13
+ candidates = mail_parts
14
+ .select { |part| part.content_type.to_s['pkcs7-signature'].nil? } # skip signature
15
+ .sort_by { |part| part.content_type.to_s.match(/^application\/edi/i) ? 0 : 1 }
16
+ candidates[0]
17
+ end
18
+
19
+ # @param [Mail::Part] attachment
20
+ # @param [String] mic_algorithm
21
+ # @return [String] message integrity check string
22
+ def self.mic(attachment, mic_algorithm)
23
+ digest = As2::DigestSelector.for_code(mic_algorithm)
24
+ digest.base64digest(attachment.raw_source.lstrip)
25
+ end
26
+
5
27
  def initialize(message, private_key, public_certificate)
6
28
  # TODO: might need to use OpenSSL::PKCS7.read_smime rather than .new sometimes
7
29
  @pkcs7 = OpenSSL::PKCS7.new(message)
@@ -80,8 +102,7 @@ module As2
80
102
  end
81
103
 
82
104
  def mic
83
- digest = As2::DigestSelector.for_code(mic_algorithm)
84
- digest.base64digest(attachment.raw_source.strip)
105
+ self.class.mic(attachment, mic_algorithm)
85
106
  end
86
107
 
87
108
  def mic_algorithm
@@ -90,13 +111,11 @@ module As2
90
111
 
91
112
  # Return the attached file, use .filename and .body on the return value
92
113
  def attachment
93
- if mail.has_attachments?
94
- # TODO: match 'application/edi*', test with 'application/edi-x12'
95
- # test also with "application/edi-consent; name=this_is_a_filename.txt"
96
- mail.parts.find{ |a| a.content_type.match(/^application\/edi/) }
97
- else
98
- mail
99
- end
114
+ self.class.choose_attachment(parts)
115
+ end
116
+
117
+ def parts
118
+ mail&.parts
100
119
  end
101
120
 
102
121
  private
data/lib/as2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module As2
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OfficeLuv
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-03-21 00:00:00.000000000 Z
12
+ date: 2022-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -168,7 +168,7 @@ files:
168
168
  - lib/as2/mime_generator.rb
169
169
  - lib/as2/server.rb
170
170
  - lib/as2/version.rb
171
- homepage: https://github.com/andjosh/as2
171
+ homepage: https://github.com/alexdean/as2
172
172
  licenses:
173
173
  - MIT
174
174
  metadata: