]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added some private key handling functions. They are primitive enough for now.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 12 Feb 2003 12:48:42 +0000 (12:48 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 12 Feb 2003 12:48:42 +0000 (12:48 +0000)
17 files changed:
NEWS
includes/gnutls/compat8.h
includes/gnutls/x509.h
lib/gnutls.h.in.in
lib/gnutls_dh_primes.c
lib/gnutls_int.h
lib/gnutls_privkey.c
lib/gnutls_ui.h
lib/gnutls_x509.c
lib/x509/Makefile.am
lib/x509/compat.c
lib/x509/crl.c
lib/x509/pkcs7.c
lib/x509/pkcs7.h
lib/x509/privkey.c [new file with mode: 0644]
lib/x509/x509.c
lib/x509/x509.h

diff --git a/NEWS b/NEWS
index cdf11ef7f15ee0b4e4ac9de8be0c9177ed33b29b..857f3bd370947d1eab589098cd615169ae8efb16 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,8 +12,8 @@ Version 0.9.0
 - Several changes in the temporary (DH/RSA) parameter codebase. No DH 
   parameters are now included in the library. Also the credentials structure 
   can now hold only one temporary parameter of a kind.
-- Added a new Certificate and PKCS7 structures handling API, defined
-  in gnutls/x509.h
+- Added a new Certificate, CRL, Private key and PKCS7 structures handling 
+  API, defined in gnutls/x509.h
 - Added support for Certificate Revocation lists. Functions defined
   in gnutls/x509.h
 - The only functions were removed are:
index 8ed390a32bd251644b2e400e35e7d61f0ec0a238..3ee99453649639e4f2d24595f0e260f5984b20c3 100644 (file)
@@ -48,6 +48,8 @@ int gnutls_x509_check_certificates_hostname(const gnutls_datum * cert,
                                 const char *hostname);
 
 #define gnutls_x509_fingerprint gnutls_fingerprint
-#define gnutls_x509_certificate_format gnutls_x509_crt_format
+#define gnutls_x509_certificate_format gnutls_x509_crt_fmt
+
+int gnutls_x509_extract_key_pk_algorithm( const gnutls_datum * key);
 
 #endif
index 0812b09c979b2115a81e98cdcf7559377d0c7713..65e40467eae892a9bfec242ca1c200d20cd1e7c3 100644 (file)
@@ -52,7 +52,7 @@ typedef struct gnutls_x509_crt_int* gnutls_x509_crt;
 int gnutls_x509_crt_init(gnutls_x509_crt * cert);
 void gnutls_x509_crt_deinit(gnutls_x509_crt cert);
 int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data,
-       gnutls_x509_crt_format format);
+       gnutls_x509_crt_fmt format);
 int gnutls_x509_crt_get_issuer_dn(gnutls_x509_crt cert, char *buf,
         int *sizeof_buf);
 int gnutls_x509_crt_get_issuer_dn_by_oid(gnutls_x509_crt cert, 
@@ -116,7 +116,7 @@ int gnutls_x509_crl_init(gnutls_x509_crl * crl);
 void gnutls_x509_crl_deinit(gnutls_x509_crl crl);
 
 int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data, 
-       gnutls_x509_crt_format format);
+       gnutls_x509_crt_fmt format);
 
 int gnutls_x509_crl_get_issuer_dn(const gnutls_x509_crl crl, 
        char *buf, int *sizeof_buf);
@@ -154,7 +154,7 @@ void gnutls_pkcs7_deinit(gnutls_pkcs7 pkcs7);
 int gnutls_pkcs7_get_certificate_count( gnutls_pkcs7 pkcs7);
 
 int gnutls_pkcs7_import(gnutls_pkcs7 pkcs7, const gnutls_datum * data,
-       gnutls_x509_crt_format format);
+       gnutls_x509_crt_fmt format);
 
 int gnutls_pkcs7_get_certificate(gnutls_pkcs7 pkcs7, int indx, 
        char* certificate, int* certificate_size);
