I am attempting fully automate system provisioning, including a point-to-site VPN. One of the last pieces is to upload the client root certificate for the Virtual Network Gateway. I am able to download an existing certificate using the REST API.
$uri = [uri]"${serviceUrl}${subId}/services/networking/$VNetName/gateway/clientrootcertificates/$rootCertThumbprint" $response = Invoke-WebRequest -Uri $uri -Method Get -Headers @{"x-ms-version"="2013-03-01"} -Certificate $subscriptionCertificate
The response contains the HEX encoded binary public certificate for the specified root cert. Now to upload (using the API fromhttp://msdn.microsoft.com/en-us/library/windowsazure/dn205129.aspx). My assumption is that the Request Body would look like (The same HEX encoded binary):
<Binary xmlns="http://schemas.microsoft.com/windowsazure">30820311308201FDA00302010202102830443541EE31B84EC0B46321567397300906052B0E03021D0500301E311C301A060355040313134465762D524150494447617465526F6F744341301E170D313330383 0373030303235305A170D3339313233313233353935395A301E311C301A060355040313134465762D524150494447617465526F6F74434130820122300D06092A864886F70D01010105000382010F003082010A0282010100D69EFF64A9743904019CFBD432D755BA0CD74800F9C339 706D5ABF1DA81F5D0FF3C99AD1A2376DB5FEDEAB5B0C7011B0C7A06E5AA56408FED3C39A9263E5D58033C95343CD9F8324EB7FD3388EF7294D6ADC242A32BF7AA6FF223D303DC3E2F7B4B15BAA87C9D2B6E1DFCE0D672DC8B3ED96738F2B35691ABD49527AA351082EDEE898AE331E7 570979769189A09DD0B89E58BB440C9DABDA8870E61F45B9F9DA2ECD92FE1E2F748EE69D02C0990C5268B6705A8F6990335CF40B98C2A86EF2DF6C867E2CCC1913A3DC02A3B0458EC21269C0D0685F947371E35F35E2CAF7E042DB1441D96FD6007E8F54F6E6B3C895707DB198655F0 10CECBE144397E828DDF0203010001A3533051304F0603551D01044830468010AC31CCDA3128283DA80D4AC4DE6A803DA120301E311C301A060355040313134465762D524150494447617465526F6F74434182102830443541EE31B84EC0B46321567397300906052B0E03021D05000 3820101005825CFB989A116B36450BF37F882B92F9F1A2D7E1E947F9AEF0C328C022AFC5D31AA40C006E853D97D1A2C22FD9BB687C97303F6C133BADE1AC0AD1AE9961BCC15B22CDA7EF84F5C78A72688ED0F8610B75EBBD4D97560695874A67C5D81B9E3724A75CFE83F0417B0299C 0AEA14E6C302ED1329E3A584B8BDDF739EEEF5C9D21D3CB5CE8B8AD66EA1C79DAB2843A0438EF1BF8C014406B9D24E3011116561F1A670C35F05535FB9C0492BB1F7E212F2A23A05B0EC4BA7D46A724681EB30C5764092D825B8BD4604E6F8B65ECE4B04720A8F3A70EABDE8655805F 35952706A7B1CEAD2CDF539003676E301203DC7EE4181F179ACAB9A17BDBD2DA59FD9ECB93A</Binary>
Making the REST call using:
$contentType = "application/xml" $headers = @{"x-ms-version"="2013-03-01"} $response = Invoke-WebRequest -Uri $uri -Method Post -Headers $headers -Body $body -Certificate $subscriptionCertificate
This results in:
<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InternalError</Code><Message>The server encountered an internal error. Please retry the request.</Message></Error>
If I do not specify the contentType header, I get this result:
<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>BadRequest</Code><Message>The certificate data is not valid.</Message></Error>
I am not exactly sure what I am doing wrong.
The fear of the Lord is the beginning of knowledge, But fools despise wisdom and instruction