/** * Authenticates the controller to the Tor server. * * <p>By default, the current Tor implementation trusts all local users, and the controller can * authenticate itself by calling authenticate(new byte[0]). * * <p>If the 'CookieAuthentication' option is true, Tor writes a "magic cookie" file named * "control_auth_cookie" into its data directory. To authenticate, the controller must send the * contents of this file in <b>auth</b>. * * <p>If the 'HashedControlPassword' option is set, <b>auth</b> must contain the salted hash of a * secret password. The salted hash is computed according to the S2K algorithm in RFC 2440 * (OpenPGP), and prefixed with the s2k specifier. This is then encoded in hexadecimal, prefixed * by the indicator sequence "16:". * * <p>You can generate the salt of a password by calling 'tor --hash-password <password>' or by * using the provided PasswordDigest class. To authenticate under this scheme, the controller * sends Tor the original secret that was used to generate the password. */ public void authenticate(byte[] auth) throws IOException { String cmd = "AUTHENTICATE " + Bytes.hex(auth) + "\r\n"; sendAndWaitForResponse(cmd, null); }