Précédent   Forum du club des développeurs et IT Pro > C et C++ > Bibliothèques > Autres
Autres Vos questions sur les autres bibliothèques
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 20/04/2012, 14h13   #1
styde
Invité de passage
 
Femme
Inscription : avril 2012
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Belgique

Informations forums :
Inscription : avril 2012
Messages : 3
Points : 1
Points : 1
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 :
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.
styde est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 13h57   #2
styde
Invité de passage
 
Femme
Inscription : avril 2012
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Belgique

Informations forums :
Inscription : avril 2012
Messages : 3
Points : 1
Points : 1
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 :
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
Citation:
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 :
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>
styde est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2012, 14h00   #3
styde
Invité de passage
 
Femme
Inscription : avril 2012
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Belgique

Informations forums :
Inscription : avril 2012
Messages : 3
Points : 1
Points : 1
Par défaut Une solution

Au cas où ça pourrait aider quelqu'un un jour...

http://stackoverflow.com/a/10315094/1213453
styde est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 13h43.


 
 
 
 
Partenaires

Hébergement Web