[test suite] added fko_destroy() calls to fko-wrapper
This commit is contained in:
parent
1caf6035d9
commit
838782f198
@ -13,119 +13,229 @@
|
|||||||
#include "fko.h"
|
#include "fko.h"
|
||||||
|
|
||||||
#define ENABLE_GPG_TESTS 0
|
#define ENABLE_GPG_TESTS 0
|
||||||
#define FCN_CALLS 5
|
#define FCN_CALLS 5
|
||||||
|
#define CTX_DESTROY 0
|
||||||
|
#define NO_CTX_DESTROY 1
|
||||||
|
|
||||||
static void display_ctx(fko_ctx_t ctx);
|
static void display_ctx(fko_ctx_t ctx);
|
||||||
|
static void test_loop(int destroy_ctx_flag);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
test_loop(NO_CTX_DESTROY);
|
||||||
|
test_loop(CTX_DESTROY);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_loop(int destroy_ctx_flag)
|
||||||
|
{
|
||||||
fko_ctx_t ctx = NULL, decrypt_ctx = NULL;
|
fko_ctx_t ctx = NULL, decrypt_ctx = NULL;
|
||||||
int i;
|
int i;
|
||||||
char *spa_data;
|
char *spa_data = NULL;
|
||||||
|
|
||||||
printf("fko_new(): %d\n", fko_new(&ctx));
|
printf("fko_new(): %d\n", fko_new(&ctx));
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_client_timeout(30): %d\n",
|
printf("fko_set_spa_client_timeout(30): %d\n",
|
||||||
fko_set_spa_client_timeout(ctx, 30));
|
fko_set_spa_client_timeout(ctx, 30));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_message_type(FKO_COMMAND_MSG): %d\n",
|
printf("fko_set_spa_message_type(FKO_COMMAND_MSG): %d\n",
|
||||||
fko_set_spa_message_type(ctx, FKO_COMMAND_MSG));
|
fko_set_spa_message_type(ctx, FKO_COMMAND_MSG));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_message_type(FKO_ACCESS_MSG): %d\n",
|
printf("fko_set_spa_message_type(FKO_ACCESS_MSG): %d\n",
|
||||||
fko_set_spa_message_type(ctx, FKO_ACCESS_MSG));
|
fko_set_spa_message_type(ctx, FKO_ACCESS_MSG));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_timestamp(%d): %d\n",
|
printf("fko_set_timestamp(%d): %d\n",
|
||||||
i, fko_set_timestamp(ctx, i));
|
i, fko_set_timestamp(ctx, i));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_message(1.1.1.1,tcp/22): %d\n",
|
printf("fko_set_spa_message(1.1.1.1,tcp/22): %d\n",
|
||||||
fko_set_spa_message(ctx, "1.1.1.1,tcp/22"));
|
fko_set_spa_message(ctx, "1.1.1.1,tcp/22"));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_nat_access(1.2.3.4,1234): %d\n",
|
printf("fko_set_spa_nat_access(1.2.3.4,1234): %d\n",
|
||||||
fko_set_spa_nat_access(ctx, "1.2.3.4,1234"));
|
fko_set_spa_nat_access(ctx, "1.2.3.4,1234"));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_username(someuser): %d\n",
|
printf("fko_set_username(someuser): %d\n",
|
||||||
fko_set_username(ctx, "someuser"));
|
fko_set_username(ctx, "someuser"));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_RIJNDAEL): %d\n",
|
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_RIJNDAEL): %d\n",
|
||||||
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_RIJNDAEL));
|
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_RIJNDAEL));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_encryption_mode(FKO_ENC_MODE_CBC): %d\n",
|
printf("fko_set_spa_encryption_mode(FKO_ENC_MODE_CBC): %d\n",
|
||||||
fko_set_spa_encryption_mode(ctx, FKO_ENC_MODE_CBC));
|
fko_set_spa_encryption_mode(ctx, FKO_ENC_MODE_CBC));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ENABLE_GPG_TESTS) {
|
if (ENABLE_GPG_TESTS) {
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_GPG): %d\n",
|
printf("fko_set_spa_encryption_type(FKO_ENCRYPTION_GPG): %d\n",
|
||||||
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG));
|
fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_gpg_home_dir(/home/mbr/.gnupg): %d\n",
|
printf("fko_set_gpg_home_dir(/home/mbr/.gnupg): %d\n",
|
||||||
fko_set_gpg_home_dir(ctx, "/home/mbr/.gnupg"));
|
fko_set_gpg_home_dir(ctx, "/home/mbr/.gnupg"));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_gpg_recipient(1234asdf): %d\n",
|
printf("fko_set_gpg_recipient(1234asdf): %d\n",
|
||||||
fko_set_gpg_recipient(ctx, "1234asdf"));
|
fko_set_gpg_recipient(ctx, "1234asdf"));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_digest_type(FKO_DEFAULT_DIGEST): %d\n",
|
printf("fko_set_spa_digest_type(FKO_DEFAULT_DIGEST): %d\n",
|
||||||
fko_set_spa_digest_type(ctx, FKO_DEFAULT_DIGEST));
|
fko_set_spa_digest_type(ctx, FKO_DEFAULT_DIGEST));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_set_spa_hmac_type(FKO_HMAC_SHA256): %d\n",
|
printf("fko_set_spa_hmac_type(FKO_HMAC_SHA256): %d\n",
|
||||||
fko_set_spa_hmac_type(ctx, FKO_HMAC_SHA256));
|
fko_set_spa_hmac_type(ctx, FKO_HMAC_SHA256));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_spa_data_final(testtest, 8, hmactest, 8): %d\n",
|
printf("fko_spa_data_final(testtest, 8, hmactest, 8): %d\n",
|
||||||
fko_spa_data_final(ctx, "testtest", 8, "hmactest", 8));
|
fko_spa_data_final(ctx, "testtest", 8, "hmactest", 8));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_get_spa_data(): %d\n",
|
printf("fko_get_spa_data(): %d\n",
|
||||||
fko_get_spa_data(ctx, &spa_data));
|
fko_get_spa_data(ctx, &spa_data));
|
||||||
printf(" %s\n", spa_data);
|
printf(" %s\n", spa_data == NULL ? "<NULL>" : spa_data);
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now decrypt */
|
/* now decrypt */
|
||||||
printf("fko_new_with_data(): %d\n",
|
printf("fko_new_with_data(): %d\n",
|
||||||
fko_new_with_data(&decrypt_ctx, spa_data, NULL,
|
fko_new_with_data(&decrypt_ctx, spa_data, NULL,
|
||||||
0, ctx->encryption_mode, NULL, 0, 0));
|
0, FKO_ENC_MODE_CBC, NULL, 0, 0));
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
printf("fko_decrypt_spa_data(): %d\n",
|
printf("fko_decrypt_spa_data(): %d\n",
|
||||||
fko_decrypt_spa_data(decrypt_ctx, "testtest", 8));
|
fko_decrypt_spa_data(decrypt_ctx, "testtest", 8));
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<FCN_CALLS; i++) {
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
display_ctx(decrypt_ctx);
|
display_ctx(decrypt_ctx);
|
||||||
|
if (destroy_ctx_flag == CTX_DESTROY)
|
||||||
|
{
|
||||||
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fko_destroy(ctx);
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
fko_destroy(decrypt_ctx);
|
fko_destroy(ctx);
|
||||||
|
ctx = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
for (i=0; i<FCN_CALLS; i++) {
|
||||||
|
fko_destroy(decrypt_ctx);
|
||||||
|
decrypt_ctx = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show the fields of the FKO context.
|
/* Show the fields of the FKO context.
|
||||||
@ -179,7 +289,7 @@ display_ctx(fko_ctx_t ctx)
|
|||||||
printf(" Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
|
printf(" Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
|
||||||
printf(" Nat Access: %s\n", nat_access == NULL ? "<NULL>" : nat_access);
|
printf(" Nat Access: %s\n", nat_access == NULL ? "<NULL>" : nat_access);
|
||||||
printf(" Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
|
printf(" Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
|
||||||
printf(" Client Timeout: %u\n", client_timeout);
|
printf(" Client Timeout: %d\n", client_timeout);
|
||||||
printf(" Digest Type: %d\n", digest_type);
|
printf(" Digest Type: %d\n", digest_type);
|
||||||
printf(" HMAC Type: %d\n", hmac_type);
|
printf(" HMAC Type: %d\n", hmac_type);
|
||||||
printf("Encryption Mode: %d\n", encryption_mode);
|
printf("Encryption Mode: %d\n", encryption_mode);
|
||||||
@ -192,4 +302,3 @@ display_ctx(fko_ctx_t ctx)
|
|||||||
|
|
||||||
printf("\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n", spa_data);
|
printf("\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n", spa_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user