SHA-256 SAS Signature — Azure Service Bus
Firma SAS con SHA-256SHA-256 SAS signature
Generación de tokens para Azure Service Bus desde Microsoft Dynamics NAVToken generation for Azure Service Bus from Microsoft Dynamics NAV
Cualquier cliente que conozca el nombre de una regla de autorización y una de sus claves de firma puede generar un token SAS. El token incluye cuatro valores principales:Any client that knows the name of an authorization rule and one of its signing keys can generate a SAS token. The token contains four main values:
seInstante de expiración expresado en segundos desde el 1 de enero de 1970 UTC.Expiration time expressed as seconds since January 1, 1970 UTC.
sknNombre de la regla de autorización asociada a la clave SAS.Name of the authorization rule associated with the SAS key.
srURI completa del recurso de Service Bus al que se solicita acceso.Full URI of the Service Bus resource being accessed.
sigFirma HMAC-SHA256 codificada para validar el emisor del token.Encoded HMAC-SHA256 signature used to validate the token issuer.
Aplica URL encoding a la URI completa del recurso.Apply URL encoding to the full resource URI.
Une la URI y la expiración mediante un salto de línea.Join the URI and expiration time with a line feed.
Calcula HMAC-SHA256, convierte a Base64 y aplica URL encoding.Calculate HMAC-SHA256, convert to Base64 and apply URL encoding.
SHA-256('https://<yournamespace>.servicebus.windows.net/' + '\n' + 1438205742)El ámbito forma parte de la firmaThe scope is part of the signature
El destinatario recibe los valores sin el hash, vuelve a calcularlo con los mismos parámetros y verifica que el emisor posee una clave válida. La URI debe identificar por completo el recurso solicitado.The recipient receives the unhashed values, recalculates the hash with the same parameters and verifies that the issuer owns a valid key. The URI must fully identify the requested resource.
PROCEDURE GetSignatureSHA256@1000000003(
WebServiceURL@1000000001 : Text;
pSharedKey@1000000000 : Text;
VAR pSignature@1000000010 : Text;
VAR pSignatureExpiration@1000000011 : Text);
VAR
ExpirySeconds@1000000002 : BigInteger;
CRLF@1000000003 : Char;
Crypto@1000000004 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.HMACSHA256";
Encoding@1000000005 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding";
Convert@1000000007 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert";
TextToSign@1000000008 : Text;
HttpUtility@1000000009 : DotNet "'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.HttpUtility";
BEGIN
CLEAR(pSignature);
CLEAR(pSignatureExpiration);
CRLF := 10;
ExpirySeconds := ROUND((CURRENTDATETIME - CREATEDATETIME(010170D,000000T)) / 1000,1) + 7200;
TextToSign := HttpUtility.UrlEncode(WebServiceURL) + FORMAT(CRLF) + FORMAT(ExpirySeconds);
Crypto := Crypto.HMACSHA256(Encoding.ASCII.GetBytes(pSharedKey));
pSignatureExpiration := FORMAT(ExpirySeconds);
pSignature := HttpUtility.UrlEncode(
Convert.ToBase64String(
Crypto.ComputeHash(Encoding.ASCII.GetBytes(TextToSign))));
END;
Comentarios
Publicar un comentario