You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/08/04 18:46:54 UTC

svn commit: r1837445 - in /jmeter/trunk: src/core/org/apache/jmeter/resources/ src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/ src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/ xdocs/ xdocs/usermanual/

Author: pmouawad
Date: Sat Aug  4 18:46:53 2018
New Revision: 1837445

URL: http://svn.apache.org/viewvc?rev=1837445&view=rev
Log:
Bug 62595 - SMTPSampler does not allow configuring the SSL/TLS protocols to be used on handshake

Contributed by Felipe Cuozzo
Bugzilla Id: 62595

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SecuritySettingsPanel.java
    jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sat Aug  4 18:46:53 2018
@@ -1131,6 +1131,8 @@ smtp_subject=Subject:
 smtp_suppresssubj=Suppress Subject Header
 smtp_timestamp=Include timestamp in subject
 smtp_to=Address To:
+smtp_tlsprotocols=Override System SSL/TLS Protocols\:
+smtp_tlsprotocols_tooltip=Specify a custom SSL/TLS protocol as space separated list to use on handshake, example TLSv1 TLSv1.1 TLSv1.2
 smtp_trustall=Trust all certificates
 smtp_trustall_tooltip=<html><b>Enforces</b> JMeter to trust all certificates, whatever CA it comes from.</html>
 smtp_truststore=Local truststore:

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Sat Aug  4 18:46:53 2018
@@ -1120,6 +1120,8 @@ smtp_subject=Sujet \:
 smtp_suppresssubj=Supprimer l'ent\u00EAte Sujet (Subject)
 smtp_timestamp=Ajouter un horodatage dans le sujet
 smtp_to=Adresse destinataire (To) \:
+smtp_tlsprotocols=Utiliser les protocoles System SSL/TLS,\:
+smtp_tlsprotocols_tooltip=Sp\u00e9cifier une liste s\u00e9par\u00e9e par des espaces de protocoles SSL / TLS \u00e0 utiliser lors du handshake
 smtp_trustall=Faire confiance \u00E0 tous les certificats
 smtp_trustall_tooltip=<html><b>Forcer</b> JMeter \u00E0 faire confiance \u00E0 tous les certificats, quelque soit l'autorit\u00E9 de certification du certificat.</html>
 smtp_truststore=Coffre de cl\u00E9s local \:

Modified: jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SecuritySettingsPanel.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SecuritySettingsPanel.java?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SecuritySettingsPanel.java (original)
+++ jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SecuritySettingsPanel.java Sat Aug  4 18:46:53 2018
@@ -46,6 +46,7 @@ public class SecuritySettingsPanel exten
     public static final String ENFORCE_STARTTLS     = "SMTPSampler.enforceStartTLS"; // $NON-NLS-1$
     public static final String USE_LOCAL_TRUSTSTORE = "SMTPSampler.useLocalTrustStore"; // $NON-NLS-1$
     public static final String TRUSTSTORE_TO_USE    = "SMTPSampler.trustStoreToUse"; // $NON-NLS-1$
+    public static final String TLS_PROTOCOLS        = "SMTPSampler.tlsProtocols"; // $NON-NLS-1$
     //--JMX attribute names
 
     private ButtonGroup bgSecuritySettings;
@@ -66,6 +67,10 @@ public class SecuritySettingsPanel exten
 
     private JTextField tfTrustStoreToUse;
 
+    private JTextField tfTlsProtocolsToUse;
+
+    private JLabel jlTlsProtocolsToUse;
+
 
     public SecuritySettingsPanel() {
         super();
@@ -79,7 +84,7 @@ public class SecuritySettingsPanel exten
                 JMeterUtils.getResString("smtp_security_settings"))); // $NON-NLS-1$
 
         GridBagConstraints gridBagConstraints = new GridBagConstraints();
