Пример #1
0
    public async Task ParseCircEvent1Async()
    {
        string data = "650 CIRC 5 EXTENDED $51BD782616C3EBA543B0D4EE34D7C1CE1ED2291D~Geodude BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2021-06-10T06:26:32.440036 SOCKS_USERNAME=\"AXNH6A3AVT9863JK4VNWD\" SOCKS_PASSWORD=\"AXNH6A3AVT9863JK4VNWD\"\r\n";

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        CircEvent circEvent = CircEvent.FromReply(rawReply);

        Assert.NotNull(circEvent.CircuitInfo);

        CircuitInfo info = circEvent.CircuitInfo;

        Assert.Equal("5", info.CircuitID);
        Assert.Equal(CircStatus.EXTENDED, info.CircStatus);

        CircPath circPath = Assert.Single(info.CircPaths);

        Assert.Equal("$51BD782616C3EBA543B0D4EE34D7C1CE1ED2291D", circPath.FingerPrint);
        Assert.Equal("Geodude", circPath.Nickname);

        Assert.Equal(new List <BuildFlag>()
        {
            BuildFlag.NEED_CAPACITY
        }, info.BuildFlags);
        Assert.Equal(Purpose.GENERAL, info.Purpose);
        Assert.Equal("2021-06-10T06:26:32.440036", info.TimeCreated);
        Assert.Equal("AXNH6A3AVT9863JK4VNWD", info.UserName);
        Assert.Equal("AXNH6A3AVT9863JK4VNWD", info.UserPassword);
    }
Пример #2
0
        public async Task ParseUnknownEventAsync()
        {
            // "XXX" is not a valid event name.
            string data = "650 XXX NOTICE\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            _ = Assert.Throws <NotSupportedException>(() => AsyncEventParser.Parse(rawReply));
        }
Пример #3
0
        public async Task ParseCircEventAsync()
        {
            string data = "650 CIRC 16 LAUNCHED BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2021-06-10T05:42:43.808915\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            IAsyncEvent asyncEvent = AsyncEventParser.Parse(rawReply);

            CircEvent @event = Assert.IsType <CircEvent>(asyncEvent);

            Assert.NotNull(@event);
        }
Пример #4
0
        public async Task ParseSystemClientEventAsync()
        {
            string data = "650 STATUS_CLIENT NOTICE BOOTSTRAP PROGRESS=14 TAG=handshake SUMMARY=\"Handshaking with a relay\"\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            IAsyncEvent asyncEvent = AsyncEventParser.Parse(rawReply);

            BootstrapStatusEvent @event = Assert.IsType <BootstrapStatusEvent>(asyncEvent);

            Assert.NotNull(@event);
        }
Пример #5
0
    public async Task AuthMethodHashedPasswordAsync()
    {
        string data = "250-PROTOCOLINFO 1\r\n250-AUTH METHODS=HASHEDPASSWORD\r\n250-VERSION Tor=\"0.4.3.5\"\r\n250 OK\r\n";

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        ProtocolInfoReply reply = ProtocolInfoReply.FromReply(rawReply);

        Assert.Equal(1, reply.ProtocolVersion);
        Assert.Equal("0.4.3.5", reply.TorVersion);
        Assert.Single(reply.AuthMethods);
        Assert.Contains("HASHEDPASSWORD", reply.AuthMethods);
    }
Пример #6
0
    public async Task ParseOrConnEventAsync()
    {
        string data = "650 ORCONN $A1B28D636A56AAFFE92ADCCA937AA4BD5333BB4C~bakunin4 LAUNCHED ID=5\r\n";

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        OrConnEvent orConnEvent = OrConnEvent.FromReply(rawReply);

        Assert.Equal("$A1B28D636A56AAFFE92ADCCA937AA4BD5333BB4C~bakunin4", orConnEvent.Target);
        Assert.Equal(OrStatus.LAUNCHED, orConnEvent.OrStatus);
        Assert.Null(orConnEvent.NCircs);
        Assert.Equal("5", orConnEvent.ConnId);
    }
