Parse Azure PublishSettings to get PEM Certificate

A typical Azure PublishSettings file will look like below:

<?xml version=”1.0″ encoding=”utf-8″?>
Url=””    ManagementCertificate=”Cert-Data”>
Name=”Subscription Name” />

The code snippet below will generate PEM file from your Azure PublishSettings file.

Save the code as generate.rb. Run it as:
ruby generate.rb filename.publishsettings

def generate(settings_file_name)
require ‘nokogiri’
require ‘base64’
require ‘openssl’
require ‘uri’

doc = Nokogiri::XML(
profile = doc.at_css(“PublishProfile”)
@cert_data =“ManagementCertificate”).value))
@host_name = URI(profile.attribute(“Url”).value).host
@subscription_id =  doc.at_css(“Subscription”).attribute(“Id”).value

puts @cert_data
puts @cert_data.key
puts @cert_data.certificate
puts @host_name
puts @subscription_id

pem_data= @cert_data.key.to_s + @cert_data.certificate.to_s

File.write(“your_certificate.pem”, pem_data)

generate ARGV[0]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s