-        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
+        gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 3);
         gridBagConstraints.fill = GridBagConstraints.NONE;
         gridBagConstraints.anchor = GridBagConstraints.WEST;
         gridBagConstraints.weightx = 0.5;
@@ -93,8 +98,10 @@ public class SecuritySettingsPanel exten
         cbUseLocalTrustStore = new JCheckBox(JMeterUtils.getResString("smtp_usetruststore")); // $NON-NLS-1$
 
         jlTrustStoreToUse = new JLabel(JMeterUtils.getResString("smtp_truststore")); // $NON-NLS-1$
+        jlTlsProtocolsToUse = new JLabel(JMeterUtils.getResString("smtp_tlsprotocols")); // $NON-NLS-1$
 
         tfTrustStoreToUse = new JTextField(20);
+        tfTlsProtocolsToUse = new JTextField(20);
 
         rbUseNone.setSelected(true);
         bgSecuritySettings = new ButtonGroup();
@@ -160,6 +167,17 @@ public class SecuritySettingsPanel exten
         gridBagConstraints.gridy = 2;
         tfTrustStoreToUse.setToolTipText(JMeterUtils.getResString("smtp_truststore_tooltip")); // $NON-NLS-1$
         this.add(tfTrustStoreToUse, gridBagConstraints);
+
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 3;
+        gridBagConstraints.gridwidth = 1;
+        jlTlsProtocolsToUse.setToolTipText(JMeterUtils.getResString("smtp_tlsprotocols_tooltip")); // $NON-NLS-1$
+        this.add(jlTlsProtocolsToUse, gridBagConstraints);
+
+        gridBagConstraints.gridx = 1;
+        gridBagConstraints.gridy = 3;
+        tfTrustStoreToUse.setToolTipText(JMeterUtils.getResString("smtp_tlsprotocols_tooltip")); // $NON-NLS-1$
+        this.add(tfTlsProtocolsToUse, gridBagConstraints);
     }
 
     /**
@@ -218,12 +236,14 @@ public class SecuritySettingsPanel exten
             cbUseLocalTrustStore.setSelected(false);
             cbUseLocalTrustStore.setEnabled(false);
             tfTrustStoreToUse.setEditable(false);
+            tfTlsProtocolsToUse.setEditable(false);
         } else if (source == rbUseSSL) {
             cbTrustAllCerts.setEnabled(true);
             cbEnforceStartTLS.setEnabled(false);
             cbEnforceStartTLS.setSelected(false);
             cbUseLocalTrustStore.setEnabled(true);
             tfTrustStoreToUse.setEditable(false);
+            tfTlsProtocolsToUse.setEditable(true);
         } else if (source == rbUseStartTLS) {
             cbTrustAllCerts.setEnabled(true);
             cbTrustAllCerts.setSelected(false);
@@ -231,6 +251,7 @@ public class SecuritySettingsPanel exten
             cbUseLocalTrustStore.setEnabled(true);
             cbUseLocalTrustStore.setSelected(false);
             tfTrustStoreToUse.setEditable(false);
+            tfTlsProtocolsToUse.setEditable(true);
         }
     }
     /**
@@ -334,6 +355,26 @@ public class SecuritySettingsPanel exten
     public void setTrustStoreToUse(String trustStoreToUse) {
         tfTrustStoreToUse.setText(trustStoreToUse);
     }
+
+    /**
+     * Returns the TLS protocols to use for handshake
+     *
+     * @return Space separated list of protocols
+     */
+    public String getTlsProtocolsToUse() {
+        return tfTlsProtocolsToUse.getText();
+    }
+
+    /**
+     * Set the TLS protocols to use for handshake
+     *
+     * @param tlsProtocols
+     *              Space separated list of protocols to use
+     */
+    public void setTlsProtocolsToUse(String tlsProtocols) {
+        tfTlsProtocolsToUse.setText(tlsProtocols);
+    }
+
     public void setUseNoSecurity(boolean selected) {
         rbUseNone.setSelected(selected);
     }
