I'm creating an authorization flow in Microsoft Azure, currently using a Logic app (consumption), doing some code in an Azure function as well.
For the flow to work I need to create a "Digest" header. The function code for that is pasted below. This works as expected and the header is created correctly.
"Digest" creation:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Text;
namespace NordeaAuthorization
{
public static class CreateDigest
{
[FunctionName("CreateDigest")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string value = req.Query["value"];
var crypt = new System.Security.Cryptography.SHA256Managed();
var hash = new StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(value));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
var response = Convert.ToBase64String(crypto);
return new OkObjectResult(response);
}
}
}
I'm also required to provide a "Signature" header. And this is where I get completely stuck.
The "Signature" header should be created like this:
*The signature headers required for all POST or PUT requests are: "(request-target) x-bank-originating-host x-bank-originating-date content-type digest":
POST: https://open.bank.com/corporate/v2/authorize X-Bank-Originating-Host: open.bank.com X-Bank-Originating-Date: Thu, 05 Jun 2019 21:31:40 GMT content-type: application/json digest: Signature: keyId="",algorithm="rsa-sha256", headers="(request-target) x-bank-originating-host x-bank-originating-date content-type digest", signature="
Where*
*<client_id> is the Client Id assigned to the TPP's client application is the hash (SHA256) digest of the request body is the BASE64 encoded version of the RSA-SHA256 encrypted signing string
The client would compose the signing string as:
HTTP (request-target): post /corporate/v2/authorize\n x-bank-originating-host: open.bank.com\n x-bank-originating-date: Thu, 05 Jun 2019 21:31:40 GMT\n content-type: application/json\n digest: SHA-256=jcC/ttW7JucGTN9hWfqMsFeON6D+vZtQGWJA+W0PL/g= (created in previous function)
Note that the '\n' symbols above are included to demonstrate where the new line character should be inserted. There is no new line on the final line of the signing string. Note also that the value for the digest shown above serves only as an example and in reality needs to be computed based on the request message body.*
How would you move forward in trying to achive this in an Azure Function in C#? Where would you upload the certificate and how would you access it in trying to create the signing header?
I've tried uploading the certificate to an Azure Key Vault, but it seems invalid, I have contacted the issuer about this. It is also an .p12 file, which is not supported in Azure Key vault. Not sure if there is an actual issue with the certificate or that something just went wrong when I changed file extension to .pfx. Still, waiting for an answer from the issuer.
Code wise - Haven't tried anything yet, as I don't know how to construct the flow itself.