Vidalia  0.3.1
TorSettings.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file TorSettings.h
13 ** \brief Settings used for starting and running Tor
14 */
15 
16 #ifndef _TORSETTINGS_H
17 #define _TORSETTINGS_H
18 
19 #include "AbstractTorSettings.h"
20 
21 #include <QHostAddress>
22 
23 
24 /** Manages Tor-specific settings, such as location, command-line arguments,
25  * and control interface information. */
27 {
28  Q_OBJECT
29 
30 public:
31  /** Available Tor authentication methods. */
33  NullAuth, /**< No authentication. */
34  CookieAuth, /**< Use a "magic" cookie for authentication. */
35  PasswordAuth, /**< Use a hashed password for authentication. */
36  UnknownAuth /**< Unknown authentication method. */
37  };
38 
39  /** Default constructor. */
41  /** Applies any changes to Tor's control port or authentication settings. */
42  bool apply(QString *errmsg = 0);
43 
44  /** Gets the name and path of Tor's executable. */
45  QString getExecutable() const;
46  /** Sets the name and path of Tor's executable. */
47  void setExecutable(const QString &torExecutable);
48 
49  /** Gets the location of Tor's data directory. */
50  QString getDataDirectory() const;
51  /** Sets the location to use for Tor's data directory. */
52  void setDataDirectory(const QString &dataDir);
53 
54  /** Gets the torrc to use when starting Tor. */
55  QString getTorrc() const;
56  /** Sets the torrc to use when starting Tor. */
57  void setTorrc(const QString &torrc);
58 
59  /** Get Tor's control interface address. */
60  QHostAddress getControlAddress() const;
61  /** Set Tor's control interface address. */
62  void setControlAddress(const QHostAddress &addr);
63 
64  /** Get the control port. */
65  quint16 getControlPort() const;
66  /** Set the control port. */
67  void setControlPort(quint16 port);
68 
69  /** Get the path for ControlSocket */
70  QString getSocketPath() const;
71 
72  /** Get the current control method */
74 
75  /** Returns true if Vidalia will get the ControlPort automatically from
76  * Tor */
77  bool autoControlPort() const;
78 
79  /** Sets whether Vidalia should get the ControlPort from Tor */
80  void setAutoControlPort(const bool autoControl);
81 
82  /** Set the control method */
84 
85  /** Set the path for ControlSocket */
86  void setSocketPath(const QString &path);
87 
88  /** Returns the plaintext (i.e., not hashed) control password used when
89  * authenticating to Tor. */
90  QString getControlPassword() const;
91  /** Sets the control password used when starting Tor with
92  * HashedControlPassword to <b>password</b>. */
93  void setControlPassword(const QString &password);
94 
95  /** Returns true if a new, random control password is to be used each time
96  * Tor is started. */
97  bool useRandomPassword() const;
98  /** Sets whether or not to generate and use a random control password each
99  * time Tor is started. */
101 
102  /** Returns the current authentication method used when connecting to Tor.*/
104  /** Sets the authentication method used when starting Tor to <b>method</b>.*/
106 
107  /** Returns the current list of ports that will cause Tor to issue a warning
108  * when the user tries to connect to one of them. */
109  QList<quint16> getWarnPlaintextPorts() const;
110  /** Sets the list of ports that will cause Tor to issue a warning when the
111  * user tries to connect to one of them. */
112  void setWarnPlaintextPorts(const QList<quint16> &ports);
113 
114  /** Returns the current list of ports that will cause Tor to reject the
115  * connection when the user tries to connect to one of them. */
116  QList<quint16> getRejectPlaintextPorts() const;
117  /** Sets the list of ports that will cause Tor to reject the connection
118  * when the user tries to connect to one of them. */
119  void setRejectPlaintextPorts(const QList<quint16> &ports);
120 
121  /** Generates a random control password consisting of PASSWORD_LEN
122  * characters. */
123  static QString randomPassword();
124  /** Returns the hash of <b>password</b> as given by the command
125  * "tor --hash-password foo". */
126  static QString hashPassword(const QString &password);
127 
128  /** Returns true if Vidalia needs to bootstrap the torrc file */
129  bool bootstrap() const;
130  /** Enables or disables bootstrap */
131  void setBootstrap(bool enabled);
132  /** Returns the path of the bootstrap torrc file */
133  QString bootstrapFrom() const;
134  /** Sets the location of the bootstrap torrc file */
135  void setBootstrapFrom(const QString &from);
136 
137 private:
138  /** Returns the AuthenticationMethod enum value for the string
139  * description of the authentication method given in <b>authMethod</b>. */
140  AuthenticationMethod toAuthenticationMethod(const QString &authMethod) const;
141  /** Returns the string description of the authentication method specified by
142  * <b>method</b>. The authentication method string is stored in Vidalia's
143  * configuration file. */
144  QString toString(AuthenticationMethod type) const;
145 };
146 
147 #endif
148 
TorSettings::UnknownAuth
@ UnknownAuth
Definition: TorSettings.h:36
TorSettings::NullAuth
@ NullAuth
Definition: TorSettings.h:33
TorSettings::toString
QString toString(AuthenticationMethod type) const
Definition: TorSettings.cpp:376
TorSettings::setAutoControlPort
void setAutoControlPort(const bool autoControl)
Definition: TorSettings.cpp:469
TorSettings::setControlPort
void setControlPort(quint16 port)
Definition: TorSettings.cpp:223
TorSettings::getDataDirectory
QString getDataDirectory() const
Definition: TorSettings.cpp:149
TorSettings::CookieAuth
@ CookieAuth
Definition: TorSettings.h:34
TorSettings::setControlMethod
void setControlMethod(ControlMethod::Method method)
Definition: TorSettings.cpp:251
TorControl
Definition: TorControl.h:49
TorSettings::randomPassword
static QString randomPassword()
Definition: TorSettings.cpp:404
TorSettings::bootstrapFrom
QString bootstrapFrom() const
Definition: TorSettings.cpp:457
TorSettings::getControlPassword
QString getControlPassword() const
Definition: TorSettings.cpp:259
TorSettings
Definition: TorSettings.h:26
TorSettings::getControlMethod
ControlMethod::Method getControlMethod() const
Definition: TorSettings.cpp:244
TorSettings::apply
bool apply(QString *errmsg=0)
Definition: TorSettings.cpp:102
TorSettings::getRejectPlaintextPorts
QList< quint16 > getRejectPlaintextPorts() const
Definition: TorSettings.cpp:348
TorSettings::setControlPassword
void setControlPassword(const QString &password)
Definition: TorSettings.cpp:267
TorSettings::autoControlPort
bool autoControlPort() const
Definition: TorSettings.cpp:463
TorSettings::setWarnPlaintextPorts
void setWarnPlaintextPorts(const QList< quint16 > &ports)
Definition: TorSettings.cpp:336
AbstractTorSettings::torControl
TorControl * torControl() const
Definition: AbstractTorSettings.h:68
TorSettings::setUseRandomPassword
void setUseRandomPassword(bool useRandomPassword)
Definition: TorSettings.cpp:283
TorSettings::setBootstrap
void setBootstrap(bool enabled)
Definition: TorSettings.cpp:439
TorSettings::setControlAddress
void setControlAddress(const QHostAddress &addr)
Definition: TorSettings.cpp:209
TorSettings::setAuthenticationMethod
void setAuthenticationMethod(AuthenticationMethod method)
Definition: TorSettings.cpp:313
TorSettings::setExecutable
void setExecutable(const QString &torExecutable)
Definition: TorSettings.cpp:174
TorSettings::getAuthenticationMethod
AuthenticationMethod getAuthenticationMethod() const
Definition: TorSettings.cpp:290
TorSettings::setDataDirectory
void setDataDirectory(const QString &dataDir)
Definition: TorSettings.cpp:156
TorSettings::toAuthenticationMethod
AuthenticationMethod toAuthenticationMethod(const QString &authMethod) const
Definition: TorSettings.cpp:390
TorSettings::getSocketPath
QString getSocketPath() const
Definition: TorSettings.cpp:230
TorSettings::setSocketPath
void setSocketPath(const QString &path)
Definition: TorSettings.cpp:237
TorSettings::setRejectPlaintextPorts
void setRejectPlaintextPorts(const QList< quint16 > &ports)
Definition: TorSettings.cpp:363
AbstractTorSettings.h
ControlMethod::Method
Method
Definition: ControlMethod.h:24
TorSettings::getControlAddress
QHostAddress getControlAddress() const
Definition: TorSettings.cpp:201
TorSettings::TorSettings
TorSettings(TorControl *torControl=0)
Definition: TorSettings.cpp:69
TorSettings::getTorrc
QString getTorrc() const
Definition: TorSettings.cpp:181
TorSettings::setBootstrapFrom
void setBootstrapFrom(const QString &from)
Definition: TorSettings.cpp:451
TorSettings::getWarnPlaintextPorts
QList< quint16 > getWarnPlaintextPorts() const
Definition: TorSettings.cpp:321
TorSettings::getControlPort
quint16 getControlPort() const
Definition: TorSettings.cpp:216
TorSettings::AuthenticationMethod
AuthenticationMethod
Definition: TorSettings.h:32
TorSettings::hashPassword
static QString hashPassword(const QString &password)
Definition: TorSettings.cpp:412
TorSettings::getExecutable
QString getExecutable() const
Definition: TorSettings.cpp:164
TorSettings::setTorrc
void setTorrc(const QString &torrc)
Definition: TorSettings.cpp:194
AbstractTorSettings
Definition: AbstractTorSettings.h:22
TorSettings::useRandomPassword
bool useRandomPassword() const
Definition: TorSettings.cpp:275
TorSettings::bootstrap
bool bootstrap() const
Definition: TorSettings.cpp:445
TorSettings::PasswordAuth
@ PasswordAuth
Definition: TorSettings.h:35