hsm_key_factory.c File Reference
`#include "config.h"`
`#include "db/hsm_key.h"`
`#include "db/policy.h"`
`#include "db/policy_key.h"`
`#include "db/key_data.h"`
`#include "log.h"`
`#include "scheduler/schedule.h"`
`#include "scheduler/task.h"`
`#include "enforcer/enforce_task.h"`
`#include "daemon/engine.h"`
`#include "duration.h"`
`#include "libhsm.h"`
`#include <math.h>`
`#include <pthread.h>`
`#include "hsmkey/hsm_key_factory.h"`

Go to the source code of this file.

## Data Structures

struct | __hsm_key_factory_task

## Functions

void | hsm_key_factory_deinit (void)
int | hsm_key_factory_generate (engine_type *engine, const db_connection_t *connection, const policy_t *policy, const policy_key_t *policy_key, time_t duration)
int | hsm_key_factory_generate_policy (engine_type *engine, const db_connection_t *connection, const policy_t *policy, time_t duration)
int | hsm_key_factory_generate_all (engine_type *engine, const db_connection_t *connection, time_t duration)
int | hsm_key_factory_schedule_generate_policy (engine_type *engine, const policy_t *policy_orig, time_t duration)
int | hsm_key_factory_schedule_generate_all (engine_type *engine, time_t duration)
hsm_key_t * | hsm_key_factory_get_key (engine_type *engine, const db_connection_t *connection, const policy_key_t *policy_key, hsm_key_state_t hsm_key_state)
int | hsm_key_factory_release_key_id (const db_value_t *hsm_key_id, const db_connection_t *connection)
int | hsm_key_factory_release_key (hsm_key_t *hsm_key, const db_connection_t *connection)

## Function Documentation

## hsm_key_factory_deinit()

void hsm_key_factory_deinit | ( | void |  | ) |

Definition at line 82 of file hsm_key_factory.c.

Referenced by engine_dealloc().

## hsm_key_factory_generate()

int hsm_key_factory_generate | ( | engine_type * | engine,
|  | const db_connection_t * | connection,
|  | const policy_t * | policy,
|  | const policy_key_t * | policy_key,
|  | time_t | duration
| ) |  |

TODO

Returns
  0 success, 1 error

Definition at line 92 of file hsm_key_factory.c.

## hsm_key_factory_generate_all()

int hsm_key_factory_generate_all | ( | engine_type * | engine,
|  | const db_connection_t * | connection,
|  | time_t | duration
| ) |  |

TODO

Returns
  0 success, 1 error

Definition at line 376 of file hsm_key_factory.c.

## hsm_key_factory_generate_policy()

int hsm_key_factory_generate_policy | ( | engine_type * | engine,
|  | const db_connection_t * | connection,
|  | const policy_t * | policy,
|  | time_t | duration
| ) |  |

TODO

Returns
  0 success, 1 error

Definition at line 336 of file hsm_key_factory.c.

## hsm_key_factory_get_key()

hsm_key_t* hsm_key_factory_get_key | ( | engine_type * | engine,
|  | const db_connection_t * | connection,
|  | const policy_key_t * | policy_key,
|  | hsm_key_state_t | hsm_key_state
| ) |  |

Allocate a private or shared HSM key for the policy key provided. This will also schedule a task for generating more keys if needed.

Parameters

  [in] | engine | an engine_type.
  [in] | connection | a database connection.
  [in] | policy_key | a policy key.
  [in] | hsm_key_state | indicate if its a private or shared key that should be fetched (HSM_KEY_STATE_PRIVATE | HSM_KEY_STATE_SHARED).

Returns
  an allocated HSM key or NULL on error or if there are no unused keys available for allocation right now.

Definition at line 619 of file hsm_key_factory.c.

## hsm_key_factory_release_key()

int hsm_key_factory_release_key | ( | hsm_key_t * | hsm_key,
|  | const db_connection_t * | connection
| ) |  |

Release a key, if its not used anyore it will be marked DELETE.

Parameters

  [in] | hsm_key | a hsm_key_t pointer with the hsm_key to release.

Returns
  non-zero on error.

Definition at line 753 of file hsm_key_factory.c.

## hsm_key_factory_release_key_id()

int hsm_key_factory_release_key_id | ( | const db_value_t * | hsm_key_id,
|  | const db_connection_t * | connection
| ) |  |

Release a key, if its not used anyore it will be marked DELETE.

Parameters

  [in] | hsm_key_id | a db_value_t pointer with the hsm_key database id.

Returns
  non-zero on error.

Definition at line 694 of file hsm_key_factory.c.

## hsm_key_factory_schedule_generate_all()

int hsm_key_factory_schedule_generate_all | ( | engine_type * | engine,
|  | time_t | duration
| ) |  |

Schedule a task to generate keys for all policies and policy keys we currently have.

Parameters

  [in] | engine | an engine_type.
  [in] | duration | a time_t specifying the duration to generate keys from, if its zero then the duration from conf.xml is taken.

Returns
  non-zero on error.

Definition at line 588 of file hsm_key_factory.c.

References __hsm_key_factory_task::duration, __hsm_key_factory_task::engine, __hsm_key_factory_task::policy, __hsm_key_factory_task::policy_key, and __hsm_key_factory_task::reschedule_enforce_task.

## hsm_key_factory_schedule_generate_policy()

int hsm_key_factory_schedule_generate_policy | ( | engine_type * | engine,
|  | const policy_t * | policy_orig,
|  | time_t | duration
| ) |  |

Schedule a task to generate keys for a specific policy.

Parameters

  [in] | engine | an engine_type. [in] policy_orig a policy_t pointer to the policy we will generate keys for.
  [in] | duration | a time_t specifying the duration to generate keys from, if its zero then the duration from conf.xml is taken.

Returns
  non-zero on error.

Definition at line 550 of file hsm_key_factory.c.

References __hsm_key_factory_task::duration, __hsm_key_factory_task::engine, __hsm_key_factory_task::policy, __hsm_key_factory_task::policy_key, policy_new_copy(), and __hsm_key_factory_task::reschedule_enforce_task.