Debian Codegraph @

README.html

raw
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Tie::EncryptedHash - Hashes with encrypting fields.</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:root@localhost" />
8 </head>
9
10 <body style="background-color: white">
11
12 <p><a name="__index__"></a></p>
13 <!-- INDEX BEGIN -->
14
15 <ul>
16
17 <li><a href="#name">NAME</a></li>
18 <li><a href="#synopsis">SYNOPSIS</a></li>
19 <li><a href="#description">DESCRIPTION</a></li>
20 <li><a href="#motivation">MOTIVATION</a></li>
21 <li><a href="#construction">CONSTRUCTION</a></li>
22 <ul>
23
24 <li><a href="#tied_hash">Tied Hash</a></li>
25 <li><a href="#blessed_object">Blessed Object</a></li>
26 </ul>
27
28 <li><a href="#reserved_attributes">RESERVED ATTRIBUTES</a></li>
29 <ul>
30
31 <li><a href="#__password">__password</a></li>
32 <li><a href="#__cipher">__cipher</a></li>
33 <li><a href="#__hide">__hide</a></li>
34 </ul>
35
36 <li><a href="#behavior">BEHAVIOR</a></li>
37 <ul>
38
39 <li><a href="#references">References</a></li>
40 <li><a href="#opaque_mode">Opaque Mode</a></li>
41 <li><a href="#multiple_passwords_and_ciphers">Multiple Passwords and Ciphers</a></li>
42 <li><a href="#error_handling">Error Handling</a></li>
43 </ul>
44
45 <li><a href="#quirks">QUIRKS</a></li>
46 <ul>
47
48 <li><a href="#autovivification">Autovivification</a></li>
49 <li><a href="#data__dumper">Data::Dumper</a></li>
50 <li><a href="#speed">Speed</a></li>
51 </ul>
52
53 <li><a href="#standard_usage">STANDARD USAGE</a></li>
54 <li><a href="#see_also">SEE ALSO</a></li>
55 <li><a href="#acknowledgements">ACKNOWLEDGEMENTS</a></li>
56 <li><a href="#author">AUTHOR</a></li>
57 <li><a href="#license">LICENSE </a></li>
58 </ul>
59 <!-- INDEX END -->
60
61 <hr />
62 <p>
63 </p>
64 <h1><a name="name">NAME</a></h1>
65 <p>Tie::EncryptedHash - Hashes (and objects based on hashes) with encrypting fields.</p>
66 <p>
67 </p>
68 <hr />
69 <h1><a name="synopsis">SYNOPSIS</a></h1>
70 <pre>
71 use Tie::EncryptedHash;</pre>
72 <pre>
73 my %s = ();
74 tie %s, Tie::EncryptedHash, 'passwd';</pre>
75 <pre>
76 $s{foo} = &quot;plaintext&quot;; # Normal field, stored in plaintext.
77 print $s{foo}; # (plaintext)
78
79 $s{_bar} = &quot;signature&quot;; # Fieldnames that begin in single
80 # underscore are encrypted.
81 print $s{_bar}; # (signature) Though, while the password
82 # is set, they behave like normal fields.
83 delete $s{__password}; # Delete password to disable access
84 # to encrypting fields.
85 print $s{_bar}; # (Blowfish NuRVFIr8UCAJu5AWY0w...)</pre>
86 <pre>
87 $s{__password} = 'passwd'; # Restore password to gain access.
88 print $s{_bar}; # (signature)
89
90 $s{_baz}{a}{b} = 42; # Refs are fine, we encrypt them too.</pre>
91 <p>
92 </p>
93 <hr />
94 <h1><a name="description">DESCRIPTION</a></h1>
95 <p>Tie::EncryptedHash augments Perl hash semantics to build secure, encrypting
96 containers of data. Tie::EncryptedHash introduces special hash fields that
97 are coupled with encrypt/decrypt routines to encrypt assignments at <code>STORE()</code>
98 and decrypt retrievals at FETCH(). By design, <em>encrypting fields</em> are
99 associated with keys that begin in single underscore. The remaining
100 keyspace is used for accessing normal hash fields, which are retained
101 without modification.</p>
102 <p>While the password is set, a Tie::EncryptedHash behaves exactly like a
103 standard Perl hash. This is its <em>transparent mode</em> of access. Encrypting
104 and normal fields are identical in this mode. When password is deleted,
105 encrypting fields are accessible only as ciphertext. This is
106 Tie::EncryptedHash's <em>opaque mode</em> of access, optimized for serialization.</p>
107 <p>Encryption is done with Crypt::CBC(3) which encrypts in the cipher block
108 chaining mode with Blowfish, DES or IDEA. Tie::EncryptedHash uses Blowfish
109 by default, but can be instructed to employ any cipher supported by
110 Crypt::CBC(3).</p>
111 <p>
112 </p>
113 <hr />
114 <h1><a name="motivation">MOTIVATION</a></h1>
115 <p>Tie::EncryptedHash was designed for storage and communication of key
116 material used in public key cryptography algorithms. I abstracted out the
117 mechanism for encrypting selected fields of a structured data record because
118 of the sheer convenience of this data security method.</p>
119 <p>Quite often, applications that require data confidentiality eschew strong
120 cryptography in favor of OS-based access control mechanisms because of the
121 additional costs of cryptography integration. Besides cipher
122 implementations, which are available as ready-to-deploy perl modules, use of
123 cryptography in an application requires code to aid conversion and
124 representation of encrypted data. This code is usually encapsulated in a
125 data access layer that manages encryption, decryption, access control and
126 re-structuring of flat plaintext according to a data model.
127 Tie::EncryptedHash provides these functions under the disguise of a Perl
128 hash so perl applications can use strong cryptography without the cost of
129 implementing a complex data access layer.</p>
130 <p>
131 </p>
132 <hr />
133 <h1><a name="construction">CONSTRUCTION</a></h1>
134 <p>
135 </p>
136 <h2><a name="tied_hash">Tied Hash</a></h2>
137 <p><code>tie %h, Tie::EncryptedHash, 'Password', 'Cipher';</code></p>
138 <p>Ties %h to Tie::EncryptedHash and sets the value of password and cipher to
139 'Password' and 'Cipher'. Both arguments are optional.</p>
140 <p>
141 </p>
142 <h2><a name="blessed_object">Blessed Object</a></h2>
143 <p><code>$h = new Tie::EncryptedHash __password =</code> 'Password',
144 __cipher =&gt; 'Cipher';&gt;</p>
145 <p>The <code>new()</code> constructor returns an object that is both tied and blessed into
146 Tie::EncryptedHash. Both arguments are optional. When used in this manner,
147 Tie::EncryptedHash behaves like a class with encrypting data members.</p>
148 <p>
149 </p>
150 <hr />
151 <h1><a name="reserved_attributes">RESERVED ATTRIBUTES</a></h1>
152 <p>The attributes __password, __cipher and __hide are reserved for
153 communication with object methods. They are ``write-only'' from everywhere
154 except the class to which the hash is tied. __scaffolding is inaccessible.
155 Tie::EncryptedHash stores the current encryption password and some transient
156 data structures in these fields and restricts access to them on need-to-know
157 basis.</p>
158 <p>
159 </p>
160 <h2><a name="__password">__password</a></h2>
161 <p><code>$h{__password} = &quot;new password&quot;;
162 delete $h{__password};</code></p>
163 <p>The password is stored under the attribute <code>__password</code>. In addition to
164 specifying a password at construction, assigning to the __password attribute
165 sets the current encryption password to the assigned value. Deleting the
166 __password unsets it and switches the hash into opaque mode.</p>
167 <p>
168 </p>
169 <h2><a name="__cipher">__cipher</a></h2>
170 <p><code>$h{__cipher} = 'DES'; $h{__cipher} = 'Blowfish';</code></p>
171 <p>The cipher used for encryption/decryption is stored under the attribute
172 __cipher. The value defaults to 'Blowfish'.</p>
173 <p>
174 </p>
175 <h2><a name="__hide">__hide</a></h2>
176 <p><code>$h{__hide} = 1;</code></p>
177 <p>Setting this attribute <em>hides</em> encrypting fields in opaque mode. 'undef'
178 is returned at <code>FETCH()</code> and EXISTS().</p>
179 <p>
180 </p>
181 <hr />
182 <h1><a name="behavior">BEHAVIOR</a></h1>
183 <p>
184 </p>
185 <h2><a name="references">References</a></h2>
186 <p>A reference stored in an encrypting field is serialized before encryption.
187 The data structure represented by the reference is folded into a single line
188 of ciphertext which is stored under the first level key. In the opaque
189 mode, therefore, only the first level of keys of the hash will be visible.</p>
190 <p>
191 </p>
192 <h2><a name="opaque_mode">Opaque Mode</a></h2>
193 <p>The opaque mode introduces several other constraints on access of encrypting
194 fields. Encrypting fields return ciphertext on <code>FETCH()</code> unless __hide
195 attribute is set, which forces Tie::EncryptedHash to behave as if encrypting
196 fields don't exist. Irrespective of __hide, however, <code>DELETE()</code> and <code>CLEAR()</code>
197 fail in opaque mode. So does <code>STORE()</code> on an existing encrypting field.
198 Plaintext assignments to encrypting fields are silently ignored, but
199 ciphertext assignments are fine. Ciphertext assignments can be used to move
200 data between different EncryptedHashes.</p>
201 <p>
202 </p>
203 <h2><a name="multiple_passwords_and_ciphers">Multiple Passwords and Ciphers</a></h2>
204 <p>Modality of Tie::EncryptedHash's access system breaks down when more than
205 one password is used to with different encrypting fields. This is a
206 feature. Tie::EncryptedHash lets you mix passwords and ciphers in the same
207 hash. Assign new values to __password and __cipher and create a new
208 encrypting field. Transparent mode will be restricted to fields encrypted
209 with the current password.</p>
210 <p>
211 </p>
212 <h2><a name="error_handling">Error Handling</a></h2>
213 <p>Tie::Encrypted silently ignores access errors. It doesn't carp/croak when
214 you perform an illegal operation (like assign plaintext to an encrypting
215 field in opaque mode). This is to prevent data lossage, the kind that
216 results from abnormal termination of applications.</p>
217 <p>
218 </p>
219 <hr />
220 <h1><a name="quirks">QUIRKS</a></h1>
221 <p>
222 </p>
223 <h2><a name="autovivification">Autovivification</a></h2>
224 <p>Due to the nature of autovivified references (which spring into existence
225 when an undefined reference is dereferenced), references are stored as
226 plaintext in transparent mode. Analogous ciphertext representations are
227 maintained in parallel and restored to encrypting fields when password is
228 deleted. This process is completely transparent to the user, though it's
229 advisable to delete the password after the final assignment to a
230 Tie::EncryptedHash. This ensures plaintext representations and scaffolding
231 data structures are duly flushed.</p>
232 <p>
233 </p>
234 <h2><a name="data__dumper">Data::Dumper</a></h2>
235 <p>Serialization of references is done with Data::Dumper, therefore the nature
236 of data that can be assigned to encrypting fields is limited by what
237 Data::Dumper can grok. We set $Data::Dumper::Purity = 1, so
238 self-referential and recursive structures should be OK.</p>
239 <p>
240 </p>
241 <h2><a name="speed">Speed</a></h2>
242 <p>Tie::EncryptedHash'es keep their contents encrypted as much as possible, so
243 there's a rather severe speed penalty. With Blowfish, <code>STORE()</code> on
244 EncryptedHash can be upto 70 times slower than a standard perl hash.
245 Reference STORE()'es will be quicker, but speed gain will be adjusted at
246 FETCH(). <code>FETCH()</code> is about 35 times slower than a standard perl hash. DES
247 affords speed improvements of upto 2x, but is not considered secure for
248 long-term storage of data. These values were computed on a DELL PIII-300
249 Mhz notebook with 128 Mb RAM running perl 5.003 on Linux 2.2.16. Variations
250 in speed might be different on your machine.</p>
251 <p>
252 </p>
253 <hr />
254 <h1><a name="standard_usage">STANDARD USAGE</a></h1>
255 <p>The standard usage for this module would be something along the lines of:
256 populate Tie::EncryptedHash with sensitive data, delete the password,
257 serialize the encrypted hash with Data::Dumper, store the result on disk or
258 send it over the wire to another machine. Later, when the sensitive data is
259 required, procure the EncryptedHash, set the password and accesses the
260 encrypted data fields.</p>
261 <p>
262 </p>
263 <hr />
264 <h1><a name="see_also">SEE ALSO</a></h1>
265 <p>Data::Dumper(3),
266 Crypt::CBC(3),
267 Crypt::DES(3),
268 Crypt::Blowfish(3),
269 Tie::SecureHash(3)</p>
270 <p>
271 </p>
272 <hr />
273 <h1><a name="acknowledgements">ACKNOWLEDGEMENTS</a></h1>
274 <p>The framework of Tie::EncryptedHash derives heavily from Damian Conway's
275 Tie::SecureHash. Objects that are blessed as well as tied are just one of
276 the pleasant side-effects of stealing Damian's code. Thanks to Damian for
277 this brilliant module.</p>
278 <p>PacificNet (http://www.pacificnet.net) loaned me the aforementioned notebook
279 to hack from the comfort of my bed. Thanks folks!</p>
280 <p>
281 </p>
282 <hr />
283 <h1><a name="author">AUTHOR</a></h1>
284 <p>Vipul Ved Prakash &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</p>
285 <p>
286 </p>
287 <hr />
288 <h1><a name="license">LICENSE</a></h1>
289 <p>This module is distributed under the same license as Perl itself.
290
291 </p>
292
293 </body>
294
295 </html>