Skip to content

Commit

Permalink
Merge pull request #110 from spacekpe/cka_extractable
Browse files Browse the repository at this point in the history
add libhsm configuration option <AllowExtraction/>
  • Loading branch information
jschlyter committed Sep 6, 2014
2 parents ec01611 + 672d2c7 commit 6f9a591
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions NEWS
@@ -1,3 +1,8 @@
* Enforcer: New repository option <AllowExtraction/> allows to generate keys
with CKA_EXTRACTABLE attribute set to TRUE so keys can be wrapped
and extracted from HSM.


OpenDNSSEC 1.4.6 - 2014-07-21

* Signer Engine: Print secondary server address when logging notify reply
Expand Down
5 changes: 4 additions & 1 deletion conf/conf.rnc
Expand Up @@ -50,7 +50,10 @@ start = element Configuration {
element RequireBackup { empty }?,

# Do not maintain public keys in the repository (optional)
element SkipPublicKey { empty }?
element SkipPublicKey { empty }?,

# Generate extractable keys (CKA_EXTRACTABLE = TRUE) (optional)
element AllowExtraction { empty }?
}*
},

Expand Down
3 changes: 3 additions & 0 deletions conf/conf.xml.in
Expand Up @@ -9,6 +9,9 @@
<TokenLabel>OpenDNSSEC</TokenLabel>
<PIN>1234</PIN>
<SkipPublicKey/>
<!--
<AllowExtraction/>
-->
</Repository>

<!--
Expand Down
15 changes: 12 additions & 3 deletions libhsm/src/lib/libhsm.c
Expand Up @@ -504,6 +504,7 @@ static void
hsm_config_default(hsm_config_t *config)
{
config->use_pubkey = 1;
config->allow_extract = 0;
}

/* creates a session_t structure, and automatically adds and initializes
Expand Down Expand Up @@ -2054,6 +2055,8 @@ hsm_open(const char *config,
module_pin = (char *) xmlNodeGetContent(curNode);
if (xmlStrEqual(curNode->name, (const xmlChar *)"SkipPublicKey"))
module_config.use_pubkey = 0;
if (xmlStrEqual(curNode->name, (const xmlChar *)"AllowExtraction"))
module_config.allow_extract = 1;
curNode = curNode->next;
}

Expand Down Expand Up @@ -2341,10 +2344,12 @@ hsm_generate_rsa_key(hsm_ctx_t *ctx,
CK_BBOOL ctrue = CK_TRUE;
CK_BBOOL cfalse = CK_FALSE;
CK_BBOOL ctoken = CK_TRUE;
CK_BBOOL cextractable = CK_FALSE;

if (!ctx) ctx = _hsm_ctx;
session = hsm_find_repository_session(ctx, repository);
if (!session) return NULL;
cextractable = session->module->config->allow_extract ? CK_TRUE : CK_FALSE;

/* check whether this key doesn't happen to exist already */
do {
Expand Down Expand Up @@ -2380,7 +2385,7 @@ hsm_generate_rsa_key(hsm_ctx_t *ctx,
{ CKA_SENSITIVE, &ctrue, sizeof (ctrue) },
{ CKA_TOKEN, &ctrue, sizeof (ctrue) },
{ CKA_PRIVATE, &ctrue, sizeof (ctrue) },
{ CKA_EXTRACTABLE, &cfalse, sizeof (cfalse) }
{ CKA_EXTRACTABLE, &cextractable, sizeof (cextractable) }
};

rv = ((CK_FUNCTION_LIST_PTR)session->module->sym)->C_GenerateKeyPair(session->session,
Expand Down Expand Up @@ -2420,6 +2425,7 @@ hsm_generate_dsa_key(hsm_ctx_t *ctx,
CK_OBJECT_HANDLE domainPar, publicKey, privateKey;
CK_BBOOL ctrue = CK_TRUE;
CK_BBOOL cfalse = CK_FALSE;
CK_BBOOL cextractable = CK_FALSE;

/* ids we create are 16 bytes of data */
unsigned char id[16];
Expand Down Expand Up @@ -2466,12 +2472,13 @@ hsm_generate_dsa_key(hsm_ctx_t *ctx,
{ CKA_SENSITIVE, &ctrue, sizeof(ctrue) },
{ CKA_TOKEN, &ctrue, sizeof(ctrue) },
{ CKA_PRIVATE, &ctrue, sizeof(ctrue) },
{ CKA_EXTRACTABLE, &cfalse, sizeof(cfalse) }
{ CKA_EXTRACTABLE, &cextractable, sizeof (cextractable) }
};

if (!ctx) ctx = _hsm_ctx;
session = hsm_find_repository_session(ctx, repository);
if (!session) return NULL;
cextractable = session->module->config->allow_extract ? CK_TRUE : CK_FALSE;

/* check whether this key doesn't happen to exist already */

Expand Down Expand Up @@ -2533,6 +2540,7 @@ hsm_generate_gost_key(hsm_ctx_t *ctx,
CK_OBJECT_HANDLE publicKey, privateKey;
CK_BBOOL ctrue = CK_TRUE;
CK_BBOOL cfalse = CK_FALSE;
CK_BBOOL cextractable = CK_FALSE;

/* ids we create are 16 bytes of data */
unsigned char id[16];
Expand Down Expand Up @@ -2569,12 +2577,13 @@ hsm_generate_gost_key(hsm_ctx_t *ctx,
{ CKA_SENSITIVE, &ctrue, sizeof(ctrue) },
{ CKA_TOKEN, &ctrue, sizeof(ctrue) },
{ CKA_PRIVATE, &ctrue, sizeof(ctrue) },
{ CKA_EXTRACTABLE, &cfalse, sizeof(cfalse) }
{ CKA_EXTRACTABLE, &cextractable, sizeof (cextractable) }
};

if (!ctx) ctx = _hsm_ctx;
session = hsm_find_repository_session(ctx, repository);
if (!session) return NULL;
cextractable = session->module->config->allow_extract ? CK_TRUE : CK_FALSE;

/* check whether this key doesn't happen to exist already */

Expand Down
1 change: 1 addition & 0 deletions libhsm/src/lib/libhsm.h
Expand Up @@ -75,6 +75,7 @@
/*! HSM configuration */
typedef struct {
unsigned int use_pubkey; /*!< Maintain public keys in HSM */
unsigned int allow_extract; /*!< Generate CKA_EXTRACTABLE private keys */
} hsm_config_t;

/*! Data type to describe an HSM */
Expand Down

0 comments on commit 6f9a591

Please sign in to comment.