Skip to content

Instantly share code, notes, and snippets.

@hh
Forked from anonymous/azure-knife-cert.rb
Created December 17, 2012 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hh/4323170 to your computer and use it in GitHub Desktop.
Save hh/4323170 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'base64'
publishfile = Dir.glob('*publishsettings').first
publishxml = open(publishfile).read
cert_base64 = /(?<=ManagementCertificate=\")(?<cert>.*)\">/.match(publishxml)['cert']
cert_pks12 = Base64.decode64(cert_base64)
cert = OpenSSL::PKCS12.new cert_pks12
#cert.certificate
#=> #<OpenSSL::X509::Certificate subject=/CN=Windows Azure Tools,
# issuer=/CN=Windows Azure Tools, serial=146843026396629116628912196159077583730,
# not_before=2012-12-17 22:05:25 UTC, not_after=2013-12-17 22:05:25 UTC>
# We could probably just drop the publishsettings file into .chef and detect it automatically
open("#{publishfile.sub(/publishsettings/,'pem')}",'wb').write cert.certificate.to_pem
@hh
Copy link
Author

hh commented Dec 17, 2012

This may be an easier approach to using azure certificates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment