]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/crypto.c
Tweak Win32 build
[bacula/bacula] / bacula / src / lib / crypto.c
index f1639e71d63ae8c9a05c7937d0c0c418f5fe1cc0..c450b2bcaa3dc9d9b9124a6fd98c0dbf77d085eb 100644 (file)
@@ -19,7 +19,7 @@
  * license please contact Landon Fuller <landonf@opendarwin.org>.
  */
 /*
-   Copyright (C) 2005 Kern Sibbald
+   Copyright (C) 2005-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -176,6 +176,7 @@ ASN1_SEQUENCE(SignatureData) = {
 
 ASN1_SEQUENCE(CryptoData) = {
    ASN1_SIMPLE(CryptoData, version, ASN1_INTEGER),
+   ASN1_SIMPLE(CryptoData, contentEncryptionAlgorithm, ASN1_OBJECT),
    ASN1_SIMPLE(CryptoData, iv, ASN1_OCTET_STRING),
    ASN1_SET_OF(CryptoData, recipientInfo, RecipientInfo)
 } ASN1_SEQUENCE_END(CryptoData);
@@ -913,6 +914,7 @@ SIGNATURE *crypto_sign_decode(const void *sigData, size_t length)
    if (!sig->sigData) {
       /* Allocation / Decoding failed in OpenSSL */
       openssl_post_errors(M_ERROR, _("Signature decoding failed"));
+      free(sig);
       return NULL;
    }
 
@@ -1136,6 +1138,9 @@ crypto_error_t crypto_session_decode(const void *data, size_t length, alist *key
       return CRYPTO_ERROR_INTERNAL;
    }
 
+   /* Initialize required fields */
+   cs->session_key = NULL;
+
    /* d2i_CryptoData modifies the supplied pointer */
    cs->cryptoData = d2i_CryptoData(NULL, &p, length);
 
@@ -1239,7 +1244,7 @@ CIPHER_CONTEXT *crypto_cipher_new (CRYPTO_SESSION *cs, bool encrypt, size_t *blo
     */
    if ((ec = EVP_get_cipherbyobj(cs->cryptoData->contentEncryptionAlgorithm)) == NULL) {
       Emsg1(M_ERROR, 0, _("Unsupported contentEncryptionAlgorithm: %d\n"), OBJ_obj2nid(cs->cryptoData->contentEncryptionAlgorithm));
-      crypto_cipher_free(cipher_ctx);
+      free(cipher_ctx);
       return NULL;
    }
 
@@ -1345,9 +1350,12 @@ int init_crypto (void)
    /* Load libssl and libcrypto human-readable error strings */
    SSL_load_error_strings();
 
-   /* Register OpenSSL ciphers */
+   /* Initialize OpenSSL SSL  library */
    SSL_library_init();
 
+   /* Register OpenSSL ciphers and digests */
+   OpenSSL_add_all_algorithms();
+
    if (!openssl_seed_prng()) {
       Emsg0(M_ERROR_TERM, 0, _("Failed to seed OpenSSL PRNG\n"));
    }
@@ -1383,6 +1391,9 @@ int cleanup_crypto (void)
    /* Free libssl and libcrypto error strings */
    ERR_free_strings();
 
+   /* Free all ciphers and digests */
+   EVP_cleanup();
+
    /* Free memory used by PRNG */
    RAND_cleanup();