Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.

Commit b51a31d

Browse files
committed
Updates for 0.11
- Fixes realloc bug - Fixes pkgconfig bug.
1 parent 66ab9e3 commit b51a31d

File tree

6 files changed

+66
-12
lines changed

6 files changed

+66
-12
lines changed

NEWS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
jose-c NEWS -- history of user-visible changes
22
Copyright (C) 2014-2015 Cryptotronix, LLC.
33

4-
Noteworthy changes in version 0.10.0 (TBD)
4+
Noteworthy changes in version 0.11.0 (Friday, 16 Oct 2015)
5+
----------------------------------------------------
6+
* Fixes realloc bug in jwe_encrypt
7+
* Fixes pkg-config template for missing directory
8+
9+
10+
Noteworthy changes in version 0.10.0 (Thursday, 8 Oct 2015)
511
----------------------------------------------------
612
* Adds JWE support for alg=A256KW, enc=A256GCM if compiled
713
--with-openssl.

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with libcryptoauth. If not, see <http://www.gnu.org/licenses/>.
1717

18-
AC_INIT([libjose-c], [0.10.0], [bugs@cryptotronix.com], [josec],
18+
AC_INIT([libjose-c], [0.11.0], [bugs@cryptotronix.com], [josec],
1919
[https://github.com/cryptotronix/jose-c])
2020
AC_PREREQ([2.59])
2121
AC_USE_SYSTEM_EXTENSIONS
@@ -59,7 +59,7 @@ AC_DEFINE([JOSEC_HAVE_OPENSSL], [1], [Use OpenSSL backend])
5959
# For information on how to properly maintain the library version information,
6060
# refer to the libtool manual, section "Updating library version information":
6161
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
62-
AC_SUBST([JOSEC_SO_VERSION], [7:0:0])
62+
AC_SUBST([JOSEC_SO_VERSION], [7:1:0])
6363
AC_SUBST([JOSEC_API_VERSION], [0.10])
6464

6565
# Override the template file name of the generated .pc file, so that there

josec.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Description: Library for produce JOSE messages
88
Version: @PACKAGE_VERSION@
99
URL: @PACKAGE_URL@
1010
Libs: -L${libdir} -ljosec
11-
Cflags: -I${includedir}/josec-@JOSEC_API_VERSION@ -I${libdir}/josec-@JOSEC_API_VERSION@/include
11+
Cflags: -I${includedir}/josec-@JOSEC_API_VERSION@

src/jwe.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,20 @@ create_cek (const json_t *kek, const uint8_t key[JWE_AESKW_KEY_SIZE],
393393
return rc;
394394
}
395395

396+
static char*
397+
_realloc_zero (char *orig, size_t nl)
398+
{
399+
size_t ol = strlen(orig);
400+
assert (nl > ol);
401+
assert (NULL != orig);
402+
403+
char *out = realloc (orig, nl);
404+
assert (out);
405+
memset (out+ol, 0, nl-ol);
406+
407+
return out;
408+
}
409+
396410
static const char *
397411
build_jwe (json_t *hdr, json_t *cek, json_t *iv,
398412
json_t *ciphertext, json_t *tag)
@@ -407,6 +421,7 @@ build_jwe (json_t *hdr, json_t *cek, json_t *iv,
407421
size_t l = json_string_length (hdr);
408422
size_t tot = l + 2;
409423
char *tmp = malloc (tot);
424+
memset (tmp, 0, tot);
410425
assert (tmp);
411426

412427
strncpy (tmp, json_string_value (hdr), l);
@@ -415,16 +430,16 @@ build_jwe (json_t *hdr, json_t *cek, json_t *iv,
415430
l = json_string_length (cek);
416431
tot = tot + l + 2;
417432

418-
tmp = realloc (tmp, tot);
419-
assert (tmp);
433+
tmp = _realloc_zero (tmp, tot);
434+
420435
strncat (tmp, json_string_value (cek), l);
421436
strcat (tmp, ".");
422437

423438
/* Add iv */
424439
l = json_string_length (iv);
425440
tot = tot + l + 2;
426441

427-
tmp = realloc (tmp, tot);
442+
tmp = _realloc_zero (tmp, tot);
428443
assert (tmp);
429444
strncat (tmp, json_string_value (iv), l);
430445
strcat (tmp, ".");
@@ -433,7 +448,7 @@ build_jwe (json_t *hdr, json_t *cek, json_t *iv,
433448
l = json_string_length (ciphertext);
434449
tot = tot + l + 2;
435450

436-
tmp = realloc (tmp, tot);
451+
tmp = _realloc_zero (tmp, tot);
437452
assert (tmp);
438453
strncat (tmp, json_string_value (ciphertext), l);
439454
strcat (tmp, ".");
@@ -442,7 +457,7 @@ build_jwe (json_t *hdr, json_t *cek, json_t *iv,
442457
l = json_string_length (tag);
443458
tot = tot + l + 1;
444459

445-
tmp = realloc (tmp, tot);
460+
tmp = _realloc_zero (tmp, tot);
446461
assert (tmp);
447462
strncat (tmp, json_string_value (tag), l);
448463

test/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ check_libjosec_LDADD = $(LIBS_TO_ADD) $(CRYPTO_LIBS)
3131

3232
check_jwe_SOURCES = test_jwe.c $(top_builddir)/libjosec.h
3333
check_jwe_CFLAGS = @CHECK_CFLAGS@ $(CFLAGS_TO_ADD)
34-
check_jwe_LDADD = $(LIBS_TO_ADD) $(CRYPTO_LIBS)
34+
check_jwe_LDADD = $(LIBS_TO_ADD) $(CRYPTO_LIBS) $(OPENSSL_LIBS)
3535

3636
# jwtwrap_SOURCES = jwt_wrap.c $(top_builddir)/libjosec.h
3737
# jwtwrap_CFLAGS = $(CFLAGS_TO_ADD)

test/test_jwe.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,35 @@ START_TEST(test_jwe_failures)
158158
}
159159
END_TEST
160160

161+
START_TEST(t_loop)
162+
{
163+
int i;
164+
for (i=0; i<1000; i++)
165+
{
166+
json_t *alg = json_string ("A256KW");
167+
uint8_t t[32];
168+
memset (t, 0x61, 32);
169+
170+
json_t *jwk = jwk_build_symmetric_key (alg, t, 32);
171+
172+
uint8_t p[256];
173+
memset (p, 0x62, 256);
174+
175+
const char *jwe;
176+
int rc = jwe_encrypt (A256KW, A256GCM, p, 256, jwk, &jwe);
177+
178+
ck_assert_msg (0 == rc, "RC = %d", rc);
179+
printf ("JWE: %s\n", jwe);
180+
181+
uint8_t *out;
182+
size_t outl;
183+
rc = jwe_decrypt (jwk, jwe, &out, &outl);
184+
185+
ck_assert_msg (0 == rc, "RC: %d", rc);
186+
}
187+
}
188+
END_TEST
189+
161190
static Suite *
162191
jwe_suite(void)
163192
{
@@ -169,9 +198,11 @@ jwe_suite(void)
169198
/* Core test case */
170199
tc_core = tcase_create("Core");
171200

172-
//tcase_add_test(tc_core, t_build_key);
173-
//tcase_add_test(tc_core, test_jwe_encrypt);
201+
202+
tcase_add_test(tc_core, t_build_key);
203+
tcase_add_test(tc_core, test_jwe_encrypt);
174204
tcase_add_test(tc_core, test_jwe_failures);
205+
tcase_add_test(tc_core, t_loop);
175206

176207
suite_add_tcase(s, tc_core);
177208

@@ -188,6 +219,8 @@ int main(void)
188219
s = jwe_suite();
189220
sr = srunner_create(s);
190221

222+
init_ssl();
223+
srunner_set_fork_status (sr, CK_NOFORK);
191224
srunner_run_all(sr, CK_NORMAL);
192225
number_failed = srunner_ntests_failed(sr);
193226
srunner_free(sr);

0 commit comments

Comments
 (0)