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
66 changes: 66 additions & 0 deletions src/lib/P11Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,3 +1753,69 @@ CK_RV P11AttrModulusBits::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR p

return CKR_OK;
}

/*****************************************
* CKA_PRIME
*****************************************/

// Set default value
bool P11AttrPrime::setDefault()
{
OSAttribute attr(ByteString(""));
return osobject->setAttribute(type, attr);
}

/*****************************************
* CKA_SUBPRIME
*****************************************/

// Set default value
bool P11AttrSubPrime::setDefault()
{
OSAttribute attr(ByteString(""));
return osobject->setAttribute(type, attr);
}

/*****************************************
* CKA_BASE
*****************************************/

// Set default value
bool P11AttrBase::setDefault()
{
OSAttribute attr(ByteString(""));
return osobject->setAttribute(type, attr);
}

/*****************************************
* CKA_PRIME_BITS
*****************************************/

// Set default value
bool P11AttrPrimeBits::setDefault()
{
OSAttribute attr((unsigned long)0);
return osobject->setAttribute(type, attr);
}

// Update the value if allowed
CK_RV P11AttrPrimeBits::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op)
{
// Attribute specific checks

if (op != OBJECT_OP_GENERATE)
{
return CKR_ATTRIBUTE_READ_ONLY;
}

if (ulValueLen != sizeof(CK_ULONG))
{
return CKR_ATTRIBUTE_VALUE_INVALID;
}

// Store data

osobject->setAttribute(type, *(CK_ULONG*)pValue);

return CKR_OK;
}
63 changes: 63 additions & 0 deletions src/lib/P11Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,4 +1005,67 @@ class P11AttrModulusBits : public P11Attribute
virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
};

/*****************************************
* CKA_PRIME
*****************************************/

class P11AttrPrime : public P11Attribute
{
public:
// Constructor
P11AttrPrime(OSObject* osobject, CK_ULONG inchecks = 0) : P11Attribute(osobject) { type = CKA_PRIME; checks = ck1|inchecks; }

protected:
// Set the default value of the attribute
virtual bool setDefault();
};

/*****************************************
* CKA_SUBPRIME
*****************************************/

class P11AttrSubPrime : public P11Attribute
{
public:
// Constructor
P11AttrSubPrime(OSObject* osobject, CK_ULONG inchecks = 0) : P11Attribute(osobject) { type = CKA_SUBPRIME; checks = ck1|inchecks; }

protected:
// Set the default value of the attribute
virtual bool setDefault();
};

/*****************************************
* CKA_BASE
*****************************************/

class P11AttrBase : public P11Attribute
{
public:
// Constructor
P11AttrBase(OSObject* osobject, CK_ULONG inchecks = 0) : P11Attribute(osobject) { type = CKA_BASE; checks = ck1|inchecks; }

protected:
// Set the default value of the attribute
virtual bool setDefault();
};

/*****************************************
* CKA_PRIME_BITS
*****************************************/

class P11AttrPrimeBits : public P11Attribute
{
public:
// Constructor
P11AttrPrimeBits(OSObject* osobject) : P11Attribute(osobject) { type = CKA_PRIME_BITS; size = sizeof(CK_ULONG); checks = ck2|ck3;}

protected:
// Set the default value of the attribute
virtual bool setDefault();

// Update the value if allowed
virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
};

#endif // !_SOFTHSM_V2_P11ATTRIBUTES_H
152 changes: 148 additions & 4 deletions src/lib/P11Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,53 @@ bool P11RSAPublicKeyObj::init(OSObject *osobject)
return true;
}

// Constructor
P11DSAPublicKeyObj::P11DSAPublicKeyObj()
{
initialized = false;
}

// Add attributes
bool P11DSAPublicKeyObj::init(OSObject *osobject)
{
if (initialized) return true;
if (osobject == NULL) return false;

OSAttribute attrKeyType((unsigned long)CKK_DSA);
osobject->setAttribute(CKA_KEY_TYPE, attrKeyType);

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

// Create attributes
P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck3);
P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck3);
P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck3);
P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1);

// Initialize the attributes
if
(
!attrPrime->init() ||
!attrSubPrime->init() ||
!attrBase->init() ||
!attrValue->init()
)
{
ERROR_MSG("Could not initialize the attribute");
return false;
}

// Add them to the map
attributes[attrPrime->getType()] = attrPrime;
attributes[attrSubPrime->getType()] = attrSubPrime;
attributes[attrBase->getType()] = attrBase;
attributes[attrValue->getType()] = attrValue;

initialized = true;
return true;
}

//constructor
P11PrivateKeyObj::P11PrivateKeyObj()
{
Expand Down Expand Up @@ -717,6 +764,52 @@ bool P11RSAPrivateKeyObj::init(OSObject *osobject)
return true;
}

// Constructor
P11DSAPrivateKeyObj::P11DSAPrivateKeyObj()
{
initialized = false;
}

// Add attributes
bool P11DSAPrivateKeyObj::init(OSObject *osobject)
{
// Create parent
if (!P11PrivateKeyObj::init(osobject)) return false;

OSAttribute attrKeyType((unsigned long)CKK_DSA);
osobject->setAttribute(CKA_KEY_TYPE, attrKeyType);

if (initialized) return true;

// Create attributes
P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4|P11Attribute::ck6);
P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);

// Initialize the attributes
if
(
!attrPrime->init() ||
!attrSubPrime->init() ||
!attrBase->init() ||
!attrValue->init()
)
{
ERROR_MSG("Could not initialize the attribute");
return false;
}

// Add them to the map
attributes[attrPrime->getType()] = attrPrime;
attributes[attrSubPrime->getType()] = attrSubPrime;
attributes[attrBase->getType()] = attrBase;
attributes[attrValue->getType()] = attrValue;

initialized = true;
return true;
}

// Constructor
P11SecretKeyObj::P11SecretKeyObj()
{
Expand Down Expand Up @@ -798,14 +891,18 @@ P11DomainObj::P11DomainObj()
// Add attributes
bool P11DomainObj::init(OSObject *osobject)
{
if (initialized) return true;
if (osobject == NULL) return false;

OSAttribute attrClass((unsigned long)CKO_DOMAIN_PARAMETERS);
osobject->setAttribute(CKA_CLASS, attrClass);

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

if (initialized) return true;

// Create attributes
P11Attribute* attrKeyType = new P11AttrApplication(osobject);
P11Attribute* attrLocal = new P11AttrObjectID(osobject);
P11Attribute* attrKeyType = new P11AttrKeyType(osobject);
P11Attribute* attrLocal = new P11AttrLocal(osobject);

// Initialize the attributes
if
Expand All @@ -825,3 +922,50 @@ bool P11DomainObj::init(OSObject *osobject)
initialized = true;
return true;
}

// Constructor
P11DSADomainObj::P11DSADomainObj()
{
initialized = false;
}

// Add attributes
bool P11DSADomainObj::init(OSObject *osobject)
{
if (initialized) return true;
if (osobject == NULL) return false;

OSAttribute attrKeyType((unsigned long)CKK_DSA);
osobject->setAttribute(CKA_KEY_TYPE, attrKeyType);

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

// Create attributes
P11Attribute* attrPrimeBits = new P11AttrPrimeBits(osobject);
P11Attribute* attrPrime = new P11AttrPrime(osobject);
P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject);
P11Attribute* attrBase = new P11AttrBase(osobject);

// Initialize the attributes
if
(
!attrPrimeBits->init() ||
!attrPrime->init() ||
!attrSubPrime->init() ||
!attrBase->init()
)
{
ERROR_MSG("Could not initialize the attribute");
return false;
}

// Add them to the map
attributes[attrPrimeBits->getType()] = attrPrimeBits;
attributes[attrPrime->getType()] = attrPrime;
attributes[attrSubPrime->getType()] = attrSubPrime;
attributes[attrBase->getType()] = attrBase;

initialized = true;
return true;
}
38 changes: 38 additions & 0 deletions src/lib/P11Objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ class P11RSAPublicKeyObj : public P11PublicKeyObj
bool initialized;
};

class P11DSAPublicKeyObj : public P11PublicKeyObj
{
public:
// Constructor
P11DSAPublicKeyObj();

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

protected:
bool initialized;
};

class P11PrivateKeyObj : public P11KeyObj
{
protected:
Expand All @@ -173,6 +186,19 @@ class P11RSAPrivateKeyObj : public P11PrivateKeyObj
bool initialized;
};

class P11DSAPrivateKeyObj : public P11PrivateKeyObj
{
public:
// Constructor
P11DSAPrivateKeyObj();

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

protected:
bool initialized;
};

class P11SecretKeyObj : public P11KeyObj
{
protected:
Expand All @@ -195,4 +221,16 @@ class P11DomainObj : public P11Object
bool initialized;
};

class P11DSADomainObj : public P11DomainObj
{
public:
// Constructor
P11DSADomainObj();

// Add attributes
virtual bool init(OSObject *osobject);
protected:
bool initialized;
};

#endif // !_SOFTHSM_V2_P11OBJECTS_H
Loading