11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.126 2009/06/11 14:49:14 momjian Exp $
14
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.127 2009/06/23 18:13:23 mha Exp $
15
15
*
16
16
* NOTES
17
17
*
31
31
#include "libpq-fe.h"
32
32
#include "fe-auth.h"
33
33
#include "pqsignal.h"
34
+ #include "libpq-int.h"
34
35
35
36
#ifdef WIN32
36
37
#include "win32.h"
62
63
#if (SSLEAY_VERSION_NUMBER >= 0x00907000L )
63
64
#include <openssl/conf.h>
64
65
#endif
65
- #if ( SSLEAY_VERSION_NUMBER >= 0x00907000L ) && !defined( OPENSSL_NO_ENGINE )
66
+ #ifdef USE_SSL_ENGINE
66
67
#include <openssl/engine.h>
67
68
#endif
68
69
@@ -661,23 +662,22 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
661
662
*/
662
663
if (conn -> sslkey && strlen (conn -> sslkey ) > 0 )
663
664
{
664
- #if ( SSLEAY_VERSION_NUMBER >= 0x00907000L ) && !defined( OPENSSL_NO_ENGINE )
665
+ #ifdef USE_SSL_ENGINE
665
666
if (strchr (conn -> sslkey , ':' )
666
667
#ifdef WIN32
667
668
&& conn -> sslkey [1 ] != ':'
668
669
#endif
669
670
)
670
671
{
671
672
/* Colon, but not in second character, treat as engine:key */
672
- ENGINE * engine_ptr ;
673
673
char * engine_str = strdup (conn -> sslkey );
674
674
char * engine_colon = strchr (engine_str , ':' );
675
675
676
676
* engine_colon = '\0' ; /* engine_str now has engine name */
677
677
engine_colon ++ ; /* engine_colon now has key name */
678
678
679
- engine_ptr = ENGINE_by_id (engine_str );
680
- if (engine_ptr == NULL )
679
+ conn -> engine = ENGINE_by_id (engine_str );
680
+ if (conn -> engine == NULL )
681
681
{
682
682
char * err = SSLerrmessage ();
683
683
@@ -690,7 +690,22 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
690
690
return 0 ;
691
691
}
692
692
693
- * pkey = ENGINE_load_private_key (engine_ptr , engine_colon ,
693
+ if (ENGINE_init (conn -> engine ) == 0 )
694
+ {
695
+ char * err = SSLerrmessage ();
696
+
697
+ printfPQExpBuffer (& conn -> errorMessage ,
698
+ libpq_gettext ("could not initialize SSL engine \"%s\": %s\n" ),
699
+ engine_str , err );
700
+ SSLerrfree (err );
701
+ ENGINE_free (conn -> engine );
702
+ conn -> engine = NULL ;
703
+ free (engine_str );
704
+ ERR_pop_to_mark ();
705
+ return 0 ;
706
+ }
707
+
708
+ * pkey = ENGINE_load_private_key (conn -> engine , engine_colon ,
694
709
NULL , NULL );
695
710
if (* pkey == NULL )
696
711
{
@@ -700,6 +715,9 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
700
715
libpq_gettext ("could not read private SSL key \"%s\" from engine \"%s\": %s\n" ),
701
716
engine_colon , engine_str , err );
702
717
SSLerrfree (err );
718
+ ENGINE_finish (conn -> engine );
719
+ ENGINE_free (conn -> engine );
720
+ conn -> engine = NULL ;
703
721
free (engine_str );
704
722
ERR_pop_to_mark ();
705
723
return 0 ;
@@ -1217,6 +1235,15 @@ close_SSL(PGconn *conn)
1217
1235
X509_free (conn -> peer );
1218
1236
conn -> peer = NULL ;
1219
1237
}
1238
+
1239
+ #ifdef USE_SSL_ENGINE
1240
+ if (conn -> engine )
1241
+ {
1242
+ ENGINE_finish (conn -> engine );
1243
+ ENGINE_free (conn -> engine );
1244
+ conn -> engine = NULL ;
1245
+ }
1246
+ #endif
1220
1247
}
1221
1248
1222
1249
/*
0 commit comments