public ResultsForm(BIO.Framework.Core.Evaluation.Results.Results r /*, BIO.Framework.Core.Database.Database<BIO.Framework.Core.Database.Record> d*/) { InitializeComponent(); List<string> methods = r.Methods; List<SingleBiometricAlgorithmDataVisualizer> allMethods = new List<SingleBiometricAlgorithmDataVisualizer>(); foreach (string m in methods) { TabPage page = new TabPage(m); ResultsViewer v = new ResultsViewer(); v.Dock = DockStyle.Fill; v.init(m, r/*, d*/); page.Controls.Add(v); tabControlMethods.TabPages.Add(page); allMethods.Add(v.evaluatorGenuineImpostorResultGraph1); } evaluatorsDETGraph1.init(allMethods, r); evaluatorsROCGraph1.init(allMethods, r); //this.resultsViewer1.init(method_, r, d); //ResultsViewerOLD v = new ResultsViewerOLD(); //v.init(method_, r, d); //this.Controls.Add(v); }
public virtual void init(string method_, BIO.Framework.Core.Evaluation.Results.Statistics statistics_, BIO.Framework.Core.Evaluation.Results.Results results_) { this.method = method_; this.statistics = statistics_; this.results = results_; this.specificInit(); }
public void init(List<SingleBiometricAlgorithmDataVisualizer> allMethods_, BIO.Framework.Core.Evaluation.Results.Results r_) { this.results = r_; this.allMethods = new List<Method>(); foreach (SingleBiometricAlgorithmDataVisualizer eg in allMethods_) { Method e = new Method(); e.method = eg.getMethod(); e.statistics = eg.getStatistics(); this.allMethods.Add(e); } this.initComponents(); }
public void init(string method_, BIO.Framework.Core.Evaluation.Results.Results r/*, BIO.Framework.Core.Database.Database<BIO.Framework.Core.Database.Record> d*/) { this.results = r; this.method = method_; //this.evaluationStatisticsControl1 statistics = new BIO.Framework.Core.Evaluation.Results.Statistics(method, results); statistics.autocomputeThresh(); this.evaluationStatisticsControl1.init(this.method, this.statistics, this.results); this.evaluationStatisticsControl1.setAsNeeded(); this.evaluatorGenuineImpostorResultGraph1.init(this.method, this.statistics, this.results); this.evaluatorGenuineImpostorResultGraph1.setAsNeeded(); this.evaluatorDetailResultGraph1.init(this.method, this.statistics, this.results); this.evaluatorDetailResultGraph1.setAsNeeded(); }
/// <summary> /// Support exporting certificates to <see cref="EncodingFormat.PEM">PEM</see> /// and <see cref="EncodingFormat.DER">DER</see> formats. /// </summary> public override void ExportCertificate(Crt cert, EncodingFormat fmt, Stream target) { if (fmt == EncodingFormat.PEM) { var bytes = Encoding.UTF8.GetBytes(cert.Pem); target.Write(bytes, 0, bytes.Length); } else if (fmt == EncodingFormat.DER) { using (BIO bioPem = BIO.MemoryBuffer()) { bioPem.Write(cert.Pem); using (var x509 = new X509Certificate(bioPem)) { var bytes = x509.DER; target.Write(bytes, 0, bytes.Length); } } } else { throw new NotSupportedException("unsupported encoding format"); } }
/// <summary> /// Support exporting CSR to <see cref="EncodingFormat.PEM">PEM</see> /// and <see cref="EncodingFormat.DER">DER</see> formats. /// </summary> public override void ExportCsr(Csr csr, EncodingFormat fmt, Stream target) { if (fmt == EncodingFormat.PEM) { var bytes = Encoding.UTF8.GetBytes(csr.Pem); target.Write(bytes, 0, bytes.Length); } else if (fmt == EncodingFormat.DER) { using (var xr = new X509Request(csr.Pem)) { using (var bio = BIO.MemoryBuffer()) { xr.Write_DER(bio); var arr = bio.ReadBytes((int)bio.BytesPending); target.Write(arr.Array, arr.Offset, arr.Count); } } } else { throw new NotSupportedException("encoding format has not been implemented"); } }
protected override int Write(BIO bio, ReadOnlySpan <byte> input) { var data = BIO_get_data(bio); if (!(data.Target is IPipeWriter clientPipe)) { return(-1); } var inputLength = input.Length; var writer = clientPipe.Alloc(); while (input.Length > 0) { var size = Math.Min(MaxSize, input.Length); writer.Ensure(size); input.Slice(0, size).CopyTo(writer.Buffer.Span); input = input.Slice(size); writer.Advance(size); } writer.Commit(); return(inputLength); }
/// <summary> /// Calls PEM_write_bio_X509() /// </summary> /// <param name="bio"></param> public void Write(BIO bio) { Native.ExpectSuccess(Native.PEM_write_bio_X509(bio.Handle, this.ptr)); }
/// <summary> /// Prints the LongName of this cipher. /// </summary> /// <param name="bio"></param> public override void Print(BIO bio) { bio.Write(LongName); }
/// <summary> /// Calls PEM_write_bio_DSA_PUBKEY() /// </summary> /// <param name="bio"></param> public void WritePublicKey(BIO bio) { Native.ExpectSuccess(Native.PEM_write_bio_DSA_PUBKEY(bio.Handle, ptr)); }
/// <summary> /// Calls PEM_read_bio_RSAPrivateKey() /// </summary> /// <param name="bio"></param> /// <returns></returns> public static RSA FromPrivateKey(BIO bio) { return(FromPrivateKey(bio, null, null)); }
protected override int Destroy(BIO bio) => 1;
/// <summary> /// Calls X509V3_EXT_print() /// </summary> /// <param name="bio"></param> public override void Print(BIO bio) { Native.X509V3_EXT_print(bio.Handle, this.ptr, 0, 0); }
/// <summary> /// Calls i2d_X509_bio() /// </summary> /// <param name="bio"></param> public void Write_DER(BIO bio) { Native.ExpectSuccess(Native.i2d_X509_bio(bio.Handle, this.ptr)); }
//BIO.Framework.Core.Database.IRecordEnumerable db = null; /*public DatabaseOverview(BIO.Framework.Core.Database.IRecordEnumerable db) { this.db = db; }*/ public static void showGlobalOverview(BIO.Framework.Core.Database.IRecordEnumerable dbIterator) { System.Console.WriteLine("Database size: " + dbIterator.getIRecords().Count().ToString()); System.Console.WriteLine("Unique biometrics count: " + dbIterator.getBiometricIDs().Count().ToString()); }
/// <summary> /// Calls PEM_read_bio_X509() /// </summary> /// <param name="bio"></param> public X509Certificate(BIO bio) : base(Native.ExpectNonNull(Native.PEM_read_bio_X509(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)), true) { }
private X509Certificate LoadPKCS12Certificate(string certFilename, string password) { using (BIO certFile = BIO.File(certFilename, "r")) { return(X509Certificate.FromPKCS12(certFile, password)); } }
public ROCData(BIO.Framework.Core.Evaluation.Results.Statistics s) { stats = s.createCopy(); }
private Csr GenerateCsr(CsrDetails csrDetails, RsaPrivateKey rsaKeyPair, string messageDigest = "SHA256") { var rsaKeys = CryptoKey.FromPrivateKey(rsaKeyPair.Pem, null); // Translate from our external form to our OpenSSL internal form // Ref: https://www.openssl.org/docs/manmaster/crypto/X509_NAME_new.html var xn = new X509Name(); if (!string.IsNullOrEmpty(csrDetails.CommonName /**/)) { xn.Common = csrDetails.CommonName; // CN; } if (!string.IsNullOrEmpty(csrDetails.Country /**/)) { xn.Country = csrDetails.Country; // C; } if (!string.IsNullOrEmpty(csrDetails.StateOrProvince /**/)) { xn.StateOrProvince = csrDetails.StateOrProvince; // ST; } if (!string.IsNullOrEmpty(csrDetails.Locality /**/)) { xn.Locality = csrDetails.Locality; // L; } if (!string.IsNullOrEmpty(csrDetails.Organization /**/)) { xn.Organization = csrDetails.Organization; // O; } if (!string.IsNullOrEmpty(csrDetails.OrganizationUnit /**/)) { xn.OrganizationUnit = csrDetails.OrganizationUnit; // OU; } if (!string.IsNullOrEmpty(csrDetails.Description /**/)) { xn.Description = csrDetails.Description; // D; } if (!string.IsNullOrEmpty(csrDetails.Surname /**/)) { xn.Surname = csrDetails.Surname; // S; } if (!string.IsNullOrEmpty(csrDetails.GivenName /**/)) { xn.Given = csrDetails.GivenName; // G; } if (!string.IsNullOrEmpty(csrDetails.Initials /**/)) { xn.Initials = csrDetails.Initials; // I; } if (!string.IsNullOrEmpty(csrDetails.Title /**/)) { xn.Title = csrDetails.Title; // T; } if (!string.IsNullOrEmpty(csrDetails.SerialNumber /**/)) { xn.SerialNumber = csrDetails.SerialNumber; // SN; } if (!string.IsNullOrEmpty(csrDetails.UniqueIdentifier /**/)) { xn.UniqueIdentifier = csrDetails.UniqueIdentifier; // UID; } var xr = new X509Request(0, xn, rsaKeys); var md = MessageDigest.CreateByName(messageDigest); xr.Sign(rsaKeys, md); using (var bio = BIO.MemoryBuffer()) { xr.Write(bio); return(new Csr(bio.ReadString())); } }
/// <summary> /// Calls d2i_PKCS7_bio() /// </summary> /// <param name="bio"></param> /// <returns></returns> public static PKCS7 FromDER(BIO bio) { return(new PKCS7(Native.ExpectNonNull(Native.d2i_PKCS7_bio(bio.Handle, IntPtr.Zero)))); }
protected override int Create(BIO bio) => 1;
/// <summary> /// Calls PEM_read_bio_PKCS7() /// </summary> /// <param name="bio"></param> /// <returns></returns> public static PKCS7 FromPEM(BIO bio) { return(new PKCS7(Native.ExpectNonNull(Native.PEM_read_bio_PKCS7(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)))); }
protected override int Read(BIO bio, Span <byte> output) { ref var data = ref BIO_get_data <ReadableBuffer>(bio);
private unsafe static extern IntPtr Internal_BIO_get_data(BIO a);
/// <summary> /// Returns PEM_read_bio_DSAPrivateKey() /// </summary> /// <param name="bio"></param> /// <returns></returns> public static DSA FromPrivateKey(BIO bio) { return(new DSA(Native.ExpectNonNull(Native.PEM_read_bio_DSAPrivateKey(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)), true)); }
/// <summary> /// Calls PEM_read_bio_X509_REQ() /// </summary> /// <param name="bio"></param> public X509Request(BIO bio) : base(Native.ExpectNonNull(Native.PEM_read_bio_X509_REQ(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)), true) { }
/// <summary> /// Calls DSA_print() /// </summary> /// <param name="bio"></param> public override void Print(BIO bio) { Native.ExpectSuccess(Native.DSA_print(bio.Handle, ptr, 0)); }
internal static extern void BIO_set_init(BIO a, int ptr);
/// <summary> /// Returns the cipher's LongName /// </summary> /// <param name="bio"></param> public override void Print(BIO bio) { bio.Write("CipherContext: " + cipher.LongName); }
/// <summary> /// Calls PEM_read_bio_PrivateKey() /// </summary> /// <param name="bio"></param> /// <param name="passwd"></param> /// <returns></returns> public static CryptoKey FromPrivateKey(BIO bio, string passwd) { PasswordCallback callback = new PasswordCallback(passwd); return(FromPrivateKey(bio, callback.OnPassword, null)); }
/// <summary> /// Calls X509_print() /// </summary> /// <param name="bio"></param> public override void Print(BIO bio) { Native.ExpectSuccess(Native.X509_print(bio.Handle, this.ptr)); }
/// <summary> /// Calls PEM_write_bio_PKCS8PrivateKey /// </summary> /// <param name="bp"></param> /// <param name="cipher"></param> /// <param name="password"></param> public void WritePrivateKey(BIO bp, Cipher cipher, string password) { PasswordCallback callback = new PasswordCallback(password); WritePrivateKey(bp, cipher, callback.OnPassword, null); }
public static extern void SSL_set0_wbio(SSL ssl, BIO wbio);
/// <summary> /// Calls PEM_write_bio_PKCS8PrivateKey /// </summary> /// <param name="bp"></param> /// <param name="cipher"></param> /// <param name="handler"></param> /// <param name="arg"></param> public void WritePrivateKey(BIO bp, Cipher cipher, PasswordHandler handler, object arg) { PasswordThunk thunk = new PasswordThunk(handler, null); Native.ExpectSuccess(Native.PEM_write_bio_PKCS8PrivateKey(bp.Handle, this.ptr, cipher.Handle, IntPtr.Zero, 0, thunk.Callback, IntPtr.Zero)); }
private X509Chain LoadCACertificateChain(string caFilename) { using (BIO bio = BIO.File(caFilename, "r")) { return(new X509Chain(bio)); } }
public override PrivateKey GeneratePrivateKey(PrivateKeyParams pkp) { var rsaPkParams = pkp as RsaPrivateKeyParams; var ecPkParams = pkp as EcPrivateKeyParams; if (rsaPkParams != null) { int bits = RSA_BITS_DEFAULT; BigNumber e; if (string.IsNullOrEmpty(rsaPkParams.PubExp)) { e = RSA_E_F4; } else if (rsaPkParams.PubExp.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) { e = BigNumber.FromHexString(rsaPkParams.PubExp); } else { e = BigNumber.FromDecimalString(rsaPkParams.PubExp); } using (var rsa = new RSA()) { BigNumber.GeneratorHandler cbWrapper = null; if (rsaPkParams.Callback != null) { cbWrapper = (x, y, z) => rsaPkParams.Callback(x, y, z); } Cipher enc = null; string pwd = null; PasswordHandler pwdCb = null; // If we choose to encrypt: // Cipher.DES_CBC; // Cipher.DES_EDE3_CBC; // Cipher.Idea_CBC; // Cipher.AES_128_CBC; // Cipher.AES_192_CBC; // Cipher.AES_256_CBC; // and pwd != null || pwdCb != null // We can use a pwdCb to get a password interactively or we can // simply pass in a fixed password string (no cbPwd, just pwd) if (pwd != null) { pwdCb = DefaultPasswordHandler; } // Ref: http://openssl.org/docs/manmaster/crypto/RSA_generate_key_ex.html rsa.GenerateKeys(bits, e, cbWrapper, rsaPkParams.CallbackArg); using (var bio = BIO.MemoryBuffer()) { // Ref: http://openssl.org/docs/manmaster/crypto/PEM_write_bio_RSAPrivateKey.html rsa.WritePrivateKey(bio, enc, pwdCb, pwd); return(new RsaPrivateKey(bits, e.ToHexString(), bio.ReadString())); } } } else if (ecPkParams != null) { throw new NotImplementedException("EC private keys have not yet been implemented"); //var curveName = Asn1Object.FromShortName("P-256"); ////var curveName = new Asn1Object("P-256"); //using (var ec =OpenSSL.Crypto.EC.Key.FromCurveName(curveName)) //{ // ec.GenerateKey(); //} } else { throw new NotSupportedException("unsupported private key parameter type"); } }