示例#1
0
        public void TestMethod1()
        {
            Uri         uri    = new Uri("coap+tls://localhost:" + _serverPort.ToString() + "/hello");
            CoapClient  client = new CoapClient(uri);
            TcpEndPoint ep     = new TcpEndPoint();

            ep.Start();
            client.EndPoint = ep;

            Response resp = client.Get();

            Assert.AreEqual(resp.StatusCode, StatusCode.Content);
        }
示例#2
0
        static CoapServer SetupServer(ICoapConfig config, EndPoint endPoint, int port, KeySet dtlsSignKeys,
                                      KeySet dtlsValidateKeys)
        {
            //
            //

            CoapServer   server = new CoapServer(config, endPoint, port);
            DTLSEndPoint ep2    = new DTLSEndPoint(dtlsSignKeys, dtlsValidateKeys, port + 1);

            server.AddEndPoint(ep2);

            IResource root = new HelloWorldResource("hello", true);

            server.Add(root);

            IResource x = new OscoapTest("coap");

            root.Add(x);

            x = new OscoapTest("1");
            root.Add(x);

            root.Add(new OscoapTest("2"));
            root.Add(new OscoapTest("3"));
            root.Add(new OscoapTest("6"));
            root.Add(new OscoapTest("7"));

            server.Add(new OscoapTest("test"));

            server.Add(new TimeResource("observe"));

            server.Add(new LargeResource("LargeResource"));

#if DEV_VERSION
            AceTest.Setup(server, "RS1");
#if false
            server.Add(new Com.AugustCellars.CoAP.EDHOC.EdhocResource(edhocKeys, edhocSign));
#endif

            //  Setup the ACE resources
            string UseAsServer = "coaps://localhost:5689/token";
            // UseAsServer = "coaps://31.133.142.90/token";
            // UseAsServer = "coaps://31.133.134.176/token";

            KeySet myDecryptKeySet = new KeySet();
            OneKey key             = new OneKey();

            key.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet);
            key.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }));
            key.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(Encoding.UTF8.GetBytes("SERVER_KID")));
            key.Add(CoseKeyKeys.Algorithm, AlgorithmValues.AES_CCM_64_128_128);

            myDecryptKeySet.AddKey(key);

            key = new OneKey();
            key.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet);
            key.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(new byte[] { (byte)'a', (byte)'b', (byte)'c', 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }));
            key.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(new byte[] { 0x70, 0x63, 0x6F, 0x61, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74 }));
            key.Add(CoseKeyKeys.Algorithm, CBORObject.FromObject(5));
            myDecryptKeySet.AddKey(key);

            AuthZ authZ = new AuthZ(myDecryptKeySet, null);
            server.Add(authZ);
            AceOAuthTest r = new AceOAuthTest("ace-echo", true, true, UseAsServer);
            r.AuthTokenProcessor = authZ;
            server.Add(r);
            OscoapContexts = SecurityContextSet.AllContexts;
#endif

            // ep2.Add(new AceOAuthTest("ace/echo", true, true, null));

#if INCLUDE_RD
            ResourceDirectoryResource.CreateResources(server);
#endif

#if DEV_VERSION
            // server = new CoapServer(config);
            CoAPEndPoint tcp = new TcpEndPoint(port);
            tcp.Start();
            server.AddEndPoint(tcp);

            // server.Add(new HelloWorldResource("hello", false));
            // server.Add(new LargeResource("LargeResource"));
            server.Add(new LargeResource("ExtraLargeResource", 20 * 1024));
            server.Add(new StorageResource("StorageHere"));
            server.Start();

            // server = new CoapServer(config);
            tcp = new TLSEndPoint(dtlsSignKeys, dtlsValidateKeys, port + 1);
            tcp.Start();
            server.AddEndPoint(tcp);

            AceTest.Setup(server, "RS2");

            //server.Add(new HelloWorldResource("hello", false));
#endif

            server.Start();
            return(server);
        }