Vidalia 0.2.12

TorSettings.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file TorSettings.h
00013 ** \brief Settings used for starting and running Tor
00014 */
00015 
00016 #ifndef _TORSETTINGS_H
00017 #define _TORSETTINGS_H
00018 
00019 #include "AbstractTorSettings.h"
00020 
00021 #include <QHostAddress>
00022 
00023 
00024 /** Manages Tor-specific settings, such as location, command-line arguments,
00025  * and control interface information. */
00026 class TorSettings : public AbstractTorSettings
00027 {
00028   Q_OBJECT
00029 
00030 public:
00031   /** Available Tor authentication methods. */
00032   enum AuthenticationMethod {
00033     NullAuth,      /**< No authentication. */
00034     CookieAuth,    /**< Use a "magic" cookie for authentication. */
00035     PasswordAuth,  /**< Use a hashed password for authentication. */
00036     UnknownAuth    /**< Unknown authentication method. */
00037   };
00038   
00039   /** Default constructor. */
00040   TorSettings(TorControl *torControl = 0);
00041   /** Applies any changes to Tor's control port or authentication settings. */ 
00042   bool apply(QString *errmsg = 0);
00043 
00044   /** Gets the name and path of Tor's executable. */
00045   QString getExecutable() const;
00046   /** Sets the name and path of Tor's executable. */
00047   void setExecutable(const QString &torExecutable);
00048  
00049   /** Gets the location of Tor's data directory. */
00050   QString getDataDirectory() const;
00051   /** Sets the location to use for Tor's data directory. */
00052   void setDataDirectory(const QString &dataDir);
00053   
00054   /** Gets the torrc to use when starting Tor. */
00055   QString getTorrc() const;
00056   /** Sets the torrc to use when starting Tor. */
00057   void setTorrc(const QString &torrc);
00058   
00059   /** Get Tor's control interface address. */
00060   QHostAddress getControlAddress() const;
00061   /** Set Tor's control interface address. */
00062   void setControlAddress(const QHostAddress &addr);
00063   
00064   /** Get the control port. */
00065   quint16 getControlPort() const;
00066   /** Set the control port. */
00067   void setControlPort(quint16 port);
00068 
00069   /** Get the path for ControlSocket */
00070   QString getSocketPath() const;
00071 
00072   /** Get the current control method */
00073   ControlMethod::Method getControlMethod() const;
00074 
00075   /** Set the control method */
00076   void setControlMethod(ControlMethod::Method method);
00077 
00078   /** Set the path for ControlSocket */
00079   void setSocketPath(const QString &path);
00080   
00081   /** Returns the plaintext (i.e., not hashed) control password used when
00082    * authenticating to Tor. */
00083   QString getControlPassword() const;
00084   /** Sets the control password used when starting Tor with
00085    * HashedControlPassword to <b>password</b>. */
00086   void setControlPassword(const QString &password);
00087 
00088  /** Returns true if a new, random control password is to be used each time
00089   * Tor is started. */
00090   bool useRandomPassword() const;
00091   /** Sets whether or not to generate and use a random control password each
00092    * time Tor is started. */
00093   void setUseRandomPassword(bool useRandomPassword);
00094 
00095   /** Returns the current authentication method used when connecting to Tor.*/
00096   AuthenticationMethod getAuthenticationMethod() const;
00097   /** Sets the authentication method used when starting Tor to <b>method</b>.*/
00098   void setAuthenticationMethod(AuthenticationMethod method);
00099 
00100   /** Returns the current list of ports that will cause Tor to issue a warning
00101    * when the user tries to connect to one of them. */
00102   QList<quint16> getWarnPlaintextPorts() const;
00103   /** Sets the list of ports that will cause Tor to issue a warning when the
00104    * user tries to connect to one of them. */
00105   void setWarnPlaintextPorts(const QList<quint16> &ports);
00106 
00107   /** Returns the current list of ports that will cause Tor to reject the
00108    * connection when the user tries to connect to one of them. */
00109   QList<quint16> getRejectPlaintextPorts() const;
00110   /** Sets the list of ports that will cause Tor to reject the connection
00111    * when the user tries to connect to one of them. */
00112   void setRejectPlaintextPorts(const QList<quint16> &ports);
00113 
00114   /** Generates a random control password consisting of PASSWORD_LEN
00115    * characters. */
00116   static QString randomPassword();
00117   /** Returns the hash of <b>password</b> as given by the command 
00118    * "tor --hash-password foo". */
00119   static QString hashPassword(const QString &password);
00120 
00121 private:
00122   /** Returns the AuthenticationMethod enum value for the string
00123    * description of the authentication method given in <b>authMethod</b>. */
00124   AuthenticationMethod toAuthenticationMethod(const QString &authMethod) const;
00125   /** Returns the string description of the authentication method specified by
00126    * <b>method</b>. The authentication method string is stored in  Vidalia's
00127    * configuration file. */
00128   QString toString(AuthenticationMethod type) const;
00129 };
00130 
00131 #endif
00132