@@ -361,6 +402,7 @@ public class SecuritySettingsPanel exten
 
     public void clear() {
         tfTrustStoreToUse.setText("");
+        tfTlsProtocolsToUse.setText("");
         rbUseNone.setSelected(true);
     }
 
@@ -374,6 +416,7 @@ public class SecuritySettingsPanel exten
         setEnforceStartTLS(element.getPropertyAsBoolean(ENFORCE_STARTTLS));
         setUseLocalTrustStore(element.getPropertyAsBoolean(USE_LOCAL_TRUSTSTORE));
         setTrustStoreToUse(element.getPropertyAsString(TRUSTSTORE_TO_USE));
+        setTlsProtocolsToUse(element.getPropertyAsString(TLS_PROTOCOLS));
     }
 
     public void modifyTestElement(TestElement te) {
@@ -383,6 +426,6 @@ public class SecuritySettingsPanel exten
         te.setProperty(ENFORCE_STARTTLS, Boolean.toString(isEnforceStartTLS()));
         te.setProperty(USE_LOCAL_TRUSTSTORE, Boolean.toString(isUseLocalTrustStore()));
         te.setProperty(TRUSTSTORE_TO_USE, getTrustStoreToUse());
+        te.setProperty(TLS_PROTOCOLS, getTlsProtocolsToUse());
     }
-
 }

Modified: jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java (original)
+++ jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java Sat Aug  4 18:46:53 2018
@@ -21,6 +21,7 @@ package org.apache.jmeter.protocol.smtp.
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
@@ -36,6 +37,7 @@ import javax.mail.MessagingException;
 import javax.mail.Multipart;
 import javax.mail.Session;
 import javax.mail.Transport;
+import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
@@ -60,7 +62,8 @@ public class SendMailCommand {
 
     // local vars
     private static final Logger logger = LoggerFactory.getLogger(SendMailCommand.class);
- 
+    private static final String MAIL_PROPERTY_PREFIX = "mail.";
+    
     // Use the actual class so the name must be correct.
     private static final String TRUST_ALL_SOCKET_FACTORY = TrustAllSSLSocketFactory.class.getName();
     private static final String FALSE = Boolean.FALSE.toString();
@@ -74,6 +77,7 @@ public class SendMailCommand {
     private String smtpServer;
     private String smtpPort;
     private String sender;
+    private String tlsProtocols;
     private List<InternetAddress> replyTo;
     private String emlMessage;
     private List<InternetAddress> receiverTo;
@@ -130,24 +134,15 @@ public class SendMailCommand {
         String protocol = getProtocol();
 
         // set properties using JAF
-        props.setProperty("mail." + protocol + ".host", smtpServer);
-        props.setProperty("mail." + protocol + ".port", getPort());
-        props.setProperty("mail." + protocol + ".auth", Boolean.toString(useAuthentication));
+        props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".host", smtpServer);
+        props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".port", getPort());
+        props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".auth", Boolean.toString(useAuthentication));
         
         // set timeout
-        props.setProperty("mail." + protocol + ".timeout", getTimeout());
-        props.setProperty("mail." + protocol + ".connectiontimeout", getConnectionTimeout());
+        props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".timeout", getTimeout());
+        props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".connectiontimeout", getConnectionTimeout());
 
-        if (useStartTLS || useSSL) {
-            try {
-                String allProtocols = StringUtils.join(
-                    SSLContext.getDefault().getSupportedSSLParameters().getProtocols(), " ");
-                logger.info("Use ssl/tls protocols for mail: {}", allProtocols);
-                props.setProperty("mail." + protocol + ".ssl.protocols", allProtocols);
-            } catch (Exception e) {
-                logger.error("Problem setting ssl/tls protocols for mail", e);
-            }
-        }
+        configureTLSProtocols(props, protocol);
 
         if (enableDebug) {
             props.setProperty("mail.debug","true");
@@ -161,40 +156,23 @@ public class SendMailCommand {
             }
         }
 
