| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* eCryptfs: Linux filesystem encryption layer |
| 4 |
* Functions only useful for debugging. |
| 5 |
* |
| 6 |
* Copyright (C) 2006 International Business Machines Corp. |
| 7 |
* Author(s): Michael A. Halcrow <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "ecryptfs_kernel.h" |
| 11 |
|
| 12 |
/* |
| 13 |
* ecryptfs_dump_auth_tok - debug function to print auth toks |
| 14 |
* |
| 15 |
* This function will print the contents of an ecryptfs authentication |
| 16 |
* token. |
| 17 |
*/ |
| 18 |
void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok) |
| 19 |
{ |
| 20 |
char salt[ECRYPTFS_SALT_SIZE * 2 + 1]; |
| 21 |
char sig[ECRYPTFS_SIG_SIZE_HEX + 1]; |
| 22 |
|
| 23 |
ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n", |
| 24 |
auth_tok); |
| 25 |
if (auth_tok->flags & ECRYPTFS_PRIVATE_KEY) { |
| 26 |
ecryptfs_printk(KERN_DEBUG, " * private key type\n"); |
| 27 |
} else { |
| 28 |
ecryptfs_printk(KERN_DEBUG, " * passphrase type\n"); |
| 29 |
ecryptfs_to_hex(salt, auth_tok->token.password.salt, |
| 30 |
ECRYPTFS_SALT_SIZE); |
| 31 |
ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt); |
| 32 |
if (auth_tok->token.password.flags & |
| 33 |
ECRYPTFS_PERSISTENT_PASSWORD) { |
| 34 |
ecryptfs_printk(KERN_DEBUG, " * persistent\n"); |
| 35 |
} |
| 36 |
memcpy(sig, auth_tok->token.password.signature, |
| 37 |
ECRYPTFS_SIG_SIZE_HEX); |
| 38 |
sig[ECRYPTFS_SIG_SIZE_HEX] = '\0'; |
| 39 |
ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig); |
| 40 |
} |
| 41 |
ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n", |
| 42 |
auth_tok->session_key.flags); |
| 43 |
if (auth_tok->session_key.flags |
| 44 |
& ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT) |
| 45 |
ecryptfs_printk(KERN_DEBUG, |
| 46 |
" * Userspace decrypt request set\n"); |
| 47 |
if (auth_tok->session_key.flags |
| 48 |
& ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT) |
| 49 |
ecryptfs_printk(KERN_DEBUG, |
| 50 |
" * Userspace encrypt request set\n"); |
| 51 |
if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_DECRYPTED_KEY) { |
| 52 |
ecryptfs_printk(KERN_DEBUG, " * Contains decrypted key\n"); |
| 53 |
ecryptfs_printk(KERN_DEBUG, |
| 54 |
" * session_key.decrypted_key_size = [0x%x]\n", |
| 55 |
auth_tok->session_key.decrypted_key_size); |
| 56 |
ecryptfs_printk(KERN_DEBUG, " * Decrypted session key " |
| 57 |
"dump:\n"); |
| 58 |
if (ecryptfs_verbosity > 0) |
| 59 |
ecryptfs_dump_hex(auth_tok->session_key.decrypted_key, |
| 60 |
ECRYPTFS_DEFAULT_KEY_BYTES); |
| 61 |
} |
| 62 |
if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) { |
| 63 |
ecryptfs_printk(KERN_DEBUG, " * Contains encrypted key\n"); |
| 64 |
ecryptfs_printk(KERN_DEBUG, |
| 65 |
" * session_key.encrypted_key_size = [0x%x]\n", |
| 66 |
auth_tok->session_key.encrypted_key_size); |
| 67 |
ecryptfs_printk(KERN_DEBUG, " * Encrypted session key " |
| 68 |
"dump:\n"); |
| 69 |
if (ecryptfs_verbosity > 0) |
| 70 |
ecryptfs_dump_hex(auth_tok->session_key.encrypted_key, |
| 71 |
auth_tok->session_key. |
| 72 |
encrypted_key_size); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* ecryptfs_dump_hex - debug hex printer |
| 78 |
* @data: string of bytes to be printed |
| 79 |
* @bytes: number of bytes to print |
| 80 |
* |
| 81 |
* Dump hexadecimal representation of char array |
| 82 |
*/ |
| 83 |
void ecryptfs_dump_hex(char *data, int bytes) |
| 84 |
{ |
| 85 |
if (ecryptfs_verbosity < 1) |
| 86 |
return; |
| 87 |
|
| 88 |
print_hex_dump(KERN_DEBUG, "ecryptfs: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 89 |
data, bytes, false); |
| 90 |
} |