58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
![]() |
== How to fix it in Apache Commons Email
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
include::../../common/fix/code-rationale.adoc[]
|
||
|
|
||
|
:cert_variable_name: setSSLCheckServerIdentity
|
||
|
:cert_variable_safe_value: true
|
||
|
|
||
|
include::../../common/fix/code-rationale-explicit.adoc[]
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,java,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
import org.apache.commons.mail.DefaultAuthenticator;
|
||
|
import org.apache.commons.mail.Email;
|
||
|
import org.apache.commons.mail.SimpleEmail;
|
||
|
|
||
|
public void sendMail(String message) {
|
||
|
Email email = new SimpleEmail();
|
||
|
|
||
|
email.setMsg(message);
|
||
|
email.setSmtpPort(465);
|
||
|
email.setAuthenticator(new DefaultAuthenticator(username, password));
|
||
|
email.setSSLOnConnect(true); // Noncompliant
|
||
|
|
||
|
email.send();
|
||
|
}
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,java,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
import org.apache.commons.mail.DefaultAuthenticator;
|
||
|
import org.apache.commons.mail.Email;
|
||
|
import org.apache.commons.mail.SimpleEmail;
|
||
|
|
||
|
public void sendMail(String message) {
|
||
|
Email email = new SimpleEmail();
|
||
|
|
||
|
email.setMsg(message);
|
||
|
email.setSmtpPort(465);
|
||
|
email.setAuthenticator(new DefaultAuthenticator(username, password));
|
||
|
email.setSSLCheckServerIdentity(true);
|
||
|
email.setSSLOnConnect(true);
|
||
|
|
||
|
email.send();
|
||
|
}
|
||
|
----
|
||
|
|
||
|
=== How does this work?
|
||
|
|
||
|
include::../../common/fix/validation.adoc[]
|
||
|
|
||
|
include::../../common/fix/keytool.adoc[]
|