1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
--- a/perl/lib/Wallet/Object/File.pm
+++ b/perl/lib/Wallet/Object/File.pm
@@ -119,17 +119,44 @@ sub _get_crypt_key {
return $return_val;
}
+ my $msg = "\n";
+
# ldap:///basedn?attr?scope?filter
my $url = $Wallet::Config::LDAP_SECRET;
$url =~ s{^ldap:///}{}xmsi;
if ($url eq $Wallet::Config::LDAP_SECRET) {
- die("ERROR: Invalid LDAP URL $url");
+ $msg .= "INFO: LDAP_SECRET contains a hostname\n";
+ $msg .= "ERROR: Invalid LDAP_SECRET URL $url\n";
+ die $msg;
}
my @parts = split /\?/, $url;
my $base = $parts[0];
+ if (!$base) {
+ $msg .= "INFO: LDAP_SECRET does not contain a base dn\n";
+ $msg .= "ERROR: Invalid LDAP_SECRET URL $url\n";
+ die $msg;
+ }
my $attr = $parts[1];
+ if (!$attr) {
+ $msg .= "INFO: LDAP_SECRET does not contain an attribute\n";
+ $msg .= "ERROR: Invalid LDAP_SECRET URL $url\n";
+ die $msg;
+ }
my $scope = $parts[2];
+ if (!$scope) {
+ $scope = 'subtree';
+ }
my $filter = $parts[3];
+ if (!$filter) {
+ $filter = 'objectClass=*';
+ }
+
+ # Search details just in case they have to be displayed
+ my $search_details = "\n";
+ $search_details .= "INFO: base = $base\n";
+ $search_details .= "INFO: filter = $filter\n";
+ $search_details .= "INFO: scope = $scope\n";
+ $search_details .= "INFO: attribute = $attr\n";
# Search for the secret in the LDAP directory
my $ldap_obj = Wallet::ACL::LDAP::Attribute->new;
@@ -145,17 +172,23 @@ sub _get_crypt_key {
if ($search->count == 1) {
$entry = $search->pop_entry;
} elsif ($search->count > 1) {
- die 'ERROR: ' . $search->count . " LDAP entries found for $filter";
+ $msg .= 'ERROR: ' . $search->count . ' LDAP entries found for '
+ . "$filter\n";
+ die $msg;
} else {
- die "ERROR: No entry found for $url";
+ my $msg .= $search_details;
+ $msg .= "ERROR: No entry found for $url\n";
+ die $msg;
}
};
if ($@) {
- die "INFO: LDAP search failed using $url\n"
- . "ERROR: $@";
+ $msg .= "ERROR: LDAP search failed using $url\n";
+ $msg .= "ERROR: $@" . "\n";
+ die $msg;
}
if (!$entry) {
- die "ERROR: No entry returned for LDAP search using $url";
+ $msg .= "ERROR: No entry returned for LDAP search using $url";
+ die $msg;
}
my $return_val;
@@ -168,11 +201,15 @@ sub _get_crypt_key {
}
}
if (!$return_val) {
- die "ERROR: Attribute not found $url";
+ $msg .= $search_details;
+ $msg .= "ERROR: Attribute not found $url\n";
+ die $msg;
}
if ($cnt > 0) {
my $obj_cnt = $cnt + 1;
- die "ERROR: LDAP search return too many values ($obj_cnt) for $url";
+ $msg .= $search_details;
+ $msg .= "ERROR: LDAP returned too many values ($obj_cnt) for $url";
+ die $msg;
}
return $return_val;
}
@@ -184,7 +221,7 @@ sub _file_crypt {
require MIME::Base64;
my $return_string;
- my $pre = $Wallet::Config::LDAP_SECRET_PREFIX;
+ my $pre = $Wallet::Config::ENCRYPTION_PREFIX;
my $cipher = Crypt::CBC->new(
-key => $key,
@@ -219,6 +256,12 @@ sub file_decrypt {
if (defined (&Wallet::Config::file_crypt)) {
$undata = Wallet::Config::file_crypt('decrypt', $key, $data);
} else {
+ if (!$Wallet::Config::LDAP_SECRET) {
+ my $msg = "\n";
+ $msg .= "ERROR: ENCYPTION_PREFIX specified and LDAP_SECRET is "
+ . "missing\n";
+ die $msg;
+ }
$undata = $self->_file_crypt('decrypt', $key, $data);
}
if ($undata eq $data) {
@@ -234,6 +277,12 @@ sub file_encrypt {
if (defined (&Wallet::Config::file_crypt)) {
$endata = Wallet::Config::file_crypt('encrypt', $key, $data);
} else {
+ if (!$Wallet::Config::LDAP_SECRET) {
+ my $msg = "\n";
+ $msg .= "ERROR: ENCYPTION_PREFIX specified and LDAP_SECRET is "
+ . "missing\n";
+ die $msg;
+ }
$endata = $self->_file_crypt('encrypt', $key, $data);
}
return $endata;
@@ -276,7 +325,7 @@ sub get {
$self->error ("cannot get $id: $!");
return;
}
- if ($Wallet::Config::LDAP_SECRET) {
+ if ($Wallet::Config::ENCRYPTION_PREFIX) {
$data = $self->file_decrypt($data, $user, $host, $time);
}
$self->log_action ('get', $user, $host, $time);
@@ -296,7 +345,7 @@ sub checksum {
my $this_checksum;
my $this_data;
my $this_endata = read_file($path);
- if ($Wallet::Config::LDAP_SECRET) {
+ if ($Wallet::Config::ENCRYPTION_PREFIX) {
$this_data = $self->file_decrypt($this_endata, $user, $host, $time)
} else {
$this_data = $this_endata;
@@ -326,7 +375,7 @@ sub store {
return;
}
}
- if ($Wallet::Config::LDAP_SECRET) {
+ if ($Wallet::Config::ENCRYPTION_PREFIX) {
$data = $self->file_encrypt($data);
}
--- a/perl/lib/Wallet/Config.pm
+++ b/perl/lib/Wallet/Config.pm
@@ -795,31 +795,19 @@ our $LDAP_CACHE;
Specifies an LDAP URL that is used to retrieve the secret to use when
encrypting and decrypting file objects. The url must not include the
-hostname. LDAP_HOST will be used as the hostname to bind to. The
-Kerberos ticket cache specified in LDAP_CACHE is used when connecting
-to the LDAP server. GSS-API authentication is always used; there is
-currently no support for any other type of bind. The ticket cache
-must be for a principal with access to retrieve the secret. This
-variable and LDAP_CACHE must be set to use file object encryption.
+hostname. LDAP_HOST will be used as the hostname for the server to
+bind to. The Kerberos ticket cache specified in LDAP_CACHE is used
+when connecting to the LDAP server. GSS-API authentication is always
+used; there is currently no support for any other type of bind. The
+ticket cache must be for a principal with access to retrieve the
+secret. The variables LDAP_HOST, LDAP_CACHE, LDAP_SECRET, and
+ENCRYPTION_PREFIX must be set to use the default encryption
+processing.
=cut
our $LDAP_SECRET;
-=item LDAP_SECRET_PREFIX
-
-Specifies the prefix to be used when generating storing an encrypted
-file object. The prefix is used to determine whether or not a file
-object has been stored encrypted. This allows the gradual transition
-from unencrypted file objects to encrypted file objects. When file
-object encryption is enable any "get" of an unencyrpted file object
-will result in the replacement of the unencrypted object with an
-encrypted object.
-
-=cut
-
-our $LDAP_SECRET_PREFIX;
-
=back
=head2 LDAP Principal Mapping
@@ -1112,7 +1100,26 @@ as a base64 string.
return $cs;
}
-=head1 ENCRYPTION METHODS
+=head1 ENCRYPTION CONFIGURATION AND METHODS
+
+=over 4
+
+=item ENCRYPTION_PREFIX
+
+Specifies the prefix to be used when generating storing an encrypted
+file object. The prefix is used to determine whether or not a file
+object has been stored encrypted. This allows the gradual transition
+from unencrypted file objects to encrypted file objects. When file
+object encryption is enable any "get" of an unencyrpted file object
+will result in the replacement of the unencrypted object with an
+encrypted object. This variable must be set to use file and password
+encyrption.
+
+=cut
+
+our $ENCRYPTION_PREFIX;
+
+=back
The default encryption method is based on the twofish cypher. If
another encryption method is desired then the perl function file_crypt
|