20230728073916_smime_meta_information_data.rb 989 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class SMIMEMetaInformationData < ActiveRecord::Migration[6.1]
  3. def change # rubocop:disable Metrics/AbcSize
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. SMIMECertificate.in_batches.each_record do |record|
  7. begin
  8. cert = SecureMailing::SMIME::Certificate.new(record.pem)
  9. data = {
  10. email_addresses: cert.email_addresses,
  11. issuer_hash: cert.issuer.hash.to_s(16),
  12. subject_hash: cert.subject.hash.to_s(16)
  13. }
  14. rescue
  15. Rails.logger.warn <<~TEXT.squish
  16. SMIME: The migration of the certificate with fingerprint #{record.fingerprint} failed.
  17. The certificate might not be usable anymore.
  18. TEXT
  19. data = {
  20. email_addresses: [],
  21. issuer_hash: '',
  22. subject_hash: ''
  23. }
  24. end
  25. record.update!(data)
  26. end
  27. end
  28. end