view src/protocols/simple/digcalc.c @ 12024:e67993da8a22

[gaim-migrate @ 14317] I strongly suspect CruiseControl is going to yell at me for this. A voice chat API, GUI + mediastreamer. This is what I'm using for Google Talk. This doesn't actually do anything at all. There's no code in the Jabber plugin yet to use this API (although it Works For Me). All it will do is compile and link. If you're lucky. To build this, you should install oRTP from Linphone, Speex and iLBC (also from linphone, I believe). To not build this, ./configure --disable-vv. Most of the configure.ac and Makefile.am hackery was lifted right out of Linphone with a few modifications. It seems to work if you have everything installed or if you --disable-vv. I haven't really tested not having everything installed and not --disabling-vv. It's kinda funky to include all of mediastreamer in the source tree like this, but linphone doesn't build it as a separate library. I'll probably wind up writing them a patch to build it as a .so so we can link it dynamically instead. This code certainly isn't finished. It'll adapt as I progress on the Google code, but it's certainly of more use here in CVS than in my personal tree. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 09 Nov 2005 08:07:20 +0000
parents 2cf6d4cf2cb0
children
line wrap: on
line source

/*
 * Taken from RFC 2617
 *    Copyright (C) The Internet Society (1999).  All Rights Reserved.

   This document and translations of it may be copied and furnished to
   others, and derivative works that comment on or otherwise explain it
   or assist in its implementation may be prepared, copied, published
   and distributed, in whole or in part, without restriction of any
   kind, provided that the above copyright notice and this paragraph are
   included on all such copies and derivative works.  However, this
   document itself may not be modified in any way, such as by removing
   the copyright notice or references to the Internet Society or other
   Internet organizations, except as needed for the purpose of
   developing Internet standards in which case the procedures for
   copyrights defined in the Internet Standards process must be
   followed, or as required to translate it into languages other than
   English.

   The limited permissions granted above are perpetual and will not be
   revoked by the Internet Society or its successors or assigns.

   This document and the information contained herein is provided on an
   "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
   TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
   BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
   HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "cipher.h"

#include <string.h>
#include "digcalc.h"

void CvtHex(
    IN HASH Bin,
    OUT HASHHEX Hex
    )
{
    unsigned short i;
    unsigned char j;

    for (i = 0; i < HASHLEN; i++) {
        j = (Bin[i] >> 4) & 0xf;
        if (j <= 9)
            Hex[i*2] = (j + '0');
         else
            Hex[i*2] = (j + 'a' - 10);
        j = Bin[i] & 0xf;
        if (j <= 9)
            Hex[i*2+1] = (j + '0');
         else
            Hex[i*2+1] = (j + 'a' - 10);
    };
    Hex[HASHHEXLEN] = '\0';
};

/* calculate H(A1) as per spec */
void DigestCalcHA1(
    IN char * pszAlg,
    IN char * pszUserName,
    IN char * pszRealm,
    IN char * pszPassword,
    IN char * pszNonce,
    IN char * pszCNonce,
    OUT HASHHEX SessionKey
    )
{
      GaimCipher *cipher;
      GaimCipherContext *context;
      HASH HA1;

      cipher = gaim_ciphers_find_cipher("md5");
      context = gaim_cipher_context_new(cipher, NULL);
      gaim_cipher_context_append(context, (guchar *)pszUserName, strlen(pszUserName));
      gaim_cipher_context_append(context, (guchar *)":", 1);
      gaim_cipher_context_append(context, (guchar *)pszRealm, strlen(pszRealm));
      gaim_cipher_context_append(context, (guchar *)":", 1);
      gaim_cipher_context_append(context, (guchar *)pszPassword, strlen(pszPassword));
      gaim_cipher_context_digest(context, sizeof(HA1), HA1, NULL);
      if (strcmp(pszAlg, "md5-sess") == 0) {
            context = gaim_cipher_context_new(cipher, NULL);
            gaim_cipher_context_append(context, HA1, HASHLEN);
            gaim_cipher_context_append(context, (guchar *)":", 1);
            gaim_cipher_context_append(context, (guchar *)pszNonce, strlen(pszNonce));
            gaim_cipher_context_append(context, (guchar *)":", 1);
            gaim_cipher_context_append(context, (guchar *)pszCNonce, strlen(pszCNonce));
            gaim_cipher_context_digest(context, sizeof(HA1), HA1, NULL);
      };
      CvtHex(HA1, SessionKey);
      gaim_cipher_context_destroy(context);
};

/* calculate request-digest/response-digest as per HTTP Digest spec */
void DigestCalcResponse(
    IN HASHHEX HA1,           /* H(A1) */
    IN char * pszNonce,       /* nonce from server */
    IN char * pszNonceCount,  /* 8 hex digits */
    IN char * pszCNonce,      /* client nonce */
    IN char * pszQop,         /* qop-value: "", "auth", "auth-int" */
    IN char * pszMethod,      /* method from the request */
    IN char * pszDigestUri,   /* requested URL */
    IN HASHHEX HEntity,       /* H(entity body) if qop="auth-int" */
    OUT HASHHEX Response      /* request-digest or response-digest */
    )
{
      GaimCipher *cipher;
      GaimCipherContext *context;
      HASH HA2;
      HASH RespHash;
       HASHHEX HA2Hex;

      /* calculate H(A2) */
      cipher = gaim_ciphers_find_cipher("md5");
      context = gaim_cipher_context_new(cipher, NULL);
      gaim_cipher_context_append(context, (guchar *)pszMethod, strlen(pszMethod));
      gaim_cipher_context_append(context, (guchar *)":", 1);
      gaim_cipher_context_append(context, (guchar *)pszDigestUri, strlen(pszDigestUri));
      if (strcmp(pszQop, "auth-int") == 0) {
            gaim_cipher_context_append(context, (guchar *)":", 1);
            gaim_cipher_context_append(context, HEntity, HASHHEXLEN);
      };
      gaim_cipher_context_digest(context, sizeof(HA2), HA2, NULL);
       CvtHex(HA2, HA2Hex);

      gaim_cipher_context_destroy(context);
      /* calculate response */
      context = gaim_cipher_context_new(cipher, NULL);
      gaim_cipher_context_append(context, HA1, HASHHEXLEN);
      gaim_cipher_context_append(context, (guchar *)":", 1);
      gaim_cipher_context_append(context, (guchar *)pszNonce, strlen(pszNonce));
      gaim_cipher_context_append(context, (guchar *)":", 1);
      if (*pszQop) {
          gaim_cipher_context_append(context, (guchar *)pszNonceCount, strlen(pszNonceCount));
          gaim_cipher_context_append(context, (guchar *)":", 1);
          gaim_cipher_context_append(context, (guchar *)pszCNonce, strlen(pszCNonce));
          gaim_cipher_context_append(context, (guchar *)":", 1);
          gaim_cipher_context_append(context, (guchar *)pszQop, strlen(pszQop));
          gaim_cipher_context_append(context, (guchar *)":", 1);
      };
      gaim_cipher_context_append(context, HA2Hex, HASHHEXLEN);
      gaim_cipher_context_digest(context, sizeof(RespHash), RespHash, NULL);
      CvtHex(RespHash, Response);
      gaim_cipher_context_destroy(context);
};