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();
2

There are 2 best solutions below

0
On

Silvertunnel is outdated, you should use SilverTunnel-NG instead. SilverTunnel-NG is using spongycastle so it is also Android compatible.

You can find SilverTunnel-NG also on github.

2
On

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/ and JAVA_HOME/lib directories 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 bcprov and bcpkix jars. So let's write a short java program to find them:

import java.net.URL;
import java.util.Enumeration;

public class FindBouncy {
    static void printResources(String n) throws Exception {
        Enumeration<URL> e = FindBouncy.class.getClassLoader().getResources(n);
        if (!e.hasMoreElements()) {
            System.out.println(n + " not found!");
        } else {
            System.out.println(n + " found as:");
            while(e.hasMoreElements()) {
                System.out.println("    " + e.nextElement());
            }
        }
    }
    public static void main(String argv[]) throws Exception {
        printResources("org/bouncycastle/openssl/PEMReader.class");
        printResources("org/bouncycastle/asn1/ASN1InputStream.class");
    }
}

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.