Fonction hash_hmac impossible d'avoir le bon résultat

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Fonction hash_hmac impossible d'avoir le bon résultat

Fonction hash_hmac impossible d'avoir le bon résultat

par canaillou2k5 » 23 août 2015, 18:35

Bonjour,

j'essaye de m'authentifié sur un serveur smtp en CRAM-MD5.

D'après la rfc2195:
Internet Draft CRAM-MD5 SASL Mechanism November 2003


challenges and responses is part of the IMAP4 AUTHENTICATE command,
not part of the CRAM-MD5 specification itself.

S: * OK [CAPABILITY IMAP4rev1 STARTTLS LOGINDISABLED AUTH=CRAM-MD5]
C: A0001 AUTHENTICATE CRAM-MD5
S: + PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2UucmVzdG9uLm1jaS5uZXQ+
C: dGltIGI5MTNhNjAyYzdlZGE3YTQ5NWI0ZTZlNzMzNGQzODkw
S: A0001 OK CRAM-MD5 authentication successful

In this example, the shared secret is the string

tanstaaftanstaaf

Hence, the Keyed MD5 digest is produced by calculating

MD5((tanstaaftanstaaf XOR opad),
MD5((tanstaaftanstaaf XOR ipad),
<[email protected]>))

where ipad and opad are as defined in [KEYED-MD5] and the string
shown in the challenge is the base64 encoding of
<[email protected]>. The shared secret is
null-padded to a length of 64 bytes. If the shared secret is longer
than 64 bytes, the MD5 digest of the shared secret is used as a 16
byte input to the keyed MD5 calculation.

This produces a digest value (in hexadecimal) of

b913a602c7eda7a495b4e6e7334d3890

The user name is then prepended to it, forming

tim b913a602c7eda7a495b4e6e7334d3890

Which is then base64 encoded to meet the requirements of the IMAP4
AUTHENTICATE command (or the similar POP3 AUTH command), yielding

dGltIGI5MTNhNjAyYzdlZGE3YTQ5NWI0ZTZlNzMzNGQzODkw
D'après mes recherches pour calculer le Keyed MD5 digest je doit utiliser la fonction "hash_hmac"

Après des essais je reçois un "password missmatch" de mon serveur mail, voilà mon algo:

Code : Tout sélectionner

$cram_md5 = $this->Commande('AUTH CRAM-MD5', 334, 'Le serveur refuse l' authentification (AUTH LOGIN) !!!'); if($cram_md5 != false && $cram_md5 != 1) { $cram_md5 = str_replace("334 ", "", $cram_md5); $challenge = strstr(str_replace(array("<", ">"), "",base64_decode($cram_md5)), '@', true); } else return false; $digest = base64_encode($this->login_smtp.' '.hash_hmac('md5', 'mypassword', $challenge)); echo "*** ".base64_decode($cram_md5).' - '.$digest;
J'ai donc essayer de prendre le problème à l'envers en essayant de retrouver le digest avec l'exemple de la doc:
MD5((tanstaaftanstaaf XOR opad),
MD5((tanstaaftanstaaf XOR ipad),
<[email protected]>))
J'ai essayé pas mal de combinaison et je ne retombe pas sur leur résultat, j'ai lu ailleurs qu'on utilise que "1896.697170952" pour la clé, donc j'ai tout essayé:

Code : Tout sélectionner

echo hash_hmac('md5', '1896.697170952', 'tanstaaftanstaaf'); echo hash_hmac('md5', 'tanstaaftanstaaf', '1896.697170952'); echo hash_hmac('md5', '<[email protected]>', 'tanstaaftanstaaf'); echo hash_hmac('md5', 'tanstaaftanstaaf', '<[email protected]>'); echo hash_hmac('md5', '[email protected]', 'tanstaaftanstaaf'); echo hash_hmac('md5', 'tanstaaftanstaaf', '[email protected]');
Je ne retombe jamais sur leur résultat:
b913a602c7eda7a495b4e6e7334d3890
Merci pour votre aide.

Cordialement,

Eliott.