Thu, 12 Dec 2024 16:46:43 +0100
fix compatibility with older libcurl versions
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #ifndef LIBIDAV_PWDSTORE_H |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #define LIBIDAV_PWDSTORE_H |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #ifdef __cplusplus |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | extern "C" { |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #endif |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <stdlib.h> |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include <inttypes.h> |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include <cx/map.h> |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include <cx/buffer.h> |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include <cx/linked_list.h> |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "crypto.h" |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #ifdef __cplusplus |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | extern "C" { |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #endif |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | #define PWDSTORE_MAX_LEN 4096 |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | * File Format: |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | * file = header, index, enc_content |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | * header = magic, version, enc, pwfunc, salt, indexlen |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | * magic = 1 byte |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | * version = 1 byte |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | * enc = 1 byte |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | * pwfunc = 1 byte |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | * salt = 16 bytes |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | * indexlen = uint32 |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | * index = { itype length id locations zero } |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | * enc_content = iv bytes |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | * iv = 16 bytes |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | * content = { entry } |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | * entry = itype length id length username length password |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | * length = uint32 |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | * zero = 4 zero bytes |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | * itype = 1 byte |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | * id = string |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | * locations = { length string } |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | * username = string |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | * password = string |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | * The content is AES encrypted with a key derived from a password |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | * and the salt. The first 16 bytes are the aes iv. |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | * |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | * All integers are big endian |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | #define PWDS_HEADER_SIZE 24 |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | typedef struct PwdStore PwdStore; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | typedef struct PwdEntry PwdEntry; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | typedef struct PwdIndexEntry PwdIndexEntry; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | struct PwdStore { |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | * map of all credentials |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | * key is the username |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | * value is PwdEntry* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | CxMap *ids; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | * list of all credentials with location |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | * value is PwdIndexEntry* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | CxList *locations; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | * list of all credentials without location |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | * value is PwdIndexEntry* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | CxList *noloc; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | * index map that contains all elements from the lists |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | * 'locations' and 'noloc' |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | CxMap *index; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | * a buffer containing the complete file content |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | CxBuffer *content; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | * key used for encryption/decryption |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | DavKey *key; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | * optional shell command, that is used for getting the master password |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | char *unlock_cmd; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | * optional shell command, that is exected when the secretstore is closed |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | char *lock_cmd; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | * start offset of the encrypted buffer |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | uint32_t encoffset; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | * indicates if the PwdStore is decrypted with pwdstore_decrypt |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | uint8_t isdecrypted; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | }; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | #define PWDS_MAGIC(p) (p)->content->space[0] |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | #define PWDS_VERSION(p) (p)->content->space[1] |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | #define PWDS_ENC(p) (p)->content->space[2] |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | #define PWDS_PWFUNC(p) (p)->content->space[3] |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | #define PWDS_MAGIC_CHAR 'P' |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | struct PwdEntry { |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | char *id; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | char *user; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | char *password; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | }; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | struct PwdIndexEntry { |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | char *id; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | CxList *locations; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | }; |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | * opens the password store |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | * the content is still encrypted and must be decrypted using pwdstore_decrypt |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | PwdStore* pwdstore_open(const char *file); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | PwdStore* pwdstore_new(void); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
841
21403bdaf54c
add pwdstore_clone function and fix some pwdstore bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
832
diff
changeset
|
169 | PwdStore* pwdstore_clone(PwdStore *p); |
21403bdaf54c
add pwdstore_clone function and fix some pwdstore bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
832
diff
changeset
|
170 | |
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | /* |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | * decrypts the password store with the previously set password |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | int pwdstore_decrypt(PwdStore *p); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | int pwdstore_setpassword(PwdStore *p, const char *password); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | void pwdstore_encsettings(PwdStore *p, uint8_t enc, uint8_t pwfunc); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | void pwdstore_free_entry(PwdEntry *e); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | void pwdstore_free(PwdStore* p); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | int pwdstore_has_id(PwdStore *s, const char *id); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | PwdEntry* pwdstore_get(PwdStore *p, const char *id); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | void pwdstore_put(PwdStore *p, const char *id, const char *username, const char *password); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | void pwdstore_put_index(PwdStore *p, char *id, CxList *locations); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | void pwdstore_remove_entry(PwdStore *s, const char *id); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | int pwdstore_store(PwdStore *p, const char *file); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | int pwdstore_decrypt_secrets(PwdStore *secrets); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | typedef char*(*pwdstore_pwinput_func)(void *userdata); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | void pwdstore_set_pwinput_func(pwdstore_pwinput_func func, void *userdata); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | char * pwdstore_default_pwinput(char *prompt); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | /* private */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | int pwdstore_getindex(PwdStore *s); |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | #ifdef __cplusplus |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | } |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | #endif |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | #endif /* LIBIDAV_PWDSTORE_H */ |
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 |