SHA-256 Signature


Any client who has access to the name of an authorization rule and one of its signing keys can generate a SAS token. The token is generated by designing a string with the following format:
se: expiration time of the token. An integer that reflects the seconds elapsed since the 00:00:00 UTC time on January 1, 1970 (UNIX time) when the token expires.
skn: name of the authorization rule, which is the name of the SAS key.
sr: URI of the resource being accessed.
sig: signature.
The signature string is the SHA-256 hash calculated over the resource's URI (scope as described in the previous section) and the string representation of the token expiration time, separated by CRLF.
The hash calculation is similar to the following pseudocode and returns a hash value of 256 bits / 32 bytes.

SHA-256 ('https: // <yournamespace> .servicebus.windows.net /' + '\ n' + 1438205742)
The token contains the values ​​without the hash so that the recipient can recalculate the hash with the same parameters and verify that the issuer has a valid signing key.
The resource URI is the full URI of the Service Bus resource to which access is requested. For example, http: //.servicebus.windows.net/ or sb: // <namespace> .servicebus.windows.net / <entityPath>; that is, http://contoso.servicebus.windows.net/even

Cualquier cliente que tenga acceso al nombre de una regla de autorización y una de sus claves de firma puede generar un token de SAS. El token se genera diseñando una cadena con el siguiente formato:
se  : instante de expiración del token. Entero que refleja los segundos transcurridos desde la época 00:00:00 UTC el 1 de enero de 1970 (época de UNIX) cuando expira el token.
skn : nombre de la regla de autorización, que es el nombre de la clave SAS.
sr  : URI del recurso al que se accede.
sig : firma.
La cadena de firma es el hash SHA-256 calculado sobre el URI del recurso (ámbito tal y como se describe en la sección anterior) y la representación de cadenas del instante de expiración del token, separados por CRLF.
El cálculo del hash es similar al siguiente pseudocódigo y devuelve un valor de hash de 256 bits/32 bytes.

SHA-256('https://<yournamespace>.servicebus.windows.net/'+'\n'+ 1438205742)
El token contiene los valores sin el hash para que el destinatario pueda volver a calcular el hash con los mismos parámetros y verificar que el emisor posee una clave de firma válida.
El URI de recurso es el URI completo del recurso de Service Bus al que se solicita el acceso. Por ejemplo, http://.servicebus.windows.net/ o sb://<namespace>.servicebus.windows.net/<entityPath>;, es decir, http://contoso.servicebus.windows.net/even

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,17200;  
      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;

Share this:

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.

 
Copyright © NiccoWeb Business Central / Dynamics NAV / Navision. Designed by OddThemes