예제 #1
0
        public void Create_Test4()
        {
            Exception e = Assert.Throws <Exception>(() => new EdhocInitiator(keyEdDSA.PublicKey()));

            Assert.That(e.Message, Is.EqualTo("Need to supply a private key with the signing key"));
        }
예제 #2
0
파일: TestFiles.cs 프로젝트: lulzzz/CWT
        void ProcessFile(FileInfo testCase)
        {
            if (testCase.Extension != ".json")
            {
                return;
            }
            if (testCase.Name[0] == '.')
            {
                return;
            }

            Debug.Print($"Working on file {testCase}");
            Console.WriteLine("Working on file '" + testCase + "'");

            string     inputText  = testCase.OpenText().ReadToEnd();
            CBORObject test       = CBORObject.FromJSONString(inputText);
            KeySet     decodeKeys = new KeySet();
            KeySet     signKeys   = new KeySet();

            CBORObject input = test["input"];

            CWT cwt = new CWT();

            if (input.ContainsKey("encrypted"))
            {
                OneKey key = LoadKey(input["encrypted"]["key"]);
                cwt.EncryptionKey = key;
                decodeKeys.AddKey(key);
            }

            if (input.ContainsKey("mac0"))
            {
                OneKey key = LoadKey(input["mac0"]["key"]);
                cwt.MacKey = key;
                decodeKeys.AddKey(key);
            }

            if (input.ContainsKey("sign0"))
            {
                OneKey key = LoadKey(input["sign0"]["key"]);
                cwt.SigningKey = key;
                signKeys.AddKey(key.PublicKey());
            }

            CWT cwt2 = CWT.Decode(FromHex(test["output"]["cbor"].AsString()), decodeKeys, signKeys);



            CBORObject token = input["token"];

            foreach (CBORObject key in token.Keys)
            {
                CBORObject value = token[key];
                CBORObject key2  = key;
                if (key.AsString().EndsWith("_hex"))
                {
                    value = CBORObject.FromObject(FromHex(value.AsString()));
                    key2  = CBORObject.FromObject(key.AsString().Substring(0, key.AsString().Length - 4));
                }

                cwt.SetClaim(key2, value);

                Assert.True(cwt2.HasClaim(key2), $"Missing Claim {key2}");
                Assert.AreEqual(value, cwt.GetClaim(key2));
            }

            byte[] foo = cwt.EncodeToBytes();

            cwt2 = CWT.Decode(foo, decodeKeys, signKeys);
            foreach (CBORObject key in token.Keys)
            {
                CBORObject value = token[key];
                CBORObject key2  = key;
                if (key.AsString().EndsWith("_hex"))
                {
                    value = CBORObject.FromObject(FromHex(value.AsString()));
                    key2  = CBORObject.FromObject(key.AsString().Substring(0, key.AsString().Length - 4));
                }

                Assert.True(cwt2.HasClaim(key2));
                Assert.AreEqual(value, cwt.GetClaim(key2));
            }
        }
예제 #3
0
 public void TestRpk()
 {
     TlsKeyPair        tlsKey = new TlsKeyPair(RpkOneKey.PublicKey(), RpkOneKey);
     TLSClientEndPoint ep     = new TLSClientEndPoint(RpkOneKey);
 }
예제 #4
0
        static void Main(string[] args)
        {
            Options options = null;
            ParserResult <Options> optionResult = CommandLine.Parser.Default.ParseArguments <Options>(args)
                                                  .WithParsed(o => { options = o; })
                                                  .WithNotParsed(o => {
                Console.WriteLine("Invalid command line");
                Console.WriteLine(o.ToString());
                Environment.Exit(1);
            });


            Console.Title = options.Title;

#if false
            {
                //  Generate a pair of CWT messages signed by a third key.

                OneKey clientKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC);
                OneKey serverKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC);
                OneKey caKey     = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC);

                CWT clientCwt = new CWT();
                clientCwt.Cnf        = new Confirmation(clientKey.PublicKey());
                clientCwt.SigningKey = caKey;
                CBORObject clientCwtCbor  = clientCwt.EncodeToCBOR();
                string     clientCwtStr   = clientCwtCbor.ToString();
                byte[]     clientCwtBytes = clientCwt.EncodeToBytes();

                CWT serverCwt = new CWT()
                {
                    Cnf        = new Confirmation(serverKey),
                    SigningKey = caKey
                };
                CBORObject serverCwtCbor  = serverCwt.EncodeToCBOR();
                string     serverCwtStr   = serverCwtCbor.ToString();
                byte[]     serverCwtBytes = serverCwt.EncodeToBytes();

                string caStr = caKey.EncodeToCBORObject().ToString();
            }
#endif

            LogManager.Instance = new FileLogManager(Console.Out);


            FillDispatchTable(dispatchTable);
            Oscore.Register(dispatchTable);
#if DEV_VERSION
            Groups.FillDispatchTable(dispatchTable);
#endif

#if DO_ACE
            AceAuthz.AddCommands(dispatchTable);

            //  Setup plain OAuth
            AceAuthzHandler = new AceAuthz();
#endif
#if DO_RD
            ResourceDirectory.AddCommands(dispatchTable);
#endif



            if (options.Script != null)
            {
                TextReader x = new StreamReader(options.Script);
                RunScript(x);
                x.Dispose();
            }


            RunScript(Console.In);
        }