static async Task Run() { Console.WriteLine("Starting ZMQ Server"); var server = new ResponseSocket(); var serverCert = CertificatesManager.GetServerCertificate(); server.Options.CurveServer = true; server.Options.CurveCertificate = serverCert; server.Bind(@"tcp://localhost:5556"); (byte[], bool)socketMsgRequest; while (true) { socketMsgRequest = await server.ReceiveFrameBytesAsync().ConfigureAwait(false); if (!socketMsgRequest.Item2) { break; } } var receivedMsg = Message.Parser.ParseFrom(socketMsgRequest.Item1); Console.WriteLine("From Client: {0} - {1}", receivedMsg.Id, receivedMsg.Data); server.SendFrame( (new Message() { Id = 2, Data = "Response from server", }) .ToByteArray()); }
static async Task Run(string[] args) { Console.WriteLine("Starting ZMQ Client"); if (args == null || args.Length < 1) { Console.WriteLine(); Console.WriteLine("Usage: ./{0}", AppDomain.CurrentDomain.FriendlyName); Console.WriteLine(); args = new[] { "Hello" }; } var arg = args[0]; Message msg = new() { Data = arg, Id = 1 }; var clientCertificatePair = new NetMQCertificate(); var client = new RequestSocket(); //client.Options.CurveServerCertificate = CertificatesManager.GetServerCertificate(); client.Options.CurveServerKey = CertificatesManager.GetServerCertificate().PublicKey; client.Options.CurveCertificate = clientCertificatePair; client.Connect(@"tcp://localhost:5556"); var bufferedMsg = msg.ToByteArray(); client.SendFrame(bufferedMsg); (byte[], bool)socketMsgResponse; while (true) { socketMsgResponse = await client.ReceiveFrameBytesAsync().ConfigureAwait(false); if (!socketMsgResponse.Item2) { break; } } var receivedMsg = Message.Parser.ParseFrom(socketMsgResponse.Item1); Console.WriteLine("From Server: {0} - {1}", receivedMsg.Id, receivedMsg.Data); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); } }
public IActionResult GenerateCA(CreateCertificationAuthorityModel model) { if (!ModelState.IsValid) { return(View(model)); } var subjectName = $"CN={model.FriendlyName}"; var start = DateTimeOffset.UtcNow; var end = DateTimeOffset.UtcNow.AddYears(model.ValidityYears); var cm = new CertificatesManager(); var certificate = cm.CreateCertificationAuthorityCertificate(start, end, subjectName, model.FriendlyName); var pem = certificate.ToPem(); return(Ok(pem)); }
private Session() { CreateSessionFolder(); _certificates = new CertificatesManager(); }
static void Main(string[] args) { //TODO: remove Console.read() X509Certificate2 x2 = null; FormatManager fm = null; string invokedVerb = null; object invokedVerbInstance = null; var options = new Options(); if (!CommandLine.Parser.Default.ParseArguments(args, options, (verb, subOptions) => { invokedVerb = verb; invokedVerbInstance = subOptions; })) { WriteRed("Incorrect arguments."); Console.Read(); Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } #region simple signature if (invokedVerb == "sign") { var signoptioninstance = (SignOption)invokedVerbInstance; if (!File.Exists(signoptioninstance.File)) { Environment.Exit(1); } if (signoptioninstance.Path != null && signoptioninstance.Password != null) { CertificatesManager.AddProtectedCertificate(signoptioninstance.Path, signoptioninstance.Password); } x2 = CertificatesManager.FindByFriendlyName(signoptioninstance.Certificate); if (x2 != null) { fm = FormatManagerFactory.GetInstance(signoptioninstance.File); fm.EncodeAndSign(x2, signoptioninstance.File); WriteGreen("Signed " + signoptioninstance.File); Environment.Exit(0); } else { WriteRed("Could not find certificate."); Environment.Exit(1); } Console.Read(); } #endregion #region simple signature verification if (invokedVerb == "verify") { var verifyoptioninstance = (VerifyOption)invokedVerbInstance; if (!FileExists(verifyoptioninstance.File)) { Environment.Exit(1); } fm = FormatManagerFactory.GetInstance(verifyoptioninstance.File); List <KeyValuePair <X509Certificate2, bool> > UsedCertificates = new List <KeyValuePair <X509Certificate2, bool> >(); if (fm.VerifyFile(verifyoptioninstance.File, ref UsedCertificates)) { WriteGreen("All signatures in " + verifyoptioninstance.File + " were verified."); Environment.Exit(0); } else { WriteRed("Could not verify all signatures in " + verifyoptioninstance.File); Environment.Exit(1); } Console.WriteLine("Verified {0}", verifyoptioninstance.File); Console.Read(); } #endregion #region signature with metadata if (invokedVerb == "signm") { var signminstance = (SignWithMetadata)invokedVerbInstance; if (!FileExists(signminstance.File)) { Environment.Exit(1); } //make sure all the metadata fields are properly formatted signminstance.Metadata.ToList().ForEach(field => { if (!IsValidMetadata(field)) { WriteRed("Invalid field " + field); Environment.Exit(1); } else { WriteGreen("Valid field " + field); } }); STEPTRACE4PLOT fileManager = new STEPTRACE4PLOT(signminstance.File); STEPInterface.Elements elts = fileManager.GetBlocks(); var b = elts.CreateBlock(); signminstance.Metadata.ToList().ForEach(field => { string[] data = field.Split(':'); elts.AddMetadata(b, data[0], data[1]); }); x2 = CertificatesManager.FindByFriendlyName(signminstance.Certificate); if (x2 != null) { fileManager.EncodeAndSign(x2, signminstance.File, b); WriteGreen("Signed " + signminstance.File); Environment.Exit(0); } else { WriteRed("Could not find certificate."); Environment.Exit(1); } Console.WriteLine(elts.FullText()); Console.Read(); } #endregion #region signature with metadata verification if (invokedVerb == "verifym") { var verifym = (VerifyWithMetadata)invokedVerbInstance; if (!FileExists(verifym.File)) { Environment.Exit(1); } fm = new STEPTRACE4PLOT(verifym.File); List <KeyValuePair <X509Certificate2, bool> > UsedCertificates = new List <KeyValuePair <X509Certificate2, bool> >(); if (fm.VerifyFile(verifym.File, ref UsedCertificates)) { WriteGreen("All signatures in " + verifym.File + " were verified."); //Environment.Exit(0); } else { WriteRed("Could not verify all signatures in " + verifym.File); //Environment.Exit(1); } Console.WriteLine("Verified {0}", verifym.File); Console.Read(); } #endregion }