Skip to content

Commit

Permalink
#495: enable "*.ssl.checkserveridentity" property for SMTP connection…
Browse files Browse the repository at this point in the history
…s as well, as is it still relevant for opportunistic TLS upgrades.
  • Loading branch information
bbottema committed Apr 5, 2024
1 parent 3fee7a4 commit 270c617
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ public String propertyNameSSLTrust() {
}

/**
* @return "mail.smtp.ssl.checkserveridentity"
* @return "mail.smtp.ssl.checkserveridentity", which is only relevant for SMTP + opportunistic TLS
*/
@Override
public String propertyNameCheckServerIdentity() {
throw new IllegalStateException("This property is not relevant for plain SMTP");
return "mail.smtp.ssl.checkserveridentity";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static private void configureTrustedHosts(@NotNull final Session session, @NotNu
}

static private void configureServerIdentityVerification(@NotNull final Session session, @NotNull final OperationalConfig operationalConfig, @Nullable final TransportStrategy transportStrategy) {
if (transportStrategy != null && transportStrategy != TransportStrategy.SMTP) {
if (transportStrategy != null) {
session.getProperties().setProperty(transportStrategy.propertyNameCheckServerIdentity(),
Boolean.toString(operationalConfig.isVerifyingServerIdentity()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void createMailSession_MinimalConstructor_WithoutConfig() {
assertThat(session.getProperty("mail.smtp.starttls.enable")).isEqualTo("true");
assertThat(session.getProperty("mail.smtp.starttls.required")).isEqualTo("false");
assertThat(session.getProperty("mail.smtp.ssl.trust")).isEqualTo("*");
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("true");

assertThat(session.getProperty("mail.smtp.user")).isNull();
assertThat(session.getProperty("mail.smtp.auth")).isNull();
Expand Down Expand Up @@ -209,7 +209,7 @@ public void createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS()

assertThat(session.getProperty("mail.smtp.starttls.enable")).isNull();
assertThat(session.getProperty("mail.smtp.starttls.required")).isNull();
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("true");

assertThat(session.getProperty("mail.smtp.user")).isEqualTo("username smtp");
assertThat(session.getProperty("mail.smtp.auth")).isEqualTo("true");
Expand Down Expand Up @@ -239,7 +239,7 @@ public void createMailSession_MinimalConstructor_WithConfig_OPPORTUNISTIC_TLS_Ma
assertThat(session.getProperty("mail.smtp.starttls.enable")).isEqualTo("true");
assertThat(session.getProperty("mail.smtp.starttls.required")).isEqualTo("false");
assertThat(session.getProperty("mail.smtp.ssl.trust")).isEqualTo("*");
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("true");

assertThat(session.getProperty("mail.smtp.user")).isEqualTo("username smtp");
assertThat(session.getProperty("mail.smtp.auth")).isEqualTo("true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public void setup() {
public void trustAllHosts_PLAIN() {
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(EMPTY_LIST, true, false));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isEqualTo("*");
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("false");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(EMPTY_LIST, false, true));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("true");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
}

Expand Down Expand Up @@ -98,19 +98,19 @@ public void checkForMissingOAuth2Token() {
public void trustHosts() {
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(asList(), false, false));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("false");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(asList("a"), false, false));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isEqualTo("a");
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("false");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(asList("a", "b"), false, false));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isEqualTo("a b");
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("false");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
new MailerImpl(null, SMTP, NO_GOVERNANCE(), createEmptyProxyConfig(), session, createDummyOperationalConfig(asList("a", "b", "c"), false, true));
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isEqualTo("a b c");
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isNull();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.checkserveridentity")).isEqualTo("true");
assertThat(session.getProperties().getProperty("mail.smtps.ssl.checkserveridentity")).isNull();
}

Expand Down

0 comments on commit 270c617

Please sign in to comment.