Commit 20a18423 authored by Geoff Simmons's avatar Geoff Simmons

Update for current Varnish master.

parent 14b0941c
......@@ -2,50 +2,48 @@
varnishtest "blob object"
# VMOD blobcode must be installed
varnish v1 -vcl {
import blobsha256 from
"${vmod_topbuild}/src/.libs/libvmod_blobsha256.so";
import blobcode;
import blob;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new emptyblob = blobcode.blob(IDENTITY, "");
new emptyblob = blob.blob(IDENTITY, "");
new empty = blobsha256.blob(emptyblob.get());
new msgdigestblob = blobcode.blob(IDENTITY, "message digest");
new msgdigestblob = blob.blob(IDENTITY, "message digest");
new msgdigest = blobsha256.blob(msgdigestblob.get());
new alphanumblob = blobcode.blob(IDENTITY,
new alphanumblob = blob.blob(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
new alphanum = blobsha256.blob(alphanumblob.get());
new ablob = blobcode.blob(IDENTITY, "a");
new ablob = blob.blob(IDENTITY, "a");
new a = blobsha256.blob(ablob.get());
new abcblob = blobcode.blob(IDENTITY, "abc");
new abcblob = blob.blob(IDENTITY, "abc");
new abc = blobsha256.blob(abcblob.get());
new alphalcblob = blobcode.blob(IDENTITY,
new alphalcblob = blob.blob(IDENTITY,
"abcdefghijklmnopqrstuvwxyz");
new alphalc = blobsha256.blob(alphalcblob.get());
new pangramblob = blobcode.blob(IDENTITY,
new pangramblob = blob.blob(IDENTITY,
"The quick brown fox jumps over the lazy dog");
new pangram = blobsha256.blob(pangramblob.get());
new alphasoupblob = blobcode.blob(IDENTITY,
new alphasoupblob = blob.blob(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
new alphasoup = blobsha256.blob(alphasoupblob.get());
new digitsblob = blobcode.blob(IDENTITY,
new digitsblob = blob.blob(IDENTITY,
"12345678901234567890123456789012345678901234567890123456789012345678901234567890");
new digits = blobsha256.blob(digitsblob.get());
# all 256 byte values in ascending, big-endian order
new allbytesblob = blobcode.blob(BASE64,
new allbytesblob = blob.blob(BASE64,
"AQACAQMCBAMFBAYFBwYIBwkICgkLCgwLDQwODQ8OEA8REBIRExIUExUUFhUXFhgXGRgaGRsaHBsdHB4dHx4gHyEgIiEjIiQjJSQmJScmKCcpKCopKyosKy0sLi0vLjAvMTAyMTMyNDM1NDY1NzY4Nzk4Ojk7Ojw7PTw+PT8+QD9BQEJBQ0JEQ0VERkVHRkhHSUhKSUtKTEtNTE5NT05QT1FQUlFTUlRTVVRWVVdWWFdZWFpZW1pcW11cXl1fXmBfYWBiYWNiZGNlZGZlZ2ZoZ2loamlramxrbWxubW9ucG9xcHJxc3J0c3V0dnV3dnh3eXh6eXt6fHt9fH59f36Afw==");
new allbytes = blobsha256.blob(allbytesblob.get());
......@@ -57,34 +55,34 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.empty
= blobcode.encode(HEXLC, empty.hash());
= blob.encode(HEX, blob=empty.hash());
set resp.http.msgdigest
= blobcode.encode(HEXLC, msgdigest.hash());
= blob.encode(HEX, blob=msgdigest.hash());
set resp.http.alphanum
= blobcode.encode(HEXLC, alphanum.hash());
= blob.encode(HEX, blob=alphanum.hash());
set resp.http.a
= blobcode.encode(HEXUC, a.hash());
= blob.encode(HEX, blob=a.hash());
set resp.http.abc
= blobcode.encode(HEXUC, abc.hash());
= blob.encode(HEX, blob=abc.hash());
set resp.http.alphalc
= blobcode.encode(HEXUC, alphalc.hash());
= blob.encode(HEX, blob=alphalc.hash());
set resp.http.pangram
= blobcode.encode(HEXUC, pangram.hash());
= blob.encode(HEX, blob=pangram.hash());
set resp.http.alphasoup
= blobcode.encode(HEXUC, alphasoup.hash());
= blob.encode(HEX, blob=alphasoup.hash());
set resp.http.digits
= blobcode.encode(HEXUC, digits.hash());
= blob.encode(HEX, blob=digits.hash());
set resp.http.allbytes
= blobcode.encode(HEXLC, allbytes.hash());
= blob.encode(HEX, blob=allbytes.hash());
}
} -start
......@@ -99,12 +97,12 @@ client c1 {
expect resp.http.alphanum == "db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0"
# from librhash
expect resp.http.a == "CA978112CA1BBDCAFAC231B39A23DC4DA786EFF8147C4E72B9807785AFEE48BB"
expect resp.http.abc == "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"
expect resp.http.alphalc == "71C480DF93D6AE2F1EFAD1447C66C9525E316218CF51FC8D9ED832F2DAF18B73"
expect resp.http.pangram == "D7A8FBB307D7809469CA9ABCB0082E4F8D5651E46D3CDB762D02D0BF37C9E592"
expect resp.http.alphasoup == "248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1"
expect resp.http.digits == "F371BC4A311F2B009EEF952DD83CA80E2B60026C8E935592D0F9C308453C813E"
expect resp.http.a == "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"
expect resp.http.abc == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
expect resp.http.alphalc == "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
expect resp.http.pangram == "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"
expect resp.http.alphasoup == "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
expect resp.http.digits == "f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e"
# verified with: base 64 -d | sha256sum
expect resp.http.allbytes == "f62191c9a2deb78660d34fdf7070f1943211d46d13d1c26d9d8a1dc5bcb3e997"
......
This diff is collapsed.
......@@ -27,15 +27,14 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "config.h"
#include "cache/cache.h"
#include "vsha256.h"
#include "vcl.h"
#include "vrt.h"
#include "vas.h"
#include "vdef.h"
#include "cache/cache.h"
#include "vcl.h"
#include "vsb.h"
#include "vcc_if.h"
......@@ -58,7 +57,7 @@ struct vmod_blobsha256_hmac {
struct vmod_blobsha256_blob {
unsigned magic;
#define VMOD_BLOBSHA256_BLOB_MAGIC 0x2067c219
struct vmod_priv hash;
struct vrt_blob hash;
};
static void
......@@ -86,7 +85,7 @@ digest(VCL_BLOB restrict const b, uint8_t *restrict digest)
SHA256_CTX ctx[1];
SHA256_Init(ctx);
SHA256_Update(ctx, b->priv, b->len);
SHA256_Update(ctx, b->blob, b->len);
SHA256_Final(digest, ctx);
}
......@@ -98,7 +97,7 @@ hmac_init(VCL_BLOB restrict const key, SHA256_CTX * restrict const inner_ctx,
outerk[SHA256_BLOCKSZ];
if (key->len <= SHA256_BLOCKSZ)
memcpy(k, key->priv, key->len);
memcpy(k, key->blob, key->len);
else
digest(key, k);
......@@ -114,17 +113,17 @@ hmac_init(VCL_BLOB restrict const key, SHA256_CTX * restrict const inner_ctx,
static void
hmac_fini(VCL_BLOB restrict const msg, SHA256_CTX * restrict const inner_ctx,
SHA256_CTX * restrict const outer_ctx, VCL_BLOB restrict const result)
SHA256_CTX * restrict const outer_ctx, uint8_t * restrict const hmac)
{
uint8_t inner_digest[SHA256_LEN];
/* Hash the message with the inner key */
SHA256_Update(inner_ctx, msg->priv, msg->len);
SHA256_Update(inner_ctx, msg->blob, msg->len);
SHA256_Final(inner_digest, inner_ctx);
/* Hash the result with the outer key */
SHA256_Update(outer_ctx, inner_digest, SHA256_LEN);
SHA256_Final(result->priv, outer_ctx);
SHA256_Final(hmac, outer_ctx);
}
/* Object hmac */
......@@ -149,31 +148,32 @@ vmod_hmac__init(VRT_CTX, struct vmod_blobsha256_hmac **hmacp,
VCL_BLOB
vmod_hmac_hmac(VRT_CTX, struct vmod_blobsha256_hmac *h, VCL_BLOB msg)
{
struct vmod_priv *b;
struct vrt_blob *b;
uintptr_t snap;
SHA256_CTX inner_ctx[1], outer_ctx[1];
uint8_t *hmac;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(h, VMOD_BLOBSHA256_HMAC_MAGIC);
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
snap = WS_Snapshot(ctx->ws);
if ((b = WS_Alloc(ctx->ws, sizeof(struct vmod_priv))) == NULL) {
if ((b = WS_Alloc(ctx->ws, sizeof(*b))) == NULL) {
ERRNOMEM(ctx, "allocating blob in hmac.hmac()");
return NULL;
}
if ((b->priv = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
if ((hmac = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
WS_Reset(ctx->ws, snap);
ERRNOMEM(ctx, "allocating hash result in hmac.hmac()");
return NULL;
}
b->len = SHA256_LEN;
b->free = NULL;
memcpy(inner_ctx, &h->inner_ctx, sizeof(SHA256_CTX));
memcpy(outer_ctx, &h->outer_ctx, sizeof(SHA256_CTX));
hmac_fini(msg, inner_ctx, outer_ctx, b);
hmac_fini(msg, inner_ctx, outer_ctx, hmac);
b->blob = hmac;
return b;
}
......@@ -196,6 +196,7 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp,
const char *vcl_name, VCL_BLOB b)
{
struct vmod_blobsha256_blob *blob;
uint8_t *hash;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(blobp);
......@@ -205,15 +206,15 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp,
AN(blob);
*blobp = blob;
blob->hash.priv = malloc(SHA256_LEN);
if (blob->hash.priv == NULL) {
hash = malloc(SHA256_LEN);
if (hash == NULL) {
ERRNOMEM(ctx, "allocating hash in blob constructor");
return;
}
blob->hash.len = SHA256_LEN;
blob->hash.free = NULL;
digest(b, blob->hash.priv);
digest(b, hash);
blob->hash.blob = hash;
}
VCL_BLOB
......@@ -241,8 +242,9 @@ vmod_blob__fini(struct vmod_blobsha256_blob **blobp)
VCL_BLOB
vmod_hashf(VRT_CTX, VCL_BLOB msg)
{
struct vmod_priv *b;
struct vrt_blob *b;
uintptr_t snap;
uint8_t *hash;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (msg == NULL)
......@@ -250,27 +252,28 @@ vmod_hashf(VRT_CTX, VCL_BLOB msg)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
snap = WS_Snapshot(ctx->ws);
if ((b = WS_Alloc(ctx->ws, sizeof(struct vmod_priv))) == NULL) {
if ((b = WS_Alloc(ctx->ws, sizeof(*b))) == NULL) {
ERRNOMEM(ctx, "allocating blob in hash()");
return NULL;
}
if ((b->priv = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
if ((hash = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
WS_Reset(ctx->ws, snap);
ERRNOMEM(ctx, "allocating hash result in hash()");
return NULL;
}
b->len = SHA256_LEN;
b->free = NULL;
digest(msg, b->priv);
digest(msg, hash);
b->blob = hash;
return b;
}
VCL_BLOB
vmod_hmacf(VRT_CTX, VCL_BLOB msg, VCL_BLOB key)
{
struct vmod_priv *b;
struct vrt_blob *b;
uintptr_t snap;
SHA256_CTX inner_ctx[1], outer_ctx[1];
uint8_t *hmac;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (msg == NULL || key == NULL)
......@@ -278,20 +281,20 @@ vmod_hmacf(VRT_CTX, VCL_BLOB msg, VCL_BLOB key)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
snap = WS_Snapshot(ctx->ws);
if ((b = WS_Alloc(ctx->ws, sizeof(struct vmod_priv))) == NULL) {
if ((b = WS_Alloc(ctx->ws, sizeof(*b))) == NULL) {
ERRNOMEM(ctx, "allocating blob in blobsha256.hmac()");
return NULL;
}
if ((b->priv = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
if ((hmac = WS_Alloc(ctx->ws, SHA256_LEN)) == NULL) {
WS_Reset(ctx->ws, snap);
ERRNOMEM(ctx, "allocating hash result in blobsha256.hmac()");
return NULL;
}
b->len = SHA256_LEN;
b->free = NULL;
hmac_init(key, inner_ctx, outer_ctx);
hmac_fini(msg, inner_ctx, outer_ctx, b);
hmac_fini(msg, inner_ctx, outer_ctx, hmac);
b->blob = hmac;
return b;
}
......
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