20200121000001_smime_support.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. class SMIMESupport < ActiveRecord::Migration[5.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. Setting.create_if_not_exists(
  6. title: 'S/MIME integration',
  7. name: 'smime_integration',
  8. area: 'Integration::Switch',
  9. description: 'Defines if S/MIME encryption is enabled or not.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: true,
  15. name: 'smime_integration',
  16. tag: 'boolean',
  17. options: {
  18. true => 'yes',
  19. false => 'no',
  20. },
  21. },
  22. ],
  23. },
  24. state: false,
  25. preferences: {
  26. prio: 1,
  27. authentication: true,
  28. permission: ['admin.integration'],
  29. },
  30. frontend: true
  31. )
  32. Setting.create_if_not_exists(
  33. title: 'S/MIME config',
  34. name: 'smime_config',
  35. area: 'Integration::SMIME',
  36. description: 'Defines the S/MIME config.',
  37. options: {},
  38. state: {},
  39. preferences: {
  40. prio: 2,
  41. permission: ['admin.integration'],
  42. },
  43. frontend: true,
  44. )
  45. Setting.create_if_not_exists(
  46. title: 'Defines postmaster filter.',
  47. name: '0016_postmaster_filter_smime',
  48. area: 'Postmaster::PreFilter',
  49. description: 'Defines postmaster filter to handle secure mailing.',
  50. options: {},
  51. state: 'Channel::Filter::SecureMailing',
  52. frontend: false
  53. )
  54. create_table :smime_certificates do |t|
  55. t.string :subject, limit: 500, null: false
  56. t.string :doc_hash, limit: 250, null: false
  57. t.string :fingerprint, limit: 250, null: false
  58. t.string :modulus, limit: 1024, null: false
  59. t.datetime :not_before_at, null: true # rubocop:disable Zammad/ExistsDateTimePrecision
  60. t.datetime :not_after_at, null: true # rubocop:disable Zammad/ExistsDateTimePrecision
  61. t.binary :raw, limit: 10.megabytes, null: false
  62. t.binary :private_key, limit: 10.megabytes, null: true
  63. t.string :private_key_secret, limit: 500, null: true
  64. t.timestamps limit: 3, null: false
  65. end
  66. add_index :smime_certificates, [:fingerprint], unique: true
  67. add_index :smime_certificates, [:modulus]
  68. add_index :smime_certificates, [:subject]
  69. end
  70. end