Skip to content

fix Use of Weak Algorithm ntls.js #620

@RashidKhanPathan

Description

@RashidKhanPathan

please fix, use of weak algorithm in ntls.js which using DES-ECB

Description

The code at

var des = crypto.createCipheriv('DES-ECB', key, '');
uses the DES-ECB algorithm for encryption which is considered weak and insecure due to the below following reasons:

  1. DES is an outdated encryption standard with a key length of 56 bits, making it susceptible to brute-force attacks.
  2. The use of ECB mode reveals patterns in the plaintext, as identical plaintext blocks result in identical ciphertext blocks. This can leak sensitive information about the structure of the plaintext.

Code With Issue

function encrypt(buf) {
    var key = insertZerosEvery7Bits(buf);
    var des = crypto.createCipheriv('DES-ECB', key, '');
    return des.update("KGS!@#$%"); // page 57 in [MS-NLMP]
}

Impact

  • could be: The static string "KGS!@#$%" makes the encryption output predictable.
  • why its weak: Many security standards (e.g., PCI-DSS, NIST) prohibit the use of DES due to its known vulnerabilities.

Recommendation

To resolve this issue, I recommend switching to a modern encryption algorithm like AES (Advanced Encryption Standard) in GCM (Galois/Counter Mode) or CBC (Cipher Block Chaining) mode. For example:

// sample fix code
const crypto = require('crypto');

function encrypt(buf) {
    ...
    const cipher = crypto.createCipheriv('aes-256-gcm', key, iv); // fixed code
    return { encrypted, iv, tag };
    ...
}

to fix the issue

  • Replace DES-ECB with AES-GCM or AES-CBC.

References


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions