Skip to content

Commit

Permalink
catching exception for base64decode
Browse files Browse the repository at this point in the history
  • Loading branch information
gangatp committed Jan 9, 2024
1 parent d1817be commit 991caed
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(CMAKE_INSTALL_INCLUDEDIR include/lib3mf CACHE PATH "directory for installing

option(USE_INCLUDED_ZLIB "Use included zlib" ON)
option(USE_INCLUDED_LIBZIP "Use included libzip" ON)
option(USE_INCLUDED_GTEST "Used included gtest" ON)
option(USE_INCLUDED_SSL "Use included libressl" ON)
option(BUILD_FOR_CODECOVERAGE "Build for code coverage analysis" OFF)
option(STRIP_BINARIES "Strip binaries (on non-apple)" ON)
Expand Down
3 changes: 3 additions & 0 deletions Include/Common/NMR_ErrorConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,9 @@ Model error codes (0x8XXX)
// A component resource is invalid
#define NMR_ERROR_INVALIDCOMPONENTRESOURCE 0x810D

// A keystore element is not base64 encoded
#define NMR_ERROR_KEYSTOREINVALIDENCODING 0x810E

/*-------------------------------------------------------------------
XML Parser Error Constants (0x9XXX)
-------------------------------------------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions Source/Common/NMR_Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ namespace NMR {
case NMR_ERROR_KEYSTOREDUPLICATEACCESSRIGHT: return "An AccessRight already exists for this consumer in a ResourceDataGroup";
case NMR_ERROR_KEYSTOREDUPLICATERESOURCEDATAGROUP: return "A resource data group already exist for this keyuuid";
case NMR_ERROR_KEYSTOREINVALIDALGORITHM: return "The algorithm attribute is invalid";
case NMR_ERROR_KEYSTOREINVALIDENCODING: return "The keystore element value is not base64 encoded.";
case NMR_ERROR_KEYSTOREINVALIDCOMPRESSION: return "The KeyStore ResourceData compression is invalid";
case NMR_ERROR_KEYSTOREINVALIDCIPHERVALUE: return "Invalid CipherValue elment value";
case NMR_ERROR_KEYSTOREINVALIDMGF: return "The mfgalgorithm attribute has invalid value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace NMR {
}
catch (...) {
// base64_decode throws an exception if the input is not valid base64
m_pWarnings->addException(CNMRException(NMR_ERROR_KEYSTOREINVALIDENCODING), mrwInvalidOptionalValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace NMR {
}
catch (...) {
// base64_decode throws an exception if the input is not valid base64
m_pWarnings->addException(CNMRException(NMR_ERROR_KEYSTOREINVALIDENCODING), NMR::eModelWarningLevel::mrwInvalidMandatoryValue);
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions Tests/CPP_Bindings/Source/SecureContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace Lib3MF {

TEST_F(SecureContentT, ModelReaderKeyStoreNoAttributesWarnings) {
PReader reader3MF = readKeyStore(NEGATIVEUNENCRYPTEDKEYSTOREMISSINGATTRIBUTES);
CheckReaderWarnings(reader3MF, 6);
CheckReaderWarnings(reader3MF, 8);
Lib3MF_uint32 iWarning = 0;

// NMR_ERROR_KEYSTOREMISSINGCONSUMERID
Expand All @@ -418,21 +418,32 @@ namespace Lib3MF {
reader3MF->GetWarning(3, iWarning);
ASSERT_EQ(0x8105, iWarning);

// NMR_ERROR_KEYSTOREINVALIDENCODING
// invalid key store element value in ResourceData
reader3MF->GetWarning(4, iWarning);
ASSERT_EQ(0x810E, iWarning);

// NMR_ERROR_KEYSTOREINVALIDENCODING
// invalid key store element value in ResourceData
reader3MF->GetWarning(5, iWarning);
ASSERT_EQ(0x810E, iWarning);


// NMR_ERROR_KEYSTOREMISSINGALGORTHM
// missing encryptionalgorithm on cekparams
reader3MF->GetWarning(4, iWarning);
reader3MF->GetWarning(6, iWarning);
ASSERT_EQ(0x810A, iWarning);

// NMR_ERROR_MISSINGUUID
//missing guid on keystore
reader3MF->GetWarning(5, iWarning);
reader3MF->GetWarning(7, iWarning);
ASSERT_EQ(0x80B0, iWarning);

}

TEST_F(SecureContentT, ModelReaderKeyStoreInvalidAttributesWarnings) {
PReader reader3MF = readKeyStore(NEGATIVEUNENCRYPTEDKEYSTOREINVALIDATTRIBUTES);
CheckReaderWarnings(reader3MF, 8);
CheckReaderWarnings(reader3MF, 10);
Lib3MF_uint32 iWarning = 0;

// NMR_ERROR_KEYSTOREDUPLICATECONSUMERID
Expand Down Expand Up @@ -474,6 +485,16 @@ namespace Lib3MF {
// invalid compression attribute in ResourceData
reader3MF->GetWarning(7, iWarning);
ASSERT_EQ(0x80F8, iWarning);

// NMR_ERROR_KEYSTOREINVALIDENCODING
// invalid key store element value in ResourceData
reader3MF->GetWarning(8, iWarning);
ASSERT_EQ(0x810E, iWarning);

// NMR_ERROR_KEYSTOREINVALIDENCODING
// invalid key store element value in ResourceData
reader3MF->GetWarning(9, iWarning);
ASSERT_EQ(0x810E, iWarning);
}

TEST_F(SecureContentT, CheckKeyStoreConsumers) {
Expand Down

0 comments on commit 991caed

Please sign in to comment.