IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques Discussion :

OpenSSL HMAC SHA 256 pour l'api REST de Windows Azure Storage


Sujet :

Bibliothèques

  1. #1
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2012
    Messages : 3
    Points : 2
    Points
    2
    Par défaut OpenSSL HMAC SHA 256 pour l'api REST de Windows Azure Storage
    Bonjour,

    J'essaye de mettre en oeuvre les requêtes http pour accéder à un blob storage du cloud Azure.
    Pour cela je dois signer la requête en utilisant HMAC SHA 256.
    D'après le message d'erreur que je reçois, la signature que j'envoie n'est pas bonne et je pense que j'ai mal compris le fonctionnement de HMAC_Init_ex et HMAC_Update.

    Je suis sur une machine Ubuntu et j'utilise Qt Creator.
    Voici mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    unsigned char* signature = (unsigned char*) ("GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:2009-09-19\n/monCompteStorage\ncomp:list").toStdString().c_str(); //date est un QString qui a la forme "Fri, 20 Apr 2012 11:16:11 GMT"
    unsigned char* key = (unsigned char*) "***********************************"; //clé d'accès primaire de google qui fait 88 caractères
    unsigned char* result;
    unsigned int result_len = 44;
     
    result = (unsigned char*)malloc(sizeof(char) * result_len);
    ENGINE_load_builtin_engines();
    ENGINE_register_all_complete();
     
    HMAC_CTX ctx;
    HMAC_CTX_init(&ctx);
    HMAC_Init_ex(&ctx, key, 88, EVP_sha256(), NULL);
    HMAC_Update(&ctx, signature, 56);
    HMAC_Final(&ctx, result, &result_len);
    HMAC_CTX_cleanup(&ctx);
     
    QByteArray array = QByteArray::fromRawData((char*)result, result_len);
    array = array.toBase64();
    qDebug() << array;
    Bonne journée à tous.

  2. #2
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2012
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Update du code et réponse obtenue
    J'ai changé le code (je pense que j'avais confondu la taille et le nombre de caractères )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    unsigned char* signature = (unsigned char*) ("GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:2009-09-19\n/monCompteStorage\ncomp:list").toStdString().c_str(); //date est un QString qui a la forme "Fri, 20 Apr 2012 11:16:11 GMT"
    unsigned char* key = (unsigned char*) "***********************************"; //clé d'accès primaire d'Azure
    unsigned char* result;
    unsigned int result_len = 32;
     
    result = (unsigned char*)malloc(sizeof(char) * result_len);
    ENGINE_load_builtin_engines();
    ENGINE_register_all_complete();
     
    HMAC_CTX ctx;
    HMAC_CTX_init(&ctx);
    HMAC_Init_ex(&ctx, key, 32, EVP_sha256(), NULL);
    HMAC_Update(&ctx, signature, 32);
    HMAC_Final(&ctx, result, &result_len);
    HMAC_CTX_cleanup(&ctx);
     
    QByteArray array = QByteArray::fromRawData((char*)result, result_len);
    array = array.toBase64();
    qDebug() << array;

    Mais la signature n'est toujours pas bonne et je ne comprend toujours pas d'où doit venir l'argument len qu'il faut donner à int HMAC_Update.
    La doc d'OpenSSL
    int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
    const EVP_MD *md, ENGINE *impl);
    int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
    int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);

    Je rajoute la réponse que je reçois d'Azure:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    <?xml version="1.0" encoding="utf-8"?>
    <Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
    RequestId:f34e06cc-3ed1-46a0-b0b4-4651d429517c
    Time:2012-04-23T11:44:59.1146695Z</Message>
    <AuthenticationErrorDetail>The MAC signature found in the HTTP request 'Fuqpu3bnt9bAIsAjI5eDctLukvcsaozmF4EO+lVwY9o=' is not the same as any computed signature. Server used following string to sign: 'GET
     
     
     
    x-ms-date:Mon, 23 Apr 2012 11:45:17 GMT
    /monCompteStorage/?comp=list'.</AuthenticationErrorDetail>
    </Error>

  3. #3
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2012
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Une solution
    Au cas où ça pourrait aider quelqu'un un jour...

    http://stackoverflow.com/a/10315094/1213453

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PayPal] Utilisation de l'API REST PayPal pour faire des paiements réccurents (tous les mois)
    Par dtcSearch dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 29/10/2014, 11h28
  2. Réponses: 24
    Dernier message: 20/05/2014, 09h54
  3. Réponses: 0
    Dernier message: 03/12/2013, 09h00
  4. Génération d'un HMAC SHA 256
    Par Cognitivehome dans le forum Sécurité
    Réponses: 0
    Dernier message: 17/04/2012, 21h35
  5. Une petite aide pour les API ?
    Par Yop dans le forum Windows
    Réponses: 2
    Dernier message: 04/04/2002, 21h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo