~ubuntu-branches/ubuntu/maverick/strongswan/maverick

« back to all changes in this revision

Viewing changes to src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2008-12-05 17:21:42 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081205172142-9g77wgyzcj0blq7p
* New upstream release, fixes a MOBIKE issue.
  Closes: #507542: strongswan: endless loop
* Explicitly enable compilation with libcurl for CRL fetching
  Closes: #497756: strongswan: not compiled with curl support; crl 
                   fetching not available
* Enable compilation with SSH agent support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
13
 * for more details.
14
14
 *
15
 
 * $Id: openssl_rsa_private_key.c 3963 2008-05-15 12:41:06Z tobias $
 
15
 * $Id: openssl_rsa_private_key.c 4564 2008-11-04 13:01:36Z martin $
16
16
 */
17
17
 
18
18
#include "openssl_rsa_private_key.h"
74
74
 * Build an EMPSA PKCS1 signature described in PKCS#1
75
75
 */
76
76
static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
77
 
                                                                           int type, chunk_t data, chunk_t *signature)
 
77
                                                                           int type, chunk_t data, chunk_t *out)
78
78
{
79
79
        bool success = FALSE;
 
80
        u_char *sig = NULL;
 
81
        u_int len;
80
82
        const EVP_MD *hasher = EVP_get_digestbynid(type);
81
83
        if (!hasher)
82
84
        {
105
107
                goto error;
106
108
        }
107
109
        
108
 
        *signature = chunk_alloc(RSA_size(this->rsa));
109
 
        
110
 
        if (!EVP_SignFinal(ctx, signature->ptr, &signature->len, key))
111
 
        {
112
 
                goto error;
113
 
        }
114
 
        
115
 
        success = TRUE;
 
110
        sig = malloc(EVP_PKEY_size(key));
 
111
        if (EVP_SignFinal(ctx, sig, &len, key))
 
112
        {
 
113
                out->ptr = sig;
 
114
                out->len = len;
 
115
                success = TRUE;
 
116
        }
 
117
        else
 
118
        {
 
119
                free(sig);
 
120
        }
116
121
        
117
122
error:
118
123
        if (key)
369
374
 */
370
375
static void add(private_builder_t *this, builder_part_t part, ...)
371
376
{
372
 
        va_list args;
 
377
        if (!this->key)
 
378
        {
 
379
                va_list args;
 
380
                chunk_t chunk;
373
381
        
 
382
                switch (part)
 
383
                {
 
384
                        case BUILD_BLOB_ASN1_DER:
 
385
                        {
 
386
                                va_start(args, part);
 
387
                                chunk = va_arg(args, chunk_t);
 
388
                                this->key = load(chunk_clone(chunk));
 
389
                                va_end(args);
 
390
                                return;
 
391
                        }               
 
392
                        case BUILD_KEY_SIZE:
 
393
                        {
 
394
                                va_start(args, part);
 
395
                                this->key = generate(va_arg(args, u_int));
 
396
                                va_end(args);
 
397
                                return;
 
398
                        }
 
399
                        default:
 
400
                                break;
 
401
                }
 
402
        }
374
403
        if (this->key)
375
404
        {
376
 
                DBG1("ignoring surplus build part %N", builder_part_names, part);
377
 
                return;
378
 
        }
379
 
        
380
 
        switch (part)
381
 
        {
382
 
                case BUILD_BLOB_ASN1_DER:
383
 
                {
384
 
                        va_start(args, part);
385
 
                        this->key = load(va_arg(args, chunk_t));
386
 
                        va_end(args);
387
 
                        break;
388
 
                }               
389
 
                case BUILD_KEY_SIZE:
390
 
                {
391
 
                        va_start(args, part);
392
 
                        this->key = generate(va_arg(args, u_int));
393
 
                        va_end(args);
394
 
                        break;
395
 
                }
396
 
                default:
397
 
                        DBG1("ignoring unsupported build part %N", builder_part_names, part);
398
 
                        break;
399
 
        }
 
405
                destroy((private_openssl_rsa_private_key_t*)this->key);
 
406
        }
 
407
        builder_cancel(&this->public);
400
408
}
401
409
 
402
410
/**