// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { PkiConfig.LoadLicense("LacunaPkiLicense.config"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
static void Main(string[] args) { // This is a TRIAL token. It will expire at 31/08/2020. PkiConfig.LoadLicense(Convert.FromBase64String("AxAAIIy8jc59Q0q95BZrL57K5hEAUEtJIFN1aXRlIFNhbXBsZXMIAAD0Ze31HdgICACAXwryrU7YCAAAAAAAAAQAfwAAAAABL2+ls7EW5LHD/tEetd49d0JpmU7pXEjhH0pU1ZSp5qjvKxL8c8PZz6ODTf68+lfQtXkKaRlQH6hu7VTSU3fvhCmZovDB5ruKqJPn+MQRDBbS8Wkr/meVo9LBS+3NFOky+EY43ebFoFxTbVZl2lCjb0DuskJiZGuHOBJ1v2XpGdKCmh1c1LmMvpc+OPegzNuMCXoEzSN9DdRtKnDzRxvOnvPglCX9+oV89LWsmVzonRp1a+tluqa8Ron9pFdHI9cWBElcXpmwXbKbmP0Sy5yYbYpE+rYsNgD5sV/FwF8uOxGWA0/mRWLZlO3OcGWoYo7qBBDmCUApAcRmZR3tXqhELQ==")); var connection = new ConnectionBuilder() .WithLogging() .Build(); // "List Certificates" operation. connection.On <string, List <CertificateModel> >("list-certs", _ => { var store = WindowsCertificateStore.LoadPersonalCurrentUser(); return(store.GetCertificatesWithKey().Select(c => new CertificateModel(c.Certificate)).ToList()); }); // "Sign a PDF" operation. connection.On <SignatureRequestModel, string>("sign-pdf", request => { var signer = new PadesSigner(); var store = WindowsCertificateStore.LoadPersonalCurrentUser(); var signingCert = store.GetCertificatesWithKey().First(c => c.Certificate.ThumbprintSHA256.SequenceEqual(request.CertThumb)); signer.SetSigningCertificate(signingCert); signer.SetPdfToSign(request.FileToSign); var trustArbitrator = new LinkedTrustArbitrator(TrustArbitrators.PkiBrazil, TrustArbitrators.Windows); // For development purposes, we also trust in Lacuna Software's test certificates. var lacunaRoot = Lacuna.Pki.PKCertificate.Decode(Convert.FromBase64String("MIIGGTCCBAGgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBfMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDEdMBsGA1UECwwUTGFjdW5hIFNvZnR3YXJlIC0gTFMxHDAaBgNVBAMME0xhY3VuYSBSb290IFRlc3QgdjEwHhcNMTUwMTE2MTk1MjQ1WhcNMjUwMTE2MTk1MTU1WjBfMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDEdMBsGA1UECwwUTGFjdW5hIFNvZnR3YXJlIC0gTFMxHDAaBgNVBAMME0xhY3VuYSBSb290IFRlc3QgdjEwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCDm5ey0c4ij8xnDnV2EBATjJbZjteEh8BBiGtVx4dWpXbWQ6hEw8E28UyLsF6lCM2YjQge329g7hMANnrnrNCvH1ny4VbhHMe4eStiik/GMTzC79PYS6BNfsMsS6+W18a45eyi/2qTIHhJYN8xS4/7pAjrVpjL9dubALdiwr26I3a4S/h9vD2iKJ1giWnHU74ckVp6BiRXrz2ox5Ps7p420VbVU6dTy7QR2mrhAus5va9VeY1LjvCH9S9uSf6kt+HP1Kj7hlOOlcnluXmuD/IN68/CQeC+dLOr0xKmDvYv7GWluXhxpUZmh6NaLzSGzGNACobOezKmby06s4CvsmMKQuZrTx113+vJkYSgI2mBN5v8LH60DzuvIhMvDLWPZCwfnyGCNHBwBbdgzBWjsfuSFJyaKdJLmpu5OdWNOLjvexqEC9VG83biYr+8XMiWl8gUW8SFqEpNoLJ59nwsRf/R5R96XTnG3md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cmXzE/2SFV2cO3mJAtpaO99uwLvj3Y3quMBuIhDGD0ReDXNAniXXXVPfE96NUcDF2Dq2g8kj+EmxPy6PGZ15p1XZO1yiqsGEVreIXqgcU1tPUv8peNYb6jHTHuUyXGTzbsamGZFEDsLG7NRxg0eZWP1w=")); // COMMENT the line below before production release trustArbitrator.Add(new TrustedRoots(lacunaRoot)); signer.SetPolicy(PadesPoliciesForGeneration.GetPadesBasic(trustArbitrator)); signer.ComputeSignature(); byte[] signedPdf = signer.GetPadesSignature(); var tempLocation = Path.GetTempFileName(); File.WriteAllBytes(tempLocation, signedPdf); return(tempLocation); }); // Acknowledges that the connection is running. connection.On <string, string>("ping", argument => "pong"); // wait for incoming requests connection.Listen(); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { try { restPkiClient = Util.GetRestPkiClient(); PkiConfig.LoadLicense(Util.GetPkiSdkLicense()); } catch (Exception ex) { MessageBox.Show($"{ex.Message}\r\n\r\nSigner will close.", "Configuration Error"); addLog(ex.Message); //Application.Current.Shutdown(); } addLog($"RestPKI token found"); await listCertificatesWithKey(); checkBoxSafeSign.IsChecked = false; checkBoxSafeNet.IsChecked = false; }
public static int Main(string[] args) { var license = "======= Ask for a license at [email protected] ========="; if (license == "======= Ask for a license at [email protected] =========") { Console.WriteLine("License not set"); return(0); } PkiConfig.LoadLicense(Convert.FromBase64String(license)); return(CommandLine.Parser.Default.ParseArguments <ListOptions, SignOptions, ValidadeOptions>(args) .MapResult( (ListOptions opts) => RunListAndReturnExitCode(opts), (SignOptions opts) => RunSignAndReturnExitCode(opts), (ValidadeOptions opts) => RunValidateAndReturnExitCode(opts), errs => 1)); }
static void process(Options options) { PkiConfig.LoadLicense(Convert.FromBase64String(LicenseBase64)); var isTest = options.Test > 0; var testCount = options.Test; var documentsInputDir = options.SourceDir; var signedDocumentsOutputDir = options.DestinationDir; if (isTest) { Util.CheckTestDirectories(documentsInputDir, signedDocumentsOutputDir); DeleteFiles(documentsInputDir, signedDocumentsOutputDir); PdfGenerate(testCount, documentsInputDir); } else { if (!Directory.Exists(documentsInputDir) && string.IsNullOrWhiteSpace(options.File)) { Console.WriteLine($"Error! The directory was not found: {documentsInputDir}"); return; } if (!Directory.Exists(signedDocumentsOutputDir) && string.IsNullOrWhiteSpace(options.File)) { Directory.CreateDirectory(signedDocumentsOutputDir); } Console.WriteLine(); } // Signer certificate PKCertificateWithKey cert = null; var store = Pkcs11CertificateStore.Load("eTPKCS11.dll", new StaticLoginProvider(options.Pin)); if (string.IsNullOrEmpty(options.CertThumbprint)) { List <PKCertificateWithKey> certificates; Console.WriteLine(); Console.WriteLine("Listing Certificates..."); if (string.IsNullOrEmpty(options.Pin)) { certificates = WindowsCertificateStore.LoadPersonalCurrentUser().GetCertificatesWithKey(); } else { certificates = store.GetCertificatesWithKey(); } for (var i = 0; i < certificates.Count; i++) { Console.WriteLine($"[{i}] {certificates[i].Certificate.SubjectDisplayName} (Issued by {certificates[i].Certificate.IssuerDisplayName})"); } Console.WriteLine(); Console.Write("Select the signer certificate: "); var indexstring = Console.ReadLine(); if (!int.TryParse(indexstring, out var index)) { Console.WriteLine($"Error! Invalid index: {indexstring}"); return; } cert = certificates[index]; } else { var thumbprint = PkiUtil.DecodeHexString(options.CertThumbprint); if (string.IsNullOrEmpty(options.Pin)) { cert = WindowsCertificateStore.LoadPersonalCurrentUser().GetCertificatesWithKey().FirstOrDefault(c => c.Certificate.ThumbprintSHA1.SequenceEqual(thumbprint)); } else { cert = store.GetCertificatesWithKey().FirstOrDefault(c => c.Certificate.ThumbprintSHA1.SequenceEqual(thumbprint)); } if (cert == null) { Console.WriteLine($"Error! No certificate was found with thumbprint: {options.CertThumbprint}"); return; } } Console.WriteLine($"Signer: {cert.Certificate.SubjectDisplayName} (thumbprint: {Util.ToHex(cert.Certificate.ThumbprintSHA1)})"); Metadata metadata = null; if (!string.IsNullOrEmpty(options.Metadata) && Util.FileExists(options.Metadata)) { try { var metadataContent = File.ReadAllBytes(options.Metadata); var metadataJson = Encoding.UTF8.GetString(metadataContent); metadata = JsonConvert.DeserializeObject <MetadataModel>(metadataJson).ToEntity(); } catch (Exception ex) { Log(ex.ToString()); Console.WriteLine($"Error parsing metadata file: {ex}"); } } if (string.IsNullOrWhiteSpace(options.File)) { Console.WriteLine("Getting things ready."); Sign(cert, documentsInputDir, signedDocumentsOutputDir, options.Reprocess, options.VisualRep, metadata); } else { var visual = CreateVisualRepresentation(cert.Certificate, options.VisualRep, (metadata != null)); var policy = GetSignaturePolicy().GetPolicy(cert.Certificate); policy.SignerSpecs.AttributeGeneration.EnableLtv = false; if (!SignFile(options.File, cert, policy, visual, metadata, "", "Signed_" + options.File)) { Console.WriteLine($"Error signing file"); return; } else { Console.WriteLine($"File successfully signed."); } } store.Dispose(); }