Class: Cert::CertChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/cert/cert_checker.rb

Overview

This class checks if a specific certificate is installed on the current mac

Class Method Summary collapse

Class Method Details

.installed_identiesObject



13
14
15
16
17
18
19
20
21
# File 'lib/cert/cert_checker.rb', line 13

def self.installed_identies
  available = `security find-identity -v -p codesigning`
  ids = []
  available.split("\n").each do |current|
    (ids << current.match(/.*\) (.*) \".*/)[1]) rescue nil # the last line does not match
  end

  return ids
end

.is_installed?(path) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/cert/cert_checker.rb', line 4

def self.is_installed?(path)
  raise "Could not find file '#{path}'".red unless File.exists?(path)

  ids = installed_identies
  finger_print = sha1_fingerprint(path)

  return ids.include?finger_print
end

.sha1_fingerprint(path) ⇒ Object



23
24
25
26
27
28
# File 'lib/cert/cert_checker.rb', line 23

def self.sha1_fingerprint(path)
  result = `openssl x509 -in "#{path}" -inform der -noout -sha1 -fingerprint`
  result = result.match(/SHA1 Fingerprint=(.*)/)[1]
  result.gsub!(":", "")
  return result
end