❔ Load Certificate from Azure Key Vault as memorystream
I have a code that works perfect when testing it local and set my certificates as paths.
When uploading it on Azure it do not work to use the path. My guess is that I have to upload the certificates on Key Vault and call the certificates from there.
I'm using .NET Core Web App
In the Nugget from Swish you can enter the certificate as direct path or as a stream.
Do anyone have a solution how to fix this?
Have a look at this files :
https://github.com/RickardPettersson/swish-api-csharp/blob/master/SwishApi/Models/ClientCertificate.cs
https://github.com/RickardPettersson/swish-api-csharp/blob/master/SwishApi/PayoutClient.cs
https://github.com/RickardPettersson/swish-api-csharp/issues/23
38 Replies
Reading that issue, just set the
UseMachineKeySet
to true and pass a stream, and you're good to go?The problem is that I dont know how to make the stream from Key Vault.
Oh, you went with keyvault after all? Okay
https://learn.microsoft.com/en-us/dotnet/api/overview/azure/security.keyvault.certificates-readme?view=azure-dotnet
specifically https://learn.microsoft.com/en-us/dotnet/api/azure.security.keyvault.certificates.certificateclient.downloadcertificateasync?view=azure-dotnet#azure-security-keyvault-certificates-certificateclient-downloadcertificateasync(azure-security-keyvault-certificates-downloadcertificateoptions-system-threading-cancellationtoken)
weird that it doesnt accept certs in
X509Certificate2
format natively thou. but you should be able to turn that into a certYeah thats why I dont get it to work, but you think something like this?
worth a try. unfortunately the documentation for
RawData
doesnt indicate if it includes the private key or notAnd then make it two streams? one for each cert?
yes
remember that the streams cant be re-used either
at least not without rewinding them first, but even then that might not be enough
Its only used once when you do the payout.
okay, then thats less of an issue
its wrapped in a OnPost()
So when you click the button it will run
please dont download the certs each time the button is clicked lol
download them at startup and keep them in memory as X509s
I get error on these
I just want to make it work before i move the logic
well uh
X509Certificate2
doesn't have a Certificate
property.
so.. dont try to access it? 😛
Stil not working, I can see in the breakpoints that I get the cert.
dude
wtf
var certificate2 = response2.Value;
is already an X509Certificate2xD
Anyway with or without that I get
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=SwishApi
StackTrace:
at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate)
Not really going to dig through that project
Got it to work...
First of all i loaded the public cert, not the secret.
Right, the private key
Okay thats slightly different. You base64 encoded your certs as secrets
Yes, i'm newbie. Im taking a 8 month course now as Developer
You should be able to get a private key from the certs uploaded as certs itself, but this workaround works
Okey, the example was with filepath but i got access denied so i thought better to use Key Vault since im planning building a Saas solution for this since Swish it self dosent offer the service public. Just API
.. you're making a Swish SAAS? Did you get approval from swish for this?
For companies to make payouts
Are you Swedish?
Yes
English only on server.
There are services that almost do what I want already, so can't see that it should be any problems.
Take a look at utbetalningar.nu
Sure, but you'll need to contact swish and have this approved.
You don't make a saas around another companies services without their approval
they will just ban your cert and kill your app, so why not check with them first?
Its the customers certs. to use my service.
When you request cert for Payout from your bank they ask if you have a solution to use the cert and for what purpose you want the cert.
Ah okay.
Or you generate the certs in the swish panel but to get access
I see
Denna tjänsten är inte i samarbete eller gjord av GetSwish AB.alright, looks like utbetalningar.nu is in a similar position as yours
But this small service im building now is for a friend that buys and sell video games and other collectables like trading cards etc.
When he buying from private individuals its easier to swish from the companys account rather than transfer money and swish from personal.
sure
also less illegal from a tax perspective 😄
Yes :
But next problem. When I running from local it works now getting from Key Vault and do the memorystream without enter password.
When uploaded on Azure with no password I get
And with password
I get this
The same way with password as I used with path and then it worked.
I have set permission for my app to get secrets in Key Vault
¯\_(ツ)_/¯
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.