fko-wrapper update to print fko_errstr() text, and to have one successful HMAC cycle
This commit is contained in:
parent
66399fed1a
commit
69ba2d7a06
@ -1,6 +1,7 @@
|
||||
/* This code is designed to call libfko functions multiple times without
|
||||
* calling fko_destroy() until the very end. This allows valgrind to verify
|
||||
* whether memory is proerly handled between calls.
|
||||
/*
|
||||
* This code is designed to repeatedly call libfko functions multiple times
|
||||
* with and without calling fko_destroy(). This allows valgrind to verify
|
||||
* whether memory is properly handled between calls.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -35,11 +36,11 @@ test_loop(int destroy_ctx_flag)
|
||||
int i;
|
||||
char *spa_data = NULL;
|
||||
|
||||
printf("fko_new(): %d\n", fko_new(&ctx));
|
||||
printf("fko_new(): %s\n", fko_errstr(fko_new(&ctx)));
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_client_timeout(30): %d\n",
|
||||
fko_set_spa_client_timeout(ctx, 30));
|
||||
printf("fko_set_spa_client_timeout(30): %s\n",
|
||||
fko_errstr(fko_set_spa_client_timeout(ctx, 30)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -48,8 +49,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_message_type(FKO_COMMAND_MSG): %d\n",
|
||||
fko_set_spa_message_type(ctx, FKO_COMMAND_MSG));
|
||||
printf("fko_set_spa_message_type(FKO_COMMAND_MSG): %s\n",
|
||||
fko_errstr(fko_set_spa_message_type(ctx, FKO_COMMAND_MSG)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -58,8 +59,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_message_type(FKO_ACCESS_MSG): %d\n",
|
||||
fko_set_spa_message_type(ctx, FKO_ACCESS_MSG));
|
||||
printf("fko_set_spa_message_type(FKO_ACCESS_MSG): %s\n",
|
||||
fko_errstr(fko_set_spa_message_type(ctx, FKO_ACCESS_MSG)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -68,8 +69,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_timestamp(%d): %d\n",
|
||||
i, fko_set_timestamp(ctx, i));
|
||||
printf("fko_set_timestamp(%d): %s\n",
|
||||
i, fko_errstr(fko_set_timestamp(ctx, i)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -78,8 +79,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_message(1.1.1.1,tcp/22): %d\n",
|
||||
fko_set_spa_message(ctx, "1.1.1.1,tcp/22"));
|
||||
printf("fko_set_spa_message(1.1.1.1,tcp/22): %s\n",
|
||||
fko_errstr(fko_set_spa_message(ctx, "1.1.1.1,tcp/22")));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -88,8 +89,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_nat_access(1.2.3.4,1234): %d\n",
|
||||
fko_set_spa_nat_access(ctx, "1.2.3.4,1234"));
|
||||
printf("fko_set_spa_nat_access(1.2.3.4,1234): %s\n",
|
||||
fko_errstr(fko_set_spa_nat_access(ctx, "1.2.3.4,1234")));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -98,8 +99,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_username(someuser): %d\n",
|
||||
fko_set_username(ctx, "someuser"));
|
||||
printf("fko_set_username(someuser): %s\n",
|
||||
fko_errstr(fko_set_username(ctx, "someuser")));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -108,8 +109,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_RIJNDAEL): %d\n",
|
||||
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_RIJNDAEL));
|
||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_RIJNDAEL): %s\n",
|
||||
fko_errstr(fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_RIJNDAEL)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -118,8 +119,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_encryption_mode(FKO_ENC_MODE_CBC): %d\n",
|
||||
fko_set_spa_encryption_mode(ctx, FKO_ENC_MODE_CBC));
|
||||
printf("fko_set_spa_encryption_mode(FKO_ENC_MODE_CBC): %s\n",
|
||||
fko_errstr(fko_set_spa_encryption_mode(ctx, FKO_ENC_MODE_CBC)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -129,8 +130,8 @@ test_loop(int destroy_ctx_flag)
|
||||
|
||||
if (ENABLE_GPG_TESTS) {
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_GPG): %d\n",
|
||||
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG));
|
||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_GPG): %s\n",
|
||||
fko_errstr(fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -139,8 +140,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_gpg_home_dir(/home/mbr/.gnupg): %d\n",
|
||||
fko_set_gpg_home_dir(ctx, "/home/mbr/.gnupg"));
|
||||
printf("fko_set_gpg_home_dir(/home/mbr/.gnupg): %s\n",
|
||||
fko_errstr(fko_set_gpg_home_dir(ctx, "/home/mbr/.gnupg")));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -149,8 +150,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_gpg_recipient(1234asdf): %d\n",
|
||||
fko_set_gpg_recipient(ctx, "1234asdf"));
|
||||
printf("fko_set_gpg_recipient(1234asdf): %s\n",
|
||||
fko_errstr(fko_set_gpg_recipient(ctx, "1234asdf")));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -161,8 +162,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_digest_type(FKO_DEFAULT_DIGEST): %d\n",
|
||||
fko_set_spa_digest_type(ctx, FKO_DEFAULT_DIGEST));
|
||||
printf("fko_set_spa_digest_type(FKO_DEFAULT_DIGEST): %s\n",
|
||||
fko_errstr(fko_set_spa_digest_type(ctx, FKO_DEFAULT_DIGEST)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -171,8 +172,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_hmac_type(FKO_HMAC_SHA256): %d\n",
|
||||
fko_set_spa_hmac_type(ctx, FKO_HMAC_SHA256));
|
||||
printf("fko_set_spa_hmac_type(FKO_HMAC_SHA256): %s\n",
|
||||
fko_errstr(fko_set_spa_hmac_type(ctx, FKO_HMAC_SHA256)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -181,8 +182,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_spa_data_final(testtest, 8, hmactest, 8): %d\n",
|
||||
fko_spa_data_final(ctx, "testtest", 8, "hmactest", 8));
|
||||
printf("fko_spa_data_final(testtest, 8, hmactest, 8): %s\n",
|
||||
fko_errstr(fko_spa_data_final(ctx, "testtest", 8, "hmactest", 8)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
@ -191,8 +192,8 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_get_spa_data(): %d\n",
|
||||
fko_get_spa_data(ctx, &spa_data));
|
||||
printf("fko_get_spa_data(): %s\n",
|
||||
fko_errstr(fko_get_spa_data(ctx, &spa_data)));
|
||||
printf(" %s\n", spa_data == NULL ? "<NULL>" : spa_data);
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
@ -201,14 +202,42 @@ test_loop(int destroy_ctx_flag)
|
||||
}
|
||||
}
|
||||
|
||||
/* now decrypt */
|
||||
printf("fko_new_with_data(): %d\n",
|
||||
fko_new_with_data(&decrypt_ctx, spa_data, NULL,
|
||||
0, FKO_ENC_MODE_CBC, NULL, 0, 0));
|
||||
printf("fko_new_with_data(): %s\n",
|
||||
fko_errstr(fko_new_with_data(&decrypt_ctx, spa_data, NULL,
|
||||
0, FKO_ENC_MODE_CBC, NULL, 0, FKO_HMAC_SHA256)));
|
||||
|
||||
/* verify hmac, decrypt, and display ctx all together*/
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_decrypt_spa_data(): %d\n",
|
||||
fko_decrypt_spa_data(decrypt_ctx, "testtest", 8));
|
||||
printf("fko_verify_hmac(): %s\n",
|
||||
fko_errstr(fko_verify_hmac(decrypt_ctx, "hmactest", 8)));
|
||||
|
||||
printf("fko_decrypt_spa_data(): %s\n",
|
||||
fko_errstr(fko_decrypt_spa_data(decrypt_ctx, "testtest", 8)));
|
||||
|
||||
display_ctx(decrypt_ctx);
|
||||
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* now, separately verify hmac, decrypt, and display ctx */
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_verify_hmac(): %s\n",
|
||||
fko_errstr(fko_verify_hmac(decrypt_ctx, "hmactest", 8)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* now decrypt */
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_decrypt_spa_data(): %s\n",
|
||||
fko_errstr(fko_decrypt_spa_data(decrypt_ctx, "testtest", 8)));
|
||||
if (destroy_ctx_flag == CTX_DESTROY)
|
||||
{
|
||||
fko_destroy(ctx);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user