.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "VMOD_DIGEST" 3 "2016-03-16" "1.0.2" .SH NAME vmod_digest \- Varnish Digest Module .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX import digest; digest.hmac_md5(,); digest.hmac_sha1(, ); digest.hmac_sha256(, ); digest.base64url(); digest.base64url_nopad(); digest.base64_hex(); digest.base64url_hex(); digest.base64url_nopad_hex(); digest.base64_decode(); digest.base64url_decode(); digest.base64url_nopad_decode(); digest.version() digest.hash_sha1(); digest.hash_sha224(); digest.hash_sha256(); digest.hash_sha384(); digest.hash_sha512(); digest.hash_gost(); digest.hash_md2(); digest.hash_md4(); digest.hash_md5(); digest.hash_crc32(); digest.hash_crc32b(); digest.hash_adler32(); digest.hash_haval128(); digest.hash_haval160(); digest.hash_haval192(); digest.hash_haval224(); digest.hash_haval256(); digest.hash_ripemd128(); digest.hash_ripemd160(); digest.hash_ripemd256(); digest.hash_ripemd320(); digest.hash_tiger(); digest.hash_tiger128(); digest.hash_tiger160(); digest.hash_snefru128(); digest.hash_snefru256(); .EE .UNINDENT .UNINDENT .SH DESCRIPTION .sp Varnish Module (vmod) for computing HMAC, message digests and working with base64. .sp All HMAC\- and hash\-functionality is provided by libmhash, while base64 is implemented locally. .SH FUNCTIONS .sp Example VCL: .INDENT 0.0 .INDENT 3.5 .sp .EX backend foo { ... }; import digest; sub vcl_recv { if (digest.hmac_sha256(\(dqkey\(dq,req.http.x\-data) != req.http.x\-data\-sig) { return (synth(401, \(dqNaughty user!\(dq)); } } .EE .UNINDENT .UNINDENT .SS hmac_(hash) .INDENT 0.0 .TP .B Prototype .INDENT 7.0 .INDENT 3.5 .sp .EX digest.hmac_md5(,); digest.hmac_sha1(, ); digest.hmac_sha256(, ); digest.base64url(); digest.base64url_nopad(); .EE .UNINDENT .UNINDENT .TP .B Returns String .TP .B 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. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .EX set resp.http.x\-data\-sig = digest.base64({\(dqcontent with newline in it\(dq}); .EE .UNINDENT .UNINDENT .UNINDENT .SS base64_hex, base64url_hex, base64url_nopad_hex .INDENT 0.0 .TP .B Prototype .INDENT 7.0 .INDENT 3.5 .sp .EX digest.base64_hex(); digest.base64url_hex(); digest.base64url_nopad_hex(); .EE .UNINDENT .UNINDENT .TP .B Returns String .TP .B 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. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .EX set resp.http.x\-data\-sig = digest.base64_hex(\(dq0xdd26bfddf122c1055d4c\(dq); .EE .UNINDENT .UNINDENT .UNINDENT .SS hash_(algorithm) .INDENT 0.0 .TP .B Prototype .INDENT 7.0 .INDENT 3.5 .sp .EX digest.hash_sha1(); digest.hash_sha224(); digest.hash_sha256(); digest.hash_sha384(); digest.hash_sha512(); digest.hash_gost(); digest.hash_md2(); digest.hash_md4(); digest.hash_md5(); digest.hash_crc32(); digest.hash_crc32b(); digest.hash_adler32(); digest.hash_haval128(); digest.hash_haval160(); digest.hash_haval192(); digest.hash_haval224(); digest.hash_haval256(); digest.hash_ripemd128(); digest.hash_ripemd160(); digest.hash_ripemd256(); digest.hash_ripemd320(); digest.hash_tiger(); digest.hash_tiger128(); digest.hash_tiger160(); digest.hash_snefru128(); digest.hash_snefru256(); .EE .UNINDENT .UNINDENT .TP .B Returns String .TP .B 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. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .EX set resp.http.x\-data\-md5 = digest.hash_md5(resp.http.x\-data); .EE .UNINDENT .UNINDENT .UNINDENT .SS base64_decode, base64url_decode, base64url_nopad_decode .INDENT 0.0 .TP .B Prototype .INDENT 7.0 .INDENT 3.5 .sp .EX digest.base64_decode(); digest.base64url_decode(); digest.base64url_nopad_decode(); .EE .UNINDENT .UNINDENT .TP .B Returns String .TP .B 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. .TP .B Example .INDENT 7.0 .TP .B :: synthetic(digest.base64_decode(req.http.x\-parrot)); .UNINDENT .UNINDENT .SS version .INDENT 0.0 .TP .B Prototype .INDENT 7.0 .INDENT 3.5 .sp .EX digest.version() .EE .UNINDENT .UNINDENT .TP .B Returns string .TP .B Description Returns the string constant version\-number of the digest vmod. .TP .B Example .INDENT 7.0 .INDENT 3.5 .sp .EX set resp.http.X\-digest\-version = digest.version(); .EE .UNINDENT .UNINDENT .UNINDENT .SH INSTALLATION .sp 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 \fBvarnishtest\fP tool. .sp Building requires the Varnish header files and uses pkg\-config to find the necessary paths. .sp Usage: .INDENT 0.0 .INDENT 3.5 .sp .EX \&./autogen.sh \&./configure .EE .UNINDENT .UNINDENT .sp If you have installed Varnish to a non\-standard directory, call \fBautogen.sh\fP and \fBconfigure\fP with \fBPKG_CONFIG_PATH\fP pointing to the appropriate path. For example, when varnishd configure was called with \fB\-\-prefix=$PREFIX\fP, use .INDENT 0.0 .INDENT 3.5 PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig export PKG_CONFIG_PATH .UNINDENT .UNINDENT .sp Make targets: .INDENT 0.0 .IP \(bu 2 make \- builds the vmod. .IP \(bu 2 make install \- installs your vmod. .IP \(bu 2 make check \- runs the unit tests in \fBsrc/tests/*.vtc\fP .IP \(bu 2 make distcheck \- run check and prepare a tarball of the vmod. .UNINDENT .SH AUTHOR .sp Original author: Kristian Lyngstøl <\fI\%kristian@varnish\-software.com\fP>. .sp This Vmod was written for Media Norge, Schibsted and others. .sp The bulk of the functionality is acquired through libmhash. .SH BUGS .sp No bugs at all! .sp 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). .sp The \fIbase64url_nopad_decode()\fP and \fIbase64url_decode()\fP 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. .SH SEE ALSO .INDENT 0.0 .IP \(bu 2 libmhash .IP \(bu 2 varnishd(1) .IP \(bu 2 vcl(7) .IP \(bu 2 \fI\%https://github.com/varnish/libvmod\-digest\fP .UNINDENT .SH AUTHOR Kristian Lyngstøl .\" Generated by docutils manpage writer. .