Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2012 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4323169 to your computer and use it in GitHub Desktop.
Save anonymous/4323169 to your computer and use it in GitHub Desktop.
knife-azure makes the user jump through hoops to get at the certificate, I think the gem should look for a .pubishsettings file in .chef dir by default and process it to get the cert (like we have on line 8). This gist writes out the .pem file, but I don't think having a .pem file is necessary.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment