File: README.rst

package info (click to toggle)
varnish-vmod-digest 6.4%2B20220108-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176 kB
  • sloc: ansic: 362; sh: 68; makefile: 60
file content (297 lines) | stat: -rw-r--r-- 8,285 bytes parent folder | download
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
===========
vmod_digest
===========

---------------------
Varnish Digest Module
---------------------

:Manual section: 3
:Author: Kristian Lyngstøl
:Date: 2016-03-16
:Version: 1.0.2

SYNOPSIS
========

::

        import digest;

        digest.hmac_md5(<key>,<message>);
        digest.hmac_sha1(<key>, <message>);
        digest.hmac_sha256(<key>, <message));

        digest.base64(<string>);
        digest.base64url(<string>);
        digest.base64url_nopad(<string>);
        digest.base64_hex(<string>);
        digest.base64url_hex(<string>);
        digest.base64url_nopad_hex(<string>);
        digest.base64_decode(<string>);
        digest.base64url_decode(<string>);
        digest.base64url_nopad_decode(<string>);

        digest.version()

        digest.hash_sha1(<string>);
        digest.hash_sha224(<string>);
        digest.hash_sha256(<string>);
        digest.hash_sha384(<string>);
        digest.hash_sha512(<string>);
        digest.hash_gost(<string>);
        digest.hash_md2(<string>);
        digest.hash_md4(<string>);
        digest.hash_md5(<string>);
        digest.hash_crc32(<string>);
        digest.hash_crc32b(<string>);
        digest.hash_adler32(<string>);
        digest.hash_haval128(<string>);
        digest.hash_haval160(<string>);
        digest.hash_haval192(<string>);
        digest.hash_haval224(<string>);
        digest.hash_haval256(<string>);
        digest.hash_ripemd128(<string>);
        digest.hash_ripemd160(<string>);
        digest.hash_ripemd256(<string>);
        digest.hash_ripemd320(<string>);
        digest.hash_tiger(<string>);
        digest.hash_tiger128(<string>);
        digest.hash_tiger160(<string>);
        digest.hash_snefru128(<string>);
        digest.hash_snefru256(<string>);

DESCRIPTION
===========

Varnish Module (vmod) for computing HMAC, message digests and working with
base64.

All HMAC- and hash-functionality is provided by libmhash, while base64 is
implemented locally.

FUNCTIONS
=========

Example VCL::

	backend foo { ... };

	import digest;

	sub vcl_recv {
		if (digest.hmac_sha256("key",req.http.x-data) != req.http.x-data-sig)
		{
			return (synth(401, "Naughty user!"));
		}
	}


hmac_(hash)
-----------

Prototype
        ::

	        digest.hmac_md5(<key>,<message>);
	        digest.hmac_sha1(<key>, <message>);
	        digest.hmac_sha256(<key>, <message));
Returns
        String. Hex-encoded prepended with 0x.
Description
        All the various hmac-functions work the same, but use a different
	hash mechanism.
Example
        ::

                set resp.http.x-data-sig =
                        digest.hmac_sha256("secretkey",resp.http.x-data);

base64, base64url, base64url_nopad
----------------------------------

Prototype
        ::

                digest.base64(<string>);
                digest.base64url(<string>);
                digest.base64url_nopad(<string>);
Returns
        String
Description
        Returns the base64-encoded version of the input-string. The
        base64url-variant uses base64 url-encoding (+/ replaced by -_) and
        the base64url_nopad does the same, but avoids adding padding. The
        latter is more commonly used, though an (allowed) exception to the
        RFC4648.
