0

Transaction Data Signing

I need an idea to develop a very secure algorithm to authenticate online operations using PHP in the server and an Android app in the user's device.

What is the idea?

The user try to login in the system. The server sends a confirmation request to user's device (Android).

The user sees the date, country, city, IP, browser and OS in the app, all about the login try, and if all this informations match, he can clicks on confirm. The app will generate an 8 decimal digit token based in this informations and send it to server, the server will try to generate a token with the same informations and if both tokens match, the server accept the login try.

This is just one possible operation.

What do I need?

An universal algorithm to authenticate any online operation.

e.g.:

function generateRandonTokenUsingNParameters(){
    $args = func_num_args();
    $token = ""; //Start token

    for($i=0; $i < $args; $i++){
        $token = CRAZY_MATH_USING_ALL_PARAMETERS_TO_GENERATE_8_DIGITS_TOKEN($token, func_get_arg($i));
    }

    return $token; //Final token based in all informations of the operation

}

//e.g.
//LOGIN INFORMATION
$date = "2014-05-30 01:02:00"
$ip = "192.168.0.1";
$browser = "Chrome";
$city = "Los Angeles";
$country = "USA";
$os = "Windows";
$android_app_local_seed = "698dc19d489c4e4db73e28a713eab07b"; //each user have a different seed in his app

//PRINTING LOGIN TOKEN
echo generateRandonTokenUsingNParameters($date, $ip, $browser, $city, $country, $os, $android_app_local_seed);

What would you use in the CRAZY_MATH_USING_ALL_PARAMETERS_TO_GENERATE_8_DIGITS_TOKEN() function?

P.S.: I need an 8 decimal digit numeric token. Because if the user does not have internet connection, he can read the operation's details using QR Code and he will need insert the token in the system manually.

  • 1
    Firstly, is there any reason why a cryptographic hash of a string concatenation of these parameters wouldn't be suitable? Secondly, it seems as though the user could arbitrarily manipulate just about all of these parameters and log in - although I guess the local seed is designed to prevent that? Why do you need all the other info, why couldn't you hash the seed? – thexacre May 30 '14 at 4:26
  • @thexacre yes, the seed prevents someone that knows the algorithm from generating tokens that could be used to login in any account. I need all the other informations to sign the operation. The token can be used just by the person trying to login using that ip, browser and os. – Lucas NN May 30 '14 at 4:51
  • HMAC with a shared key is what you'd want to use. Don't forget to use a nonce or a timestamp as part of input. It is ok to only use the first X bits of you only need that degree of bruteforce resistance (because your server rate limits the requests) – Natanael Nov 29 '14 at 7:26
1

Stringify the sent information in a standard way, take the SHA256 hash, sign it with the private half of the key-pair that is genned for the handset when the application is installed (the public half is sent to the server at enrollment time).

Most importantly, HMAC is easy to do wrong because it is crypto and crypto is really hard to do right (even Ron Rivest -- the R in RSA, and possibly one of the top expert in crypto -- can come up with something like RC4 which has some protocol-level weaknesses_. DO NOT ROLL YOUR OWN CRYPTO. I would bet money you will not do it correctly. Instead, use existing algorithms, existing methodologies, existing libraries. HMAC using SHA256+ECDSA is well understood and has been tested. If you go with EC crypto for your public-private key-pair-generation and signing, use a curve that is well known, such as the NIST curves, since they have the most scrutiny and have highly funded cryptanalytic research by the federal government.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.