-        if (trustAllCerts) {
-            if (useSSL) {
-                props.setProperty("mail.smtps.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
-                props.setProperty("mail.smtps.ssl.socketFactory.fallback", FALSE);
-            } else if (useStartTLS) {
-                props.setProperty("mail.smtp.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
-                props.setProperty("mail.smtp.ssl.socketFactory.fallback", FALSE);
-            }
-        } else if (useLocalTrustStore){
-            File truststore = new File(trustStoreToUse);
-            logger.info("load local truststore - try to load truststore from: {}", truststore.getAbsolutePath());
-            if(!truststore.exists()){
-                logger.info("load local truststore -Failed to load truststore from: {}", truststore.getAbsolutePath());
-                truststore = new File(FileServer.getFileServer().getBaseDir(), trustStoreToUse);
-                logger.info("load local truststore -Attempting to read truststore from: {}", truststore.getAbsolutePath());
-                if(!truststore.exists()){
-                    logger.info("load local truststore -Failed to load truststore from: {}. Local truststore not available, aborting execution.",
-                            truststore.getAbsolutePath());
-                    throw new IOException("Local truststore file not found. Also not available under : " + truststore.getAbsolutePath());
-                }
-            }
-            if (useSSL) {
-                // Requires JavaMail 1.4.2+
-                props.put("mail.smtps.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
-                props.put("mail.smtps.ssl.socketFactory.fallback", FALSE);
-            } else if (useStartTLS) {
-                // Requires JavaMail 1.4.2+
-                props.put("mail.smtp.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
-                props.put("mail.smtp.ssl.socketFactory.fallback", FALSE);
-            }
-        }
+        configureCertificateTrust(props);
 
         session = Session.getInstance(props, null);
         
+        Message message = buildMessage();
+        message.saveChanges();
+        return message;
+    }
+
+    /**
+     * @return
+     * @throws MessagingException
+     * @throws FileNotFoundException
+     * @throws IOException
+     * @throws AddressException
+     */
+    private Message buildMessage() throws MessagingException, IOException {
         Message message;
         if (sendEmlMessage) {
             message = new MimeMessage(session, new BufferedInputStream(new FileInputStream(emlMessage)));
@@ -264,11 +242,59 @@ public class SendMailCommand {
             Argument argument = (Argument) headerFields.get(i).getObjectValue();
             message.setHeader(argument.getName(), argument.getValue());
         }
-
-        message.saveChanges();
         return message;
     }
 
+    private void configureCertificateTrust(Properties props) throws IOException {
+        if (trustAllCerts) {
+            if (useSSL) {
+                props.setProperty("mail.smtps.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
+                props.setProperty("mail.smtps.ssl.socketFactory.fallback", FALSE);
+            } else if (useStartTLS) {
+                props.setProperty("mail.smtp.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
+                props.setProperty("mail.smtp.ssl.socketFactory.fallback", FALSE);
+            }
+        } else if (useLocalTrustStore){
+            File truststore = new File(trustStoreToUse);
+            logger.info("load local truststore - try to load truststore from: {}", truststore.getAbsolutePath());
+            if(!truststore.exists()){
+                logger.info("load local truststore -Failed to load truststore from: {}", truststore.getAbsolutePath());
+                truststore = new File(FileServer.getFileServer().getBaseDir(), trustStoreToUse);
+                logger.info("load local truststore -Attempting to read truststore from: {}", truststore.getAbsolutePath());
+                if(!truststore.exists()){
+                    logger.info("load local truststore -Failed to load truststore from: {}. Local truststore not available, aborting execution.",
+                            truststore.getAbsolutePath());
+                    throw new IOException("Local truststore file not found. Also not available under : " + truststore.getAbsolutePath());
+                }
+            }
+            if (useSSL) {
+                // Requires JavaMail 1.4.2+
+                props.put("mail.smtps.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
+                props.put("mail.smtps.ssl.socketFactory.fallback", FALSE);
+            } else if (useStartTLS) {
+                // Requires JavaMail 1.4.2+
+                props.put("mail.smtp.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
+                props.put("mail.smtp.ssl.socketFactory.fallback", FALSE);
+            }
+        }
+    }
+
+    void configureTLSProtocols(Properties props, String protocol) {
+        String tlsProtocolsToUse = getTlsProtocolsToUse();
+        if (useStartTLS || useSSL) {
+            if (StringUtils.isEmpty(tlsProtocolsToUse)) {
+                try {
+                    tlsProtocolsToUse = StringUtils.join(
+                        SSLContext.getDefault().getSupportedSSLParameters().getProtocols(), " ");
+                } catch (Exception e) {
+                    logger.error("Problem setting ssl/tls protocols for mail", e);
+                }
+            }
+            logger.info("Using ssl/tls protocols for mail: {}", tlsProtocolsToUse);
+            props.setProperty(MAIL_PROPERTY_PREFIX + protocol + ".ssl.protocols", tlsProtocolsToUse);
+        }
+    }
+
     /**
      * Sends message to mailserver, waiting for delivery if using synchronous
      * mode.
@@ -849,4 +875,18 @@ public class SendMailCommand {
     public void setReplyTo(List<InternetAddress> replyTo) {
         this.replyTo = replyTo;
     }
+
+    /**
+     * Sets the list of protocols to be used on TLS handshake
+     *
+     * @param tlsProtocols
+     *          Space separated list
+     */
+    public void setTlsProtocolsToUse(String tlsProtocols) {
+        this.tlsProtocols = tlsProtocols;
+    }
+
+    public String getTlsProtocolsToUse() {
+        return this.tlsProtocols;
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Aug  4 18:46:53 2018
@@ -97,6 +97,7 @@ this behaviour, set <code>httpclient.res
   <li><pr>376</pr>JUnitSampler logs exceptions except assertion-failures from test cases as warnings. Contributed by Davide Angelocola (davide.angelocola at fisglobal.com)</li>
   <li><bug>62244</bug>Rename <code>Test Action</code> to <code>Flow Control Action</code></li>
   <li><bug>62302</bug>Move JSR223 Sampler up the menu. Contributed by orimarko at gmail.com</li>
+  <li><bug>62595</bug>SMTPSampler does not allow configuring the SSL/TLS protocols to be used on handshake. Contributed by Felipe Cuozzo (felipe.cuozzo at gmail.com)</li>
 </ul>
 
 <h3>Controllers</h3>
@@ -298,6 +299,7 @@ this behaviour, set <code>httpclient.res
     <li>blue414 (blue414 at 163.com)</li>
     <li>Aaron Levin</li>
     <li>Allen (444104595 at qq.com)</li>
+    <li>Felipe Cuozzo (felipe.cuozzo at gmail.com)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter.</p>
 <p>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1837445&r1=1837444&r2=1837445&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Aug  4 18:46:53 2018
@@ -1810,6 +1810,7 @@ Defaults are: SMTP=25, SSL=465, StartTLS
 Relative paths are resolved against the current directory.
 <br />Failing that, against the directory containing the test script (JMX file).
 </property>
+<property name="Override System SSL/TLS Protocols" required="No">Specify a custom SSL/TLS protocol as space separated list to use on handshake example <code>TLSv1 TLSv1.1 TLSv1.2</code>. Defaults to all supported protocols.</property>
 <property name="Subject" required="">The e-mail message subject.</property>
 <property name="Suppress Subject Header" required="">If selected, the "<code>Subject:</code>" header is omitted from the mail that is sent. 
 This is different from sending an empty "<code>Subject:</code>" header, though some e-mail clients may display it identically.</property>