public override AbstractCertificate ParseServerCertificate(short certificateType, Stream io) { switch (certificateType) { case CertificateType.CwtPublicKey: try { CwtPublicKey cwtPub = CwtPublicKey.Parse(io); CWT cwtServer = CWT.Decode(cwtPub.EncodedCwt(), CwtTrustKeySet, CwtTrustKeySet); AsymmetricKeyParameter pubKey = cwtServer.Cnf.Key.AsPublicKey(); SubjectPublicKeyInfo spi = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pubKey); cwtPub.SetSubjectPublicKeyInfo(spi); return(cwtPub); } catch { return(null); } default: return(null); } }
public void GetCwtKey(CwtPublicKey rpk) { try { CWT cwt = CWT.Decode(rpk.EncodedCwt(), CwtTrustKeySet, CwtTrustKeySet); AsymmetricKeyParameter pub = cwt.Cnf.Key.AsPublicKey(); SubjectPublicKeyInfo spi = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pub); rpk.SetSubjectPublicKeyInfo(spi); AuthenticationKey = cwt.Cnf.Key; return; } catch { } TlsEvent ev = new TlsEvent(TlsEvent.EventCode.ServerCertificate) { Certificate = rpk }; EventHandler <TlsEvent> handler = TlsEventHandler; if (handler != null) { handler(this, ev); } if (!ev.Processed) { throw new TlsFatalAlert(AlertDescription.certificate_unknown); } AuthenticationKey = ev.KeyValue; }
public void test2() { double[] signal = new double[] { 1385, 1458, 1546, 1359, 1365, 1434, 1344, 1485, 1415, 1327, 1396, 1363, 1418, 1405, 1414, 1481, 1324, 1321, 1260, 1441, 1409, 1501, 1440, 1428, 1456, 1546, 1598, 1444, 1389, 1395, 1425, 1318, 1384, 1489, 1456, 1424, 1491, 1476, 1493, 1470, 1452, 1409, 1463, 1406, 1470, 1506, 1410 }; List <double> t = new List <double>(); for (int i = 0; i < signal.Length; i++) { t.Add(i); } SortedDictionary <double, List <double> > matrix = new SortedDictionary <double, List <double> >(); for (int a = 1; a <= 5; a += 1) { double[] processed = CWT.Transform(signal, a); matrix[a] = processed.ToList(); } RidgeLineFinder coeffMatrix = new RidgeLineFinder(); List <RidgeLine> lines = coeffMatrix.Find(t, matrix); foreach (var item in lines) { Console.WriteLine(item.Pos); Console.WriteLine(item.Length); Console.WriteLine(GetString <int>(item.Index)); Console.WriteLine(GetString <double>(item.Trace) + "\n"); } }
public DTLSClientChannel(CWT cwt, OneKey userKey, KeySet cwtTrustKeys, int port) { _port = port; _userKey = userKey; _userCwt = cwt; CwtTrustKeySet = cwtTrustKeys; }
public void GetCwtKey(CwtPublicKey rpk) { CWT cwt; try { cwt = CWT.Decode(rpk.EncodedCwt(), CwtTrustRoots, CwtTrustRoots); AuthenticationKey = cwt.Cnf.Key; } catch (Exception e) { TlsEvent ev = new TlsEvent(TlsEvent.EventCode.ClientCertificate) { Certificate = rpk }; EventHandler <TlsEvent> handler = TlsEventHandler; if (handler != null) { handler(this, ev); } if (!ev.Processed) { throw new TlsFatalAlert(AlertDescription.certificate_unknown); } AuthenticationKey = ev.KeyValue; } }
public void test2() { double[] u = new double[] { -2, 1, 3 }; double[] v = new double[] { 3, 4, 1, 5, 6 }; double[] w = CWT.Convolve(u, v); foreach (double i in w) { Console.WriteLine(i); } }
private static void AddTlsCwt(string[] commands) { if (commands.Length != 4) { Console.Write($"Incorrect number of arguments: {commands.Length}"); return; } CBORObject cbor = CBORDiagnostics.Parse(commands[2]); CWT cwt = CWT.Decode(cbor.EncodeToBytes(), CwtRootKeys, CwtRootKeys); cbor = CBORDiagnostics.Parse(commands[3]); _TlsKeys.Add(commands[1], new TlsKeyPair(cwt, new OneKey(cbor))); }
public void test4() { double[] t = new double[] { 1385, 1458, 1546, 1359, 1365, 1434, 1344, 1485, 1415, 1327, 1396, 1363, 1418, 1405, 1414, 1481, 1324, 1321, 1260, 1441, 1409, 1501, 1440, 1428, 1456, 1546, 1598, 1444, 1389, 1395, 1425, 1318, 1384, 1489, 1456, 1424, 1491, 1476, 1493, 1470, 1452, 1409, 1463, 1406, 1470, 1506, 1410 }; //{ // 1385,1458,1546,1359,1365,1434,1344,1485,1415,1327,1396,1363,1418,1405,1414,1481,1324,1321,1260,1441,1409,1501,1440,1428,1456,1546,1598,1444,1389,1395,1425,1318,1384,1489,1456,1424,1491,1476,1493,1470,1452,1409,1463,1406,1470,1506,1410,1452,1424,1418,1306,1335,1299,1391,1423,1609,1449,1385,1417,1400,1457,1504,1395,1628,1481,1430,1302,1468,1411,1423,1421,1424,1411,1454,1492,1514,1531,1340,1388,1360,1412,1531,1379,1397,1392,1475,1450,1484,1448,1513,1321,1408,1558,1623,1537,1515,1562,1434,1470,1470,1473 //}; double[] y = CWT.Transform(t, 2.0); foreach (double v in y) { Console.WriteLine(v); } }
public void test1() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); string path = @"C:\Users\Rui Zhang\Downloads\Serum_1_C18_03292019_Ali.raw"; ISpectrumReader reader = new ThermoRawSpectrumReader(); reader.Init(path); //for (int i = reader.GetFirstScan(); i < reader.GetLastScan(); i++) int i = 342; RidgeLineFinder coeffMatrix = new RidgeLineFinder(1.0, 2, 1, 2); { if (reader.GetMSnOrder(i) < 2) { ISpectrum spectrum = reader.GetSpectrum(i); List <IPeak> peaks = spectrum.GetPeaks(); double[] signal = peaks.Select(p => p.GetIntensity()).ToArray(); SortedDictionary <double, List <double> > matrix = new SortedDictionary <double, List <double> >(); for (double a = 1; a <= 120; a += 6) { double[] processed = CWT.Transform(signal, a); matrix[a] = processed.ToList(); } List <RidgeLine> lines = coeffMatrix.Find(spectrum.GetPeaks().Select(p => p.GetMZ()).ToList(), matrix); Console.WriteLine(lines.Count); Console.WriteLine(peaks.Count); foreach (RidgeLine line in lines) { Console.WriteLine(line.Pos); } } //break; } Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms"); //Console.Read(); }
public void test3() { int n = 20; double[] t = new double[n]; for (int i = 0; i < n; i++) { t[i] = i - (n - 1) / 2.0; } double[] y = CWT.Transform(t, 1.0); foreach (double v in y) { Console.WriteLine(v); } }
public void Test_Issuer() { CWT cwt = new CWT(); Assert.AreEqual(false, cwt.HasClaim(ClaimId.Issuer)); Assert.AreEqual(false, cwt.HasClaim("iss")); cwt.Issuer = "Audience1"; Assert.AreEqual(true, cwt.HasClaim(ClaimId.Issuer)); Assert.AreEqual(true, cwt.HasClaim("iss")); Assert.AreEqual("Audience1", cwt.GetClaim(ClaimId.Issuer).AsString()); Assert.AreEqual("Audience1", cwt.GetClaim("iss").AsString()); Assert.AreEqual("Audience1", cwt[ClaimId.Issuer].AsString()); CwtException e = Assert.Throws <CwtException>(() => cwt.SetClaim(ClaimId.Issuer, CBORObject.FromObject(1))); cwt.SetClaim("iss", "TestValue"); Assert.AreEqual(cwt.Issuer, "TestValue"); }
public void Test_Audience() { CWT cwt = new CWT(); Assert.AreEqual(false, cwt.HasClaim(ClaimId.Audience)); Assert.AreEqual(false, cwt.HasClaim("aud")); cwt.Audience = "Audience1"; Assert.AreEqual(true, cwt.HasClaim(ClaimId.Audience)); Assert.AreEqual(true, cwt.HasClaim("aud")); Assert.AreEqual("Audience1", cwt.GetClaim(ClaimId.Audience).AsString()); Assert.AreEqual("Audience1", cwt.GetClaim("aud").AsString()); Assert.AreEqual("Audience1", cwt[ClaimId.Audience].AsString()); CwtException e = Assert.Throws <CwtException>(() => cwt.SetClaim(ClaimId.Audience, CBORObject.FromObject(1))); cwt.SetClaim("aud", "TestValue"); Assert.AreEqual(cwt.Audience, "TestValue"); }
public TlsKeyPair(CWT publicKey, OneKey privateKey) { this.PrivateKey = privateKey; this.PublicCwt = publicKey; CertType = CertificateType.CwtPublicKey; // 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)); } }
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); }