Пример #7
0
        public async Task ParseCircuitEstablishedStatusEventAsync()
        {
            string data = "650 STATUS_CLIENT NOTICE CIRCUIT_ESTABLISHED\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            StatusEvent statusEvent = StatusEvent.FromReply(rawReply);

            Assert.Equal(StatusType.STATUS_CLIENT, statusEvent.Type);
            Assert.Equal(StatusSeverity.NOTICE, statusEvent.Severity);
            Assert.Equal("CIRCUIT_ESTABLISHED", statusEvent.Action);
            Assert.Empty(statusEvent.Arguments);
        }
Пример #8
0
    public async Task AuthMethodCookieAsync()
    {
        // Yes, Tor really returns: "C:\\Users\\Wasabi\\AppData\\Roaming\\WalletWasabi\\Client\\control_auth_cookie" path on Windows.
        string data = "250-PROTOCOLINFO 1\r\n250-AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"C:\\\\Users\\\\Wasabi\\\\AppData\\\\Roaming\\\\WalletWasabi\\\\Client\\\\control_auth_cookie\"\r\n250-VERSION Tor=\"0.4.5.7\"\r\n250 OK\r\n";

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        ProtocolInfoReply reply = ProtocolInfoReply.FromReply(rawReply);

        Assert.Equal(1, reply.ProtocolVersion);
        Assert.Equal("0.4.5.7", reply.TorVersion);
        Assert.Equal(2, reply.AuthMethods.Length);
        Assert.Equal("COOKIE", reply.AuthMethods[0]);
        Assert.Equal("SAFECOOKIE", reply.AuthMethods[1]);
        Assert.Equal(@"C:\Users\Wasabi\AppData\Roaming\WalletWasabi\Client\control_auth_cookie", reply.CookieFilePath);
    }
Пример #9
0
        public async Task ParseBootstrapStatusEvent2Async()
        {
            string data = "650 STATUS_CLIENT NOTICE BOOTSTRAP PROGRESS=95 TAG=circuit_create SUMMARY=\"Establishing a Tor circuit\"\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            StatusEvent statusEvent = StatusEvent.FromReply(rawReply);

            Assert.Equal(StatusType.STATUS_CLIENT, statusEvent.Type);
            Assert.Equal(StatusSeverity.NOTICE, statusEvent.Severity);
            Assert.Equal("BOOTSTRAP", statusEvent.Action);
            Assert.Equal(3, statusEvent.Arguments.Count);
            Assert.Equal("95", statusEvent.Arguments["PROGRESS"]);
            Assert.Equal("circuit_create", statusEvent.Arguments["TAG"]);
            Assert.Equal("Establishing a Tor circuit", statusEvent.Arguments["SUMMARY"]);
        }
Пример #10
0
        public async Task ParseBootstrapStatusEvent1Async()
        {
            string data = "650 STATUS_CLIENT NOTICE BOOTSTRAP PROGRESS=14 TAG=handshake SUMMARY=\"Handshaking with a relay\"\r\n";

            TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

            StatusEvent statusEvent = StatusEvent.FromReply(rawReply);

            Assert.Equal(StatusType.STATUS_CLIENT, statusEvent.Type);
            Assert.Equal(StatusSeverity.NOTICE, statusEvent.Severity);
            Assert.Equal("BOOTSTRAP", statusEvent.Action);
            Assert.Equal(3, statusEvent.Arguments.Count);
            Assert.Equal("14", statusEvent.Arguments["PROGRESS"]);
            Assert.Equal("handshake", statusEvent.Arguments["TAG"]);
            Assert.Equal("Handshaking with a relay", statusEvent.Arguments["SUMMARY"]);
        }
