/**
* OnionCoffee - Anonymous Communication through TOR Network
* Copyright (C) 2005-2007 RWTH Aachen University, Informatik IV
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package TorJava;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.security.KeyPair;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bouncycastle.asn1.x509.RSAPublicKeyStructure;
import org.bouncycastle.crypto.params.RSAKeyParameters;
import org.bouncycastle.jce.provider.JCERSAPrivateKey;
import org.bouncycastle.jce.provider.JCERSAPublicKey;
import TorJava.Common.Common;
import TorJava.Common.Encoding;
import TorJava.Common.Encryption;
import TorJava.Common.Parsing;
import TorJava.Common.StreamsAndHTTP;
import TorJava.Common.TorException;
/**
* This class maintains a list of the currently known Tor routers. It has
* the capability to update stats and find routes that fit to certain criteria.
*
* @author Lexi Pimenidis
* @author Tobias Koelsch
* @author Andriy Panchenko
* @author Michael Koellejan
* @author Johannes Renner
* @author Connell Gauld
*/
class Directory {
Tor tor;
public static final String CONSENSUS_CACHE_FILENAME = "networkstatus_cached.dat";
// List of known Tor servers
ConcurrentHashMap<String, Server> torServers;
HashMap<String, String> identityDigestToNickname;
HashMap<String, String> nicknameToDigestDescriptor;
HashMap<String, String> nicknameToIdentityDigest;
ArrayList<NetworkStatusDescription> latestDirCaches;
// HashMap that has class C address as key, and a HashSet with nicks
// of Nodes that have IP-Address of that class
HashMap<String, HashSet<String>> addressNeighbours;
// HashMap where keys are CountryCodes, and values are HashSets with nicks
// of Nodes having an IP-address in the specific country
HashMap<String, HashSet<String>> countryNeighbours;
// HashSet excluded by config nodes
HashSet<String> excludedNodesByConfig;
Random rnd;
static final String PUBLISHED_ITEM_SIMPLEDATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
// Number of retries to find a route on one recursive stap before falling
// back and changing previous node
static final int RETRIES_ON_RECURSIVE_ROUTE_BUILD = 10;
// time intervals to poll descriptor fetchers for result
static final int FETCH_THREAD_QUERY_TIME = 2000; // 2 second
SimpleDateFormat dateFormat;
Date published;
JCERSAPrivateKey signingKeyPrivate;
JCERSAPublicKey signingKey;
ArrayList<String> recommendedSoftware;
boolean updateRunning = false;
int updateCounter = 0;
int nodeCounter = 0;
boolean stop = false;
/**
* Initialize directory from the network
*/
public Directory(Tor tor, KeyPair dirServerKeys) {
init(tor, dirServerKeys);
// is done from background mgmt .. but should be done here a first time
// NOTE FROM LEXI: refreshListOfServers MUST NOT be called from here,
// but instead MUST be called from background mgmt
//refreshListOfServers();
}
/**
* Initialize directory from a file
* @param filename
* the file that stores informations about the directory
*/
public Directory(Tor tor, KeyPair dirServerKeys, String filename, String fingerprint) {
init(tor, dirServerKeys);
readDirectoryFromFile(filename, fingerprint);
}
/** Initialize the directory object **/
private void init(Tor tor, KeyPair dirServerKeys) {
this.tor = tor;
if (dirServerKeys != null) {
try {
signingKey = (org.bouncycastle.jce.provider.JCERSAPublicKey)(dirServerKeys.getPublic());
signingKeyPrivate = (org.bouncycastle.jce.provider.JCERSAPrivateKey)(dirServerKeys.getPrivate());
} catch(ClassCastException e) {
System.err.println("TorJava.Directory.init: caught infamous ClassCastException. No solution known.");
e.printStackTrace();
}
}
torServers = new ConcurrentHashMap<String,Server>();
identityDigestToNickname = new HashMap<String, String>();
nicknameToDigestDescriptor = new HashMap<String, String>();
latestDirCaches = new ArrayList<NetworkStatusDescription>();
nicknameToIdentityDigest = new HashMap<String, String>();
addressNeighbours = new HashMap<String,HashSet<String>>();
countryNeighbours = new HashMap<String,HashSet<String>>();
rnd = new Random();
dateFormat = new SimpleDateFormat(PUBLISHED_ITEM_SIMPLEDATE_FORMAT);
recommendedSoftware = new ArrayList<String>();
excludedNodesByConfig = new HashSet<String>();
excludedNodesByConfig.addAll(TorConfig.avoidedNodes);
}
/**
* Render the directory in the extensible information format. used to write
* it to disk and also used by the directory-server
*
* @return directory in extensible information format.
*/
public String renderDirectory() throws IOException {
StringBuffer rawDir = new StringBuffer();
rawDir.append("signed-directory\n");
published = new Date(System.currentTimeMillis());
rawDir.append("published " + dateFormat.format(published) + "\n");
StringBuffer tmpRecommendedSoftware = new StringBuffer();
ListIterator<String> rsIterator = recommendedSoftware.listIterator();
while (rsIterator.hasNext()) {
tmpRecommendedSoftware.append(rsIterator.next() + ",");
}
rawDir.append("recommended-software "
+ tmpRecommendedSoftware.toString() + "\n");
rawDir.append("router-status " + renderRouterStatus() + "\n");
rawDir.append("opt ranking-index " + renderRankingIndex() + "\n");
rawDir.append("dir-signing-key\n"
+ Encryption.getPEMStringFromRSAPublicKey(
Encryption.getRSAPublicKeyStructureFromJCERSAPublicKey(
signingKey)) + "\n");
Iterator<String> serverNames = (torServers.keySet()).iterator();
while (serverNames.hasNext()) {
Server s = (Server) torServers.get((String) (serverNames.next()));
rawDir.append(s.routerDescriptor);
rawDir.append("\n");
}
// sign data
rawDir.append("directory-signature " + tor.config.nickname + "\n");
byte[] data = rawDir.toString().getBytes();
rawDir.append(Encryption.binarySignatureToPEM(Encryption.signData(data,
new RSAKeyParameters(true, signingKeyPrivate.getModulus(),
signingKeyPrivate.getPrivateExponent()))));
return rawDir.toString();
}
/**
* Render an array of servers with the
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android TorProxy应用实现了Android手机无线电电传通讯(TOR)-IT计算机-毕业设计.zip (398个子文件)
ITorProxyControl.aidl 1KB
HiddenServiceDescriptor.aidl 983B
resources.ap_ 46KB
resources.ap_ 27KB
resources.ap_ 6KB
resources.ap_ 5KB
TorProxy.apk 970KB
Shadow.apk 83KB
TorProxyExample.apk 17KB
TorProxyLib.apk 13KB
.classpath 434B
.classpath 339B
.classpath 339B
.classpath 273B
COPYING 18KB
COPYING 18KB
wc.db 216KB
classes.dex 1.91MB
classes.dex 72KB
classes.dex 21KB
classes.dex 13KB
entries 3B
format 3B
home 2KB
error.htm 3KB
about.htm 2KB
about.htm 2KB
unknownhosterror.htm 2KB
sslerror.htm 2KB
bc.jar 2.05MB
bcprov-jdk14-133.jar 1.01MB
bcpg-jdk14-133.jar 132KB
GeoIP-1.1.8.jar 27KB
TorProxyLib.jar 14KB
export-torproxylib.jardesc 1013B
Directory.java 75KB
Tor.java 33KB
TorConfig.java 30KB
Server.java 26KB
Circuit.java 21KB
Shadow.java 20KB
Encryption.java 16KB
Encoding.java 16KB
Node.java 15KB
TorBackgroundMgmt.java 15KB
CellRelay.java 15KB
SSLSocketFactory.java 15KB
CountryToCoordinates.java 14KB
SocksConnection.java 13KB
ServiceDescriptor.java 12KB
TorProxyControlService.java 12KB
HTTPConnection.java 10KB
AnonProxy.java 10KB
TCPStream.java 9KB
Logger.java 9KB
TLSConnection.java 9KB
FirstNodeHandler.java 8KB
PostProcessor.java 8KB
StreamsAndHTTP.java 8KB
TLSDispatcher.java 7KB
CookieManager.java 7KB
DirectoryServer.java 7KB
TorProxyExample.java 7KB
GeoIP.java 6KB
ServerMain.java 6KB
Cell.java 6KB
SocksProxy.java 6KB
TorProxySettings.java 6KB
PrivateKeyHandler.java 6KB
Queue.java 6KB
TCPStreamThreadTor2Java.java 5KB
CacheObject.java 5KB
ControlServiceConnectivityTest.java 5KB
TorSocketImpl.java 5KB
TorKeeper.java 5KB
HiddenServiceProperties.java 4KB
TCPStreamProperties.java 4KB
ControlServiceInterfaceTest.java 4KB
WebAddress.java 4KB
CacheManager.java 4KB
ShadowWebView.java 4KB
TorX509TrustManager.java 4KB
TorNotifications.java 3KB
AESCounterMode.java 3KB
EditPreferences.java 3KB
TCPStreamThreadJava2Tor.java 3KB
UnitTests.java 3KB
QueueFlowControlHandler.java 3KB
TCPStreamOutputStream.java 3KB
ResolveStream.java 3KB
SocksSocketFactory.java 3KB
DefaultHiddenServiceRequestHandler.java 3KB
HiddenServiceKeySet.java 3KB
QueueTor2JavaHandler.java 3KB
DescriptorCache.java 3KB
TorSocket.java 3KB
SiteListAdapter.java 3KB
Parsing.java 3KB
CellRelayExtend.java 2KB
CellRelayIntroduce1.java 2KB
共 398 条
- 1
- 2
- 3
- 4
资源评论
芝麻粒儿
- 粉丝: 5w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功