Score:0

Derrive a new key from Trusted Third Party (e.g. Kerberos) session key

gh flag

Kerberos (and I assume other Trusted Third Party protocols) use (hash) an existing shared secret key to create a session key used for authentication. I read that this authentication secret key can then be used to create another secret key to be used as the session key for message encryption.

"If a message integrity or confidentiality key is required, a Kerberos sub-key or a Kerberos session key from the Kerberos ticket is used. A key can be derived from either the Kerberos sub-key or the Kerberos session key." https://www.ibm.com/docs/en/was-nd/9.0.5?topic=token-kerberos-usage-overview-web-services.

Is that true and if so, how is this done? Or why can't the auth session key also be used as the session key for encryption?

Score:1
gf flag

In the Kerberos protocol, the authentication process involves using a shared secret key between the client and the Kerberos server to establish a session key. This session key is primarily used for mutual authentication and integrity checks. However, it is not directly suitable for encryption purposes due to security considerations and cryptographic best practices.

To derive an encryption key from the authentication session key in Kerberos, a technique called key derivation is typically employed. Key derivation involves applying cryptographic functions to transform the existing key into a new key suitable for encryption. This process ensures that even if the authentication session key is compromised, the encryption key remains secure.

Here's an example Python code snippet illustrating how key derivation can be performed using a cryptographic library called cryptography:

from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend

# Authentication session key obtained from *Kerberos* (e.g., as a string)
auth_session_key = "a1b2c3d4e5f6g7h8"

# Key derivation parameters
salt = b"salt_value"  # Unique salt value
iterations = 1000  # Number of iterations
key_length = 32  # Desired length of the derived key (in bytes)

# Perform key derivation
kdf = PBKDF2HMAC(
    algorithm=hashes.SHA256(),
    length=key_length,
    salt=salt,
    iterations=iterations,
    backend=default_backend()
)
encryption_key = kdf.derive(auth_session_key.encode())

# Print the derived encryption key
print(f"Derived encryption key: {encryption_key.hex()}")


In this example, the PBKDF2HMAC function from the cryptography library is used for key derivation. It takes parameters such as the chosen hash algorithm (SHA-256), the desired key length, the salt value, and the number of iterations for the key derivation process.

The authentication session key (auth_session_key) is first encoded as bytes. Then, the key derivation is performed using the kdf.derive() method, which derives an encryption key from the authentication session key based on the provided parameters.

Please note that the process of extracting a specific key may be different depending on the requirements and cryptographic algorithms used in a specific protocol or system, I will give you another example below.

from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.backends import default_backend

# Derived encryption key obtained from key derivation
encryption_key = b'\x12\x34\x56\x78\x90\xab\xcd\xef\x12\x34\x56\x78\x90\xab\xcd\xef'

# Message to be encrypted
message = b'Hello, World!'

# Generate a random initialization vector (IV)
iv = b'\x00' * 16  # 16 bytes for AES-128

# Create a cipher object using the encryption key, AES-128 algorithm, and CBC mode
cipher = Cipher(algorithms.AES(encryption_key), modes.CBC(iv), backend=default_backend())

# Encrypt the message
encryptor = cipher.encryptor()
ciphertext = encryptor.update(message) + encryptor.finalize()

# Print the encrypted ciphertext
print(f"Encrypted ciphertext: {ciphertext.hex()}")

# Create a new encryptor object (resetting the state)
encryptor = cipher.encryptor()

# Encrypt another message using the same encryption key and IV
another_message = b'Hello again!'
another_ciphertext = encryptor.update(another_message) + encryptor.finalize()

# Print the encrypted ciphertext of the second message
print(f"Encrypted ciphertext (another message): {another_ciphertext.hex()}")

# Create a new decryptor object using the encryption key and IV
decryptor = cipher.decryptor()

# Decrypt the ciphertext
decrypted_message = decryptor.update(ciphertext) + decryptor.finalize()

# Print the decrypted message
print(f"Decrypted message: {decrypted_message}")

# Create a new decryptor object (resetting the state)
decryptor = cipher.decryptor()

# Decrypt the ciphertext of the second message
decrypted_another_message = decryptor.update(another_ciphertext) + decryptor.finalize()

# Print the decrypted message of the second ciphertext
print(f"Decrypted message (another message): {decrypted_another_message}")

This extended example demonstrates the process of deriving an encryption key, encrypting a message, and then decrypting it using the derived key. It uses the AES-128 algorithm in CBC mode for encryption and decryption.

The encryption process involves creating a cipher object using the derived encryption key and initialization vector (IV). The message is encrypted using the encryptor object, and the resulting ciphertext is printed.

A new encryptor object is created to demonstrate encrypting another message using the same encryption key and IV.

To decrypt the ciphertext, a decryptor object is created using the same encryption key and IV. The ciphertext is then decrypted using the decryptor object, and the resulting plaintext message is printed.

Please note that this example is for demonstration purposes and does not cover aspects such as key management, secure transmission of the encryption key or padding for variable length messages.

Elliot avatar
gh flag
extremely clear and helpful response. appreciate explanation and example code.
MrPyMmdrza avatar
gf flag
@Elliot thank you
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.