2010年4月17日星期六

Using HMAC-SHA1 in qOAuth on Symbian

In the wake of qDou 0.2.5 release,I am working on Deploying qDou on Sybmain recently,But I am sorry about.........;-( I must admit I am a rookie on Symbian,irrespective Of  playing with Symbiam Os phone,or Development on Symbian Os.To take trial instance how scornful I was when using a 3250,I thought that it was just phone with colorful push buttons that can make happy noise and it was just a practical tools for accessing family,friends and business associats (maybe in the future,Because I am an undergraduate still now ).Upon a careful study these days,I learn a lot on Symbian development,really,Or at least To a rookie.When I look back,I just feel funny.So I change my mind.Symbian is Strong.
Back to the topic,becouse qDou release depends on qOAuth and oAuth request using the HMAC-SHA1 signature method.
On the Windows or linux,In order to do that
the following steps are
1. build OpenSSL 0.9.6+
2. build qca-2.0.0
3. build the qca plugin for OpenSSL (the Capabilities of qca-ossl contains HMAC_SHA1)?
4. build qOAuth
But on the Symbian,as a result of different platform,you will have a lot of work to do.
even though you achieved,Maybe It doesn't work at last and you will get into trouble when deploy your apps on Symbian.em.........There is a easy way,Look this.
How to generate oauth signature using HMAC-SHA1 in Symbian C++
Follow These Tips .
we just need to do little stuff
1.add macro Q_OS_SYMBIAN to remove anything about QCA from *.cpp or *.h in qOAuth when Precompiled
2.generating your own random number method to replace the following codes
QCA::InitializationVector iv( 16 );
QByteArray nonce = iv.toByteArray().toHex();
3.add these lines in function:createSignature
#ifdnef Q_OS_SYMBIAN
.....
.....
.....
#else 

CSHA1* sha=CSHA1::NewL();
TBuf8<100> keyVal;
keyVal.Copy(_L8(QByteArray(consumerSecret + "&" + tokenSecret).constData()));
CHMAC* hmac=CHMAC::NewL(keyVal,sha);
TBuf8<1024> baseString;
TPtrC8 hashedSig(hmac->Hash(baseString));
TImCodecB64 b64enc;
b64enc.Initialise();
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
buf->Des().Copy(hashedSig);
TBuf8<512> result;
b64enc.Encode(buf->Des(),result);
result.Copy(result.Left(result.Length()));
if(hmac)
{
    delete hmac;
    hmac=NULL;
}
digest = QByteArray::fromRawData((char*)result.Ptr(),result.Length());
#endif
It's very easy right?
hope this is useful for thoses like me who want to use qOauth on Symbian
see you.

6 条评论:

  1. 能说一说那个QOauth具体怎么build么。。我研究了N久没搞明白。。
    我重新将qt4编译了一次,这次带上了openSSL。
    之后又build了QCA。
    build QCA的plugin的时候,它提示我EVP_md2没有声明,毫无办法之下,将那个源文件里面EVP_md2通通注释掉。然后得了个阉割的dll。。
    然后我又build了QOAuth,得到qoauth1.dll和qoauth1d.dll,现在是不知道怎么将它弄进项目中。不知道怎么将这些东西放到Qt文件夹里面。能说一下么?谢谢~~

    回复删除
  2. @Morr
    那是QCA编译的时候在linux下的一个bug,需要修改一下源码,
    具体是怎样的,我搞忘了,错误google一下,应该OK,windows下是没有问题的。

    1. build OpenSSL 0.9.6+
    2. build qca-2.0.0
    3. build the qca plugin for OpenSSL (the Capabilities of qca-ossl contains HMAC_SHA1)?
    4. build qOAuth
    这4步完成了之后,
    你还需要把openssl编译之后生成的libeay32.dll和ssleay32.dll放在你的工程目录下....
    希望你能编译成功 :-)

    回复删除
  3. 哈,我后来又自己搞掂了。。

    回复删除
  4. I just wanted you all to know that if you want OAuth with Qt on Symbian but you don't want to compile QCA separately, you can check you kQOAuth: http://www.johanpaul.com/blog/kqoauth/

    It's a Qt OAuth library that has no external dependencies so it is working very easily for Symbian. Just as any other Qt lib.

    回复删除
  5. @Kypeli
    Great.
    Thanks for your information.
    It really makes my work easier.

    回复删除