Commit d09f51c2 authored by Geoff Simmons's avatar Geoff Simmons

Compatibility with Varnish 5.0.

This forces a change in the function names to hashf() and hmacf(),
since it is not possible for a VMOD to have object method names
that are the same as function names.
parent fb281624
Pipeline #195 skipped
...@@ -27,22 +27,20 @@ import blobsha256 [from "path"] ; ...@@ -27,22 +27,20 @@ import blobsha256 [from "path"] ;
CONTENTS CONTENTS
======== ========
* Object blob * hmac(BLOB)
* BLOB blob.hash() * blob(BLOB)
* BLOB hash(BLOB) * BLOB hashf(BLOB)
* BLOB hmac(BLOB, BLOB) * BLOB hmacf(BLOB, BLOB)
* Object hmac
* BLOB hmac.hmac(BLOB)
* STRING version() * STRING version()
.. _obj_hmac: .. _obj_hmac:
Object hmac hmac
=========== ----
::
Prototype new OBJ = hmac(BLOB key)
new OBJ = blobsha256.hmac(BLOB key)
Description Description
Creates an object that generates HMACs based on SHA256 and the Creates an object that generates HMACs based on SHA256 and the
...@@ -54,10 +52,11 @@ Example ...@@ -54,10 +52,11 @@ Example
.. _func_hmac.hmac: .. _func_hmac.hmac:
BLOB hmac.hmac(BLOB) hmac.hmac
-------------------- ---------
::
Prototype
BLOB hmac.hmac(BLOB msg) BLOB hmac.hmac(BLOB msg)
Description Description
...@@ -69,12 +68,12 @@ Example ...@@ -69,12 +68,12 @@ Example
.. _obj_blob: .. _obj_blob:
Object blob blob
=========== ----
::
Prototype new OBJ = blob(BLOB blob)
new OBJ = blobsha256.blob(BLOB blob)
Description Description
Creates an object that returns the SHA256 digest of the given Creates an object that returns the SHA256 digest of the given
...@@ -86,10 +85,11 @@ Example ...@@ -86,10 +85,11 @@ Example
.. _func_blob.hash: .. _func_blob.hash:
BLOB blob.hash() blob.hash
---------------- ---------
::
Prototype
BLOB blob.hash() BLOB blob.hash()
Description Description
...@@ -98,34 +98,37 @@ Description ...@@ -98,34 +98,37 @@ Description
Example Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash()); set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
.. _func_hash: .. _func_hashf:
hashf
-----
BLOB hash(BLOB) ::
---------------
Prototype BLOB hashf(BLOB msg)
BLOB hash(BLOB msg)
Description Description
Returns the SHA256 digest for ``msg``. Returns the SHA256 digest for ``msg``.
.. _func_hmac: .. _func_hmacf:
BLOB hmac(BLOB, BLOB) hmacf
--------------------- -----
Prototype ::
BLOB hmac(BLOB msg, BLOB key)
BLOB hmacf(BLOB msg, BLOB key)
Description Description
Returns the SHA256 HMAC for ``msg`` based on ``key``. Returns the SHA256 HMAC for ``msg`` based on ``key``.
.. _func_version: .. _func_version:
STRING version() version
---------------- -------
::
Prototype
STRING version() STRING version()
Description Description
...@@ -133,3 +136,23 @@ Description ...@@ -133,3 +136,23 @@ Description
Example Example
std.log("Using VMOD blobsha256 version " + blobsha256.version()); std.log("Using VMOD blobsha256 version " + blobsha256.version());
REQUIREMENTS
------------
This version of the VMOD requires at least Varnish 5.0. See the
project repository for versions that are compatible with other Varnish
versions.
COPYRIGHT
=========
::
Copyright (c) 2016 UPLEX Nils Goroll Systemoptimierung
All rights reserved
Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
See LICENSE
...@@ -59,7 +59,7 @@ AS_VAR_IF([$1], [""], [$5], [$4])dnl ...@@ -59,7 +59,7 @@ AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR ])# PKG_CHECK_VAR
]) ])
PKG_CHECK_MODULES([libvarnishapi], [varnishapi]) PKG_CHECK_MODULES([libvarnishapi], [varnishapi >= 5.0.0])
PKG_CHECK_VAR([LIBVARNISHAPI_DATAROOTDIR], [varnishapi], [datarootdir]) PKG_CHECK_VAR([LIBVARNISHAPI_DATAROOTDIR], [varnishapi], [datarootdir])
PKG_CHECK_VAR([LIBVARNISHAPI_BINDIR], [varnishapi], [bindir]) PKG_CHECK_VAR([LIBVARNISHAPI_BINDIR], [varnishapi], [bindir])
PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir]) PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir])
......
...@@ -27,7 +27,8 @@ VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc ...@@ -27,7 +27,8 @@ VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc
.PHONY: $(VMOD_TESTS) .PHONY: $(VMOD_TESTS)
$(top_srcdir)/src/tests/*.vtc: libvmod_blobsha256.la $(top_srcdir)/src/tests/*.vtc: libvmod_blobsha256.la
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@ PATH=@LIBVARNISHAPI_SBINDIR@:$$PATH \
@VARNISHTEST@ -Dvmod_topbuild=$(abs_top_builddir) $@
check: $(VMOD_TESTS) check: $(VMOD_TESTS)
......
...@@ -5,8 +5,7 @@ varnishtest "SHA256 hash" ...@@ -5,8 +5,7 @@ varnishtest "SHA256 hash"
# VMOD blobcode must be installed # VMOD blobcode must be installed
varnish v1 -vcl { varnish v1 -vcl {
import blobsha256 from import blobsha256 from "${vmod_topbuild}/src/.libs/libvmod_blobsha256.so";
"${vmod_topbuild}/src/.libs/libvmod_blobsha256.so";
import blobcode; import blobcode;
backend b { .host = "${bad_ip}"; } backend b { .host = "${bad_ip}"; }
...@@ -43,50 +42,50 @@ varnish v1 -vcl { ...@@ -43,50 +42,50 @@ varnish v1 -vcl {
sub vcl_synth { sub vcl_synth {
set resp.http.empty set resp.http.empty
= blobcode.encode(HEXLC, blobsha256.hash( = blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY, ""))); blobcode.decode(IDENTITY, "")));
set resp.http.msgdigest set resp.http.msgdigest
= blobcode.encode(HEXLC, blobsha256.hash( = blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"message digest"))); "message digest")));
set resp.http.alphanum set resp.http.alphanum
= blobcode.encode(HEXLC, blobsha256.hash( = blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"))); "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")));
set resp.http.a set resp.http.a
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, "a"))); blobcode.decode(IDENTITY, "a")));
set resp.http.abc set resp.http.abc
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, "abc"))); blobcode.decode(IDENTITY, "abc")));
set resp.http.alphalc set resp.http.alphalc
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"abcdefghijklmnopqrstuvwxyz"))); "abcdefghijklmnopqrstuvwxyz")));
set resp.http.pangram set resp.http.pangram
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"The quick brown fox jumps over the lazy dog"))); "The quick brown fox jumps over the lazy dog")));
set resp.http.alphasoup set resp.http.alphasoup
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
set resp.http.digits set resp.http.digits
= blobcode.encode(HEXUC, blobsha256.hash( = blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, blobcode.decode(IDENTITY,
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"))); "12345678901234567890123456789012345678901234567890123456789012345678901234567890")));
# all 256 byte values in ascending, big-endian order # all 256 byte values in ascending, big-endian order
set resp.http.allbytes set resp.http.allbytes
= blobcode.encode(HEXLC, blobsha256.hash( = blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(BASE64, blobcode.decode(BASE64,
"AQACAQMCBAMFBAYFBwYIBwkICgkLCgwLDQwODQ8OEA8REBIRExIUExUUFhUXFhgXGRgaGRsaHBsdHB4dHx4gHyEgIiEjIiQjJSQmJScmKCcpKCopKyosKy0sLi0vLjAvMTAyMTMyNDM1NDY1NzY4Nzk4Ojk7Ojw7PTw+PT8+QD9BQEJBQ0JEQ0VERkVHRkhHSUhKSUtKTEtNTE5NT05QT1FQUlFTUlRTVVRWVVdWWFdZWFpZW1pcW11cXl1fXmBfYWBiYWNiZGNlZGZlZ2ZoZ2loamlramxrbWxubW9ucG9xcHJxc3J0c3V0dnV3dnh3eXh6eXt6fHt9fH59f36Afw=="))); "AQACAQMCBAMFBAYFBwYIBwkICgkLCgwLDQwODQ8OEA8REBIRExIUExUUFhUXFhgXGRgaGRsaHBsdHB4dHx4gHyEgIiEjIiQjJSQmJScmKCcpKCopKyosKy0sLi0vLjAvMTAyMTMyNDM1NDY1NzY4Nzk4Ojk7Ojw7PTw+PT8+QD9BQEJBQ0JEQ0VERkVHRkhHSUhKSUtKTEtNTE5NT05QT1FQUlFTUlRTVVRWVVdWWFdZWFpZW1pcW11cXl1fXmBfYWBiYWNiZGNlZGZlZ2ZoZ2loamlramxrbWxubW9ucG9xcHJxc3J0c3V0dnV3dnh3eXh6eXt6fHt9fH59f36Afw==")));
...@@ -131,48 +130,48 @@ varnish v1 -vcl { ...@@ -131,48 +130,48 @@ varnish v1 -vcl {
# hmac function # hmac function
set resp.http.rfc4231t1f = blobcode.encode(HEXLC, set resp.http.rfc4231t1f = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, "Hi There"), blobsha256.hmacf(blobcode.decode(IDENTITY, "Hi There"),
blobcode.decode(HEX, blobcode.decode(HEX,
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
))); )));
set resp.http.rfc4231t2f set resp.http.rfc4231t2f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, blobsha256.hmacf(blobcode.decode(IDENTITY,
"what do ya want for nothing?"), "what do ya want for nothing?"),
blobcode.decode(IDENTITY, "Jefe"))); blobcode.decode(IDENTITY, "Jefe")));
set resp.http.rfc4231t3f set resp.http.rfc4231t3f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(HEX, blobsha256.hmacf(blobcode.decode(HEX,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"), "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"),
blobcode.decode(HEX, blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
set resp.http.rfc4231t4f set resp.http.rfc4231t4f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(HEX, blobsha256.hmacf(blobcode.decode(HEX,
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"),
blobcode.decode(HEX, blobcode.decode(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819"))); "0102030405060708090a0b0c0d0e0f10111213141516171819")));
set resp.http.rfc4231t5f set resp.http.rfc4231t5f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, blobsha256.hmacf(blobcode.decode(IDENTITY,
"Test With Truncation"), "Test With Truncation"),
blobcode.decode(HEX, blobcode.decode(HEX,
"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c"))); "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c")));
set resp.http.rfc4231t6f set resp.http.rfc4231t6f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, blobsha256.hmacf(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key - Hash Key First"), "Test Using Larger Than Block-Size Key - Hash Key First"),
blobcode.decode(HEX, blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
set resp.http.rfc4231t7f set resp.http.rfc4231t7f
= blobcode.encode(HEXLC, = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, blobsha256.hmacf(blobcode.decode(IDENTITY,
"This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm."), "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm."),
blobcode.decode(HEX, blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
......
...@@ -244,7 +244,7 @@ vmod_blob__fini(struct vmod_blobsha256_blob **blobp) ...@@ -244,7 +244,7 @@ vmod_blob__fini(struct vmod_blobsha256_blob **blobp)
/* Functions */ /* Functions */
VCL_BLOB VCL_BLOB
vmod_hash(VRT_CTX, VCL_BLOB msg) vmod_hashf(VRT_CTX, VCL_BLOB msg)
{ {
struct vmod_priv *b; struct vmod_priv *b;
char *snap; char *snap;
...@@ -275,7 +275,7 @@ vmod_hash(VRT_CTX, VCL_BLOB msg) ...@@ -275,7 +275,7 @@ vmod_hash(VRT_CTX, VCL_BLOB msg)
} }
VCL_BLOB VCL_BLOB
vmod_hmac(VRT_CTX, VCL_BLOB msg, VCL_BLOB key) vmod_hmacf(VRT_CTX, VCL_BLOB msg, VCL_BLOB key)
{ {
struct vmod_priv *b; struct vmod_priv *b;
char *snap; char *snap;
......
...@@ -11,9 +11,6 @@ $Module blobsha256 3 SHA256 digests and hmacs for the VCL blob type ...@@ -11,9 +11,6 @@ $Module blobsha256 3 SHA256 digests and hmacs for the VCL blob type
$Object hmac(BLOB key) $Object hmac(BLOB key)
Prototype
new OBJ = blobsha256.hmac(BLOB key)
Description Description
Creates an object that generates HMACs based on SHA256 and the Creates an object that generates HMACs based on SHA256 and the
given ``key``. given ``key``.
...@@ -33,9 +30,6 @@ Example ...@@ -33,9 +30,6 @@ Example
$Object blob(BLOB blob) $Object blob(BLOB blob)
Prototype
new OBJ = blobsha256.blob(BLOB blob)
Description Description
Creates an object that returns the SHA256 digest of the given Creates an object that returns the SHA256 digest of the given
``blob``. ``blob``.
...@@ -52,12 +46,12 @@ Description ...@@ -52,12 +46,12 @@ Description
Example Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash()); set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
$Function BLOB hash(BLOB msg) $Function BLOB hashf(BLOB msg)
Description Description
Returns the SHA256 digest for ``msg``. Returns the SHA256 digest for ``msg``.
$Function BLOB hmac(BLOB msg, BLOB key) $Function BLOB hmacf(BLOB msg, BLOB key)
Description Description
Returns the SHA256 HMAC for ``msg`` based on ``key``. Returns the SHA256 HMAC for ``msg`` based on ``key``.
...@@ -69,3 +63,10 @@ Description ...@@ -69,3 +63,10 @@ Description
Example Example
std.log("Using VMOD blobsha256 version " + blobsha256.version()); std.log("Using VMOD blobsha256 version " + blobsha256.version());
REQUIREMENTS
------------
This version of the VMOD requires at least Varnish 5.0. See the
project repository for versions that are compatible with other Varnish
versions.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment