Git Product home page Git Product logo

nginx_mod_akamai_g2o's People

Contributors

erankor avatar refractalize avatar unitedmarsupials-zz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nginx_mod_akamai_g2o's Issues

Suggested improvements

Hello!

Although I have no doubt, the current version works, several (substantial?) improvements can/should be made. I incorporate all of these in the G2O module for Varnish, which I wrote for my employer and so speak from some experience...

Multiple nonce-keys.

The process of changing the nonce/password with Akamai is not instantaneous. This is why Akamai are using the nonce concept to begin with -- to allow for multiple (at least -- two) passwords to remain valid in parallel. For some time after you change the Akamai configuration some of their servers will still be using the old nonce, so your back-end (origin) should recognize both. I implement this with a simple array of structures -- because the number of valid nonces is small (though greater than 1), linear search through the array is the fastest method :)

Conversion to string

You are wasting time for each hit converting the computed digest into a character string and then using strcmp to compare it with the supplied signature. Instead, it is faster to convert the supplied signature into numbers (of type uint64_t) and then comparing the two pairs of numbers:

    union qdigest {
        unsigned char   bytes[16];
        uint64_t    numbers[2];
    };
    ...
    union qdigest    expected, computed;
    ...
    b64decode(signature, expected.bytes);
    ...
    HMAC_Final(tcontexts + count, computed.bytes, &len);
    ...
    if (len != 16 ||
        expected.numbers[0] != computed.numbers[0] ||
        expected.numbers[1] != computed.numbers[1]) {
        /* Report mismatch */

Recomputing the digest anew

Some of the HMAC computations need only be done once (for each key), yet the current code recomputes the digest anew for each hit. Each thread can keep the HMAC-context for each key and keep reusing it. These two calls need only be done once for each key (in each thread):

    HMAC_CTX_init(context); /* Is this even necessary? */
    HMAC_Init_ex(context, key, len, EVP_md5(), NULL);

After this, for each hit only the following needs to happen:

    HMAC_Update(context, (const unsigned char *)d, strlen(d));
    HMAC_Update(context, (const unsigned char *)path, strlen(path));
    HMAC_Final(context, computed.bytes, &len);
    HMAC_Init_ex(context, NULL, 0, NULL, NULL);

The last call resets the context back to just the key - by passing the zeros, the caller indicates, he wants to reuse the already-supplied key. Presumably, this is faster, than full reinitialization.

I can not (easily) offer a working patch, because I don't have an nginx installation readily available. But you should be able to incorporate (some of) these ideas easily yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.