I'm trying to connect to a tor hidden service using silvertunnel netlib, but I keep getting the same exception:
Exception in thread "org.silvertunnel.netlib.layer.tor.directory.DirectoryManagerThread" java.lang.NoSuchMethodError: org.bouncycastle.asn1.ASN1InputStream.readObject()Lorg/bouncycastle/asn1/DERObject; at org.bouncycastle.openssl.PEMReader.readRSAPublicKey(PEMReader.java:193) at org.bouncycastle.openssl.PEMReader.readObject(PEMReader.java:110) at org.silvertunnel.netlib.layer.tor.util.Encryption.extractPublicRSAKey(Encryption.java:342) at org.silvertunnel.netlib.layer.tor.directory.AuthorityKeyCertificate.(AuthorityKeyCertificate.java:104) at org.silvertunnel.netlib.layer.tor.directory.AuthorityKeyCertificates.(AuthorityKeyCertificates.java:100) at org.silvertunnel.netlib.layer.tor.directory.AuthorityKeyCertificates.(AuthorityKeyCertificates.java:80) at org.silvertunnel.netlib.layer.tor.directory.Directory.getAuthorityKeyCertificates(Directory.java:492) at org.silvertunnel.netlib.layer.tor.directory.Directory.updateNetworkStatusNew(Directory.java:324) at org.silvertunnel.netlib.layer.tor.directory.Directory.refreshListOfServers(Directory.java:287) at org.silvertunnel.netlib.layer.tor.directory.DirectoryManagerThread.updateDirectory(DirectoryManagerThread.java:60) at org.silvertunnel.netlib.layer.tor.directory.DirectoryManagerThread.run(DirectoryManagerThread.java:76)
I've tried different versions of bouncycastle, but I just can't get it to work. Does anyone know what the problem might be?
Here's my code:
String host = "some_site.onion";
int port = 7878;
TcpipNetAddress remoteAddress = new TcpipNetAddress(host, port);
NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
netLayer.waitUntilReady();
NetSocket netSocket = netLayer.createNetSocket(null, null, remoteAddress);
BufferedReader br = new BufferedReader(new InputStreamReader(netSocket.getInputStream()));
System.out.println(br.readLine());
br.close();
netSocket.close();
You likely have a version of bouncy castle in your java install, and this error is being caused because one version is trying to call into the other version. Check your
JAVA_HOME/jre/lib/ext/andJAVA_HOME/libdirectories for files whose names begin with "bcprov".Okay, since you commented that didn't work, I still think that you have multiple versions of bouncycastle on your classpath. Specifically, I think you have a different version of the
bcprovandbcpkixjars. So let's write a short java program to find them:Run that in eclipse and find where the "PEMReader" class (old class that was in old versions of the bcpkix jars) and where the "ASN1InputStream" class (class that should be in both old and newer bcprov jars) are coming from. Use versions of those jars that match each other.