d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Idea For A Easy Program In C?
Prev12
Add Reply New Topic New Poll
Member
Posts: 2,429
Joined: Jul 22 2010
Gold: 104.60
Jun 6 2012 03:11pm
Quote (ikusus @ Jun 6 2012 10:32pm)
http://www.wowwiki.com/Battle.net%5FMobile%5FAuthenticator%5FSpecification

write simple console app that generates valid one-time codes :) imho pretty good programming excercise, writing programs according to specification. And program by itself would be very useful, if written in pure C (you could port to arduino board, you could port to linux phones, etc).

Arduino + pure C implementation = hardware battle.net authenticator :)


Interesting, thx for sharing :)
Maybe I'll implement this in C in my spare time
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Jun 6 2012 03:38pm
Quote (dos350 @ Jun 6 2012 01:43pm)
wow dont listen 2 this guy that is againt eula


why are you here?
Banned
Posts: 2,525
Joined: Jan 2 2012
Gold: 0.01
Warn: 10%
Jun 7 2012 03:35am
Code
def get_token(secret, digits=8, seconds=30)
       t = Time.new.to_i
       m = [t/seconds].pack("Q<").reverse
       r = OpenSSL::HMAC.digest("sha1", [secret].pack("H*"), m)
       k = r[19].ord
       i = k & 0x0f
       h = r[i...(i+4)].reverse.unpack("L<")[0] & 0x7fffffff
       return (h % (10 ** digits)).to_s.rjust(8, "0")
end


Ruby version above ^^ note that all should be big endian but ruby supports it (or: different than native) in version 1.9.3+, and I want to run it on my cellphone where I only have 1.9.1 and cba to compile myself. So made it little endian + #reverse. On big endian systems you'd probably have to run with ruby 1.9.3+ OR remove those #reverse 's OR run on 1.9.3, remove reverses and change Q< to Q> and L< to L>

Secret + serial key has to be requested from blizz servers (kinda complicated scheme, but can post later when I'm done). Then just get_token("asdfasdfasdf") and we'll have currently working 8 digits for authenticator.

edit: and that's basically the part you'd have to do in pure C. Simple, eh? Except try to cut dependencies (e.g. implement hmac-sha1 yourself, not use openssl) to make it 100% portable. I wouldn't make requesting serial/secret in the same app.

This post was edited by ikusus on Jun 7 2012 03:59am
Member
Posts: 4,250
Joined: Apr 17 2005
Gold: 0.01
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll