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"] ;
CONTENTS
========
* Object blob
* BLOB blob.hash()
* BLOB hash(BLOB)
* BLOB hmac(BLOB, BLOB)
* Object hmac
* BLOB hmac.hmac(BLOB)
* hmac(BLOB)
* blob(BLOB)
* BLOB hashf(BLOB)
* BLOB hmacf(BLOB, BLOB)
* STRING version()
.. _obj_hmac:
Object hmac
===========
hmac
----
::
Prototype
new OBJ = blobsha256.hmac(BLOB key)
new OBJ = hmac(BLOB key)
Description
Creates an object that generates HMACs based on SHA256 and the
......@@ -54,10 +52,11 @@ Example
.. _func_hmac.hmac:
BLOB hmac.hmac(BLOB)
--------------------
hmac.hmac
---------
::
Prototype
BLOB hmac.hmac(BLOB msg)
Description
......@@ -69,12 +68,12 @@ Example
.. _obj_blob:
Object blob
===========
blob
----
::
Prototype
new OBJ = blobsha256.blob(BLOB blob)
new OBJ = blob(BLOB blob)
Description
Creates an object that returns the SHA256 digest of the given
......@@ -86,10 +85,11 @@ Example
.. _func_blob.hash:
BLOB blob.hash()
----------------
blob.hash
---------
::
Prototype
BLOB blob.hash()
Description
......@@ -98,34 +98,37 @@ Description
Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
.. _func_hash:
.. _func_hashf:
hashf
-----
BLOB hash(BLOB)
---------------
::
Prototype
BLOB hash(BLOB msg)
BLOB hashf(BLOB msg)
Description
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
Returns the SHA256 HMAC for ``msg`` based on ``key``.
.. _func_version:
STRING version()
----------------
version
-------
::
Prototype
STRING version()
Description
......@@ -133,3 +136,23 @@ Description
Example
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
])# 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_BINDIR], [varnishapi], [bindir])
PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir])
......
......@@ -27,7 +27,8 @@ VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc
.PHONY: $(VMOD_TESTS)
$(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)
......
......@@ -5,8 +5,7 @@ varnishtest "SHA256 hash"
# VMOD blobcode must be installed
varnish v1 -vcl {
import blobsha256 from
"${vmod_topbuild}/src/.libs/libvmod_blobsha256.so";
import blobsha256 from "${vmod_topbuild}/src/.libs/libvmod_blobsha256.so";
import blobcode;
backend b { .host = "${bad_ip}"; }
......@@ -43,50 +42,50 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.empty
= blobcode.encode(HEXLC, blobsha256.hash(
= blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY, "")));
set resp.http.msgdigest
= blobcode.encode(HEXLC, blobsha256.hash(
= blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"message digest")));
set resp.http.alphanum
= blobcode.encode(HEXLC, blobsha256.hash(
= blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")));
set resp.http.a
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, "a")));
set resp.http.abc
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY, "abc")));
set resp.http.alphalc
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"abcdefghijklmnopqrstuvwxyz")));
set resp.http.pangram
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"The quick brown fox jumps over the lazy dog")));
set resp.http.alphasoup
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
set resp.http.digits
= blobcode.encode(HEXUC, blobsha256.hash(
= blobcode.encode(HEXUC, blobsha256.hashf(
blobcode.decode(IDENTITY,
"12345678901234567890123456789012345678901234567890123456789012345678901234567890")));
# all 256 byte values in ascending, big-endian order
set resp.http.allbytes
= blobcode.encode(HEXLC, blobsha256.hash(
= blobcode.encode(HEXLC, blobsha256.hashf(
blobcode.decode(BASE64,
"AQACAQMCBAMFBAYFBwYIBwkICgkLCgwLDQwODQ8OEA8REBIRExIUExUUFhUXFhgXGRgaGRsaHBsdHB4dHx4gHyEgIiEjIiQjJSQmJScmKCcpKCopKyosKy0sLi0vLjAvMTAyMTMyNDM1NDY1NzY4Nzk4Ojk7Ojw7PTw+PT8+QD9BQEJBQ0JEQ0VERkVHRkhHSUhKSUtKTEtNTE5NT05QT1FQUlFTUlRTVVRWVVdWWFdZWFpZW1pcW11cXl1fXmBfYWBiYWNiZGNlZGZlZ2ZoZ2loamlramxrbWxubW9ucG9xcHJxc3J0c3V0dnV3dnh3eXh6eXt6fHt9fH59f36Afw==")));
......@@ -131,48 +130,48 @@ varnish v1 -vcl {
# hmac function
set resp.http.rfc4231t1f = blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY, "Hi There"),
blobsha256.hmacf(blobcode.decode(IDENTITY, "Hi There"),
blobcode.decode(HEX,
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
)));
set resp.http.rfc4231t2f
= blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY,
blobsha256.hmacf(blobcode.decode(IDENTITY,
"what do ya want for nothing?"),
blobcode.decode(IDENTITY, "Jefe")));
set resp.http.rfc4231t3f
= blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(HEX,
blobsha256.hmacf(blobcode.decode(HEX,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"),
blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
set resp.http.rfc4231t4f
= blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(HEX,
blobsha256.hmacf(blobcode.decode(HEX,
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"),
blobcode.decode(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819")));
set resp.http.rfc4231t5f
= blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY,
blobsha256.hmacf(blobcode.decode(IDENTITY,
"Test With Truncation"),
blobcode.decode(HEX,
"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c")));
set resp.http.rfc4231t6f
= blobcode.encode(HEXLC,
blobsha256.hmac(blobcode.decode(IDENTITY,
blobsha256.hmacf(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key - Hash Key First"),
blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
set resp.http.rfc4231t7f
= 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."),
blobcode.decode(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
......
......@@ -244,7 +244,7 @@ vmod_blob__fini(struct vmod_blobsha256_blob **blobp)
/* Functions */
VCL_BLOB
vmod_hash(VRT_CTX, VCL_BLOB msg)
vmod_hashf(VRT_CTX, VCL_BLOB msg)
{
struct vmod_priv *b;
char *snap;
......@@ -275,7 +275,7 @@ vmod_hash(VRT_CTX, VCL_BLOB msg)
}
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;
char *snap;
......
......@@ -11,9 +11,6 @@ $Module blobsha256 3 SHA256 digests and hmacs for the VCL blob type
$Object hmac(BLOB key)
Prototype
new OBJ = blobsha256.hmac(BLOB key)
Description
Creates an object that generates HMACs based on SHA256 and the
given ``key``.
......@@ -33,9 +30,6 @@ Example
$Object blob(BLOB blob)
Prototype
new OBJ = blobsha256.blob(BLOB blob)
Description
Creates an object that returns the SHA256 digest of the given
``blob``.
......@@ -52,12 +46,12 @@ Description
Example
set req.http.X-Hash = blobcode.encode(BASE64, foo.hash());
$Function BLOB hash(BLOB msg)
$Function BLOB hashf(BLOB msg)
Description
Returns the SHA256 digest for ``msg``.
$Function BLOB hmac(BLOB msg, BLOB key)
$Function BLOB hmacf(BLOB msg, BLOB key)
Description
Returns the SHA256 HMAC for ``msg`` based on ``key``.
......@@ -69,3 +63,10 @@ Description
Example
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