added decryption tests to fko-wrapper
This commit is contained in:
@@ -15,16 +15,15 @@
|
||||
#define ENABLE_GPG_TESTS 0
|
||||
#define FCN_CALLS 5
|
||||
|
||||
static void display_ctx(fko_ctx_t ctx);
|
||||
|
||||
int main(void) {
|
||||
|
||||
fko_ctx_t ctx = NULL;
|
||||
fko_ctx_t ctx = NULL, decrypt_ctx = NULL;
|
||||
int i;
|
||||
char *spa_data;
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
/* call fko_new() several times without also calling fko_destroy() */
|
||||
printf("fko_new(): %d\n", fko_new(&ctx));
|
||||
}
|
||||
printf("fko_new(): %d\n", fko_new(&ctx));
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_set_spa_client_timeout(30): %d\n",
|
||||
@@ -89,8 +88,13 @@ int main(void) {
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_spa_data_final(testtest, 8, NULL, 0): %d\n",
|
||||
fko_spa_data_final(ctx, "testtest", 8, NULL, 0));
|
||||
printf("fko_set_hmac_mode(FKO_HMAC_SHA256): %d\n",
|
||||
fko_set_hmac_mode(ctx, FKO_HMAC_SHA256));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
@@ -99,7 +103,85 @@ int main(void) {
|
||||
printf(" %s\n", spa_data);
|
||||
}
|
||||
|
||||
/* now decrypt */
|
||||
printf("fko_new_with_data(): %d\n",
|
||||
fko_new_with_data(&decrypt_ctx, spa_data, NULL,
|
||||
0, ctx->encryption_mode, NULL, 0));
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
printf("fko_decrypt_spa_data(): %d\n",
|
||||
fko_decrypt_spa_data(decrypt_ctx, "testtest", 8));
|
||||
}
|
||||
|
||||
for (i=0; i<FCN_CALLS; i++) {
|
||||
display_ctx(decrypt_ctx);
|
||||
}
|
||||
|
||||
fko_destroy(ctx);
|
||||
fko_destroy(decrypt_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Show the fields of the FKO context.
|
||||
*/
|
||||
static void
|
||||
display_ctx(fko_ctx_t ctx)
|
||||
{
|
||||
char *rand_val = NULL;
|
||||
char *username = NULL;
|
||||
char *version = NULL;
|
||||
char *spa_message = NULL;
|
||||
char *nat_access = NULL;
|
||||
char *server_auth = NULL;
|
||||
char *enc_data = NULL;
|
||||
char *hmac_data = NULL;
|
||||
char *spa_digest = NULL;
|
||||
char *spa_data = NULL;
|
||||
|
||||
time_t timestamp = 0;
|
||||
short msg_type = -1;
|
||||
short digest_type = -1;
|
||||
int encryption_mode = -1;
|
||||
int client_timeout = -1;
|
||||
|
||||
/* Should be checking return values, but this is temp code. --DSS
|
||||
*/
|
||||
fko_get_rand_value(ctx, &rand_val);
|
||||
fko_get_username(ctx, &username);
|
||||
fko_get_timestamp(ctx, ×tamp);
|
||||
fko_get_version(ctx, &version);
|
||||
fko_get_spa_message_type(ctx, &msg_type);
|
||||
fko_get_spa_message(ctx, &spa_message);
|
||||
fko_get_spa_nat_access(ctx, &nat_access);
|
||||
fko_get_spa_server_auth(ctx, &server_auth);
|
||||
fko_get_spa_client_timeout(ctx, &client_timeout);
|
||||
fko_get_spa_digest_type(ctx, &digest_type);
|
||||
fko_get_spa_encryption_mode(ctx, &encryption_mode);
|
||||
fko_get_encoded_data(ctx, &enc_data);
|
||||
fko_get_hmac_data(ctx, &hmac_data);
|
||||
fko_get_spa_digest(ctx, &spa_digest);
|
||||
fko_get_spa_data(ctx, &spa_data);
|
||||
|
||||
printf("\nFKO Field Values:\n=================\n\n");
|
||||
printf(" Random Value: %s\n", rand_val == NULL ? "<NULL>" : rand_val);
|
||||
printf(" Username: %s\n", username == NULL ? "<NULL>" : username);
|
||||
printf(" Timestamp: %u\n", (unsigned int) timestamp);
|
||||
printf(" FKO Version: %s\n", version == NULL ? "<NULL>" : version);
|
||||
printf(" Message Type: %i\n", msg_type);
|
||||
printf(" Message String: %s\n", spa_message == NULL ? "<NULL>" : spa_message);
|
||||
printf(" Nat Access: %s\n", nat_access == NULL ? "<NULL>" : nat_access);
|
||||
printf(" Server Auth: %s\n", server_auth == NULL ? "<NULL>" : server_auth);
|
||||
printf(" Client Timeout: %u\n", client_timeout);
|
||||
printf(" Digest Type: %d\n", digest_type);
|
||||
printf("Encryption Mode: %d\n", encryption_mode);
|
||||
printf("\n Encoded Data: %s\n", enc_data == NULL ? "<NULL>" : enc_data);
|
||||
printf("SPA Data Digest: %s\n", spa_digest == NULL ? "<NULL>" : spa_digest);
|
||||
printf(" HMAC-SHA256: %s\n", hmac_data == NULL ? "<NULL>" : hmac_data);
|
||||
|
||||
if (enc_data != NULL && spa_digest != NULL)
|
||||
printf(" Plaintext: %s:%s\n", enc_data, spa_digest);
|
||||
|
||||
printf("\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n", spa_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user