Example
        ::

                set resp.http.x-data-sig =
                        digest.base64({"content with
                        newline in it"});

base64_hex, base64url_hex, base64url_nopad_hex
-----------------------------------------------

Prototype
        ::

                digest.base64_hex(<string>);
                digest.base64url_hex(<string>);
                digest.base64url_nopad_hex(<string>);
Returns
        String
Description
        Returns the base64-encoded version of the hex encoded input-string. The
        input-string can start with an optional 0x. Input is hex-decoded into binary
        and the encoding is identical to base64, base64url, and base64url_nopad.
Example
        ::

                set resp.http.x-data-sig =
                        digest.base64_hex("0xdd26bfddf122c1055d4c");

hash_(algorithm)
----------------

Prototype
        ::

                digest.hash_sha1(<string>);
                digest.hash_sha224(<string>);
                digest.hash_sha256(<string>);
                digest.hash_sha384(<string>);
                digest.hash_sha512(<string>);
                digest.hash_gost(<string>);
                digest.hash_md2(<string>);
                digest.hash_md4(<string>);
                digest.hash_md5(<string>);
                digest.hash_crc32(<string>);
                digest.hash_crc32b(<string>);
                digest.hash_adler32(<string>);
                digest.hash_haval128(<string>);
                digest.hash_haval160(<string>);
                digest.hash_haval192(<string>);
                digest.hash_haval224(<string>);
                digest.hash_haval256(<string>);
                digest.hash_ripemd128(<string>);
                digest.hash_ripemd160(<string>);
                digest.hash_ripemd256(<string>);
                digest.hash_ripemd320(<string>);
                digest.hash_tiger(<string>);
                digest.hash_tiger128(<string>);
                digest.hash_tiger160(<string>);
                digest.hash_snefru128(<string>);
                digest.hash_snefru256(<string>);
Returns
        String
Description
        Computes the digest/hash of the supplied, using the specified hash
        algorithm. If in doubt as to which to pick, use SHA256. For
        detailed discussions, see The Internet.
Example
        ::

                set resp.http.x-data-md5 =
                        digest.hash_md5(resp.http.x-data);

base64_decode, base64url_decode, base64url_nopad_decode
-------------------------------------------------------

Prototype
        ::

                digest.base64_decode(<string>);
                digest.base64url_decode(<string>);
                digest.base64url_nopad_decode(<string>);
Returns
        String
Description
        Decodes the bas64 and base64url-encoded strings. All functions
        treat padding the same, meaning base64url_decode and
        base64url_nopad_decode are identical, but available for consistency
        and practicality.
Example
        ::
                synthetic(digest.base64_decode(req.http.x-parrot));

version
-------

Prototype
        ::

                digest.version()
Returns
        string
Description
        Returns the string constant version-number of the digest vmod.
Example
        ::

                set resp.http.X-digest-version = digest.version();


INSTALLATION
============

The source tree is based on autotools to configure the building, and
does also have the necessary bits in place to do functional unit tests
using the ``varnishtest`` tool.

Building requires the Varnish header files and uses pkg-config to find
the necessary paths.

Usage::

 ./autogen.sh
 ./configure

If you have installed Varnish to a non-standard directory, call
``autogen.sh`` and ``configure`` with ``PKG_CONFIG_PATH`` pointing to
the appropriate path. For example, when varnishd configure was called
with ``--prefix=$PREFIX``, use

 PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
 export PKG_CONFIG_PATH

Make targets:

* make - builds the vmod.
* make install - installs your vmod.
* make check - runs the unit tests in ``src/tests/*.vtc``
* make distcheck - run check and prepare a tarball of the vmod.


AUTHOR
======

Original author: Kristian Lyngstøl <kristian@varnish-software.com>.

This Vmod was written for Media Norge, Schibsted and others.

The bulk of the functionality is acquired through libmhash.


BUGS
====

No bugs at all!

If the key is NULL for hmac-functions, the function will fail and return
NULL itself, and do no hmac-computation at all. This should be used as an
indication of some greater flaw in your software/VCL. (I.e.: Your key
should be under your control, not user-supplied without verification).

The `base64url_nopad_decode()` and `base64url_decode()` functions do not
differ much. The exception is that nopad_decode() does not know about
padding at all, and might get confused if the input actually is padded.

SEE ALSO
========

* libmhash
* varnishd(1)
* vcl(7)
* https://github.com/varnish/libvmod-digest