Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/lib/P11Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,17 @@ P11SecretKeyObj::P11SecretKeyObj()
// Add attributes
bool P11SecretKeyObj::init(OSObject *osobject)
{
if (initialized) return true;
if (osobject == NULL) return false;

OSAttribute attrClass((unsigned long)CKO_SECRET_KEY);
osobject->setAttribute(CKA_CLASS, attrClass);
OSAttribute attrKeyType(keytype);
osobject->setAttribute(CKA_KEY_TYPE, attrKeyType);

// Create parent
if (!P11KeyObj::init(osobject)) return false;

if (initialized) return true;

// Create attributes
P11Attribute* attrSensitive = new P11AttrSensitive(osobject);
P11Attribute* attrEncrypt = new P11AttrEncrypt(osobject);
Expand All @@ -745,6 +751,7 @@ bool P11SecretKeyObj::init(OSObject *osobject)
P11Attribute* attrCheckValue = new P11AttrCheckValue(osobject);
P11Attribute* attrWrapWithTrusted = new P11AttrWrapWithTrusted(osobject);
P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
P11Attribute* attrValue = new P11AttrValue(osobject,0);
// CKA_WRAP_TEMPLATE is not supported
// CKA_UNWRAP_TEMPLATE is not supported

Expand All @@ -763,7 +770,8 @@ bool P11SecretKeyObj::init(OSObject *osobject)
!attrNeverExtractable->init() ||
!attrCheckValue->init() ||
!attrWrapWithTrusted->init() ||
!attrTrusted->init()
!attrTrusted->init() ||
!attrValue->init()
)
{
ERROR_MSG("Could not initialize the attribute");
Expand All @@ -784,11 +792,30 @@ bool P11SecretKeyObj::init(OSObject *osobject)
attributes[attrCheckValue->getType()] = attrCheckValue;
attributes[attrWrapWithTrusted->getType()] = attrWrapWithTrusted;
attributes[attrTrusted->getType()] = attrTrusted;
attributes[attrValue->getType()] = attrValue;

initialized = true;
return true;
}

// Set Key Type
bool P11SecretKeyObj::setKeyType(CK_KEY_TYPE keytype)
{
if (!initialized)
{
this->keytype = keytype;
return true;
}
else
return false;
}

// Get Key Type
CK_KEY_TYPE P11SecretKeyObj::getKeyType()
{
return this->keytype;
}

// Constructor
P11DomainObj::P11DomainObj()
{
Expand Down
8 changes: 7 additions & 1 deletion src/lib/P11Objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,19 @@ class P11RSAPrivateKeyObj : public P11PrivateKeyObj

class P11SecretKeyObj : public P11KeyObj
{
protected:
public:
// Constructor
P11SecretKeyObj();

// Add attributes
virtual bool init(OSObject *osobject);

// Better than multiply subclasses
virtual bool setKeyType(CK_KEY_TYPE keytype);
virtual CK_KEY_TYPE getKeyType();
protected:
bool initialized;
CK_KEY_TYPE keytype;
};

class P11DomainObj : public P11Object
Expand Down
Loading