• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

/build/buildd-opendnssec_1.3.2-1~bpo60+1-mips-pXL6jA/opendnssec-1.3.2/libhsm/src/libhsm.h

Go to the documentation of this file.
00001 /* $Id: libhsm.h 4474 2011-02-16 10:43:54Z sion $ */
00002 
00003 /*
00004  * Copyright (c) 2009 .SE (The Internet Infrastructure Foundation).
00005  * Copyright (c) 2009 NLNet Labs.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00023  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00025  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00027  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef HSM_H
00031 #define HSM_H 1
00032 
00033 #include <stdint.h>
00034 
00035 #define HSM_MAX_SESSIONS 100
00036 /* 
00037  * Note that currently the MySQL kasp schema limits the number of HSMs to 
00038  * 127; so to increase it beyond that requires some database changes similar
00039  * to when keypairs(id) was increased, see svn r4465.
00040  */
00041 #define HSM_MAX_ALGONAME 16
00042 
00043 #define HSM_ERROR_MSGSIZE 512
00044 
00049 #define HSM_OK                    0
00050 #define HSM_ERROR                 0x10000001
00051 #define HSM_PIN_INCORRECT         0x10000002
00052 #define HSM_CONFIG_FILE_ERROR     0x10000003
00053 #define HSM_REPOSITORY_NOT_FOUND  0x10000004
00054 #define HSM_NO_REPOSITORIES       0x10000005
00055 #define HSM_MODULE_NOT_FOUND      0x10000006
00056 
00057 
00059 typedef struct {
00060     unsigned int use_pubkey;     
00061 } hsm_config_t;
00062 
00064 typedef struct {
00065     unsigned int id;             
00066     char         *name;          
00067     char         *token_label;   
00068     char         *path;          
00069     void         *handle;        
00070     void         *sym;           
00071     hsm_config_t *config;        
00072 } hsm_module_t;
00073 
00075 typedef struct {
00076     hsm_module_t  *module;
00077     unsigned long session;
00078 } hsm_session_t;
00079 
00081 typedef struct {
00082     const hsm_module_t *module;      
00083     unsigned long      private_key;  
00084     unsigned long      public_key;   
00085 } hsm_key_t;
00086 
00088 typedef struct {
00089   char          *id;             
00090   unsigned long algorithm;       
00091   char          *algorithm_name; 
00092   unsigned long keysize;         
00093 } hsm_key_info_t;
00094 
00096 typedef struct {
00097     hsm_session_t *session[HSM_MAX_SESSIONS];  
00098     size_t        session_count;               
00101     int error;
00102 
00105     const char *error_action;
00106 
00108     char error_message[HSM_ERROR_MSGSIZE];
00109 } hsm_ctx_t;
00110 
00111 
00129 int
00130 hsm_open(const char *config,
00131          char *(pin_callback)(const char *repository, void *),
00132          void *data);
00133 
00134 
00142 char *
00143 hsm_prompt_pin(const char *repository, void *data);
00144 
00145 
00152 int
00153 hsm_close();
00154 
00155 
00161 hsm_ctx_t *
00162 hsm_create_context(void);
00163 
00164 
00171 void
00172 hsm_destroy_context(hsm_ctx_t *context);
00173 
00174 
00187 hsm_key_t **
00188 hsm_list_keys(hsm_ctx_t *context, size_t *count);
00189 
00190 
00204 hsm_key_t **
00205 hsm_list_keys_repository(hsm_ctx_t *context,
00206                          size_t *count,
00207                          const char *repository);
00208 
00209 
00214 size_t
00215 hsm_count_keys(hsm_ctx_t *context);
00216 
00217 
00223 size_t
00224 hsm_count_keys_repository(hsm_ctx_t *context,
00225                           const char *repository);
00226 
00227 
00228 
00238 hsm_key_t *
00239 hsm_find_key_by_id(hsm_ctx_t *context,
00240                    const char *id);
00241 
00255 hsm_key_t *
00256 hsm_generate_rsa_key(hsm_ctx_t *context,
00257                      const char *repository,
00258                      unsigned long keysize);
00259 
00260 
00271 int
00272 hsm_remove_key(hsm_ctx_t *context, hsm_key_t *key);
00273 
00274 
00279 void
00280 hsm_key_free(hsm_key_t *key);
00281 
00282 
00289 void
00290 hsm_key_list_free(hsm_key_t **key_list, size_t count);
00291 
00292 
00301 char *
00302 hsm_get_key_id(hsm_ctx_t *context,
00303                const hsm_key_t *key);
00304 
00305 
00315 hsm_key_info_t *
00316 hsm_get_key_info(hsm_ctx_t *context,
00317                  const hsm_key_t *key);
00318 
00319 
00324 void
00325 hsm_key_info_free(hsm_key_info_t *key_info);
00326 
00335 int
00336 hsm_random_buffer(hsm_ctx_t *ctx,
00337                   unsigned char *buffer,
00338                   unsigned long length);
00339 
00340 
00346 uint32_t
00347 hsm_random32(hsm_ctx_t *ctx);
00348 
00349 
00355 uint64_t
00356 hsm_random64(hsm_ctx_t *ctx);
00357 
00358 
00359 
00360 /*
00361  * Additional functions for debugging, and non-general use-cases.
00362  */
00363 
00375 int
00376 hsm_attach(const char *repository,
00377            const char *token_name,
00378            const char *path,
00379            const char *pin,
00380            const hsm_config_t *config);
00381 
00387 int
00388 hsm_detach(const char *repository);
00389 
00395 int
00396 hsm_token_attached(hsm_ctx_t *ctx,
00397                    const char *repository);
00398 
00407 char *
00408 hsm_get_error(hsm_ctx_t *gctx);
00409 
00410 /* a few debug functions for applications */
00411 void hsm_print_session(hsm_session_t *session);
00412 void hsm_print_ctx(hsm_ctx_t *gctx);
00413 void hsm_print_key(hsm_key_t *key);
00414 void hsm_print_error(hsm_ctx_t *ctx);
00415 void hsm_print_tokeninfo(hsm_ctx_t *gctx);
00416 
00417 #endif /* HSM_H */

Generated on Sat Dec 17 2011 10:19:13 for OpenDNSSEC-libhsm by  doxygen 1.7.1