~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/utils/dump_auth_tok.c

  • Committer: mhalcrow@us.ibm.com
  • Date: 2007-11-06 22:56:01 UTC
  • Revision ID: git-v1:f8357de9d554b274497b5cce9db4347254b7e7eb
Initial import of eCryptfs filesystem userspace utilities (mount helper, daemon component,
etc.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (C) 2004-2006 International Business Machines
 
3
 * Written by Michael A. Halcrow <mhalcrow@us.ibm.com>
 
4
 * Modified by Michael C. Thompson <mcthomps@us.ibm.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License as
 
8
 * published by the Free Software Foundation; either version 2 of the
 
9
 * License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include <stdarg.h>
 
23
#ifdef USE_PRINTF
 
24
#include <stdio.h>
 
25
#else
 
26
#include <syslog.h>
 
27
#endif
 
28
#include "ecryptfs.h"
 
29
 
 
30
void PRINT(char *fmt, ...)
 
31
{
 
32
        va_list args;
 
33
 
 
34
        va_start(args, fmt);
 
35
#ifdef USE_PRINTF
 
36
        vfprintf(stdout, fmt, args);
 
37
#else
 
38
        syslog(LOG_NOTICE, fmt, args);
 
39
#endif
 
40
        va_end(args);
 
41
}
 
42
 
 
43
/**
 
44
 * Dump hexadecimal representation of char array
 
45
 *
 
46
 * @param data
 
47
 * @param bytes
 
48
 */
 
49
void dump_hex(char *data, int bytes)
 
50
{
 
51
        char buf[128];
 
52
        char tmp[8];
 
53
        int i = 0;
 
54
        int pretty_print = 1;
 
55
        buf[0] = '\0';
 
56
        if (bytes != 0) {
 
57
                sprintf(tmp, "0x%.2x.", (unsigned char)data[i]);
 
58
                strcat(buf, tmp);
 
59
                i++;
 
60
        }
 
61
        while (i < bytes) {
 
62
                sprintf(tmp, "0x%.2x.", (unsigned char)data[i]);
 
63
                strcat(buf, tmp);
 
64
                i++;
 
65
                if (i%16 == 0) {
 
66
                        strcat(buf, "\n");
 
67
                        pretty_print = 0;
 
68
                } else {
 
69
                        pretty_print = 1;
 
70
                }
 
71
        }
 
72
        if (pretty_print) {
 
73
                strcat(buf, "\n");
 
74
        }
 
75
        PRINT("%s", buf);
 
76
}
 
77
 
 
78
void dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
 
79
{
 
80
        struct ecryptfs_password *password;
 
81
 
 
82
        PRINT("Auth tok at mem loc [%p]:\n", auth_tok);
 
83
        PRINT(" * instanceof = [%d]\n", auth_tok->instanceof);
 
84
        PRINT(" * instantiated = [%d]\n", auth_tok->instantiated);
 
85
        switch (auth_tok->instanceof) {
 
86
                char salt[ECRYPTFS_SALT_SIZE + 1];
 
87
                char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
 
88
        case ECRYPTFS_PASSWORD:
 
89
                password = &(auth_tok->token.password);
 
90
                PRINT("eCryptfs Password:\n");
 
91
                PRINT(" * password = [%s]\n", password->password);
 
92
                PRINT(" * password_size = [%d]\n", password->password_size);
 
93
                PRINT(" * salt = ");
 
94
                dump_hex(password->salt, ECRYPTFS_SALT_SIZE);
 
95
                PRINT(" * saltless = [%d]\n", password->saltless);
 
96
                PRINT(" * signature = [%.*s]\n", ECRYPTFS_SIG_SIZE_HEX,
 
97
                        password->signature);
 
98
                PRINT(" * hash algorithm = [%d]\n", password->hash_algo);
 
99
                PRINT(" * hash iterations = [%d]\n", password->hash_iterations);
 
100
                if (!password->session_key_encryption_key_set) {
 
101
                        PRINT("Session key encryption key not set\n");
 
102
                        goto skip_password_key;
 
103
                }
 
104
                PRINT(" * Session key encryption key set = [%d]\n",
 
105
                        password->session_key_encryption_key_set);
 
106
                PRINT(" * Session key encryption key size = [0x%x]\n",
 
107
                        password->session_key_encryption_key_size);
 
108
                PRINT(" * Key dump:\n" );
 
109
                dump_hex(password->session_key_encryption_key,
 
110
                        password->session_key_encryption_key_size);
 
111
 skip_password_key:
 
112
                break;
 
113
        case ECRYPTFS_PRIVATE_KEY:
 
114
                PRINT(" * signature = [%.*s]\n", ECRYPTFS_SIG_SIZE_HEX,
 
115
                        auth_tok->token.private_key.signature);
 
116
                break;
 
117
        default:
 
118
                PRINT(" * Unrecognized instanceof\n" );
 
119
        }
 
120
        PRINT(" * session_key.flags = [0x%x]\n",
 
121
                auth_tok->session_key.flags );
 
122
        PRINT("Contents of session_key field\n");
 
123
        if (auth_tok->session_key.flags
 
124
            & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT) {
 
125
                PRINT(" * Userspace decrypt request set\n" );
 
126
        }
 
127
        if (auth_tok->session_key.flags
 
128
            & ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT) {
 
129
                PRINT(" * Userspace encrypt request set\n" );
 
130
        }
 
131
        if (auth_tok->session_key.flags
 
132
            & ECRYPTFS_CONTAINS_DECRYPTED_KEY) {
 
133
                PRINT(" * Contains decrypted key\n" );
 
134
                PRINT(" * session_key.decrypted_key_size = "
 
135
                        "[0x%x]\n", auth_tok->session_key.decrypted_key_size );
 
136
                PRINT(" * Key dump:\n" );
 
137
                dump_hex( auth_tok->session_key.decrypted_key,
 
138
                        ECRYPTFS_MAX_KEY_BYTES );
 
139
        }
 
140
        if (auth_tok->session_key.flags
 
141
            & ECRYPTFS_CONTAINS_ENCRYPTED_KEY) {
 
142
                PRINT(" * Contains encrypted key\n" );
 
143
                PRINT(" * session_key.encrypted_key_size = "
 
144
                        "[0x%x]\n", auth_tok->session_key.encrypted_key_size );
 
145
                PRINT(" * Key dump:\n" );
 
146
                dump_hex( auth_tok->session_key.encrypted_key,
 
147
                          ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES );
 
148
        }
 
149
}