debug.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. ecryptfs_printk(KERN_DEBUG, " * (NO PRIVATE KEY SUPPORT "
  39. "IN ECRYPTFS VERSION 0.1)\n");
  40. } else {
  41. ecryptfs_printk(KERN_DEBUG, " * passphrase type\n");
  42. ecryptfs_to_hex(salt, auth_tok->token.password.salt,
  43. ECRYPTFS_SALT_SIZE);
  44. salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
  45. ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
  46. if (auth_tok->token.password.flags &
  47. ECRYPTFS_PERSISTENT_PASSWORD) {
  48. ecryptfs_printk(KERN_DEBUG, " * persistent\n");
  49. }
  50. memcpy(sig, auth_tok->token.password.signature,
  51. ECRYPTFS_SIG_SIZE_HEX);
  52. sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
  53. ecryptfs_printk(KERN_DEBUG, " * signature = [%s]\n", sig);
  54. }
  55. ecryptfs_printk(KERN_DEBUG, " * session_key.flags = [0x%x]\n",
  56. auth_tok->session_key.flags);
  57. if (auth_tok->session_key.flags
  58. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT)
  59. ecryptfs_printk(KERN_DEBUG,
  60. " * Userspace decrypt request set\n");
  61. if (auth_tok->session_key.flags
  62. & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT)
  63. ecryptfs_printk(KERN_DEBUG,
  64. " * Userspace encrypt request set\n");
  65. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_DECRYPTED_KEY) {
  66. ecryptfs_printk(KERN_DEBUG, " * Contains decrypted key\n");
  67. ecryptfs_printk(KERN_DEBUG,
  68. " * session_key.decrypted_key_size = [0x%x]\n",
  69. auth_tok->session_key.decrypted_key_size);
  70. ecryptfs_printk(KERN_DEBUG, " * Decrypted session key "
  71. "dump:\n");
  72. if (ecryptfs_verbosity > 0)
  73. ecryptfs_dump_hex(auth_tok->session_key.decrypted_key,
  74. ECRYPTFS_DEFAULT_KEY_BYTES);
  75. }
  76. if (auth_tok->session_key.flags & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) {
  77. ecryptfs_printk(KERN_DEBUG, " * Contains encrypted key\n");
  78. ecryptfs_printk(KERN_DEBUG,
  79. " * session_key.encrypted_key_size = [0x%x]\n",
  80. auth_tok->session_key.encrypted_key_size);
  81. ecryptfs_printk(KERN_DEBUG, " * Encrypted session key "
  82. "dump:\n");
  83. if (ecryptfs_verbosity > 0)
  84. ecryptfs_dump_hex(auth_tok->session_key.encrypted_key,
  85. auth_tok->session_key.
  86. encrypted_key_size);
  87. }
  88. }
  89. /**
  90. * ecryptfs_dump_hex - debug hex printer
  91. * @data: string of bytes to be printed
  92. * @bytes: number of bytes to print
  93. *
  94. * Dump hexadecimal representation of char array
  95. */
  96. void ecryptfs_dump_hex(char *data, int bytes)
  97. {
  98. int i = 0;
  99. int add_newline = 1;
  100. if (ecryptfs_verbosity < 1)
  101. return;
  102. if (bytes != 0) {
  103. printk(KERN_DEBUG "0x%.2x.", (unsigned char)data[i]);
  104. i++;
  105. }
  106. while (i < bytes) {
  107. printk("0x%.2x.", (unsigned char)data[i]);
  108. i++;
  109. if (i % 16 == 0) {
  110. printk("\n");
  111. add_newline = 0;
  112. } else
  113. add_newline = 1;
  114. }
  115. if (add_newline)
  116. printk("\n");
  117. }