Use certificate from ceritifcate store private key, in Azure websites - azure-web-app-service

To use the Azure storage client encryption with a certificate or other encryption/decryption using a certificate one need access to the private key of the certificate.
We use Azure websites/web app (NOT webroles) and want be able to upload a certificate to the certificate store on Azure and access the private key of the certificate.
I'm able to get the certificate from the certificate store, but when I try to access the private key I get key is not exportable.
It possible to upload the file with the code and load the certificate from file, but it would be more convenient and safe to use the certificate store.
Is there a way to do this ?
I have followed this guide: https://azure.microsoft.com/nb-no/blog/using-certificates-in-azure-websites-applications/ but that only give me access to the certificate not the private key.

Make sure that the PFX file that you are uploading to the Azure web app's certificate list in the portal contains the private key in the first place. You can try to import the pfx in your local machine and export it while checking the option "export the private key". If the export the private key option is grayed while doing the export then it means the pfx is missing the private key.
Your application should be able to access the private key of the certificate if the pfx had it.

#RuneSynnevåg, I think you just need to follow the tutorial Enable HTTPS for an app in Azure App Service to do the steps described in the section "Get a certificate using Certreq.exe (Windows only)" and upload the pfx certificate file for your webapp by following the step 3.

Related

Im trying to generate a CSR from our SharePoint page to a vendors website to pull information from them. Where am i supposed to generate the CSR from?

Is it supposed to be done in Azure since its SharePoint or is it in a different server. I have looked into Azure Key Vault but before proceeding need confirmation if this is correct. And if so how to go about generating it.
Please check if the below points are helpful:
For a simple way to create a CSR that works on any Microsoft server
platform, you can use the DigiCert.Azure Key Vault partners with the
following certificate authorities to simplify certificate creation.
DigiCert, GlobalSign.( offers OV TLS/SSL certificates with
DigiCert /GlobalSign)
Azure Key Vault supports storing digital certificates issued by any
certificate authority (CA). It supports (CSR) with a private/public
key pair.
If you are a Microsoft azure user you can create csr in keyvault.The thing we need to make sure is that the private key and resulting public key are a matching pair.( AFAIK CSR need not have to be
generated on SharePoint. )
One of the biggest advantage of managing certificates through Key
Vault is the Private Key of the certificate is never exposed outside
the Key Vault Security World. reference
The Private Key would be stored within Key Vault, and Public Key would
be attached to CSR and submitted to the CA.
During certificate
Import, the Public Key (attached with the certificate) would be
matched against the Private Key (stored within Key Vault) to complete
the Key Pair.
Steps to generate csr in azure keyvault :
Sign into the Azure portal and select the key vault where you wish
to install your certificate.
Select Certificates in the right-hand Settings menu.
Click the Generate/Import button to open the Create a certificate
window.
Enter or select the details in the Create a certificate form fields
Select Certificate issued by a integrated CA / non- integrated CA and
other fields Click the Create button to generate your new key pair and
CSR.
And check this blog / Creating and merging a certificate
signing request in Azure Key Vault | Microsoft Docs for complete
details of steps.
References:
Get started with Key Vault certificates | Microsoft Docs
Access SharePoint online content using Azure key vault certificate
and Azure function app | Sundar’s blog (sundarcloud.com)

Imported TLS-certificate does not show up in App Service

I have a strange problem when importing a certificate from Azure Key vault to be used in an App Service. As you can see in the images below, it says the certificate is imported successfully but it does not show up as expected.
This have previous worked just fine for other app services and my custom domain matches the wildcard certificate that I am trying to use.
Any ideas what causes this strange behavior?
If you choose to upload or import a private certificate to App Service, your certificate must meet the following requirements:
Exported as a password-protected PFX file, encrypted using triple DES.
Contains private key at least 2048 bits long
Contains all intermediate certificates in the certificate chain
Some certificate authorities provide certificates in different formats, therefore before importing the certificate, make sure that they are either in .pem or .pfx format.
When you are importing the certificate, you need to ensure that the
key is included in the file itself. If you have the private key
separately in a different format, you would need to combine the key
with the certificate.
you can also refer https://www.huuhka.net/app-service-imported-ssl-certificate-from-another-subscription-kv/ if you have any failure messages while importing the key vault certificate
If you are using free managed certificate , you may check its pre-requisites to be fulfilled as free certificates come with few limitations , which can be referred from https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate?WT.mc_id=AZ-MVP-5003781#private-certificate-requirements
So, I made a workaround solution by setting an Managed Identity on my App Service giving it correct permissions to the keyvault. And then adding the application and correct permissions in Access policies for the keyvault.
After that the certificate showed up as expected when adding a binding on my App Service.
Seems you got the right solutions and might have encountered this issue due to your logged in user RBAC role.
When ever you use app service certificate it gets stored inside Azure Key vault and to use that key vault certificate/secret you need to have access policies to get the secret and set the secret.
More details at:
https://learn.microsoft.com/en-us/azure/key-vault/general/assign-access-policy-portal#:~:text=Assign%20an%20access%20policy%201%20In%20the%20Azure,the%20Principal%20selection%20pane.%20...%20More%20items...%20

