Skip to content

Commit

Permalink
Rename method and re-allocating.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Sep 20, 2024
1 parent 807c3f5 commit 6136ad0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ void verifySession(
final X509Certificate x509 = (X509Certificate) cert;
// Sanitize and log peer principal
final X500Principal peer = x509.getSubjectX500Principal();
LOG.debug("Sanitized peer principal: {}", sanitizeX500Principal(peer));
LOG.debug("Sanitized peer principal: {}", toEscapedString(peer));

// Sanitize and log issuer principal
final X500Principal issuer = x509.getIssuerX500Principal();
LOG.debug("Sanitized issuer principal: {}", sanitizeX500Principal(issuer));
LOG.debug("Sanitized issuer principal: {}", toEscapedString(issuer));


final Collection<List<?>> altNames1 = x509.getSubjectAlternativeNames();
Expand Down Expand Up @@ -462,7 +462,7 @@ void verifySession(
}

/**
* Sanitizes an X500Principal by escaping control characters.
* Converts an X500Principal to a cleaned string by escaping control characters.
* <p>
* This method processes the RFC2253 format of the X500Principal and escapes
* any ISO control characters to avoid issues in logging or other outputs.
Expand All @@ -471,15 +471,15 @@ void verifySession(
*
* <p><strong>Note:</strong> For testing purposes, this method is package-private
* to allow access within the same package. This allows tests to verify the correct
* behavior of the sanitization process.</p>
* behavior of the escaping process.</p>
*
* @param principal the X500Principal to sanitize
* @return the sanitized string representation of the X500Principal
* @param principal the X500Principal to escape
* @return the escaped string representation of the X500Principal
*/
@Internal
String sanitizeX500Principal(final X500Principal principal) {
String toEscapedString(final X500Principal principal) {
final String principalValue = principal.getName(X500Principal.RFC2253);
final StringBuilder sanitizedPrincipal = new StringBuilder();
final StringBuilder sanitizedPrincipal = new StringBuilder(principalValue.length());
for (final char c : principalValue.toCharArray()) {
if (Character.isISOControl(c)) {
sanitizedPrincipal.append("\\x").append(String.format("%02x", (int) c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
public class SSLConnectionSocketFactoryTest {

@Test
public void testSanitizeX500Principal_withControlCharacters() {
public void testToEscapedString_withControlCharacters() {
// Create a X500Principal with control characters
final X500Principal principal = new X500Principal("CN=Test\b\bName\n,O=TestOrg");

// Call the sanitizeX500Principal method
final SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(SSLContexts.createDefault());
final String sanitized = factory.sanitizeX500Principal(principal);
final String sanitized = factory.toEscapedString(principal);

// Assert that control characters are properly escaped
assertEquals("CN=Test\\x08\\x08Name\\x0a,O=TestOrg", sanitized);
Expand Down

0 comments on commit 6136ad0

Please sign in to comment.