From 02cc84b761145e24e6bdb009602631c827d57208 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 22 May 2015 19:54:52 +0300 Subject: [PATCH] Update cn-s as well --- db/migrate/20150522164020_update_certs.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/migrate/20150522164020_update_certs.rb b/db/migrate/20150522164020_update_certs.rb index e08e34080..5cdaa7549 100644 --- a/db/migrate/20150522164020_update_certs.rb +++ b/db/migrate/20150522164020_update_certs.rb @@ -4,9 +4,17 @@ class UpdateCerts < ActiveRecord::Migration if x.crt.present? && x.csr.present? x.interface = Certificate::REGISTRAR x.md5 = OpenSSL::Digest::MD5.new(x.parsed_crt.to_der).to_s + + pc = x.parsed_crt.try(:subject).try(:to_s) || '' + cn = pc.scan(/\/CN=(.+)/).flatten.first + x.common_name = cn.split('/').first elsif x.crt.present? && x.csr.blank? x.interface = Certificate::API x.md5 = OpenSSL::Digest::MD5.new(x.parsed_crt.to_der).to_s + + pc = x.parsed_crt.try(:subject).try(:to_s) || '' + cn = pc.scan(/\/CN=(.+)/).flatten.first + x.common_name = cn.split('/').first elsif x.crt.blank? && x.csr.present? x.interface = Certificate::REGISTRAR end