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