@@ -191,6 +191,18 @@ int gnutls_x509_crt_get_fingerprint(gnutls_x509_crt cert,
        gnutls_digest_algorithm algo, char *buf,
         int *sizeof_buf);
 
+/* Private key handling
+ */
+struct gnutls_x509_privkey_int;
+typedef struct gnutls_x509_privkey_int* gnutls_x509_privkey;
+
+int gnutls_x509_privkey_init(gnutls_x509_privkey * key);
+void gnutls_x509_privkey_deinit(gnutls_x509_privkey key);
+int gnutls_x509_privkey_import(gnutls_x509_privkey key, const gnutls_datum * data,
+       gnutls_x509_crt_fmt format);
+int gnutls_x509_privkey_get_pk_algorithm( gnutls_x509_privkey key);
+
+
 #ifdef __cplusplus
 }
 #endif
index 166ead13c9e299671000ea916cc35a53f8157378..6ec7b25a659761bf8629b03e52995b8d839cfebe 100644 (file)
@@ -116,8 +116,8 @@ typedef enum gnutls_protocol_version { GNUTLS_SSL3=1, GNUTLS_TLS1 } gnutls_proto
 typedef enum gnutls_certificate_type { GNUTLS_CRT_X509=1, GNUTLS_CRT_OPENPGP 
 } gnutls_certificate_type;
 
-typedef enum gnutls_x509_crt_format { GNUTLS_X509_FMT_DER, 
-       GNUTLS_X509_FMT_PEM } gnutls_x509_crt_format;
+typedef enum gnutls_x509_crt_fmt { GNUTLS_X509_FMT_DER, 
+       GNUTLS_X509_FMT_PEM } gnutls_x509_crt_fmt;
 
 typedef enum gnutls_pk_algorithm { GNUTLS_PK_RSA = 1, GNUTLS_PK_DSA,
        GNUTLS_PK_UNKNOWN = 0xff
@@ -310,20 +310,20 @@ int gnutls_certificate_set_dh_params(gnutls_certificate_credentials res, gnutls_
 int gnutls_certificate_set_rsa_params(gnutls_certificate_credentials res, gnutls_rsa_params rsa_params);
 
 int gnutls_certificate_set_x509_trust_file( gnutls_certificate_credentials res, const char* CAFILE, 
-       gnutls_x509_crt_format);
+       gnutls_x509_crt_fmt);
 int gnutls_certificate_set_x509_trust_mem(gnutls_certificate_credentials res, 
-       const gnutls_datum *CA, gnutls_x509_crt_format);
+       const gnutls_datum *CA, gnutls_x509_crt_fmt);
 
 int gnutls_certificate_set_x509_crl_file(gnutls_certificate_credentials res, 
-               const char *crlfile, gnutls_x509_crt_format type);
+               const char *crlfile, gnutls_x509_crt_fmt type);
 int gnutls_certificate_set_x509_crl_mem(gnutls_certificate_credentials res, 
-       const gnutls_datum *CRL, gnutls_x509_crt_format type);
+       const gnutls_datum *CRL, gnutls_x509_crt_fmt type);
 
 int gnutls_certificate_set_x509_key_file( gnutls_certificate_credentials res, 
-       const char *CERTFILE, const char* KEYFILE, gnutls_x509_crt_format);
+       const char *CERTFILE, const char* KEYFILE, gnutls_x509_crt_fmt);
 int gnutls_certificate_set_x509_key_mem(gnutls_certificate_credentials res, 
        const gnutls_datum* CERT, const gnutls_datum* KEY,
-       gnutls_x509_crt_format);
+       gnutls_x509_crt_fmt);
 
 /* global state functions 
  */
