You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/09/18 12:58:54 UTC
[commons-net] 05/05: Replace use of org.apache.commons.net.util.Base64 with java.util.Base64 in org.apache.commons.net.smtp
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit 88e36500b965c89ef89e07e19fe2c79c626a1948
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 18 08:58:43 2023 -0400
Replace use of org.apache.commons.net.util.Base64 with
java.util.Base64 in org.apache.commons.net.smtp
---
src/changes/changes.xml | 3 +++
.../apache/commons/net/smtp/AuthenticatingSMTPClient.java | 15 +++++++--------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8fd7e670..e87e8a82 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -163,6 +163,9 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">
Replace use of org.apache.commons.net.util.Base64 with java.util.Base64 in org.apache.commons.net.pop3.
</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">
+ Replace use of org.apache.commons.net.util.Base64 with java.util.Base64 in org.apache.commons.net.smtp.
+ </action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">
Bump commons-parent from 54 to 62 #132, #137, #153.
diff --git a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
index 81959c78..120c69a0 100644
--- a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
+++ b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
@@ -23,13 +23,12 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
+import java.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.SSLContext;
-import org.apache.commons.net.util.Base64;
-
/**
* An SMTP Client class with authentication support (RFC4954).
*
@@ -164,11 +163,11 @@ public class AuthenticatingSMTPClient extends SMTPSClient {
if (method.equals(AUTH_METHOD.PLAIN)) {
// the server sends an empty response ("334 "), so we don't have to read it.
return SMTPReply
- .isPositiveCompletion(sendCommand(Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password).getBytes(getCharset()))));
+ .isPositiveCompletion(sendCommand(Base64.getEncoder().encodeToString(("\000" + username + "\000" + password).getBytes(getCharset()))));
}
if (method.equals(AUTH_METHOD.CRAM_MD5)) {
// get the CRAM challenge
- final byte[] serverChallenge = Base64.decodeBase64(getReplyString().substring(4).trim());
+ final byte[] serverChallenge = Base64.getDecoder().decode(getReplyString().substring(4).trim());
// get the Mac instance
final Mac hmacMd5 = Mac.getInstance("HmacMD5");
hmacMd5.init(new SecretKeySpec(password.getBytes(getCharset()), "HmacMD5"));
@@ -181,18 +180,18 @@ public class AuthenticatingSMTPClient extends SMTPSClient {
toEncode[usernameBytes.length] = ' ';
System.arraycopy(hmacResult, 0, toEncode, usernameBytes.length + 1, hmacResult.length);
// send the reply and read the server code:
- return SMTPReply.isPositiveCompletion(sendCommand(Base64.encodeBase64StringUnChunked(toEncode)));
+ return SMTPReply.isPositiveCompletion(sendCommand(Base64.getEncoder().encodeToString(toEncode)));
}
if (method.equals(AUTH_METHOD.LOGIN)) {
// the server sends fixed responses (base64("Username") and
// base64("Password")), so we don't have to read them.
- if (!SMTPReply.isPositiveIntermediate(sendCommand(Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))))) {
+ if (!SMTPReply.isPositiveIntermediate(sendCommand(Base64.getEncoder().encodeToString(username.getBytes(getCharset()))))) {
return false;
}
- return SMTPReply.isPositiveCompletion(sendCommand(Base64.encodeBase64StringUnChunked(password.getBytes(getCharset()))));
+ return SMTPReply.isPositiveCompletion(sendCommand(Base64.getEncoder().encodeToString(password.getBytes(getCharset()))));
}
if (method.equals(AUTH_METHOD.XOAUTH) || method.equals(AUTH_METHOD.XOAUTH2)) {
- return SMTPReply.isPositiveIntermediate(sendCommand(Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))));
+ return SMTPReply.isPositiveIntermediate(sendCommand(Base64.getEncoder().encodeToString(username.getBytes(getCharset()))));
}
return false; // safety check
}