Skip to content

Commit

Permalink
Issue 26: Update to SecApi 3.1.2 sa_import_parameters_soc (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericeberry authored Jan 28, 2023
1 parent f062f75 commit 9cc8913
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/sec_adapter_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ Sec_Result SecCipher_ProcessCtrWithOpaqueDataShift(Sec_CipherHandle* cipherHandl
Sec_Result SecCipher_KeyCheckOpaque(Sec_CipherHandle* cipherHandle, Sec_OpaqueBufferHandle* opaqueBufferHandle,
SEC_SIZE checkLength, SEC_BYTE* expected) {

#if (SA_SPECIFICATION_MAJOR >= 3 && \
((SA_SPECIFICATION_MINOR == 1 && SA_SPECIFICATION_REVISION >= 2) || SA_SPECIFICATION_MINOR > 1))

#if MIN_SA_VERSION(3, 1, 2)
return SEC_RESULT_UNIMPLEMENTED_FEATURE;
#else
if (opaqueBufferHandle == NULL) {
Expand Down
22 changes: 19 additions & 3 deletions src/sec_adapter_key.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020-2022 Comcast Cable Communications Management, LLC
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2430,7 +2430,11 @@ static Sec_Result process_key_container(Sec_ProcessorHandle* processorHandle, SE
sa_import_parameters_rsa_private_key_info rsa_parameters;
sa_import_parameters_ec_private_bytes ec_parameters;
sa_import_parameters_typej typej_parameters;
#if MIN_SA_VERSION(3, 1, 2)
sa_import_parameters_soc parameters_soc;
#else
sa_import_parameters_soc_legacy parameters_soc_legacy;
#endif
Sec_KeyHandle* cipherKeyHandle = NULL;
Sec_KeyHandle* hmacKeyHandle = NULL;
sa_status status;
Expand Down Expand Up @@ -2563,19 +2567,31 @@ static Sec_Result process_key_container(Sec_ProcessorHandle* processorHandle, SE
*out_key_container = SEC_KEYCONTAINER_SOC;
memmove(key_buffer, p_data, *key_length);
key_format = SA_KEY_FORMAT_SOC;
#if MIN_SA_VERSION(3, 1, 2)
// Not sure of the key type, so just give all rights.
rights_set_allow_all(&rights, SEC_KEYTYPE_AES_128);
size_t length = sizeof(sa_import_parameters_soc);
parameters_soc.length[0] = length >> 8 & 0xff;
parameters_soc.length[1] = length & 0xff;
parameters_soc.version = VERSION_2_KEY_CONTAINER;
parameters_soc.default_rights = rights;
parameters_soc.object_id = object_id;
parameters = &parameters_soc;
#else
if (is_jwt_key_container(key_buffer, *key_length)) {
parameters = NULL;
} else {
size_t length = sizeof(sa_import_parameters_soc_legacy);
// Not sure of the key type, so just give all rights.
rights_set_allow_all(&rights, SEC_KEYTYPE_AES_128);
size_t length = sizeof(sa_import_parameters_soc_legacy);
parameters_soc_legacy.length[0] = length >> 8 & 0xff;
parameters_soc_legacy.length[1] = length & 0xff;
parameters_soc_legacy.version = VERSION_2_KEY_CONTAINER;
parameters_soc_legacy.default_rights = rights;
parameters_soc_legacy.object_id = object_id;
parameters = &parameters_soc_legacy;
}

#endif
break;

case SEC_KEYCONTAINER_EXPORTED:
Expand Down
5 changes: 5 additions & 0 deletions src/sec_adapter_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

#define MAX_QUEUE_SIZE 32

#define MIN_SA_VERSION(x, y, z) ( \
(SA_SPECIFICATION_MAJOR > x) || \
(SA_SPECIFICATION_MAJOR == x && SA_SPECIFICATION_MINOR > y) || \
(SA_SPECIFICATION_MAJOR == x && SA_SPECIFICATION_MINOR == y && SA_SPECIFICATION_REVISION >= z))

typedef struct {
SA_COMMAND_ID command_id;
va_list* arguments;
Expand Down
3 changes: 1 addition & 2 deletions test/main/cpp/keyctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,7 @@ do {
}

Sec_Result testKeyCtrlSvpCheckOpaque(int version, const char* alg, TestKey contentKey) {
#if (SA_SPECIFICATION_MAJOR >= 3 && \
((SA_SPECIFICATION_MINOR == 1 && SA_SPECIFICATION_REVISION >= 2) || SA_SPECIFICATION_MINOR > 1))
#if MIN_SA_VERSION(3, 1, 2)
return SEC_RESULT_SUCCESS;
#else
TestCtx ctx;
Expand Down
8 changes: 3 additions & 5 deletions test/main/cpp/svp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include "svp.h" // NOLINT
#include "digest.h"
#include "sa.h"
#include "sec_adapter_processor.h"
#include "test_ctx.h"
#if (SA_SPECIFICATION_MAJOR >= 3 && ((SA_SPECIFICATION_MINOR == 1 && SA_SPECIFICATION_REVISION < 2) || \
SA_SPECIFICATION_MINOR < 1))
#if !(MIN_SA_VERSION(3, 1, 2))
#include "cipher.h"
#endif

Expand Down Expand Up @@ -90,9 +90,7 @@ Sec_Result testSetTime() {
}

Sec_Result testKeycheckOpaque(SEC_OBJECTID id, TestKey key, TestKc kc, Sec_StorageLoc loc) {
#if (SA_SPECIFICATION_MAJOR >= 3 && \
((SA_SPECIFICATION_MINOR == 1 && SA_SPECIFICATION_REVISION >= 2) || SA_SPECIFICATION_MINOR > 1))

#if MIN_SA_VERSION(3, 1, 2)
return SEC_RESULT_SUCCESS;
#else
TestCtx ctx;
Expand Down

0 comments on commit 9cc8913

Please sign in to comment.