Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * eCryptfs: Linux filesystem encryption layer
0004  * Functions only useful for debugging.
0005  *
0006  * Copyright (C) 2006 International Business Machines Corp.
0007  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
0008  */
0009 
0010 #include "ecryptfs_kernel.h"
0011 
0012 /*
0013  * ecryptfs_dump_auth_tok - debug function to print auth toks
0014  *
0015  * This function will print the contents of an ecryptfs authentication
0016  * token.
0017  */
0018 void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
0019 {
0020     char salt[ECRYPTFS_SALT_SIZE * 2 + 1];
0021     char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
0022 
0023     ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n",
0024             auth_tok);
0025     if (auth_tok->flags & ECRYPTFS_PRIVATE_KEY) {
0026         ecryptfs_printk(KERN_DEBUG, " * private key type\n");
0027     } else {
0028         ecryptfs_printk(KERN_DEBUG, " * passphrase type\n");
0029         ecryptfs_to_hex(salt, auth_tok->token.password.salt,
0030                 ECRYPTFS_SALT_SIZE);
0031         salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
0032         ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
0033         if (auth_tok->token.password.flags &
0034             ECRYPTFS_PERSISTENT_PASSWORD) {
0035             ecryptfs_printk(KERN_DEBUG, " * persistent\n");
0036         }
0037         memcpy(sig, auth_tok->token.password.signature,
0038                ECRYPTFS_SIG_SIZE_HEX);
0039         sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
0040         ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
0041     }
0042     ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",
0043             auth_tok->session_key.flags);
0044     if (auth_tok->session_key.flags
0045         & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT)
0046         ecryptfs_printk(KERN_DEBUG,
0047                 " * Userspace decrypt request set\n");
0048     if (auth_tok->session_key.flags
0049         & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT)
0050         ecryptfs_printk(KERN_DEBUG,
0051                 " * Userspace encrypt request set\n");
0052     if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_DECRYPTED_KEY) {
0053         ecryptfs_printk(KERN_DEBUG, " * Contains decrypted key\n");
0054         ecryptfs_printk(KERN_DEBUG,
0055                 " * session_key.decrypted_key_size = [0x%x]\n",
0056                 auth_tok->session_key.decrypted_key_size);
0057         ecryptfs_printk(KERN_DEBUG, " * Decrypted session key "
0058                 "dump:\n");
0059         if (ecryptfs_verbosity > 0)
0060             ecryptfs_dump_hex(auth_tok->session_key.decrypted_key,
0061                       ECRYPTFS_DEFAULT_KEY_BYTES);
0062     }
0063     if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) {
0064         ecryptfs_printk(KERN_DEBUG, " * Contains encrypted key\n");
0065         ecryptfs_printk(KERN_DEBUG,
0066                 " * session_key.encrypted_key_size = [0x%x]\n",
0067                 auth_tok->session_key.encrypted_key_size);
0068         ecryptfs_printk(KERN_DEBUG, " * Encrypted session key "
0069                 "dump:\n");
0070         if (ecryptfs_verbosity > 0)
0071             ecryptfs_dump_hex(auth_tok->session_key.encrypted_key,
0072                       auth_tok->session_key.
0073                       encrypted_key_size);
0074     }
0075 }
0076 
0077 /**
0078  * ecryptfs_dump_hex - debug hex printer
0079  * @data: string of bytes to be printed
0080  * @bytes: number of bytes to print
0081  *
0082  * Dump hexadecimal representation of char array
0083  */
0084 void ecryptfs_dump_hex(char *data, int bytes)
0085 {
0086     if (ecryptfs_verbosity < 1)
0087         return;
0088 
0089     print_hex_dump(KERN_DEBUG, "ecryptfs: ", DUMP_PREFIX_OFFSET, 16, 1,
0090                data, bytes, false);
0091 }