]> git.ipfire.org Git - people/ms/dma.git/blobdiff - crypto.c
Merge pull request #34 from mtremer/better-authentication
[people/ms/dma.git] / crypto.c
index 60837b194b90d4e2bc00e57bd83786e6f3d3f671..0ebcf78c86d8babcd89d71c00f4cd959e6f7c2b7 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -77,10 +77,14 @@ init_cert_file(SSL_CTX *ctx, const char *path)
 }
 
 int
-smtp_init_crypto(int fd, int feature)
+smtp_init_crypto(int fd, int feature, struct smtp_features* features)
 {
        SSL_CTX *ctx = NULL;
+#if (OPENSSL_VERSION_NUMBER >= 0x00909000L)
        const SSL_METHOD *meth = NULL;
+#else
+       SSL_METHOD *meth = NULL;
+#endif
        X509 *cert;
        int error;
 
@@ -89,7 +93,12 @@ smtp_init_crypto(int fd, int feature)
        SSL_library_init();
        SSL_load_error_strings();
 
-       meth = TLSv1_client_method();
+       // Allow any possible version
+#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+       meth = TLS_client_method();
+#else
+       meth = SSLv23_client_method();
+#endif
 
        ctx = SSL_CTX_new(meth);
        if (ctx == NULL) {
@@ -114,8 +123,7 @@ smtp_init_crypto(int fd, int feature)
                /* TLS init phase, disable SSL_write */
                config.features |= NOSSL;
 
-               send_remote_command(fd, "EHLO %s", hostname());
-               if (read_remote(fd, 0, NULL) == 2) {
+               if (perform_server_greeting(fd, features) == 0) {
                        send_remote_command(fd, "STARTTLS");
                        if (read_remote(fd, 0, NULL) != 2) {
                                if ((feature & TLS_OPP) == 0) {
@@ -127,6 +135,7 @@ smtp_init_crypto(int fd, int feature)
                                }
                        }
                }
+
                /* End of TLS init phase, enable SSL_write/read */
                config.features &= ~NOSSL;
        }
@@ -269,6 +278,7 @@ smtp_auth_md5(int fd, char *login, char *password)
                syslog(LOG_DEBUG, "smarthost authentication:"
                       " AUTH cram-md5 not available: %s", neterr);
                /* if cram-md5 is not available */
+               free(temp);
                return (-1);
        }