Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobsha256
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobsha256
Commits
20a18423
Commit
20a18423
authored
Aug 11, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update for current Varnish master.
parent
14b0941c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
129 deletions
+131
-129
blob.vtc
src/tests/blob.vtc
+27
-29
sha256.vtc
src/tests/sha256.vtc
+72
-71
vmod_blobsha256.c
src/vmod_blobsha256.c
+32
-29
No files found.
src/tests/blob.vtc
View file @
20a18423
...
...
@@ -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 blob
code
;
import blob;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new emptyblob = blob
code
.blob(IDENTITY, "");
new emptyblob = blob.blob(IDENTITY, "");
new empty = blobsha256.blob(emptyblob.get());
new msgdigestblob = blob
code
.blob(IDENTITY, "message digest");
new msgdigestblob = blob.blob(IDENTITY, "message digest");
new msgdigest = blobsha256.blob(msgdigestblob.get());
new alphanumblob = blob
code
.blob(IDENTITY,
new alphanumblob = blob.blob(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
new alphanum = blobsha256.blob(alphanumblob.get());
new ablob = blob
code
.blob(IDENTITY, "a");
new ablob = blob.blob(IDENTITY, "a");
new a = blobsha256.blob(ablob.get());
new abcblob = blob
code
.blob(IDENTITY, "abc");
new abcblob = blob.blob(IDENTITY, "abc");
new abc = blobsha256.blob(abcblob.get());
new alphalcblob = blob
code
.blob(IDENTITY,
new alphalcblob = blob.blob(IDENTITY,
"abcdefghijklmnopqrstuvwxyz");
new alphalc = blobsha256.blob(alphalcblob.get());
new pangramblob = blob
code
.blob(IDENTITY,
new pangramblob = blob.blob(IDENTITY,
"The quick brown fox jumps over the lazy dog");
new pangram = blobsha256.blob(pangramblob.get());
new alphasoupblob = blob
code
.blob(IDENTITY,
new alphasoupblob = blob.blob(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
new alphasoup = blobsha256.blob(alphasoupblob.get());
new digitsblob = blob
code
.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 = blob
code
.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
= blob
code.encode(HEXLC,
empty.hash());
= blob
.encode(HEX, blob=
empty.hash());
set resp.http.msgdigest
= blob
code.encode(HEXLC,
msgdigest.hash());
= blob
.encode(HEX, blob=
msgdigest.hash());
set resp.http.alphanum
= blob
code.encode(HEXLC,
alphanum.hash());
= blob
.encode(HEX, blob=
alphanum.hash());
set resp.http.a
= blob
code.encode(HEXUC,
a.hash());
= blob
.encode(HEX, blob=
a.hash());
set resp.http.abc
= blob
code.encode(HEXUC,
abc.hash());
= blob
.encode(HEX, blob=
abc.hash());
set resp.http.alphalc
= blob
code.encode(HEXUC,
alphalc.hash());
= blob
.encode(HEX, blob=
alphalc.hash());
set resp.http.pangram
= blob
code.encode(HEXUC,
pangram.hash());
= blob
.encode(HEX, blob=
pangram.hash());
set resp.http.alphasoup
= blob
code.encode(HEXUC,
alphasoup.hash());
= blob
.encode(HEX, blob=
alphasoup.hash());
set resp.http.digits
= blob
code.encode(HEXUC,
digits.hash());
= blob
.encode(HEX, blob=
digits.hash());
set resp.http.allbytes
= blob
code.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 == "71
C480DF93D6AE2F1EFAD1447C66C9525E316218CF51FC8D9ED832F2DAF18B
73"
expect resp.http.pangram == "
D7A8FBB307D7809469CA9ABCB0082E4F8D5651E46D3CDB762D02D0BF37C9E
592"
expect resp.http.alphasoup == "248
D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C
1"
expect resp.http.digits == "
F371BC4A311F2B009EEF952DD83CA80E2B60026C8E935592D0F9C308453C813E
"
expect resp.http.a == "
ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
"
expect resp.http.abc == "
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
"
expect resp.http.alphalc == "71
c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b
73"
expect resp.http.pangram == "
d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e
592"
expect resp.http.alphasoup == "248
d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c
1"
expect resp.http.digits == "
f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e
"
# verified with: base 64 -d | sha256sum
expect resp.http.allbytes == "f62191c9a2deb78660d34fdf7070f1943211d46d13d1c26d9d8a1dc5bcb3e997"
...
...
src/tests/sha256.vtc
View file @
20a18423
This diff is collapsed.
Click to expand it.
src/vmod_blobsha256.c
View file @
20a18423
...
...
@@ -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
v
mod_priv
hash
;
struct
v
rt_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
v
mod_priv
*
b
;
struct
v
rt_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
v
mod_priv
*
b
;
struct
v
rt_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
v
mod_priv
*
b
;
struct
v
rt_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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment