~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs_unwrap_passphrase.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) 2007 International Business Machines
 
3
 * Author(s): Michael Halcrow <mhalcrow@us.ibm.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
18
 * 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include <ecryptfs.h>
 
23
#include "config.h"
 
24
 
 
25
void usage(void)
 
26
{
 
27
        printf("Usage:\n"
 
28
               "\n"
 
29
               "ecryptfs_unwrap_passphrase [file] [wrapping passphrase]\n"
 
30
               "\n");
 
31
}
 
32
 
 
33
int main(int argc, char *argv[])
 
34
{
 
35
        char *file;
 
36
        char passphrase[ECRYPTFS_MAX_PASSWORD_LENGTH + 1];
 
37
        char *wrapping_passphrase;
 
38
        char salt[ECRYPTFS_SALT_SIZE];
 
39
        char salt_hex[ECRYPTFS_SALT_SIZE_HEX];
 
40
        int rc = 0;
 
41
 
 
42
        if (argc != 3) {
 
43
                usage();
 
44
                goto out;
 
45
        }
 
46
        file = argv[1];
 
47
        wrapping_passphrase = argv[2];
 
48
        rc = ecryptfs_read_salt_hex_from_rc(salt_hex);
 
49
        if (rc) {
 
50
                printf("Unable to read salt value from user's "
 
51
                       ".ecryptfsrc file; using default\n");
 
52
                from_hex(salt, ECRYPTFS_DEFAULT_SALT_HEX, ECRYPTFS_SALT_SIZE);
 
53
        } else
 
54
                from_hex(salt, salt_hex, ECRYPTFS_SALT_SIZE);
 
55
        if ((rc = ecryptfs_unwrap_passphrase(passphrase, file,
 
56
                                             wrapping_passphrase, salt))) {
 
57
                printf("Error attempting to unwrap passphrase; rc = [%d]. "
 
58
                       "Check the system log for more information from "
 
59
                       "libecryptfs.\n", rc);
 
60
                rc = 1;
 
61
                goto out;
 
62
        }
 
63
        printf("%s", passphrase);
 
64
out:
 
65
        return rc;
 
66
}