How to sign CSR in Azure key vault using a Issuer Certificate

I have uploaded the issuer certificate in the azure key vault and now i want to send a CSR generated in my system to azure and get it signed by the Issuer certificate in the KV and return me back the signed certificate. Any idea on how to accomplish it?
I am sorry that you are not able to accomplish it. For Azure Key Vault's usage scenario, you may refer to What is Azure Key Vault?.
Just as explained in that article, for Certificate, Azure Key Vault lets you easily provision, manage, and deploy public and private Transport Layer Security/Secure Sockets Layer (TLS/SSL) certificates for use with Azure and your internal connected resources.
You can generate a new certificate from Public CA (DigiCert or GlobalSign).
If you want to use custom CA, you can only create a CSR, and get your certificate from that CA, and finally update your certificate to Azure Key Vault. Refer to: Create a certificate manually and get signed by a CA

Azure SSL Binding Issue- No match seleted hostname

I bougth a SSL certificate online from a seller today for my custom domain which redirected to the azure web application with cname.
I did created csr file with that domain let's call it app3.product.com by using IIS 8.And then created the .crt filel with that csr file.
After that i did found that i need the pfx file but i didn't have .key file so, i converted the .crt to .cer than uploaded it by azure portal.
The problem is Azure portal says,
No certificates match the selected hostname
Althogh my certificate issued as app3.product.com and the host name has the same domain name. It doesn't work.
I didn't include key file while i am creating the csr file also the subject of the certificate has some additional information by the issuer. The subject like app3.product.com, Certificate Issued By ... These may be the source of the issue.
Thank you in advance.
You need to include the private key. Otherwise your web server can not decrypt the data the clients (web browsers) are sending to it.
Explanation:
HTTPS/TLS/SSL are based on asymmetric cryptography which means that data gets encrypted with a so-called public key and can only be decrypted with the corresponding private key.
This means that your web server will send a certificate to the browsers which contains the domain name + the public key + a signature from a Certificate Authority (CA). The web browser then checks then if this certificate is valid (with a CA certificate) and uses the included public key to encrypt further data. Since your web server is the only one who knows the private key it can use it to decrypt the web browsers request. Actually the overall process is even a little bit more complex. You might want to have a look at the TLS handshake protocol to see how it works.

Azure Notification Hub unable to upload .p12 for APN

I am not able to upload a .p12 for APN. and this is the error message I received. Any idea what cause this error?
SubCode=40000. Failed to validate credentials with APNS. Error is The credentials supplied to the package were not recognized..TrackingId:b18f483e-6285-9d5b-895c-12e2fcc26dcf_M1_G12,TimeStamp:4/21/2014 3:16:19 AM
I was having the same issue while uploading the certificate on the backend and finally found the solution after lot of struggling. Do the following:
Select keys from your keychain
Locate desired push private key
Click the small arrow to expand the key & profile
Now select the certificate only (this is a crucial step) no both the key & certificate ONLY SELECT CERTIFICATE and click for export
Set password for your exported certificate and upload
Have a look at this picture for reference:
This is an old question but I thought I would post something that worked for me as well. Seeing as the .p12 file was created by another part of our company I was not able to get the .p12 file re-exported in the correct manner.
Instead I imported the .p12 to my local certificate store (windows) and then re-exported as a pfx.
Take a note of where the certificate is stored
Then, Use the MMC tool to view and export your certificate, making sure to export the private key as part of the pfx.
(You should probably delete the certificate from your local machine after the export is complete.)
After that you should be able to import your new pfx file into azure via the portal.

Resources