]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_sign_algorithm_get_name() and gnutls_pk_algorithm_get_name().
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 Apr 2004 09:21:32 +0000 (09:21 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 Apr 2004 09:21:32 +0000 (09:21 +0000)
NEWS
doc/TODO
doc/tex/ex-rfc2818.tex
lib/gnutls.h.in.in
lib/gnutls_algorithms.c
src/certtool.c
src/crypt-gaa.c
src/crypt-gaa.h

diff --git a/NEWS b/NEWS
index 7c6077dd9e3ad35a2bdba4f325004716d52d6cba..4ae07c881b84e12fb2a227e3434d2fd76e2067ed 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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.
index 2eb24712861acd2c57c9de6d281797aa7bc2c6ac..173aa71c793687ad53fa0c9de851357517520160 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -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)
index b32095b288c58b796e84df5327a0173bde6016b9..f0a904a391ecdf5f278024a88ffbe5f7390da78d 100644 (file)
@@ -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;
    }
index c5682ea7723e67f3c622b995f2e438f133f4e02e..a961f262bd2bc3bfc7854b0bc01ae50fd0ca9609 100644 (file)
@@ -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.
  */
index ce99a5dc34a4552bf12153c21905e631cc71c000..741d8203caade226d260a9748ace5bbbb3939193 100644 (file)
@@ -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;
+}
index 2017c3b5aba9ccf845e65585fb008971eb6f4647..ea9547e95bf9f70cf60610896d0937a0d2f2e062 100644 (file)
@@ -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);
 
 
index 77f4a8f4e83ffb3e4d6e9d267f9078cd394c1a82..cb2e8e95e2731f626362142a9d2ddcfa69900688 100644 (file)
@@ -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;
index f904827a54706209b8171b4f2b23bb75341f41ec..ba3ddf43b23d59a73cc961bd3bf55046e6f877dc 100644 (file)
@@ -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
 }