Search
Varnish Enterprise

Introduction Installation Upgrading Troubleshooting Changelog Changelog for 6.0.x Changes (Varnish Cache 4.1) Changes (Varnish Cache Plus 4.1) Known Issues Features Backend SSL/TLS Client SSL/TLS termination Cluster In-Process TLS MSE 4 Basic Configuration / Getting Started Configuration Persisted caching Categories Configuration Reference MSE 3.0 Settings mkfs.mse Memory Governor MSE 2.0 NUMA Parallel ESI Backend health counter HTTP/2 Support JSON Logging TCP Only Probes Timeouts Transit Buffer Varnish scoreboard VMODs Accept Accounting ACL (aclplus) ActiveDNS Akamai Connector AWS VCL Body Access & Transformation (xbody) Brotli Cookie Plus (cookieplus) DeviceAtlas DeviceAtlas3 Digest Dynamic backends (goto) Edgestash File Format Geolocation (geoip/mmdb) Header Manipulation (headerplus) HTTP communication (http) Image JSON parsing (json) JWT Key value storage (kvstore) Least connections director (leastconn) Module to control the built-in HTTP2 transport (h2) MSE control (mse) MSE4 control (mse4) Probe Proxy ProxyV2 TLV Attribute Extraction (proxy) Pseudo Random Number Generator Purge (purge/softpurge) Real-time Status (rtstatus) Reverse DNS (resolver) Rewrite S3 VMOD Session Slicer SQLite3 Stale Standard (std) Stat (Prometheus) Strings (str) Synthetic backends (synthbackend) Tag-based invalidation (Ykey/Xkey) TCP configuration (tcp) TLS Total Encryption (crypto) Unified director object (udo) Uniform Resource Identifier (uri) Unix Socket Utilities (unix) URL Plus (urlplus) Utils Vsthrottle

Digest

Description

The digest vmod allows for computing HMAC, message digests and working with base64.

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

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.

hmac_(hash)

All the various hmac-functions work the same, but use a different hash mechanism. Hex-encoded prepended with 0x.

For example

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

base64, base64url, base64url_nopad

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.

For example

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

base64_hex, base64url_hex, base64url_nopad_hex

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.

For example

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

hash_(algorithm)

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.

For example

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

base64_decode, base64url_decode, base64url_nopad_decode

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.

For example

synthetic(digest.base64_decode(req.http.x-parrot));

Example

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!"));
  }
}

API

hmac_sha256

STRING hmac_sha256(STRING, STRING)

Arguments: None

Type: Function

Returns: String

hmac_sha1

STRING hmac_sha1(STRING, STRING)

Arguments: None

Type: Function

Returns: String

hmac_md5

STRING hmac_md5(STRING, STRING)

Arguments: None

Type: Function

Returns: String

base64

STRING base64(STRING)

Arguments: None

Type: Function

Returns: String

base64_hex

STRING base64_hex(STRING)

Arguments: None

Type: Function

Returns: String

base64_decode

STRING base64_decode(STRING)

Arguments: None

Type: Function

Returns: String

base64url

STRING base64url(STRING)

Arguments: None

Type: Function

Returns: String

base64url_hex

STRING base64url_hex(STRING)

Arguments: None

Type: Function

Returns: String

base64url_decode

STRING base64url_decode(STRING)

Arguments: None

Type: Function

Returns: String

base64url_nopad

STRING base64url_nopad(STRING)

Arguments: None

Type: Function

Returns: String

base64url_nopad_hex

STRING base64url_nopad_hex(STRING)

Arguments: None

Type: Function

Returns: String

base64url_nopad_decode

STRING base64url_nopad_decode(STRING)

Arguments: None

Type: Function

Returns: String

hash_sha1

STRING hash_sha1(STRING)

Arguments: None

Type: Function

Returns: String

hash_sha224

STRING hash_sha224(STRING)

Arguments: None

Type: Function

Returns: String

hash_sha256

STRING hash_sha256(STRING)

Arguments: None

Type: Function

Returns: String

hash_sha384

STRING hash_sha384(STRING)

Arguments: None

Type: Function

Returns: String

hash_sha512

STRING hash_sha512(STRING)

Arguments: None

Type: Function

Returns: String

hash_md5

STRING hash_md5(STRING)

Arguments: None

Type: Function

Returns: String

hash_ripemd160

STRING hash_ripemd160(STRING)

Only available on platforms with openssl newer than 3.0.7 or libmash

Arguments: None

Type: Function

Returns: String

hash_gost

STRING hash_gost(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_md2

STRING hash_md2(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_md4

STRING hash_md4(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_crc32

STRING hash_crc32(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_crc32b

STRING hash_crc32b(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_adler32

STRING hash_adler32(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_haval128

STRING hash_haval128(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_haval160

STRING hash_haval160(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_haval192

STRING hash_haval192(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_haval224

STRING hash_haval224(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_haval256

STRING hash_haval256(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_ripemd128

STRING hash_ripemd128(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_ripemd256

STRING hash_ripemd256(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_ripemd320

STRING hash_ripemd320(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_tiger

STRING hash_tiger(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_tiger128

STRING hash_tiger128(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_tiger160

STRING hash_tiger160(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_snefru128

STRING hash_snefru128(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_snefru256

STRING hash_snefru256(STRING)

Only available on platforms with libmash

Arguments: None

Type: Function

Returns: String

hash_whirlpool

STRING hash_whirlpool(STRING)

  • libmhash
  • varnishd(1)
  • vcl(7)

Arguments: None

Type: Function

Returns: String

Availability

The digest VMOD is available in Varnish Enterprise version 6.0.0r0 and later.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203