debug.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * eCryptfs: Linux filesystem encryption layer
  3. * Functions only useful for debugging.
  4. *
  5. * Copyright (C) 2006 International Business Machines Corp.
  6. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. #include "ecryptfs_kernel.h"
  24. /**
  25. * ecryptfs_dump_auth_tok - debug function to print auth toks
  26. *
  27. * This function will print the contents of an ecryptfs authentication
  28. * token.
  29. */
  30. void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
  31. {
  32. char salt[ECRYPTFS_SALT_SIZE * 2 + 1];
  33. char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
  34. ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n",
  35. auth_tok);
  36. if (auth_tok->flags & ECRYPTFS_PRIVATE_KEY) {
  37. ecryptfs_printk(KERN_DEBUG, " * private key type\n");
  38. } else {
  39. ecryptfs_printk(KERN_DEBUG, " * passphrase type\n");
  40. ecryptfs_to_hex(salt, auth_tok->token.password.salt,
  41. ECRYPTFS_SALT_SIZE);
  42. salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
  43. ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
  44. if (auth_tok->token.password.flags &
  45. ECRYPTFS_PERSISTENT_PASSWORD) {
  46. ecryptfs_printk(KERN_DEBUG, " * persistent\n");
  47. }
  48. memcpy(sig, auth_tok->token.password.signature,
  49. ECRYPTFS_SIG_SIZE_HEX);
  50. sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
  51. ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
  52. }
  53. ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",
  54. auth_tok->session_key.flags);
  55. if (auth_tok->session_key.flags
  56. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT)
  57. ecryptfs_printk(KERN_DEBUG,
  58. " * Userspace decrypt request set\n");
  59. if (auth_tok->session_key.flags
  60. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT)
  61. ecryptfs_printk(KERN_DEBUG,
  62. " * Userspace encrypt request set\n");
  63. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_DECRYPTED_KEY) {
  64. ecryptfs_printk(KERN_DEBUG, " * Contains decrypted key\n");
  65. ecryptfs_printk(KERN_DEBUG,
  66. " * session_key.decrypted_key_size = [0x%x]\n",
  67. auth_tok->session_key.decrypted_key_size);
  68. ecryptfs_printk(KERN_DEBUG, " * Decrypted session key "
  69. "dump:\n");
  70. if (ecryptfs_verbosity > 0)
  71. ecryptfs_dump_hex(auth_tok->session_key.decrypted_key,
  72. ECRYPTFS_DEFAULT_KEY_BYTES);
  73. }
  74. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) {
  75. ecryptfs_printk(KERN_DEBUG, " * Contains encrypted key\n");
  76. ecryptfs_printk(KERN_DEBUG,
  77. " * session_key.encrypted_key_size = [0x%x]\n",
  78. auth_tok->session_key.encrypted_key_size);
  79. ecryptfs_printk(KERN_DEBUG, " * Encrypted session key "
  80. "dump:\n");
  81. if (ecryptfs_verbosity > 0)
  82. ecryptfs_dump_hex(auth_tok->session_key.encrypted_key,
  83. auth_tok->session_key.
  84. encrypted_key_size);
  85. }
  86. }
  87. /**
  88. * ecryptfs_dump_hex - debug hex printer
  89. * @data: string of bytes to be printed
  90. * @bytes: number of bytes to print
  91. *
  92. * Dump hexadecimal representation of char array
  93. */
  94. void ecryptfs_dump_hex(char *data, int bytes)
  95. {
  96. int i = 0;
  97. int add_newline = 1;
  98. if (ecryptfs_verbosity < 1)
  99. return;
  100. if (bytes != 0) {
  101. printk(KERN_DEBUG "0x%.2x.", (unsigned char)data[i]);
  102. i++;
  103. }
  104. while (i < bytes) {
  105. printk("0x%.2x.", (unsigned char)data[i]);
  106. i++;
  107. if (i % 16 == 0) {
  108. printk("\n");
  109. add_newline = 0;
  110. } else
  111. add_newline = 1;
  112. }
  113. if (add_newline)
  114. printk("\n");
  115. }