/// <summary> /// Gets the column names for the specified fields. /// </summary> /// <remarks> /// Gets the column names for the specified fields. /// </remarks> /// <returns>The column names.</returns> /// <param name="fields">The fields.</param> protected static string[] GetColumnNames(X509CrlRecordFields fields) { var columns = new List <string> (); if ((fields & X509CrlRecordFields.Id) != 0) { columns.Add("ID"); } if ((fields & X509CrlRecordFields.IsDelta) != 0) { columns.Add("DELTA"); } if ((fields & X509CrlRecordFields.IssuerName) != 0) { columns.Add("ISSUERNAME"); } if ((fields & X509CrlRecordFields.ThisUpdate) != 0) { columns.Add("THISUPDATE"); } if ((fields & X509CrlRecordFields.NextUpdate) != 0) { columns.Add("NEXTUPDATE"); } if ((fields & X509CrlRecordFields.Crl) != 0) { columns.Add("CRL"); } return(columns.ToArray()); }
/// <summary> /// Finds the CRL records for the specified issuer. /// </summary> /// <remarks> /// Searches the database for CRL records matching the specified issuer, returning /// all matching records populated with the desired fields. /// </remarks> /// <returns>The matching CRL records populated with the desired fields.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The desired fields.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="issuer"/> is <c>null</c>. /// </exception> public IEnumerable <X509CrlRecord> Find(X509Name issuer, X509CrlRecordFields fields) { if (issuer == null) { throw new ArgumentNullException(nameof(issuer)); } using (var command = GetSelectCommand(issuer, fields)) { var reader = command.ExecuteReader(); try { var parser = new X509CrlParser(); var buffer = new byte[4096]; while (reader.Read()) { yield return(LoadCrlRecord(reader, parser, ref buffer)); } } finally { #if NETSTANDARD reader.Dispose(); #else reader.Close(); #endif } } yield break; }
/// <summary> /// Finds the specified certificate revocation list. /// </summary> /// <remarks> /// Searches the database for the specified CRL, returning the matching record with /// the desired fields populated. /// </remarks> /// <returns>The matching record if found; otherwise <c>null</c>.</returns> /// <param name="crl">The certificate revocation list.</param> /// <param name="fields">The desired fields.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="crl"/> is <c>null</c>. /// </exception> public X509CrlRecord Find(X509Crl crl, X509CrlRecordFields fields) { if (crl == null) { throw new ArgumentNullException(nameof(crl)); } using (var command = GetSelectCommand(crl, fields)) { var reader = command.ExecuteReader(); try { if (reader.Read()) { var parser = new X509CrlParser(); var buffer = new byte[4096]; return(LoadCrlRecord(reader, parser, ref buffer)); } } finally { #if NETSTANDARD reader.Dispose(); #else reader.Close(); #endif } } return(null); }
/// <summary> /// Gets the database command to select the CRL records matching the specified issuer. /// </summary> /// <remarks> /// Gets the database command to select the CRL records matching the specified issuer. /// </remarks> /// <returns>The database command.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The fields to return.</param> protected override DbCommand GetSelectCommand(X509Name issuer, X509CrlRecordFields fields) { var query = "SELECT " + string.Join(", ", GetColumnNames(fields)) + " FROM CRLS "; var command = connection.CreateCommand(); command.CommandText = query + "WHERE ISSUERNAME = @ISSUERNAME"; command.AddParameterWithValue("@ISSUERNAME", issuer.ToString()); command.CommandType = CommandType.Text; return(command); }
/// <summary> /// Gets the database command to select the record for the specified CRL. /// </summary> /// <remarks> /// Gets the database command to select the record for the specified CRL. /// </remarks> /// <returns>The database command.</returns> /// <param name="crl">The X.509 CRL.</param> /// <param name="fields">The fields to return.</param> protected override DbCommand GetSelectCommand(X509Crl crl, X509CrlRecordFields fields) { var query = "SELECT " + string.Join(", ", GetColumnNames(fields)) + " FROM CRLS "; var issuerName = crl.IssuerDN.ToString(); var command = connection.CreateCommand(); command.CommandText = query + "WHERE DELTA = @DELTA AND ISSUERNAME = @ISSUERNAME AND THISUPDATE = @THISUPDATE LIMIT 1"; command.AddParameterWithValue("@DELTA", crl.IsDelta()); command.AddParameterWithValue("@ISSUERNAME", issuerName); command.AddParameterWithValue("@THISUPDATE", crl.ThisUpdate.ToUniversalTime()); command.CommandType = CommandType.Text; return(command); }
/// <summary> /// Imports a certificate revocation list. /// </summary> /// <remarks> /// Imports the specified certificate revocation list. /// </remarks> /// <param name="crl">The certificate revocation list.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="crl"/> is <c>null</c>. /// </exception> public override void Import(X509Crl crl) { if (crl == null) { throw new ArgumentNullException(nameof(crl)); } // check for an exact match... if (dbase.Find(crl, X509CrlRecordFields.Id) != null) { return; } const X509CrlRecordFields fields = ~X509CrlRecordFields.Crl; var obsolete = new List <X509CrlRecord> (); var delta = crl.IsDelta(); // scan over our list of CRLs by the same issuer to check if this CRL obsoletes any // older CRLs or if there are any newer CRLs that obsolete that obsolete this one. foreach (var record in dbase.Find(crl.IssuerDN, fields)) { if (!record.IsDelta && record.ThisUpdate >= crl.ThisUpdate) { // we have a complete CRL that obsoletes this CRL return; } if (!delta) { obsolete.Add(record); } } // remove any obsoleted CRLs foreach (var record in obsolete) { dbase.Remove(record); } dbase.Add(new X509CrlRecord(crl)); }
/// <summary> /// Finds the specified certificate revocation list. /// </summary> /// <remarks> /// Searches the database for the specified CRL, returning the matching record with /// the desired fields populated. /// </remarks> /// <returns>The matching record if found; otherwise <c>null</c>.</returns> /// <param name="crl">The certificate revocation list.</param> /// <param name="fields">The desired fields.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="crl"/> is <c>null</c>. /// </exception> public X509CrlRecord Find(X509Crl crl, X509CrlRecordFields fields) { if (crl == null) { throw new ArgumentNullException(nameof(crl)); } using (var command = GetSelectCommand(crl, fields)) { using (var reader = command.ExecuteReader()) { if (reader.Read()) { var parser = new X509CrlParser(); var buffer = new byte[4096]; return(LoadCrlRecord(reader, parser, ref buffer)); } } } return(null); }
/// <summary> /// Gets the database command to select the record for the specified CRL. /// </summary> /// <remarks> /// Gets the database command to select the record for the specified CRL. /// </remarks> /// <returns>The database command.</returns> /// <param name="crl">The X.509 CRL.</param> /// <param name="fields">The fields to return.</param> protected abstract DbCommand GetSelectCommand(X509Crl crl, X509CrlRecordFields fields);
/// <summary> /// Gets the database command to select the CRL records matching the specified issuer. /// </summary> /// <remarks> /// Gets the database command to select the CRL records matching the specified issuer. /// </remarks> /// <returns>The database command.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The fields to return.</param> protected abstract DbCommand GetSelectCommand(X509Name issuer, X509CrlRecordFields fields);
public X509CrlRecord Find(X509Crl crl, X509CrlRecordFields fields) { throw new NotImplementedException(); }
/// <summary> /// Finds the CRL records for the specified issuer. /// </summary> /// <remarks> /// Searches the database for CRL records matching the specified issuer, returning /// all matching records populated with the desired fields. /// </remarks> /// <returns>The matching CRL records populated with the desired fields.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The desired fields.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="issuer"/> is <c>null</c>. /// </exception> public IEnumerable<X509CrlRecord> Find (X509Name issuer, X509CrlRecordFields fields) { if (issuer == null) throw new ArgumentNullException ("issuer"); using (var command = GetSelectCommand (issuer, fields)) { var reader = command.ExecuteReader (); try { var parser = new X509CrlParser (); var buffer = new byte[4096]; while (reader.Read ()) { yield return LoadCrlRecord (reader, parser, ref buffer); } } finally { reader.Close (); } } yield break; }
/// <summary> /// Gets the database command to select the record for the specified CRL. /// </summary> /// <remarks> /// Gets the database command to select the record for the specified CRL. /// </remarks> /// <returns>The database command.</returns> /// <param name="crl">The X.509 CRL.</param> /// <param name="fields">The fields to return.</param> protected abstract IDbCommand GetSelectCommand (X509Crl crl, X509CrlRecordFields fields);
/// <summary> /// Gets the database command to select the CRL records matching the specified issuer. /// </summary> /// <remarks> /// Gets the database command to select the CRL records matching the specified issuer. /// </remarks> /// <returns>The database command.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The fields to return.</param> protected abstract IDbCommand GetSelectCommand (X509Name issuer, X509CrlRecordFields fields);
/// <summary> /// Gets the column names for the specified fields. /// </summary> /// <remarks> /// Gets the column names for the specified fields. /// </remarks> /// <returns>The column names.</returns> /// <param name="fields">The fields.</param> protected static string[] GetColumnNames (X509CrlRecordFields fields) { const X509CrlRecordFields all = X509CrlRecordFields.Id | X509CrlRecordFields.IsDelta | X509CrlRecordFields.IssuerName | X509CrlRecordFields.ThisUpdate | X509CrlRecordFields.NextUpdate | X509CrlRecordFields.Crl; if (fields == all) return new [] { "*" }; var columns = new List<string> (); if ((fields & X509CrlRecordFields.Id) != 0) columns.Add ("ID"); if ((fields & X509CrlRecordFields.IsDelta) != 0) columns.Add ("DELTA"); if ((fields & X509CrlRecordFields.IssuerName) != 0) columns.Add ("ISSUERNAME"); if ((fields & X509CrlRecordFields.ThisUpdate) != 0) columns.Add ("THISUPDATE"); if ((fields & X509CrlRecordFields.NextUpdate) != 0) columns.Add ("NEXTUPDATE"); if ((fields & X509CrlRecordFields.Crl) != 0) columns.Add ("CRL"); return columns.ToArray (); }
/// <summary> /// Gets the database command to select the record for the specified CRL. /// </summary> /// <remarks> /// Gets the database command to select the record for the specified CRL. /// </remarks> /// <returns>The database command.</returns> /// <param name="crl">The X.509 CRL.</param> /// <param name="fields">The fields to return.</param> protected override DbCommand GetSelectCommand (X509Crl crl, X509CrlRecordFields fields) { var query = "SELECT " + string.Join (", ", GetColumnNames (fields)) + " FROM CRLS "; var issuerName = crl.IssuerDN.ToString (); var command = connection.CreateCommand (); command.CommandText = query + "WHERE DELTA = @DELTA AND ISSUERNAME = @ISSUERNAME AND THISUPDATE = @THISUPDATE LIMIT 1"; command.AddParameterWithValue ("@DELTA", crl.IsDelta ()); command.AddParameterWithValue ("@ISSUERNAME", issuerName); command.AddParameterWithValue ("@THISUPDATE", crl.ThisUpdate); command.CommandType = CommandType.Text; return command; }
/// <summary> /// Gets the database command to select the CRL records matching the specified issuer. /// </summary> /// <remarks> /// Gets the database command to select the CRL records matching the specified issuer. /// </remarks> /// <returns>The database command.</returns> /// <param name="issuer">The issuer.</param> /// <param name="fields">The fields to return.</param> protected override DbCommand GetSelectCommand (X509Name issuer, X509CrlRecordFields fields) { var query = "SELECT " + string.Join (", ", GetColumnNames (fields)) + " FROM CRLS "; var command = connection.CreateCommand (); command.CommandText = query + "WHERE ISSUERNAME = @ISSUERNAME"; command.AddParameterWithValue ("@ISSUERNAME", issuer.ToString ()); command.CommandType = CommandType.Text; return command; }
/// <summary> /// Finds the specified certificate revocation list. /// </summary> /// <remarks> /// Searches the database for the specified CRL, returning the matching record with /// the desired fields populated. /// </remarks> /// <returns>The matching record if found; otherwise <c>null</c>.</returns> /// <param name="crl">The certificate revocation list.</param> /// <param name="fields">The desired fields.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="crl"/> is <c>null</c>. /// </exception> public X509CrlRecord Find (X509Crl crl, X509CrlRecordFields fields) { if (crl == null) throw new ArgumentNullException ("crl"); using (var command = GetSelectCommand (crl, fields)) { var reader = command.ExecuteReader (); try { if (reader.Read ()) { var parser = new X509CrlParser (); var buffer = new byte[4096]; return LoadCrlRecord (reader, parser, ref buffer); } } finally { reader.Close (); } } return null; }
public IEnumerable <X509CrlRecord> Find(X509Name issuer, X509CrlRecordFields fields) { throw new NotImplementedException(); }