Reusing a Nonce, Key Pair in Encryption

Nonces should be used for the present occasion and only once.


Background

Nonces are often bundled with a key in a communication exchange to produce a new session key for each exchange.

Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

This code takes a password, concatenates it with a nonce, then encrypts it before sending over a network:

void encryptAndSendPassword(char *password){
  char *nonce = "bad";
  ...
  char *data = (unsigned char*)malloc(20);
  int para_size = strlen(nonce) + strlen(password);
  char *paragraph = (char*)malloc(para_size);
  SHA1((const unsigned char*)paragraph,parsize,(unsigned char*)data);
  sendEncryptedData(data)
}

Because the nonce used is always the same, an attacker can impersonate a trusted party by intercepting and resending the encrypted password. This attack avoids the need to learn the unencrypted password.

Example Two

This code sends a command to a remote server, using an encrypted password and nonce to prove the command is from a trusted party:

String command = new String("some command to execute");
MessageDigest nonce = MessageDigest.getInstance("SHA");
nonce.update(String.valueOf("bad nonce"));
byte[] nonce = nonce.digest();
MessageDigest password = MessageDigest.getInstance("SHA");
password.update(nonce + "secretPassword");
byte[] digest = password.digest();
sendCommand(digest, command)

Once again the nonce used is always the same. An attacker may be able to replay previous legitimate commands or execute new arbitrary commands.

See Also

Encrypt Data

Weaknesses in this category are related to the design and architecture of data confidentiality in a system. Frequently these deal with the use of encryption libraries....

SFP Secondary Cluster: Weak Cryptography

This category identifies Software Fault Patterns (SFPs) within the Weak Cryptography cluster.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Weaknesses without Software Fault Patterns

CWE identifiers in this view are weaknesses that do not have associated Software Fault Patterns (SFPs), as covered by the CWE-888 view. As such, they represent gaps in...

CWE Cross-section

This view contains a selection of weaknesses that represent the variety of weaknesses that are captured in CWE, at a level of abstraction that is likely to be useful t...


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.