index bc92277b3cd2d041aed5cc6e42be4c771f21bef7..8b2d1c41c98d9485eb24968dc94fc2f1462aab93 100644 (file)
@@ -310,7 +310,7 @@ int gnutls_dh_params_generate(gnutls_datum * prime,
   *
   **/
 int gnutls_pkcs3_extract_dh_params(const gnutls_datum * params,
-                                  gnutls_x509_crt_format format,
+                                  gnutls_x509_crt_fmt format,
                                   gnutls_datum * prime,
                                   gnutls_datum * generator, int *bits)
 {
@@ -431,7 +431,7 @@ int gnutls_pkcs3_extract_dh_params(const gnutls_datum * params,
   **/
 int gnutls_pkcs3_export_dh_params( const gnutls_datum * prime,
                                   const gnutls_datum * generator,
-                                  gnutls_x509_crt_format format,
+                                  gnutls_x509_crt_fmt format,
                                   unsigned char* params_data, int* params_data_size)
 {
        ASN1_TYPE c2;
index d00c56fc284062f253cfc04cae8858a701b2c123..a5ac45c5cdc4344d6531ee2111063cf4bc9814f1 100644 (file)
@@ -194,8 +194,8 @@ typedef enum ContentType { GNUTLS_CHANGE_CIPHER_SPEC=20, GNUTLS_ALERT,
        GNUTLS_HANDSHAKE, GNUTLS_APPLICATION_DATA 
 } ContentType;
 
-typedef enum gnutls_x509_crt_format { GNUTLS_X509_FMT_DER, 
-       GNUTLS_X509_FMT_PEM } gnutls_x509_crt_format;
+typedef enum gnutls_x509_crt_fmt { GNUTLS_X509_FMT_DER, 
+       GNUTLS_X509_FMT_PEM } gnutls_x509_crt_fmt;
 
 typedef enum gnutls_pk_algorithm { GNUTLS_PK_RSA = 1, GNUTLS_PK_DSA,
        GNUTLS_PK_UNKNOWN = 0xff
index 37b14e797c88424c59f6c3f61bf0cb5a63ed002a..e37de43520c23bdbf322a9ee67a182a4d7f9fa46 100644 (file)
@@ -253,36 +253,3 @@ void _gnutls_free_private_key(gnutls_private_key pkey)
        return;
 }
 
-/**
-  * gnutls_x509_extract_key_pk_algorithm - This function returns the keys's PublicKey algorithm
-  * @cert: is a DER encoded private key
-  *
-  * This function will return the public key algorithm of a DER encoded private
-  * key.
-  *
-  * Returns a member of the gnutls_pk_algorithm enumeration on success,
-  * or GNUTLS_E_UNKNOWN_PK_ALGORITHM on error.
-  *
-  **/
-int gnutls_x509_extract_key_pk_algorithm( const gnutls_datum * key)
-{
-int cv, pk;
-
-        pk = GNUTLS_E_UNKNOWN_PK_ALGORITHM;
-
-       /* The only way to distinguish the keys
-        * is to count the sequence of integers.
-        */
-       cv = _gnutls_der_check_if_rsa_key( key);
-       if (cv==0)
-               pk = GNUTLS_PK_RSA;
-       else {
-               cv = _gnutls_der_check_if_dsa_key( key);
-               if (cv==0)
-                       pk = GNUTLS_PK_DSA;
-       }
-
-       return pk;
-
-}
-
index b14aaa2f4dfdfd5471a0eb99caaec5a86a713ceb..38c14bd001096712116aaa240982823aa75cb34a 100644 (file)
@@ -41,10 +41,10 @@ void gnutls_certificate_server_set_request( gnutls_session, gnutls_certificate_r
  */
 
 int gnutls_pkcs3_extract_dh_params(const gnutls_datum * params,
-       gnutls_x509_crt_format format, gnutls_datum * prime,
+       gnutls_x509_crt_fmt format, gnutls_datum * prime,
        gnutls_datum * generator, int* prime_bits);
 int gnutls_pkcs3_export_dh_params( const gnutls_datum * prime,
-       const gnutls_datum * generator, gnutls_x509_crt_format format,
+       const gnutls_datum * generator, gnutls_x509_crt_fmt format,
        unsigned char* params_data, int* params_data_size);
 
 /* get data from the session 
index 7d4a0e62af44ace78d3e0412cb508941534c1ea5..6cb8aee7f57419b902c2afcf73328536f886bbd9 100644 (file)
@@ -390,7 +390,7 @@ static int parse_pem_cert_mem( gnutls_cert** cert_list, int* ncerts,
  */
 static 
 int read_cert_mem(gnutls_certificate_credentials res, const char *cert, int cert_size, 
-       gnutls_x509_crt_format type)
+       gnutls_x509_crt_fmt type)
 {
        int ret;
 
@@ -506,7 +506,7 @@ int _gnutls_der_check_if_dsa_key(const gnutls_datum * key_struct)
  * type indicates the certificate format.
  */
 static int read_key_mem(gnutls_certificate_credentials res, const char *key, int key_size, 
-       gnutls_x509_crt_format type)
+       gnutls_x509_crt_fmt type)
 {
        int ret;
        opaque *b64 = NULL;
@@ -612,7 +612,7 @@ static int read_key_mem(gnutls_certificate_credentials res, const char *key, int
 /* Reads a certificate file
  */
 static int read_cert_file(gnutls_certificate_credentials res, const char *certfile,
-       gnutls_x509_crt_format type)
+       gnutls_x509_crt_fmt type)
 {
        int siz;
        char x[MAX_FILE_SIZE];
@@ -637,7 +637,7 @@ static int read_cert_file(gnutls_certificate_credentials res, const char *certfi
  * stores it).
  */
 static int read_key_file(gnutls_certificate_credentials res, const char *keyfile,
-       gnutls_x509_crt_format type)
+       gnutls_x509_crt_fmt type)
 {
        int siz;
        char x[MAX_FILE_SIZE];
@@ -682,7 +682,7 @@ static int read_key_file(gnutls_certificate_credentials res, const char *keyfile
   *
   **/
 int gnutls_certificate_set_x509_key_mem(gnutls_certificate_credentials res, const gnutls_datum* CERT,
-                          const gnutls_datum* KEY, gnutls_x509_crt_format type)
+                          const gnutls_datum* KEY, gnutls_x509_crt_fmt type)
 {
        int ret;
 
@@ -720,7 +720,7 @@ int gnutls_certificate_set_x509_key_mem(gnutls_certificate_credentials res, cons
   *
   **/
 int gnutls_certificate_set_x509_key_file(gnutls_certificate_credentials res, const char *CERTFILE,
-                          const char *KEYFILE, gnutls_x509_crt_format type)
+                          const char *KEYFILE, gnutls_x509_crt_fmt type)
 {
        int ret;
 
@@ -982,7 +982,7 @@ static int parse_der_ca_mem( gnutls_x509_crt** cert_list, int* ncerts,
   *
   **/
 int gnutls_certificate_set_x509_trust_mem(gnutls_certificate_credentials res, 
-       const gnutls_datum *CA, gnutls_x509_crt_format type)
+       const gnutls_datum *CA, gnutls_x509_crt_fmt type)
 {
        int ret, ret2;
 
@@ -1012,7 +1012,7 @@ int gnutls_certificate_set_x509_trust_mem(gnutls_certificate_credentials res,
   *
   **/
 int gnutls_certificate_set_x509_trust_file(gnutls_certificate_credentials res, 
-               const char *CAFILE, gnutls_x509_crt_format type)
+               const char *CAFILE, gnutls_x509_crt_fmt type)
 {
        int ret, ret2;
        int siz;
@@ -1168,7 +1168,7 @@ static int parse_der_crl_mem( gnutls_x509_crl** crl_list, int* ncrls,
  */
 static 
 int read_crl_mem(gnutls_certificate_credentials res, const char *crl, int crl_size, 
-       gnutls_x509_crt_format type)
+       gnutls_x509_crt_fmt type)
 {
        int ret;
 
@@ -1207,7 +1207,7 @@ int read_crl_mem(gnutls_certificate_credentials res, const char *crl, int crl_si
   *
   **/
 int gnutls_certificate_set_x509_crl_mem(gnutls_certificate_credentials res, 
-       const gnutls_datum *CRL, gnutls_x509_crt_format type)
+       const gnutls_datum *CRL, gnutls_x509_crt_fmt type)
 {
        int ret;
 
@@ -1230,7 +1230,7 @@ int gnutls_certificate_set_x509_crl_mem(gnutls_certificate_credentials res,
   *
   **/
 int gnutls_certificate_set_x509_crl_file(gnutls_certificate_credentials res, 
-               const char *crlfile, gnutls_x509_crt_format type)
+               const char *crlfile, gnutls_x509_crt_fmt type)
 {
        int ret;
        int siz;
index cedcc7fcb8920747c449e97023f1fbbd5210fbc2..5f7305a57e06f4e91cb21b07584d585c8d7c017c 100644 (file)
@@ -5,7 +5,7 @@ EXTRA_DIST = dn.h common.h x509.h extensions.h pkcs7.h \
 noinst_LTLIBRARIES = libx509.la
 
 COBJECTS = crl.c dn.c common.c x509.c extensions.c \
-       pkcs7.c xml.c rfc2818_hostname.c verify.c mpi.c
+       pkcs7.c xml.c rfc2818_hostname.c verify.c mpi.c privkey.c
 
 COMPAT_OBJECTS = compat.c
 
index e8e3385bd2451d4c9c76e9867e752ed2f3cfb736..0f8e457a4deae7d4b8017db830b8f56f29e407b8 100644 (file)
@@ -746,3 +746,38 @@ int gnutls_x509_verify_certificate( const gnutls_datum* cert_list, int cert_list
 
        return ret;
 }
+
+/**
+  * gnutls_x509_extract_key_pk_algorithm - This function returns the keys's PublicKey algorithm
+  * @cert: is a DER encoded private key
+  *
+  * This function will return the public key algorithm of a DER encoded private
+  * key.
+  *
+  * Returns a member of the gnutls_pk_algorithm enumeration on success,
+  * or GNUTLS_E_UNKNOWN_PK_ALGORITHM on error.
+  *
+  **/
+int gnutls_x509_extract_key_pk_algorithm( const gnutls_datum * key)
+{
+       gnutls_x509_privkey pkey;
+       int ret, pk;
+       
+       ret = gnutls_x509_privkey_init( &pkey);
+       if (ret < 0) {
+               gnutls_assert();
+               return ret;
+       }
+       
+       ret = gnutls_x509_privkey_import( pkey, key, GNUTLS_X509_FMT_DER);
+       if (ret < 0) {
+               gnutls_assert();
+               return ret;
+       }
+
+       pk = gnutls_x509_privkey_get_pk_algorithm( pkey);
+       
+       gnutls_x509_privkey_deinit( pkey);
+       return pk;
+}
+
index fbba7e4f95dc3c54e05b4227ac6563943a17bb5e..fc1d33769b9738901361e4e41f18401d691c653d 100644 (file)
@@ -83,7 +83,7 @@ void gnutls_x509_crl_deinit(gnutls_x509_crl crl)
   *
   **/
 int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data,
-                          gnutls_x509_crt_format format)
+                          gnutls_x509_crt_fmt format)
 {
        int result = 0, need_free = 0;
        int start, end;
index 175192b2378320d7cfc69b67108bf8b32c5c1c19..b82b6ec7062e5cf585147bb4a3d0806000330ddc 100644 (file)
@@ -81,7 +81,7 @@ void gnutls_pkcs7_deinit(gnutls_pkcs7 pkcs7)
   *
   **/
 int gnutls_pkcs7_import(gnutls_pkcs7 pkcs7, const gnutls_datum * data,
-       gnutls_x509_crt_format format)
+       gnutls_x509_crt_fmt format)
 {
        int result = 0, need_free = 0;
        gnutls_datum _data = { data->data, data->size };
index cf5ca7ae6b4f5fc82934ded15c85cbdf955334a6..e3ad0b817f9a98b050d068159363effe45369427 100644 (file)
@@ -8,7 +8,7 @@ typedef struct gnutls_pkcs7_int *gnutls_pkcs7;
 int gnutls_pkcs7_init(gnutls_pkcs7 * pkcs7);
 void gnutls_pkcs7_deinit(gnutls_pkcs7 pkcs7);
 int gnutls_pkcs7_import(gnutls_pkcs7 pkcs7, const gnutls_datum * data,
-       gnutls_x509_crt_format format);
+       gnutls_x509_crt_fmt format);
 int gnutls_pkcs7_get_certificate(gnutls_pkcs7 pkcs7, 
        int indx, char* certificate, int* certificate_size);
 int gnutls_pkcs7_get_certificate_count(gnutls_pkcs7 pkcs7);
diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c
new file mode 100644 (file)
index 0000000..2e5f0a6
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ *  Copyright (C) 2003 Nikos Mavroyanopoulos
+ *
+ *  This file is part of GNUTLS.
+ *
+ *  The GNUTLS library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public   
+ *  License as published by the Free Software Foundation; either 
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_datum.h>
+#include <gnutls_global.h>
+#include <gnutls_errors.h>
+#include <common.h>
+#include <gnutls_x509.h>
+#include <x509_b64.h>
+#include <x509.h>
+#include <dn.h>
+#include <extensions.h>
+#include <gnutls_privkey.h>
+
+/**
+  * gnutls_x509_privkey_init - This function initializes a gnutls_crl structure
+  * @key: The structure to be initialized
+  *
+  * This function will initialize an private key structure. 
+  *
+  * Returns 0 on success.
+  *
+  **/
+int gnutls_x509_privkey_init(gnutls_x509_privkey * key)
+{
+       *key = gnutls_calloc( 1, sizeof(gnutls_x509_privkey_int));
+
+       if (*key) {
+               return 0;               /* success */
+       }
+       return GNUTLS_E_MEMORY_ERROR;
+}
+
+/**
+  * gnutls_x509_privkey_deinit - This function deinitializes memory used by a gnutls_x509_privkey structure
+  * @key: The structure to be initialized
+  *
+  * This function will deinitialize a CRL structure. 
+  *
+  **/
+void gnutls_x509_privkey_deinit(gnutls_x509_privkey key)
+{
+       _gnutls_free_datum(&key->raw);
+
+       gnutls_free(key);
+}
+
+#define PEM_KEY_DSA "DSA PRIVATE"
+#define PEM_KEY_RSA "RSA PRIVATE"
+
+/**
+  * gnutls_x509_privkey_import - This function will import a DER or PEM encoded Certificate
+  * @key: The structure to store the parsed key
+  * @data: The DER or PEM encoded certificate.
+  * @format: One of DER or PEM
+  *
+  * This function will convert the given DER or PEM encoded Certificate
+  * to the native gnutls_x509_privkey format. The output will be stored in 'key'.
+  *
+  * If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or
+  * "CERTIFICATE" and must be a null terminated string.
+  *
+  * Returns 0 on success.
+  *
+  **/
+int gnutls_x509_privkey_import(gnutls_x509_privkey key, const gnutls_datum * data,
+       gnutls_x509_crt_fmt format)
+{
+       int result = 0, need_free = 0;
+       gnutls_datum _data = { data->data, data->size };
+
+       /* If the Certificate is in PEM format then decode it
+        */
+       if (format == GNUTLS_X509_FMT_PEM) {
+               opaque *out;
+               
+               /* Try the first header */
+               result = _gnutls_fbase64_decode(PEM_KEY_RSA, data->data, data->size,
+                       &out);
+
+               if (result <= 0) {
+                       /* try for the second header */
+                       result = _gnutls_fbase64_decode(PEM_KEY_DSA, data->data, data->size,
+                               &out);
+
+                       if (result <= 0) {
+                               if (result==0) result = GNUTLS_E_INTERNAL_ERROR;
+                               gnutls_assert();
+                               return result;
+                       }
+               }
+               
+               _data.data = out;
+               _data.size = result;
+               
+               need_free = 1;
+       }
+
+       result =
+           _gnutls_set_datum(&key->raw, _data.data, _data.size);
+       if (result < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+       
+       if (need_free) _gnutls_free_datum( &_data);
+
+       return 0;
+
+      cleanup:
+       _gnutls_free_datum(&key->raw);
+       if (need_free) _gnutls_free_datum( &_data);
+       return result;
+}
+
+
+
+/**
+  * gnutls_x509_privkey_get_pk_algorithm - This function returns the key's PublicKey algorithm
+  * @cert: should contain a gnutls_x509_privkey structure
+  *
+  * This function will return the public key algorithm of a private
+  * key.
+  *
+  * Returns a member of the gnutls_pk_algorithm enumeration on success,
+  * or a negative value on error.
+  *
+  **/
+int gnutls_x509_privkey_get_pk_algorithm( gnutls_x509_privkey key)
+{
+int cv, pk;
+
+        pk = GNUTLS_PK_UNKNOWN;
+
+       /* The only way to distinguish the keys
+        * is to count the sequence of integers.
+        */
+       cv = _gnutls_der_check_if_rsa_key( &key->raw);
+       if (cv==0)
+               pk = GNUTLS_PK_RSA;
+       else {
+               cv = _gnutls_der_check_if_dsa_key( &key->raw);
+               if (cv==0)
+                       pk = GNUTLS_PK_DSA;
+       }
+
+       return pk;
+
+}
index 0d397ae8b6552ae14108e23b2fee4b42b30accc8..c44b2c72e16d53cabee035c68017adce3a02957c 100644 (file)
@@ -85,7 +85,7 @@ void gnutls_x509_crt_deinit(gnutls_x509_crt cert)
   *
   **/
 int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data,
-       gnutls_x509_crt_format format)
+       gnutls_x509_crt_fmt format)
 {
        int result = 0, need_free = 0;
        int start, end;
index 315fa7d0a7834ea0c08c8f91f333c293c06b0be6..f096dcc06f955d587740194f08f5869b448e5a83 100644 (file)
@@ -17,8 +17,13 @@ typedef struct gnutls_x509_crt_int {
        gnutls_pk_algorithm signature_algorithm;
 } gnutls_x509_crt_int;
 
+typedef struct gnutls_x509_privkey_int {
+       gnutls_datum raw; /* we only keep raw data for the moment */
+} gnutls_x509_privkey_int;
+
 typedef struct gnutls_x509_crt_int *gnutls_x509_crt;
 typedef struct gnutls_x509_crl_int *gnutls_x509_crl;
+typedef struct gnutls_x509_privkey_int *gnutls_x509_privkey;
 
 int gnutls_x509_crt_get_issuer_dn_by_oid(gnutls_x509_crt cert, const char* oid, 
        int indx, char *buf, int *sizeof_buf);
@@ -52,15 +57,21 @@ int gnutls_x509_crl_get_certificate(gnutls_x509_crl crl, int index,
 void gnutls_x509_crl_deinit(gnutls_x509_crl crl);
 int gnutls_x509_crl_init(gnutls_x509_crl * crl);
 int gnutls_x509_crl_import(gnutls_x509_crl crl, const gnutls_datum * data,
-                          gnutls_x509_crt_format format);
+                          gnutls_x509_crt_fmt format);
 
 int gnutls_x509_crt_init(gnutls_x509_crt * cert);
 void gnutls_x509_crt_deinit(gnutls_x509_crt cert);
 int gnutls_x509_crt_import(gnutls_x509_crt cert, const gnutls_datum * data,
-       gnutls_x509_crt_format format);
+       gnutls_x509_crt_fmt format);
 
 int gnutls_x509_crt_get_key_usage(gnutls_x509_crt cert, unsigned int *key_usage,
        int *critical);
 int gnutls_x509_crt_get_version(gnutls_x509_crt cert);
 
+int gnutls_x509_privkey_init(gnutls_x509_privkey * key);
+void gnutls_x509_privkey_deinit(gnutls_x509_privkey key);
+int gnutls_x509_privkey_import(gnutls_x509_privkey key, const gnutls_datum * data,
+       gnutls_x509_crt_fmt format);
+int gnutls_x509_privkey_get_pk_algorithm( gnutls_x509_privkey key);
+
 #endif