Skip to content

Commit

Permalink
speculative enhancements to message. needs further testing before rel…
Browse files Browse the repository at this point in the history
…ease.

  1. allow caller to specify how message content is encoded. alternative: try
     both and use begin/rescue to detect if the first attempt fails.
  2. allow caller to specify which algorithm to use for MIC generation.
     this would be extracted from HTTP Disposition-Notification-Options header.
  • Loading branch information
alexdean committed Aug 17, 2022
1 parent 877c148 commit 60ebfbc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/as2/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ def self.choose_attachment(mail_parts)
candidates[0]
end

def initialize(message, private_key, public_certificate)
# TODO: might need to use OpenSSL::PKCS7.read_smime rather than .new sometimes
@pkcs7 = OpenSSL::PKCS7.new(message)
def initialize(message, private_key, public_certificate, encoding: :binary, mic_algorithm: 'sha256')
if encoding == :binary
@pkcs7 = OpenSSL::PKCS7.new(message)
elsif encoding == :base64
@pkcs7 = OpenSSL::PKCS7.read_smime(message)
else
raise "invalid encoding type. must be :binary or :base64."
end

@private_key = private_key
@public_certificate = public_certificate
@verification_error = nil
@mic_algorithm = mic_algorithm
end

def decrypted_message
Expand Down Expand Up @@ -99,7 +106,11 @@ def mic
end

def mic_algorithm
'sha256'
if As2::DigestSelector.valid_codes.include?(@mic_algorithm)
@mic_algorithm
else
'sha256'
end
end

# Return the attached file, use .filename and .body on the return value
Expand Down

0 comments on commit 60ebfbc

Please sign in to comment.