Skip to content

Commit

Permalink
#30491: If the node name is longer than 28 bytes, shorten it with SHA…
Browse files Browse the repository at this point in the history
…-224
  • Loading branch information
turing85 committed Oct 27, 2023
1 parent d110270 commit e29d3a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.quarkus.narayana.jta.runtime;

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -29,6 +32,7 @@

@Recorder
public class NarayanaJtaRecorder {
public static final String HASH_ALGORITHM_FOR_SHORTENING = "SHA-224";

private static Properties defaultProperties;

Expand All @@ -37,11 +41,20 @@ public class NarayanaJtaRecorder {
public void setNodeName(final TransactionManagerConfiguration transactions) {

try {
if (transactions.nodeName.getBytes(StandardCharsets.UTF_8).length > 28) {
String originalNodeName = transactions.nodeName;
log.infof("Node name \"%s\" is longer than 28 bytes, shortening it by using %s.", originalNodeName,
HASH_ALGORITHM_FOR_SHORTENING);
byte[] nodeNameAsBytes = originalNodeName.getBytes();
MessageDigest messageDigest224 = MessageDigest.getInstance(HASH_ALGORITHM_FOR_SHORTENING);
transactions.nodeName = new String(messageDigest224.digest(nodeNameAsBytes), StandardCharsets.UTF_8);
log.infof("New node name is \"%s\"", transactions.nodeName);
}
arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier(transactions.nodeName);
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(Collections.singletonList(transactions.nodeName));
TxControl.setXANodeName(transactions.nodeName);
} catch (CoreEnvironmentBeanException e) {
e.printStackTrace();
} catch (CoreEnvironmentBeanException | NoSuchAlgorithmException e) {
log.error("Could not set node name", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public final class TransactionManagerConfiguration {
/**
* The node name used by the transaction manager.
* For technical reasons, the node name must not exceed 28 bytes. If a node name with more than 28 bytes is provided, it
* will be hashed with SHA-224, which will produce a node name containing exactly 28 bytes.
*/
@ConfigItem(defaultValue = "quarkus")
public String nodeName;
Expand Down

0 comments on commit e29d3a8

Please sign in to comment.