Пример #11
0
    public async Task ParseCircEvent2Async()
    {
        string data = "650 CIRC 16 LAUNCHED BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2021-06-10T05:42:43.808915\r\n";

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        CircEvent circEvent = CircEvent.FromReply(rawReply);

        Assert.NotNull(circEvent.CircuitInfo);

        CircuitInfo info = circEvent.CircuitInfo;

        Assert.Equal("16", info.CircuitID);
        Assert.Equal(CircStatus.LAUNCHED, info.CircStatus);
        Assert.Equal(new List <BuildFlag>()
        {
            BuildFlag.NEED_CAPACITY
        }, info.BuildFlags);
        Assert.Equal(Purpose.GENERAL, info.Purpose);
        Assert.Equal("2021-06-10T05:42:43.808915", info.TimeCreated);
    }
    public async Task ParseReplyAsync()
    {
        StringBuilder sb = new();

        sb.Append("250+circuit-status=\r\n");
        sb.Append("1 BUILT $E9F71AC06F29B2110E3FC09016B0E50407444EE2~libertas,$D0423D3A13C18D2ED0F3D5BFD90E13E77C9AD239~d0xkb,$3A9559477D72F71215850C97FA62A0DA7380964B~PawNetBlue BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2021-05-15T14:04:17.615384\r\n");
        sb.Append("2 BUILT $E9F71AC06F29B2110E3FC09016B0E50407444EE2~libertas,$A0FA50A070CFB4B89737A27F3259F92C118A0AF0~pipiska,$7E77CC94D94C08609D70B517FF938CC61C9F8232~pitfall BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2021-05-15T14:04:18.628885\r\n");
        sb.Append("3 BUILT $E9F71AC06F29B2110E3FC09016B0E50407444EE2~libertas,$706A7674A217BA905FE677E82236B7B968A23DB7~rofltor04,$4D4938B725B89561773A161215D88B7C45C43C35~TheGreenDynamo,$18CA339AD0C33EAB035F1D869518F3D2D88BABC0~FreeAssange BUILD_FLAGS=IS_INTERNAL,NEED_CAPACITY PURPOSE=HS_CLIENT_HSDIR HS_STATE=HSCI_CONNECTING TIME_CREATED=2021-05-15T14:04:19.353271\r\n");
        sb.Append("4 EXTENDED $E9F71AC06F29B2110E3FC09016B0E50407444EE2~libertas BUILD_FLAGS=IS_INTERNAL,NEED_CAPACITY PURPOSE=MEASURE_TIMEOUT TIME_CREATED=2021-05-15T14:04:19.631228\r\n");
        sb.Append("5 BUILT $E9F71AC06F29B2110E3FC09016B0E50407444EE2~libertas,$31D270A38505D4BFBBCABF717E9FB4BCA6DDF2FF~Belgium,$B411027C926A9BFFCF7DA91E3CAF1856A321EFFD~pulsetor BUILD_FLAGS=IS_INTERNAL,NEED_CAPACITY PURPOSE=HS_CLIENT_REND HS_STATE=HSCR_JOINED REND_QUERY=wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad TIME_CREATED=2021-05-15T14:04:20.634686\r\n");
        sb.Append(".\r\n");
        sb.Append("250 OK\r\n");

        string data = sb.ToString();

        TorControlReply rawReply = await TorControlReplyReaderTest.ParseAsync(data);

        Assert.Equal(8, rawReply.ResponseLines.Count);

        GetInfoCircuitStatusReply reply = GetInfoCircuitStatusReply.FromReply(rawReply);

        Assert.Equal(5, reply.Circuits.Count);

        // Circuit #1.
        {
            CircuitInfo circuitInfo = reply.Circuits[0];

            Assert.Equal("1", circuitInfo.CircuitID);
            Assert.Equal(CircStatus.BUILT, circuitInfo.CircStatus);

            List <CircPath> circPaths = circuitInfo.CircPaths;
            Assert.Equal("$E9F71AC06F29B2110E3FC09016B0E50407444EE2", circPaths[0].FingerPrint);
            Assert.Equal("libertas", circPaths[0].Nickname);

            Assert.Equal("$D0423D3A13C18D2ED0F3D5BFD90E13E77C9AD239", circPaths[1].FingerPrint);
            Assert.Equal("d0xkb", circPaths[1].Nickname);

            Assert.Equal("$3A9559477D72F71215850C97FA62A0DA7380964B", circPaths[2].FingerPrint);
            Assert.Equal("PawNetBlue", circPaths[2].Nickname);

            BuildFlag buildFlag = Assert.Single(circuitInfo.BuildFlags);
            Assert.Equal(BuildFlag.NEED_CAPACITY, buildFlag);

            Assert.Equal(Purpose.GENERAL, circuitInfo.Purpose);
            Assert.Equal("2021-05-15T14:04:17.615384", circuitInfo.TimeCreated);

            Assert.Null(circuitInfo.Reason);
            Assert.Null(circuitInfo.RemoteReason);
            Assert.Null(circuitInfo.HsState);
            Assert.Null(circuitInfo.RendQuery);
            Assert.Null(circuitInfo.UserName);
            Assert.Null(circuitInfo.UserPassword);
        }

        // Circuit #2.
        {
            CircuitInfo circuitInfo = reply.Circuits[1];

            Assert.Equal("2", circuitInfo.CircuitID);
            Assert.Equal(CircStatus.BUILT, circuitInfo.CircStatus);

            List <CircPath> circPaths = circuitInfo.CircPaths;
            Assert.Equal("$E9F71AC06F29B2110E3FC09016B0E50407444EE2", circPaths[0].FingerPrint);
            Assert.Equal("libertas", circPaths[0].Nickname);

            Assert.Equal("$A0FA50A070CFB4B89737A27F3259F92C118A0AF0", circPaths[1].FingerPrint);
            Assert.Equal("pipiska", circPaths[1].Nickname);

            Assert.Equal("$7E77CC94D94C08609D70B517FF938CC61C9F8232", circPaths[2].FingerPrint);
            Assert.Equal("pitfall", circPaths[2].Nickname);

            BuildFlag buildFlag = Assert.Single(circuitInfo.BuildFlags);
            Assert.Equal(BuildFlag.NEED_CAPACITY, buildFlag);

            Assert.Equal(Purpose.GENERAL, circuitInfo.Purpose);
            Assert.Equal("2021-05-15T14:04:18.628885", circuitInfo.TimeCreated);

            Assert.Null(circuitInfo.Reason);
            Assert.Null(circuitInfo.RemoteReason);
            Assert.Null(circuitInfo.HsState);
            Assert.Null(circuitInfo.RendQuery);
            Assert.Null(circuitInfo.UserName);
            Assert.Null(circuitInfo.UserPassword);
        }

        // Circuit #3.
        {
            CircuitInfo circuitInfo = reply.Circuits[2];

            Assert.Equal("3", circuitInfo.CircuitID);
            Assert.Equal(CircStatus.BUILT, circuitInfo.CircStatus);

            List <CircPath> circPaths = circuitInfo.CircPaths;
            Assert.Equal("$E9F71AC06F29B2110E3FC09016B0E50407444EE2", circPaths[0].FingerPrint);
            Assert.Equal("libertas", circPaths[0].Nickname);

            Assert.Equal("$706A7674A217BA905FE677E82236B7B968A23DB7", circPaths[1].FingerPrint);
            Assert.Equal("rofltor04", circPaths[1].Nickname);

            Assert.Equal("$4D4938B725B89561773A161215D88B7C45C43C35", circPaths[2].FingerPrint);
            Assert.Equal("TheGreenDynamo", circPaths[2].Nickname);

            Assert.Equal("$18CA339AD0C33EAB035F1D869518F3D2D88BABC0", circPaths[3].FingerPrint);
            Assert.Equal("FreeAssange", circPaths[3].Nickname);

            Assert.Equal(2, circuitInfo.BuildFlags.Count);
            Assert.Equal(BuildFlag.IS_INTERNAL, circuitInfo.BuildFlags[0]);
            Assert.Equal(BuildFlag.NEED_CAPACITY, circuitInfo.BuildFlags[1]);

            Assert.Equal(Purpose.HS_CLIENT_HSDIR, circuitInfo.Purpose);
            Assert.Equal(HsState.HSCI_CONNECTING, circuitInfo.HsState);
            Assert.Equal("2021-05-15T14:04:19.353271", circuitInfo.TimeCreated);

            Assert.Null(circuitInfo.Reason);
            Assert.Null(circuitInfo.RemoteReason);
            Assert.Null(circuitInfo.RendQuery);
            Assert.Null(circuitInfo.UserName);
            Assert.Null(circuitInfo.UserPassword);
        }

        // Circuit #4.
        {
            CircuitInfo circuitInfo = reply.Circuits[3];

            Assert.Equal("4", circuitInfo.CircuitID);
            Assert.Equal(CircStatus.EXTENDED, circuitInfo.CircStatus);

            List <CircPath> circPaths = circuitInfo.CircPaths;
            Assert.Equal("$E9F71AC06F29B2110E3FC09016B0E50407444EE2", circPaths[0].FingerPrint);
            Assert.Equal("libertas", circPaths[0].Nickname);

            Assert.Equal(2, circuitInfo.BuildFlags.Count);
            Assert.Equal(BuildFlag.IS_INTERNAL, circuitInfo.BuildFlags[0]);
            Assert.Equal(BuildFlag.NEED_CAPACITY, circuitInfo.BuildFlags[1]);
            Assert.Equal(Purpose.MEASURE_TIMEOUT, circuitInfo.Purpose);
            Assert.Equal("2021-05-15T14:04:19.631228", circuitInfo.TimeCreated);

            Assert.Null(circuitInfo.HsState);
            Assert.Null(circuitInfo.Reason);
            Assert.Null(circuitInfo.RemoteReason);
            Assert.Null(circuitInfo.RendQuery);
            Assert.Null(circuitInfo.UserName);
            Assert.Null(circuitInfo.UserPassword);
        }

        // Circuit #5.
        {
            CircuitInfo circuitInfo = reply.Circuits[4];

            Assert.Equal("5", circuitInfo.CircuitID);
            Assert.Equal(CircStatus.BUILT, circuitInfo.CircStatus);

            List <CircPath> circPaths = circuitInfo.CircPaths;
            Assert.Equal("$E9F71AC06F29B2110E3FC09016B0E50407444EE2", circPaths[0].FingerPrint);
            Assert.Equal("libertas", circPaths[0].Nickname);

            Assert.Equal("$31D270A38505D4BFBBCABF717E9FB4BCA6DDF2FF", circPaths[1].FingerPrint);
            Assert.Equal("Belgium", circPaths[1].Nickname);

            Assert.Equal("$B411027C926A9BFFCF7DA91E3CAF1856A321EFFD", circPaths[2].FingerPrint);
            Assert.Equal("pulsetor", circPaths[2].Nickname);

            Assert.Equal(2, circuitInfo.BuildFlags.Count);
            Assert.Equal(BuildFlag.IS_INTERNAL, circuitInfo.BuildFlags[0]);
            Assert.Equal(BuildFlag.NEED_CAPACITY, circuitInfo.BuildFlags[1]);
            Assert.Equal(Purpose.HS_CLIENT_REND, circuitInfo.Purpose);
            Assert.Equal(HsState.HSCR_JOINED, circuitInfo.HsState);
            Assert.Equal("wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad", circuitInfo.RendQuery);
            Assert.Equal("2021-05-15T14:04:20.634686", circuitInfo.TimeCreated);

            Assert.Null(circuitInfo.Reason);
            Assert.Null(circuitInfo.RemoteReason);
            Assert.Null(circuitInfo.UserName);
            Assert.Null(circuitInfo.UserPassword);
        }
    }