Module: CertBot::MailAgent

Defined in:
lib/cert_bot/mail_agent.rb

Overview

Module to handle the mail creation and propagation of the message for a given rss item

Class Method Summary collapse

Class Method Details

.call_smtp(message, config) ⇒ Object (private)



99
100
101
102
103
104
105
106
107
# File 'lib/cert_bot/mail_agent.rb', line 99

private_class_method def self.call_smtp(message, config)
  Net::SMTP.start(config.config_hash["address"], config.config_hash["port"], helo: config.config_hash["helo"], 
                  user: config.config_hash["user"], secret: config.config_hash["password"], 
                  authtype: config.config_hash["authtype"], tls_verify: config.config_hash["tls_verify"],
                  tls_hostname: config.config_hash["tls_hostname"]) do |smtp|
    smtp.send_message(message, config.config_hash["from"], config.config_hash["to"])
  end
  nil
end

.create_introduction_string(update_status) ⇒ String (private)

private method to create the mail introduction based on the update state of the advisory

Parameters:

  • update_status (Symbol)

    the update status of the advisory

Returns:

  • (String)

    the output string for the mail text



48
49
50
51
52
53
# File 'lib/cert_bot/mail_agent.rb', line 48

private_class_method def self.create_introduction_string(update_status)
  if (CertBot::Data::UpdateStatus.get_mapping_for(update_status) == :new)
    return "Our CERT RSS Feed received a new security advisory:\n\n"
  end
  "Our CERT RSS Feed received an updated security advisory:\n\n"
end

.retrieve_cves(wid) ⇒ String (private)

private method to retrieve the cves and create an output string for the mail

Parameters:

  • wid (String)

    the id of the advisory

Returns:

  • (String)

    the output string for the mail text



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cert_bot/mail_agent.rb', line 58

private_class_method def self.retrieve_cves(wid)
  cve_list = CertBot::AdvisoryParser.retrieve_cves(wid)

  cves = "CVEs:"
  counter = 0
  cve_list.each { |cve_id|
    if (!cve_id.nil?)
      cves.concat(" ").concat(cve_id)
      counter += 1
    end

    # write only 5 cve per line then make linebreak
    if (counter == 5)
      cves.concat("\n")
      5.times { cves.concat(" ") }
      counter = 0
    end
  }
  cves
end

.retrieve_cvss_score(wid) ⇒ String (private)

private method to retrieve the cvss score and create an output string for the mail

Parameters:

  • wid (String)

    the id of the advisory

Returns:

  • (String)

    the output string for the mail text



94
95
96
97
# File 'lib/cert_bot/mail_agent.rb', line 94

private_class_method def self.retrieve_cvss_score(wid)
  cvss_score = CertBot::AdvisoryParser.retrieve_cvss_score(wid)
  "CVSS Score (#{cvss_score["version"]}): #{cvss_score["temporalscore"]/10.0}\n"
end

.retrieve_products(product_list, title) ⇒ String (private)

private method to retrieve the products and create an output string for the mail

Parameters:

  • product_list (Array)

    the list of products

Returns:

  • (String)

    the output string for the mail text



82
83
84
85
86
87
88
89
# File 'lib/cert_bot/mail_agent.rb', line 82

private_class_method def self.retrieve_products(product_list, title)
  affected_products = "#{title}:\n"
  product_list.each { |product|
    6.times { affected_products.concat(" ") }
    affected_products.concat(product["name"]).concat("\n")
  }
  affected_products
end

.send_mail(item, config_file) ⇒ String

method to generate a mail for a given item of the rss feed

Parameters:

  • item (RSS:Item)

    the rss item for a feed entry

  • config_file (String)

    the file path to the configuration file

Returns:

  • (String)

    them mail message



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cert_bot/mail_agent.rb', line 15

def self.send_mail(item, config_file)
  wid = item.link.split("=")[1]
  timestamp = item.pubDate.localtime
  config = CertBot::Configuration.new(Pathname.new(config_file))
  update_status = CertBot::AdvisoryParser.retrieve_update_status(wid)
  
  message = "From: CERT RSS <#{config.config_hash["from"]}>\n"
  message.concat("To: #{config.config_hash["to"]}\n")
  message.concat("Subject: CERT Report (#{wid}) - #{item.title.split(":")[0]}\n\n")
  message.concat(create_introduction_string(update_status))
  message.concat("Title: #{item.title}\n")
  message.concat("Description: #{item.description}\n")
  message.concat("Link: #{item.link}\n")
  message.concat("Date: #{timestamp}\n")
  message.concat("Status: #{update_status}\n")
  message.concat("Severity: #{item.category.content}\n")
  message.concat(retrieve_cvss_score(wid))
  message.concat("#{retrieve_cves(wid)}")
  message.concat("\n#{retrieve_products(CertBot::AdvisoryParser.retrieve_affected_products(wid), 
                 "Affected versions")}")
  message.concat("#{retrieve_products(CertBot::AdvisoryParser.retrieve_fixed_products(wid), 
                 "Fixed versions")}")
  message.concat("WID: #{wid}\n\n")
  message.concat("Best wishes,\n")
  message.concat("Your CERT Bot.")

  call_smtp(message, config)
  message
end