Open yahocen opened 2 months ago
Complete Java classes for debugging purposes 🙏
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import java.util.Hashtable;
public class Test {
public static String getDnsTxtValue(String domain) throws NamingException {
Hashtable<String, String> env = new Hashtable<>();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
DirContext dirContext = new InitialDirContext(env);
//There is an exception here
Attributes attrs = dirContext.getAttributes(domain, new String[] { "TXT" });
Attribute txt = attrs.get("TXT");
NamingEnumeration<?> e = txt.getAll();
String value = null;
while (e.hasMore()) {
value = e.next().toString();
}
return value;
}
public static void main(String[] args) throws NamingException {
//The record type here is TXT
System.out.println(getDnsTxtValue("_acme-challenge.example.com"));
}
}
Thank you, we'll take a look into this when possible
Before fixing this issue, you can use nslookup and Process to solve it
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static List<String> getTXTRecord(String domain) throws IOException, InterruptedException {
List<String> txtRecords = new ArrayList<>();
// 使用 ProcessBuilder 运行 nslookup 命令
var pb = new ProcessBuilder("nslookup", "-query=TXT", domain);
var process = pb.start();
// 读取命令输出
try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
boolean recordFound = false;
while ((line = reader.readLine()) != null) {
// 检查是否为TXT记录
if (line.contains("text =")) {
recordFound = true;
}
// 获取TXT记录值部分
if (recordFound && line.trim().startsWith("\"")) {
txtRecords.add(line.trim().replace("\"", ""));
}
}
}
process.waitFor();
return txtRecords;
}
public static void main(String[] args) throws IOException, InterruptedException {
//The record type here is TXT
// 示例域名
String domain = "_acme-challenge.example.com";
List<String> txtRecords = getTXTRecord(domain);
// 输出TXT记录值
txtRecords.forEach(record -> System.out.println("TXT Record: " + record));
}
}
I tested the code from here: https://github.com/oracle/graal/issues/9597#issuecomment-2324325603 it didn't run correctly as a java code
>java Test
Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com'
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
at Test.getDnsTxtValue(Test.java:16)
at Test.main(Test.java:28)
Is there something missing in the code?
I tested the code from here: #9597 (comment)我从这里测试了代码: #9597 (comment) it didn't run correctly as a java code它不能作为 Java 代码正确运行
>java Test Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com' at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214) at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81) at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434) at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235) at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141) at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129) at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171) at Test.getDnsTxtValue(Test.java:16) at Test.main(Test.java:28)
Is there something missing in the code?代码中是否缺少什么?
Hi, I'm glad there's been progress. In fact, the _acme-challenge.example.com in the code is an example domain and doesn't actually exist. I'm sorry for any inconvenience caused. Please remove the _acme-challenge section and replace it with example.com
I tested the code from here: #9597 (comment)我从这里测试了代码: #9597 (comment) it didn't run correctly as a java code它不能作为 Java 代码正确运行
>java Test Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com' at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429) at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214) at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81) at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434) at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235) at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141) at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129) at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171) at Test.getDnsTxtValue(Test.java:16) at Test.main(Test.java:28)
Is there something missing in the code?代码中是否缺少什么?
Hi, I'm glad there's been progress. In fact, the _acme-challenge.example.com in the code is an example domain and doesn't actually exist. I'm sorry for any inconvenience caused. Please remove the _acme-challenge section and replace it with example.com嗨,我很高兴取得了进展。事实上,代码中的 _acme-challenge.example.com 是一个示例域,实际上并不存在。对于给您带来的任何不便,我深表歉意。请删除 _acme-challenge 部分并将其替换为 example.com
public static void main(String[] args) throws NamingException {
//The record type here is TXT
System.out.println(getDnsTxtValue("example.com"));
}
Describe the issue I am making a small tool to apply for a free SSL certificate through the ACME protocol. I am trying to package it locally using Graalvm. The version I am currently using is Graalvm-community-openjdk-17.0.9+9.1, which includes a feature to obtain Txt resolution record values in DNS through domain names. My code works normally without executing through Native, but the following error occurs after Native. I think this is a bug
Steps to reproduce the issue My code is as follows, please reproduce the error through the following code
Describe GraalVM and your environment:
More details
Add any other information about the problem here. Especially important are stack traces or log output. Feel free to link to gists or to screenshots if necessary.