diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-06-24 15:03:29 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-06-24 15:03:29 +0000 |
commit | 540092e91921e9a89459a2709f39d9d35a0c4f8f (patch) | |
tree | 919f259cd406917ba29904f690d1353549ba55b4 /lib/gnutls_privkey.c | |
parent | a863e462ece7b4b07655121c0cbaba7d638acf05 (diff) | |
download | gnutls-540092e91921e9a89459a2709f39d9d35a0c4f8f.tar.gz |
fixes in ChangeCipherSpec handling (this also fixes rehandshake).
Several cleanups.
Diffstat (limited to 'lib/gnutls_privkey.c')
-rw-r--r-- | lib/gnutls_privkey.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/gnutls_privkey.c b/lib/gnutls_privkey.c new file mode 100644 index 0000000000..1548d654fd --- /dev/null +++ b/lib/gnutls_privkey.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2001 Nikos Mavroyanopoulos + * + * This file is part of GNUTLS. + * + * GNUTLS is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNUTLS 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; 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_errors.h> +#include <cert_b64.h> +#include <auth_x509.h> +#include <gnutls_cert.h> +#include <cert_asn1.h> +#include <cert_der.h> +#include <gnutls_datum.h> +#include <gnutls_gcry.h> + +/* Converts an RSA PKCS#1 key to + * an internal structure (gnutls_private_key) + */ +int _gnutls_pkcs1key2gnutlsKey(gnutls_private_key * pkey, gnutls_datum cert) { + int result; + opaque str[5*1024]; + int len = sizeof(str); + + pkey->pk_algorithm = GNUTLS_PK_RSA; + + /* we do return 2 MPIs + */ + pkey->params = gnutls_malloc(2*sizeof(MPI)); + + if (create_structure("rsakey", "PKCS-1.RSAPrivateKey")!=ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_ERROR; + } + + result = get_der("rsakey", cert.data, cert.size); + if (result != ASN_OK) { + gnutls_assert(); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + len = sizeof(str); + result = + read_value("rsakey.privateExponent", str, &len); + if (result != ASN_OK) { + gnutls_assert(); + delete_structure("rsakey"); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + if (gcry_mpi_scan( &pkey->params[0], /* u */ + GCRYMPI_FMT_USG, str, &len) != 0) { + gnutls_assert(); + delete_structure("rsakey"); + return GNUTLS_E_MPI_SCAN_FAILED; + } + + + len = sizeof(str); + result = + read_value("rsakey.modulus", str, &len); + if (result != ASN_OK) { + gnutls_assert(); + delete_structure("rsakey"); + _gnutls_mpi_release( &pkey->params[0]); + return GNUTLS_E_ASN1_PARSING_ERROR; + } + + if (gcry_mpi_scan( &pkey->params[1], /* A */ + GCRYMPI_FMT_USG, str, &len) != 0) { + gnutls_assert(); + delete_structure("rsakey"); + _gnutls_mpi_release( &pkey->params[0]); + return GNUTLS_E_MPI_SCAN_FAILED; + } + + delete_structure("rsakey"); + + if (gnutls_set_datum( &pkey->raw, cert.data, cert.size) < 0) { + _gnutls_mpi_release(&pkey->params[0]); + _gnutls_mpi_release(&pkey->params[1]); + gnutls_assert(); + return GNUTLS_E_MEMORY_ERROR; + } + + return 0; + + +} + +void _gnutls_free_private_key( gnutls_private_key pkey) { +int n, i; + + switch( pkey.pk_algorithm) { + case GNUTLS_PK_RSA: + n = 2;/* the number of parameters in MPI* */ + break; + default: + n=0; + } + for (i=0;i<n;i++) { + _gnutls_mpi_release( &pkey.params[i]); + } + gnutls_free_datum( &pkey.raw); + +} + |