diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2004-04-17 09:21:32 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2004-04-17 09:21:32 +0000 |
commit | c5bbc33a7068ea4c1fb693110ef54787baea288d (patch) | |
tree | 049f81ed21a577c29a01d2798d31de9467b843fc | |
parent | 7392657fa80f10593a974cc0628d6dd8b4d6e425 (diff) | |
download | gnutls-c5bbc33a7068ea4c1fb693110ef54787baea288d.tar.gz |
Added gnutls_sign_algorithm_get_name() and gnutls_pk_algorithm_get_name().
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/TODO | 1 | ||||
-rw-r--r-- | doc/tex/ex-rfc2818.tex | 2 | ||||
-rw-r--r-- | lib/gnutls.h.in.in | 4 | ||||
-rw-r--r-- | lib/gnutls_algorithms.c | 84 | ||||
-rw-r--r-- | src/certtool.c | 44 | ||||
-rw-r--r-- | src/crypt-gaa.c | 47 | ||||
-rw-r--r-- | src/crypt-gaa.h | 2 |
8 files changed, 127 insertions, 60 deletions
@@ -1,3 +1,6 @@ +Version 1.1.10 +- Added gnutls_sign_algorithm_get_name() and gnutls_pk_algorithm_get_name() + Version 1.1.9 (14/04/2004) - Added support for authority key identifier and the extended key usage X.509 extension fields. The certtoool was updated to support them. @@ -3,6 +3,7 @@ anything), contact the developer's mailing list (gnutls-dev@lists.gnupg.org), in order to avoid having people working on the same thing. Current list: +* Verify added CRLs * Document the format for the supported DN attributes. * Add support for Certificate Extensions Profile for Qualified Certificates (rfc3039) diff --git a/doc/tex/ex-rfc2818.tex b/doc/tex/ex-rfc2818.tex index b32095b288..f0a904a391 100644 --- a/doc/tex/ex-rfc2818.tex +++ b/doc/tex/ex-rfc2818.tex @@ -65,7 +65,7 @@ void verify_certificate( gnutls_session session, const char* hostname) /* Beware here we do not check for errors. */ - if ( gnutls_x509_crt_get_expiration( cert) < time(0)) { + if ( gnutls_x509_crt_get_expiration_time( cert) < time(0)) { printf("The certificate has expired\n"); return; } diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in index c5682ea772..a961f262bd 100644 --- a/lib/gnutls.h.in.in +++ b/lib/gnutls.h.in.in @@ -164,11 +164,15 @@ typedef enum gnutls_pk_algorithm { GNUTLS_PK_RSA = 1, GNUTLS_PK_DSA, GNUTLS_PK_UNKNOWN = 0xff } gnutls_pk_algorithm; +const char *gnutls_pk_algorithm_get_name( gnutls_pk_algorithm algorithm); + typedef enum gnutls_sign_algorithm { GNUTLS_SIGN_RSA_SHA = 1, GNUTLS_SIGN_DSA_SHA, GNUTLS_SIGN_RSA_MD5, GNUTLS_SIGN_RSA_MD2, GNUTLS_SIGN_UNKNOWN = 0xff } gnutls_sign_algorithm; +const char *gnutls_sign_algorithm_get_name( gnutls_sign_algorithm algorithm); + /* If you want to change this, then also change the * define in gnutls_int.h, and recompile. */ diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c index ce99a5dc34..741d8203ca 100644 --- a/lib/gnutls_algorithms.c +++ b/lib/gnutls_algorithms.c @@ -1366,3 +1366,87 @@ enum encipher_type _gnutls_kx_encipher_type(gnutls_kx_algorithm kx_algorithm) return ret; } + +/* signature algorithms; + */ +struct gnutls_sign_entry { + const char *name; + gnutls_sign_algorithm id; +}; +typedef struct gnutls_sign_entry gnutls_sign_entry; + +static const gnutls_sign_entry sign_algorithms[] = { + {"RSA-SHA", GNUTLS_SIGN_RSA_SHA}, + {"DSA-SHA", GNUTLS_SIGN_DSA_SHA}, + {"RSA-MD5", GNUTLS_SIGN_RSA_MD5}, + {"RSA-MD2", GNUTLS_SIGN_RSA_MD2}, + {0, 0} +}; + +#define GNUTLS_SIGN_LOOP(b) \ + const gnutls_sign_entry *p; \ + for(p = sign_algorithms; p->name != NULL; p++) { b ; } + +#define GNUTLS_SIGN_ALG_LOOP(a) \ + GNUTLS_SIGN_LOOP( if(p->id == algorithm) { a; break; } ) + + + +/** + * gnutls_sign_algorithm_get_name - Returns a string with the name of the specified sign algorithm + * @algorithm: is a sign algorithm + * + * Returns a string that contains the name + * of the specified sign algorithm or NULL. + **/ +const char *gnutls_sign_algorithm_get_name( gnutls_sign_algorithm algorithm) +{ + const char *ret = NULL; + + /* avoid prefix */ + GNUTLS_SIGN_ALG_LOOP(ret = + p->name); + + return ret; +} + +/* pk algorithms; + */ +struct gnutls_pk_entry { + const char *name; + gnutls_pk_algorithm id; +}; +typedef struct gnutls_pk_entry gnutls_pk_entry; + +static const gnutls_pk_entry pk_algorithms[] = { + {"RSA", GNUTLS_PK_RSA}, + {"DSA", GNUTLS_PK_DSA}, + {0, 0} +}; + +#define GNUTLS_PK_LOOP(b) \ + const gnutls_pk_entry *p; \ + for(p = sign_algorithms; p->name != NULL; p++) { b ; } + +#define GNUTLS_PK_ALG_LOOP(a) \ + GNUTLS_PK_LOOP( if(p->id == algorithm) { a; break; } ) + + + +/** + * gnutls_pk_algorithm_get_name - Returns a string with the name of the specified public key algorithm + * @algorithm: is a pk algorithm + * + * Returns a string that contains the name + * of the specified public key algorithm or NULL. + **/ +const char *gnutls_pk_algorithm_get_name( gnutls_pk_algorithm algorithm) +{ + const char *ret = NULL; + + /* avoid prefix */ + GNUTLS_PK_ALG_LOOP(ret = + p->name); + + return ret; +} diff --git a/src/certtool.c b/src/certtool.c index 2017c3b5ab..ea9547e95b 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -62,6 +62,8 @@ FILE* infile; static int in_cert_format; static int out_cert_format; +#define UNKNOWN "Unknown" + /* non interactive operation if set */ int batch; @@ -786,36 +788,6 @@ int ret; } -const char* get_pk_algorithm( gnutls_pk_algorithm a) -{ - switch (a) { - case GNUTLS_PK_RSA: - return "RSA"; - case GNUTLS_PK_DSA: - return "DSA"; - break; - default: - return "UNKNOWN"; - } -} - -const char* get_sign_algorithm( gnutls_sign_algorithm a) -{ - switch (a) { - case GNUTLS_SIGN_RSA_SHA: - return "RSA-SHA"; - case GNUTLS_SIGN_RSA_MD5: - return "RSA-MD5"; - case GNUTLS_SIGN_RSA_MD2: - return "RSA-MD2"; - case GNUTLS_SIGN_DSA_SHA: - return "DSA-SHA"; - break; - default: - return "UNKNOWN"; - } -} - /* OIDs that are handled by the gnutls' functions. */ static inline int known_oid( const char* oid) @@ -922,7 +894,8 @@ static void print_certificate_info( gnutls_x509_crt crt, FILE* out, unsigned int fprintf(out, "Signature Algorithm: "); ret = gnutls_x509_crt_get_signature_algorithm(crt); - cprint = get_sign_algorithm( ret); + cprint = gnutls_sign_algorithm_get_name( ret); + if (cprint == NULL) cprint = UNKNOWN; fprintf(out, "%s\n", cprint); } @@ -942,7 +915,8 @@ static void print_certificate_info( gnutls_x509_crt crt, FILE* out, unsigned int ret = gnutls_x509_crt_get_pk_algorithm(crt, NULL); fprintf(out, "\tPublic Key Algorithm: "); - cprint = get_pk_algorithm( ret); + cprint = gnutls_pk_algorithm_get_name( ret); + if (cprint == NULL) cprint = UNKNOWN; fprintf(out, "%s\n", cprint); @@ -1199,7 +1173,8 @@ static void print_crl_info( gnutls_x509_crl crl, FILE* out, int all) fprintf(out, "Signature Algorithm: "); ret = gnutls_x509_crl_get_signature_algorithm(crl); - cprint = get_sign_algorithm( ret); + cprint = gnutls_sign_algorithm_get_name( ret); + if (cprint == NULL) cprint = UNKNOWN; fprintf(out, "%s\n", cprint); } @@ -1316,7 +1291,8 @@ void privkey_info( void) ret = gnutls_x509_privkey_get_pk_algorithm(key); fprintf(outfile, "\tPublic Key Algorithm: "); - cprint = get_pk_algorithm( ret); + cprint = gnutls_pk_algorithm_get_name( ret); + if (cprint == NULL) cprint = UNKNOWN; fprintf(outfile, "%s\n", cprint); diff --git a/src/crypt-gaa.c b/src/crypt-gaa.c index 77f4a8f4e8..cb2e8e95e2 100644 --- a/src/crypt-gaa.c +++ b/src/crypt-gaa.c @@ -1,4 +1,4 @@ -/* File generated by GAA 1.6.5 +/* File generated by GAA 1.6.6 */ #define GAA_NO_WIN32 #line 1 "crypt.gaa" @@ -21,7 +21,7 @@ #endif #endif -void* gaa_malloc( size_t size) { +static void* gaa_malloc( size_t size) { void* ret; ret = malloc(size); if (ret==NULL) { @@ -31,7 +31,7 @@ void* ret; return ret; } -void __gaa_helpsingle(char short_name, char *name, +static void __gaa_helpsingle(char short_name, char *name, char *arg_desc, char *opt_help) { int col1, col3, col4, tabsize = 3, curr; @@ -176,7 +176,7 @@ extern "C" void gaa_help(void); - int gaa_file(char *name, gaainfo *gaaval); + int gaa_file(const char *name, gaainfo *gaaval); #ifdef __cplusplus } @@ -195,8 +195,8 @@ gaa_error = 1; \ return x; \ } -char *gaa_current_option; -int gaa_error = 0; +static char *gaa_current_option; +static int gaa_error = 0; /* Generated by gaa */ @@ -367,13 +367,13 @@ if(k > 1) \ } -char **GAAargv; -int GAAargc; -char *gaa_arg_used; -int gaa_processing_file = 0; -int inited = 0; +static char **GAAargv; +static int GAAargc; +static char *gaa_arg_used; +static int gaa_processing_file = 0; +static int inited = 0; -int gaa_getint(char *arg) +static int gaa_getint(char *arg) { int tmp; char a; @@ -385,7 +385,7 @@ int gaa_getint(char *arg) return tmp; } -char gaa_getchar(char *arg) +static char gaa_getchar(char *arg) { if(strlen(arg) != 1) { @@ -395,11 +395,11 @@ char gaa_getchar(char *arg) return arg[0]; } -char* gaa_getstr(char *arg) +static char* gaa_getstr(char *arg) { return arg; } -float gaa_getfloat(char *arg) +static float gaa_getfloat(char *arg) { float tmp; char a; @@ -449,7 +449,7 @@ struct GAAOPTION_username }; #line 349 "gaa.skel" -int gaa_is_an_argument(char *str) +static int gaa_is_an_argument(char *str) { #ifdef GAA_WIN32 if(str[0] == '/' && str[1] != 0) @@ -472,7 +472,7 @@ int gaa_is_an_argument(char *str) return GAA_MULTIPLE_OPTION; } -int gaa_get_option_num(char *str, int status) +static int gaa_get_option_num(char *str, int status) { switch(status) { @@ -507,7 +507,7 @@ int gaa_get_option_num(char *str, int status) return GAA_ERROR_NOMATCH; } -int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) +static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list) { int OK = 0; int gaa_last_non_option; @@ -754,11 +754,10 @@ struct gaastrnode typedef struct gaastrnode gaa_str_node; -int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) +static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) { int pos_ini; int a; - char ca; int i = 0, len = 0, newline = 0; if(argc == 1) { @@ -807,12 +806,12 @@ int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) fseek(file,pos_ini, SEEK_SET); do { - if(fscanf(file, "%c", &ca) != 1) - { + a = fgetc( file); + + if (a == EOF) { i+=2; break; } - a = ca; tmp_str->str[i] = a; i++; } @@ -826,7 +825,7 @@ int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc) return -1; } -int gaa_file(char *name, gaainfo *gaaval) +int gaa_file(const char *name, gaainfo *gaaval) { gaa_str_node *first_str, **tmp_str, *tmp_str2; int rval, i; diff --git a/src/crypt-gaa.h b/src/crypt-gaa.h index f904827a54..ba3ddf43b2 100644 --- a/src/crypt-gaa.h +++ b/src/crypt-gaa.h @@ -35,7 +35,7 @@ extern "C" void gaa_help(void); - int gaa_file(char *name, gaainfo *gaaval); + int gaa_file(const char *name, gaainfo *gaaval); #ifdef __cplusplus } |