From 36bec260b902aba02f38b7fc1c9d4c621c0a6f3c Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 13 Jun 2012 20:54:39 +0000 Subject: [PATCH] fixed crash due to writing an unsupported key type git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5218 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pgp/pgphandler.cc | 4 +++- openpgpsdk/src/create.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index d78af0049..fb6a897c2 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -357,7 +357,9 @@ std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key) ops_memory_t *buf = NULL ; ops_setup_memory_write(&cinfo, &buf, 0); - ops_write_transferable_public_key(key,armoured,cinfo); + if(ops_write_transferable_public_key(key,armoured,cinfo) != ops_true) + return "ERROR: This key cannot be processed by RetroShare because\nDSA certificates are not yet handled." ; + ops_writer_close(cinfo) ; std::string akey((char *)ops_memory_get_data(buf),ops_memory_get_length(buf)) ; diff --git a/openpgpsdk/src/create.c b/openpgpsdk/src/create.c index 320d527fa..14e6e5693 100644 --- a/openpgpsdk/src/create.c +++ b/openpgpsdk/src/create.c @@ -585,6 +585,12 @@ ops_boolean_t ops_write_struct_public_key(const ops_public_key_t *key, { assert(key->version == 4); + if(key->algorithm != OPS_PKA_RSA) + { + fprintf(stderr,"\nUnhandled key algorithm %d\n",key->algorithm); + return ops_false ; + } + return ops_write_ptag(OPS_PTAG_CT_PUBLIC_KEY,info) && ops_write_length(1+4+1+public_key_length(key),info) && write_public_key_body(key,info); @@ -905,7 +911,11 @@ ops_boolean_t encode_m_buf(const unsigned char *M, size_t mLen, // implementation of EME-PKCS1-v1_5-ENCODE, as defined in OpenPGP RFC - assert(pkey->algorithm == OPS_PKA_RSA); + if(pkey->algorithm != OPS_PKA_RSA) + { + fprintf(stderr,"\nUnhandled key algorithm %d\n",pkey->algorithm); + return ops_false ; + } k=BN_num_bytes(pkey->key.rsa.n); assert(mLen <= k-11);