OpenDNSSEC-libhsm  1.4.9
Data Structures | Macros | Functions | Variables
pin.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <errno.h>
#include "libhsm.h"
Include dependency graph for pin.c:

Go to the source code of this file.

Data Structures

union  semun
 

Macros

#define SHM_KEY   (key_t)0x0d50d5ec
 
#define SEM_KEY   (key_t)0x0d50d5ec
 
#define SHM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
 
#define SEM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
 

Functions

void hsm_ctx_set_error (hsm_ctx_t *ctx, int error, const char *action, const char *message,...)
 
char * prompt_pass (char *prompt)
 
int hsm_sem_open ()
 
int hsm_sem_wait (int semid)
 
int hsm_sem_post (int semid)
 
int hsm_shm_open ()
 
char * hsm_prompt_pin (unsigned int id, const char *repository, unsigned int mode)
 
char * hsm_check_pin (unsigned int id, const char *repository, unsigned int mode)
 
int hsm_logout_pin ()
 

Variables

hsm_ctx_t_hsm_ctx
 

Macro Definition Documentation

#define SEM_KEY   (key_t)0x0d50d5ec

Definition at line 52 of file pin.c.

Referenced by hsm_logout_pin(), and hsm_sem_open().

#define SEM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 54 of file pin.c.

Referenced by hsm_sem_open().

#define SHM_KEY   (key_t)0x0d50d5ec

Definition at line 51 of file pin.c.

Referenced by hsm_logout_pin(), and hsm_shm_open().

#define SHM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 53 of file pin.c.

Referenced by hsm_shm_open().

Function Documentation

char* hsm_check_pin ( unsigned int  id,
const char *  repository,
unsigned int  mode 
)

Function that will check if there is a PIN in the shared memory and returns it.

Parameters
idUsed for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
repositoryThe repository name will be included in the prompt
modeThe type of mode the function should run in.
Returns
The string the user enters

Definition at line 325 of file pin.c.

References hsm_ctx_set_error(), HSM_ERROR, HSM_MAX_PIN_LENGTH, HSM_MAX_SESSIONS, HSM_PIN_FIRST, HSM_PIN_RETRY, HSM_PIN_SAVE, hsm_sem_open(), hsm_sem_post(), hsm_sem_wait(), and hsm_shm_open().

void hsm_ctx_set_error ( hsm_ctx_t ctx,
int  error,
const char *  action,
const char *  message,
  ... 
)

Set HSM Context Error

If the ctx is given, and it's error value is still 0, the value will be set to 'error', and the error_message and error_action will be set to the given strings.

Parameters
ctxHSM context
errorerror code
actionaction for which the error occured
messageerror message format string

Definition at line 210 of file libhsm.c.

References ck_function_list::C_GetTokenInfo, CKR_FUNCTION_FAILED, CKR_OK, hsm_ctx_t::error, hsm_ctx_t::error_action, hsm_ctx_t::error_message, hsm_module_t::handle, HSM_TOKEN_LABEL_LENGTH, ck_token_info::label, hsm_module_t::path, and hsm_module_t::sym.

Referenced by hsm_check_context(), hsm_check_pin(), hsm_count_keys_session(), hsm_get_dnskey(), hsm_get_slot_id(), hsm_logout_pin(), hsm_nsec3_hash_name(), hsm_open(), hsm_sem_open(), hsm_sem_post(), hsm_sem_wait(), hsm_shm_open(), and hsm_token_attached().

int hsm_logout_pin ( )

Logout

Function that will logout the user by deleting the shared memory and semaphore. Any authenticated process will still be able to interact with the HSM.

Definition at line 413 of file pin.c.

References hsm_ctx_set_error(), HSM_ERROR, HSM_OK, SEM_KEY, and SHM_KEY.

Referenced by cmd_logout().

char* hsm_prompt_pin ( unsigned int  id,
const char *  repository,
unsigned int  mode 
)

Function that queries for a PIN, can be used as callback for hsm_open(). Stores the PIN in the shared memory.

Parameters
idUsed for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
repositoryThe repository name will be included in the prompt
modeThe type of mode the function should run in.
Returns
The string the user enters

Definition at line 228 of file pin.c.

References HSM_MAX_PIN_LENGTH, HSM_MAX_SESSIONS, HSM_PIN_FIRST, HSM_PIN_RETRY, HSM_PIN_SAVE, hsm_sem_open(), hsm_sem_post(), hsm_sem_wait(), hsm_shm_open(), and prompt_pass().

Referenced by main().

int hsm_sem_open ( )

Definition at line 105 of file pin.c.

References semun::buf, hsm_ctx_set_error(), HSM_ERROR, SEM_KEY, SEM_PERM, and semun::val.

Referenced by hsm_check_pin(), and hsm_prompt_pin().

int hsm_sem_post ( int  semid)

Definition at line 165 of file pin.c.

References hsm_ctx_set_error(), and HSM_ERROR.

Referenced by hsm_check_pin(), and hsm_prompt_pin().

int hsm_sem_wait ( int  semid)

Definition at line 151 of file pin.c.

References hsm_ctx_set_error(), and HSM_ERROR.

Referenced by hsm_check_pin(), and hsm_prompt_pin().

int hsm_shm_open ( )

Definition at line 179 of file pin.c.

References hsm_ctx_set_error(), HSM_ERROR, HSM_MAX_PIN_LENGTH, HSM_MAX_SESSIONS, SHM_KEY, and SHM_PERM.

Referenced by hsm_check_pin(), and hsm_prompt_pin().

char* prompt_pass ( char *  prompt)

Definition at line 69 of file pin.c.

References HSM_MAX_PIN_LENGTH.

Referenced by hsm_prompt_pin().

Variable Documentation

hsm_ctx_t* _hsm_ctx