summaryrefslogtreecommitdiff
path: root/identity/aidl/default/libeic/EicCbor.c
diff options
context:
space:
mode:
authorJoseph Jang <josephjang@google.com>2021-09-01 16:50:09 +0800
committerJoseph Jang <josephjang@google.com>2021-09-06 18:27:08 +0800
commitdabb3c515fc17e358a19ff78cd3d7a6fccd0a15c (patch)
tree783ae8bc42632fa0f9dbf1ecbe2079531c784670 /identity/aidl/default/libeic/EicCbor.c
parent334a6134deb33e3ebdb1c5b5e1989a5e049ed3b2 (diff)
identity: Make NoS libeic and AOSP libeic align
1. Add input parameter buffer size for CBOR data encoding because Nugget OS protobuf buffer is not null terminated. 2. Modify some libeic APIs to align with NoS libeic. Bug: 198403263 Test: atest VtsHalIdentityTargetTest atest android.security.identity.cts Change-Id: I9bc3689da2571c0925972f33b7314cbaaad0e28d
Diffstat (limited to 'identity/aidl/default/libeic/EicCbor.c')
-rw-r--r--identity/aidl/default/libeic/EicCbor.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/identity/aidl/default/libeic/EicCbor.c b/identity/aidl/default/libeic/EicCbor.c
index 0e2684fec4..b9304bcacb 100644
--- a/identity/aidl/default/libeic/EicCbor.c
+++ b/identity/aidl/default/libeic/EicCbor.c
@@ -91,7 +91,7 @@ size_t eicCborAdditionalLengthBytesFor(size_t size) {
return 8;
}
-void eicCborBegin(EicCbor* cbor, int majorType, size_t size) {
+void eicCborBegin(EicCbor* cbor, int majorType, uint64_t size) {
uint8_t data[9];
if (size < 24) {
@@ -132,10 +132,13 @@ void eicCborAppendByteString(EicCbor* cbor, const uint8_t* data, size_t dataSize
eicCborAppend(cbor, data, dataSize);
}
-void eicCborAppendString(EicCbor* cbor, const char* str) {
- size_t length = eicStrLen(str);
- eicCborBegin(cbor, EIC_CBOR_MAJOR_TYPE_STRING, length);
- eicCborAppend(cbor, (const uint8_t*)str, length);
+void eicCborAppendString(EicCbor* cbor, const char* str, size_t strLength) {
+ eicCborBegin(cbor, EIC_CBOR_MAJOR_TYPE_STRING, strLength);
+ eicCborAppend(cbor, (const uint8_t*)str, strLength);
+}
+
+void eicCborAppendStringZ(EicCbor* cbor, const char* str) {
+ eicCborAppendString(cbor, str, eicStrLen(str));
}
void eicCborAppendSimple(EicCbor* cbor, uint8_t simpleValue) {
@@ -153,13 +156,13 @@ void eicCborAppendSemantic(EicCbor* cbor, uint64_t value) {
}
void eicCborAppendUnsigned(EicCbor* cbor, uint64_t value) {
- size_t encoded = value;
+ uint64_t encoded = value;
eicCborBegin(cbor, EIC_CBOR_MAJOR_TYPE_UNSIGNED, encoded);
}
void eicCborAppendNumber(EicCbor* cbor, int64_t value) {
if (value < 0) {
- size_t encoded = -1 - value;
+ uint64_t encoded = -1 - value;
eicCborBegin(cbor, EIC_CBOR_MAJOR_TYPE_NEGATIVE, encoded);
} else {
eicCborAppendUnsigned(cbor, value);
@@ -188,19 +191,19 @@ bool eicCborCalcAccessControl(EicCbor* cborBuilder, int id, const uint8_t* reade
}
}
eicCborAppendMap(cborBuilder, numPairs);
- eicCborAppendString(cborBuilder, "id");
+ eicCborAppendStringZ(cborBuilder, "id");
eicCborAppendUnsigned(cborBuilder, id);
if (readerCertificateSize > 0) {
- eicCborAppendString(cborBuilder, "readerCertificate");
+ eicCborAppendStringZ(cborBuilder, "readerCertificate");
eicCborAppendByteString(cborBuilder, readerCertificate, readerCertificateSize);
}
if (userAuthenticationRequired) {
- eicCborAppendString(cborBuilder, "userAuthenticationRequired");
+ eicCborAppendStringZ(cborBuilder, "userAuthenticationRequired");
eicCborAppendBool(cborBuilder, userAuthenticationRequired);
- eicCborAppendString(cborBuilder, "timeoutMillis");
+ eicCborAppendStringZ(cborBuilder, "timeoutMillis");
eicCborAppendUnsigned(cborBuilder, timeoutMillis);
if (secureUserId > 0) {
- eicCborAppendString(cborBuilder, "secureUserId");
+ eicCborAppendStringZ(cborBuilder, "secureUserId");
eicCborAppendUnsigned(cborBuilder, secureUserId);
}
}
@@ -214,20 +217,21 @@ bool eicCborCalcAccessControl(EicCbor* cborBuilder, int id, const uint8_t* reade
return true;
}
-bool eicCborCalcEntryAdditionalData(const int* accessControlProfileIds,
+bool eicCborCalcEntryAdditionalData(const uint8_t* accessControlProfileIds,
size_t numAccessControlProfileIds, const char* nameSpace,
- const char* name, uint8_t* cborBuffer, size_t cborBufferSize,
- size_t* outAdditionalDataCborSize,
+ size_t nameSpaceLength, const char* name,
+ size_t nameLength, uint8_t* cborBuffer,
+ size_t cborBufferSize, size_t* outAdditionalDataCborSize,
uint8_t additionalDataSha256[EIC_SHA256_DIGEST_SIZE]) {
EicCbor cborBuilder;
eicCborInit(&cborBuilder, cborBuffer, cborBufferSize);
eicCborAppendMap(&cborBuilder, 3);
- eicCborAppendString(&cborBuilder, "Namespace");
- eicCborAppendString(&cborBuilder, nameSpace);
- eicCborAppendString(&cborBuilder, "Name");
- eicCborAppendString(&cborBuilder, name);
- eicCborAppendString(&cborBuilder, "AccessControlProfileIds");
+ eicCborAppendStringZ(&cborBuilder, "Namespace");
+ eicCborAppendString(&cborBuilder, nameSpace, nameSpaceLength);
+ eicCborAppendStringZ(&cborBuilder, "Name");
+ eicCborAppendString(&cborBuilder, name, nameLength);
+ eicCborAppendStringZ(&cborBuilder, "AccessControlProfileIds");
eicCborAppendArray(&cborBuilder, numAccessControlProfileIds);
for (size_t n = 0; n < numAccessControlProfileIds; n++) {
eicCborAppendNumber(&cborBuilder, accessControlProfileIds[n]);