Class: Sourcefire::PkcsOps
- Inherits:
-
Object
- Object
- Sourcefire::PkcsOps
- Defined in:
- lib/sourcefire/p12_utils.rb
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#key(strip_header_footer = false) ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #cert_der(strip_header_footer = false) ⇒ Object
- #cert_der_to_file(file_name, strip_header_footer = false) ⇒ Object
- #cert_pem(strip_header_footer = false) ⇒ Object
- #cert_pem_to_file(file_name, strip_header_footer = false) ⇒ Object
- #cert_public_key(strip_header_footer = false) ⇒ Object
- #extract_pkcs_12(pkcs_file, password = nil) ⇒ Object
- #key_to_file(file_name, strip_header_footer = false) ⇒ Object
- #raw_cert(strip_header_footer = false) ⇒ Object
- #raw_cert_to_file(file_name, strip_header_footer = false) ⇒ Object
Instance Attribute Details
#cert ⇒ Object
Returns the value of attribute cert.
5 6 7 |
# File 'lib/sourcefire/p12_utils.rb', line 5 def cert @cert end |
#key(strip_header_footer = false) ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/sourcefire/p12_utils.rb', line 5 def key @key end |
Instance Method Details
#cert_der(strip_header_footer = false) ⇒ Object
53 54 55 56 |
# File 'lib/sourcefire/p12_utils.rb', line 53 def cert_der( = false) processed_cert = ? p12_data_to_split_string(@cert.to_der) {|data| data.to_a[1..-2].join} : @cert processed_cert.nil? ? 'No Cert Data!' : processed_cert end |
#cert_der_to_file(file_name, strip_header_footer = false) ⇒ Object
33 34 35 36 |
# File 'lib/sourcefire/p12_utils.rb', line 33 def cert_der_to_file(file_name, = false) processed_cert = ? p12_data_to_split_string(@cert.to_der) {|data| data.to_a[1..-2].join} : @cert File.open(file_name, 'w') {|f| processed_cert.nil? ? f.write('No Cert Data!') : f.write(processed_cert) } end |
#cert_pem(strip_header_footer = false) ⇒ Object
48 49 50 51 |
# File 'lib/sourcefire/p12_utils.rb', line 48 def cert_pem( = false) processed_cert = ? p12_data_to_split_string(@cert.to_pem) {|data| data.to_a[1..-2].join} : @cert processed_cert.nil? ? 'No Cert Data!' : processed_cert end |
#cert_pem_to_file(file_name, strip_header_footer = false) ⇒ Object
28 29 30 31 |
# File 'lib/sourcefire/p12_utils.rb', line 28 def cert_pem_to_file(file_name, = false) processed_cert = ? p12_data_to_split_string(@cert.to_pem) {|data| data.to_a[1..-2].join} : @cert File.open(file_name, 'w') {|f| processed_cert.nil? ? f.write('No Cert Data!') : f.write(processed_cert) } end |
#cert_public_key(strip_header_footer = false) ⇒ Object
58 59 60 |
# File 'lib/sourcefire/p12_utils.rb', line 58 def cert_public_key( = false) ? p12_data_to_split_string(@cert.public_key) {|data| data.to_a[1..-2].join} : @cert.public_key end |
#extract_pkcs_12(pkcs_file, password = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/sourcefire/p12_utils.rb', line 8 def extract_pkcs_12(pkcs_file, password = nil) if password.nil? || password.empty? p12 = OpenSSL::PKCS12.new(File.read(pkcs_file)) else p12 = OpenSSL::PKCS12.new(File.read(pkcs_file), password) end @key = p12.key @cert = p12.certificate end |
#key_to_file(file_name, strip_header_footer = false) ⇒ Object
18 19 20 21 |
# File 'lib/sourcefire/p12_utils.rb', line 18 def key_to_file(file_name, = false) processed_key = ? p12_data_to_split_string(@key) {|data| data.to_a[1..-2].join} : @key File.open(file_name, 'w') {|f| processed_key.nil? ? f.write('No Key Data!') : f.write(processed_key) } end |
#raw_cert(strip_header_footer = false) ⇒ Object
43 44 45 46 |
# File 'lib/sourcefire/p12_utils.rb', line 43 def raw_cert( = false) processed_cert = ? p12_data_to_split_string(@cert) {|data| data.to_a[1..-2].join} : @cert processed_cert.nil? ? 'No Cert Data!' : processed_cert end |
#raw_cert_to_file(file_name, strip_header_footer = false) ⇒ Object
23 24 25 26 |
# File 'lib/sourcefire/p12_utils.rb', line 23 def raw_cert_to_file(file_name, = false) processed_cert = ? p12_data_to_split_string(@cert) {|data| data.to_a[1..-2].join} : @cert File.open(file_name, 'w') {|f| processed_cert.nil? ? f.write('No Cert Data!') : f.write(processed_cert) } end |