lib/auth/request-dh-params.js
function decryptDHParams(context) {
    var newNonce = utility.string2Buffer(context.newNonce, 32);
    var serverNonce = utility.string2Buffer(context.resPQ.server_nonce, 16);
    if (logger.isDebugEnabled()) {
        logger.debug('newNonce = %s, serverNonce = %s', newNonce.toString('hex'), serverNonce.toString('hex'));
    }
    var hashNS = utility.createSHAHash([newNonce, serverNonce]);
    var hashSN = utility.createSHAHash([serverNonce, newNonce]);
    var hashNN = utility.createSHAHash([newNonce, newNonce]);
    if (logger.isDebugEnabled()) {
        logger.debug('hashNS = %s, hashSN = %s, hashNN = %s',
            hashNS.toString('hex'), hashSN.toString('hex'), hashNN.toString('hex'));
    }
    // Create the AES key
    context.aes = {
        key: Buffer.concat([hashNS, hashSN.slice(0, 12)]),
        iv: Buffer.concat([Buffer.concat([hashSN.slice(12), hashNN]), newNonce.slice(0, 4)]),
        toPrintable: tl.utility.toPrintable
    };

    if (logger.isDebugEnabled()) {
        logger.debug('aesKey = %s', context.aes.toPrintable());
    }
    // Decrypt the message
    var answerWithHash = security.cipher.aesDecrypt(
        context.serverDHParams.encrypted_answer,
        context.aes.key,
        context.aes.iv
    );
    context.decryptedDHParams = answerWithHash;
    return context;
}
function decryptDHParams(context) {
    var newNonce = utility.string2Buffer(context.newNonce, 32);
    var serverNonce = utility.string2Buffer(context.resPQ.server_nonce, 16);
    if (logger.isDebugEnabled()) {
        logger.debug('newNonce = %s, serverNonce = %s', newNonce.toString('hex'), serverNonce.toString('hex'));
    }
    var hashNS = utility.createSHAHash([newNonce, serverNonce]);
    var hashSN = utility.createSHAHash([serverNonce, newNonce]);
    var hashNN = utility.createSHAHash([newNonce, newNonce]);
    if (logger.isDebugEnabled()) {
        logger.debug('hashNS = %s, hashSN = %s, hashNN = %s',
            hashNS.toString('hex'), hashSN.toString('hex'), hashNN.toString('hex'));
    }
    // Create the AES key
    context.aes = {
        key: Buffer.concat([hashNS, hashSN.slice(0, 12)]),
        iv: Buffer.concat([Buffer.concat([hashSN.slice(12), hashNN]), newNonce.slice(0, 4)]),
        toPrintable: tl.utility.toPrintable
    };

    if (logger.isDebugEnabled()) {
        logger.debug('aesKey = %s', context.aes.toPrintable());
    }
    // Decrypt the message
    var answerWithHash = security.cipher.aesDecrypt(
        context.serverDHParams.encrypted_answer,
        context.aes.key,
        context.aes.iv
    );
    context.decryptedDHParams = answerWithHash;
    return context;
}
function decryptDHParams ( context ) { var newNonce = utility . string2Buffer ( context . newNonce , 32 ) ; var serverNonce = utility . string2Buffer ( context . resPQ . server_nonce , 16 ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'newNonce = %s, serverNonce = %s' , newNonce . toString ( 'hex' ) , serverNonce . toString ( 'hex' ) ) ; } var hashNS = utility . createSHAHash ( [ newNonce , serverNonce ] ) ; var hashSN = utility . createSHAHash ( [ serverNonce , newNonce ] ) ; var hashNN = utility . createSHAHash ( [ newNonce , newNonce ] ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'hashNS = %s, hashSN = %s, hashNN = %s' , hashNS . toString ( 'hex' ) , hashSN . toString ( 'hex' ) , hashNN . toString ( 'hex' ) ) ; } // Create the AES key context . aes = { key : Buffer . concat ( [ hashNS , hashSN . slice ( 0 , 12 ) ] ) , iv : Buffer . concat ( [ Buffer . concat ( [ hashSN . slice ( 12 ) , hashNN ] ) , newNonce . slice ( 0 , 4 ) ] ) , toPrintable : tl . utility . toPrintable } ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( 'aesKey = %s' , context . aes . toPrintable ( ) ) ; } // Decrypt the message var answerWithHash = security . cipher . aesDecrypt ( context . serverDHParams . encrypted_answer , context . aes . key , context . aes . iv ) ; context . decryptedDHParams = answerWithHash ; return context ; }
Decrypt DH parameters and synch the local time with the server time
Decrypt DH parameters and synch the local time with the server time