Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Secure Random Number Algorithm for Initialization Vector and Avoid Static IV #190

Open
kexinoh opened this issue Aug 4, 2024 · 0 comments

Comments

@kexinoh
Copy link

kexinoh commented Aug 4, 2024

I have identified a potential security issue in the method get_initialization_vector within the class responsible for encryption configuration. The current implementation allows for the use of a static initialization vector (IV) and uses a non-secure random number generation method. The code snippet is as follows:

def get_initialization_vector(self, use_random_iv):
    if self.pubnub_configuration.use_random_initialization_vector or use_random_iv:
        return "{0:016}".format(random.randint(0, 9999999999999999))
    else:
        return Initial16bytes

Using a static IV is insecure as it can lead to the same ciphertext being generated for the same plaintext, which can be exploited by an attacker. Additionally, the use of random.randint is not cryptographically secure.
It is recommended to always use a cryptographically secure random number generator for creating the IV. The static IV fallback should be removed to ensure that a new, random IV is used for every encryption operation.
For the specific code modification, please use a secure random number generator such as os.urandom or SystemRandom from the random module, and remove the option to return a static IV.
link:

def get_initialization_vector(self, use_random_iv):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant