]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-linux/ti-softhsmv2.git/commitdiff
fix for key delete issue in database
authorSajesh Kumar Saran <sajesh@ti.com>
Thu, 4 Apr 2013 05:09:28 +0000 (01:09 -0400)
committerSajesh Kumar Saran <sajesh@ti.com>
Thu, 4 Apr 2013 05:09:28 +0000 (01:09 -0400)
src/lib/P11Objects.cpp
src/lib/SoftHSM.cpp
src/lib/cryptoki.h
src/lib/object_store/FileSystem.cpp
src/lib/object_store/FileSystem.h
src/lib/object_store/OSToken.cpp
src/lib/object_store/OSToken.h
src/lib/object_store/ObjectFile.cpp

index 46707c24ef927780517366c351bc1b075384cf94..067a4bc30966e41326e62d572a91bf35d8dd1ca3 100644 (file)
@@ -80,18 +80,58 @@ bool P11Object::init(OSObject *osobject)
        // Initialize the attributes
        if
        (
-               !attrClass->init() ||
-               !attrToken->init() ||
-               !attrPrivate->init() ||
-               !attrModifiable->init() ||
-               !attrLabel->init() ||
-               !attrCopyable->init()
+               !attrClass->init()
        )
        {
-               ERROR_MSG("Could not initialize the attribute");
+               ERROR_MSG("Could not initialize the attribute (attrClass)");
+               return false;
+       }
+       // Initialize the attributes
+       if
+       (
+               !attrToken->init()
+       )
+       {
+               ERROR_MSG("Could not initialize the attribute (attrToken)");
+               return false;
+       }
+               // Initialize the attributes
+       if
+       (
+               !attrPrivate->init()
+       )
+       {
+               ERROR_MSG("Could not initialize the attribute (attrPrivate)");
+               return false;
+       }
+               // Initialize the attributes
+       if
+       (
+               !attrModifiable->init()
+       )
+       {
+               ERROR_MSG("Could not initialize the attribute (attrModifiable)");
                return false;
        }
+               // Initialize the attributes
+       if
+       (
 
+               !attrLabel->init()
+       )
+       {
+               ERROR_MSG("Could not initialize the attribute (attrLabel)");
+               return false;
+       }
+               // Initialize the attributes
+       if
+       (
+               !attrCopyable->init()
+       )
+       {
+               ERROR_MSG("Could not initialize the attribute (attrCopyable)");
+               return false;
+       }
        // Add them to the map
        attributes[attrClass->getType()] = attrClass;
        attributes[attrToken->getType()] = attrToken;
@@ -238,6 +278,7 @@ CK_RV P11Object::saveTemplate(Token *token, bool isPrivate, CK_ATTRIBUTE_PTR pTe
 
        if (osobject->commitTransaction() == false)
        {
+               osobject->abortTransaction();
                return CKR_GENERAL_ERROR;
        }
 
index d73fb519c8b287946696509cfe6d27166c5c937d..dd675ecb265bffdd6bfbe27c2aa6a9df4d079f08 100644 (file)
@@ -2964,8 +2964,11 @@ CK_RV SoftHSM::generateRSA
                                else
                                        osobject->abortTransaction();
 
-                               if (!bOK)
+                               if (!bOK) {
+                                       handleManager->destroyObject(*phPublicKey);
+                                       osobject->destroyObject();
                                        rv == CKR_FUNCTION_FAILED;
+                               }
                        }
                }
        }
@@ -3234,8 +3237,10 @@ CK_RV SoftHSM::CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTempla
        p11object->init(object);
 
        rv = p11object->saveTemplate(token, isPrivate, pTemplate,ulCount,op);
-       if (rv != CKR_OK)
+       if (rv != CKR_OK) {
+               object->destroyObject();
                return rv;
+       }
 
        if (isToken) {
                *phObject = handleManager->addTokenObject(slot->getSlotID(), isPrivate, object);
index cef03bd8b6cafcdc4a061867d5937aab97800a98..681a3de5c2c742be479eb2ea23c0f505e8832775 100644 (file)
@@ -43,5 +43,5 @@
 
 #include "pkcs11.h"
 
-#endif // !_SOFTHSM_V2_CRYPTOKI_H
+#endif /* !_SOFTHSM_V2_CRYPTOKI_H */
 
index f5cced016e6542984595a501d1b34fba5d08888c..26a881631b252358bcb2a421d326e6e17f3edadf 100644 (file)
@@ -565,7 +565,7 @@ fsReturnCode FileSystem::addNode(uint32_t type, std::string name, uint32_t dataL
 
        nodeAllocLength = DATA_ALIGN_4(fsNodeHdrLength + dataLength); 
 
-       if (FS_LEN + nodeAllocLength > maxSize) {
+       if (FS_LEN + nodeAllocLength > maxSize  - FileSystem::getFSHashLength()) {
                ERROR_MSG("No more space in filesystem current %d, max size %d for %s",
                                FS_LEN, maxSize, name.c_str());
                return fsInvalid;
@@ -746,7 +746,7 @@ fsReturnCode FileSystem::expandNode(FSNode &node, uint32_t length)
 
        uint32_t expandLength = DATA_ALIGN_4(fsNodeHdrLength + node.getNodeDataLength() + length - nodeSize);
 
-       if (FS_LEN + expandLength > maxSize) {
+       if (FS_LEN + expandLength > maxSize - FileSystem::getFSHashLength()) {
                ERROR_MSG("expandNode, Can't expand file system for %d, maxSize %d",
                                expandLength, maxSize);
                return fsErrorGen;
index 7dff09120c32cbb6c53eba229c19fe109f930664..e30a99ddcdfb00b3da28d51d40f1703cbbf25516 100644 (file)
@@ -48,7 +48,7 @@
 #include <memory>
 
 //#define FILE_REGION_MAP
-
+#include "CryptoFactory.h"
 #include "MapRegion.h"
 #include "FileStore.h"
 
@@ -253,6 +253,11 @@ class FileSystem
 
                bool getFSHash(ByteString &hashBuf);
 
+               int getFSHashLength() const
+               {
+                       return CryptoFactory::i()->getHashAlgorithm("md5")->getHashSize();
+               }
+
                bool checkHash();
 
 };
index dfd10e3a9000927f419cc7c46562c58cd06a4058..f60eb7fd026599aa64bebebd67ca63f1c8902ce6 100644 (file)
@@ -371,11 +371,12 @@ ObjectFile* OSToken::createObject()
 }
 
 // Delete an object
-bool OSToken::deleteObject(ObjectFile* object)
+bool OSToken::deleteObject(ObjectFile* object, bool force)
 {
        if (!valid) return false;
 
-       if (objects.find(object) == objects.end())
+       if ((force != true)
+               && (objects.find(object) == objects.end()))
        {
                ERROR_MSG("Cannot delete non-existent object 0x%08X", object);
 
@@ -541,10 +542,19 @@ bool OSToken::index(bool isFirstTime /* = false */)
                // Create a new token object for the added file
                ObjectFile* newObject = new ObjectFile(this, tokenPath + OS_PATHSEP + *i);
 
-               DEBUG_MSG("(0x%08X) New object %s (0x%08X) added", this, newObject->getFilename().c_str(), newObject);
+               if (newObject->isValid()) {
 
-               objects.insert(newObject);
-               allObjects.insert(newObject);
+                       DEBUG_MSG("(0x%08X) New object %s (0x%08X) added",
+                                       this, newObject->getFilename().c_str(), newObject);
+
+                       objects.insert(newObject);
+                       allObjects.insert(newObject);
+               } else {
+                       deleteObject(newObject, true);
+                       if (!FileSystem::i()->flush()) {
+                               ERROR_MSG("Can not flush the filesystem");
+                       }
+               }
        }
 
        // Remove deleted objects
index 7b334951af0414fd6b094938bd55e21f4bf13a17..19436969dfe872ee54a90ef28c7d2638f0832b46 100644 (file)
@@ -96,7 +96,7 @@ public:
        ObjectFile* createObject();
 
        // Delete an object
-       bool deleteObject(ObjectFile* object);
+       bool deleteObject(ObjectFile* object, bool force = false);
 
        // Destructor
        virtual ~OSToken();
index a386354cae3a1089a16b4995f25d3cd1c7951b38..a544dd513fda140960b08cf26e71be8f54a381d3 100644 (file)
@@ -518,7 +518,7 @@ bool ObjectFile::commitTransaction()
 
        store();
        
-       return true;
+       return isValid();
 }
 
 // Abort an attribute transaction; loads back the previous version of the object from disk