Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft for managed ADCS database query stuff
- Loading branch information
Showing
13 changed files
with
739 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,3 +235,4 @@ _Pvt_Extensions | |
# FAKE - F# Make | ||
.fake/ | ||
/PKI.Test | ||
*.DotSettings |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
PKI/Management/CertificateServices/Database/AdcsDbColumnDataType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace SysadminsLV.PKI.Management.CertificateServices.Database { | ||
/// <summary> | ||
/// Contains possible datatypes to store the data in Certification Authority's database. | ||
/// </summary> | ||
public enum AdcsDbColumnDataType { | ||
/// <summary> | ||
/// Signed long data. | ||
/// </summary> | ||
Long = 1, | ||
/// <summary> | ||
/// Date/time. | ||
/// </summary> | ||
DateTime = 2, | ||
/// <summary> | ||
/// Binary data. | ||
/// </summary> | ||
Binary = 3, | ||
/// <summary> | ||
/// Unicode string data. | ||
/// </summary> | ||
String = 4 | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
PKI/Management/CertificateServices/Database/AdcsDbInternalEnumerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography; | ||
using CERTADMINLib; | ||
using PKI.Structs; | ||
using PKI.Utils; | ||
|
||
namespace SysadminsLV.PKI.Management.CertificateServices.Database { | ||
class AdcsDbInternalEnumerator : IDisposable { | ||
readonly String _configString; | ||
readonly AdcsDbTableName _table; | ||
readonly IEnumCERTVIEWROW _dbRow; | ||
|
||
public AdcsDbInternalEnumerator(IEnumCERTVIEWROW dbRow, String configString, AdcsDbTableName table) { | ||
_configString = configString; | ||
_table = table; | ||
_dbRow = dbRow; | ||
} | ||
|
||
public String ConfigString { get; set; } | ||
public AdcsDbViewTableName Table { get; set; } | ||
|
||
|
||
static void enumColumnView(IEnumCERTVIEWROW dbRow, AdcsDbRow row) { | ||
var dbColumn = dbRow.EnumCertViewColumn(); | ||
while (dbColumn.Next() != -1) { | ||
String colName = dbColumn.GetName(); | ||
Object colVal = dbColumn.GetValue(CertAdmConstants.CV_OUT_BASE64); | ||
switch (colName) { | ||
case "RequestID": | ||
case "ExtensionRequestId": | ||
case "AttributeRequestId": | ||
case "CRLRowId": | ||
row.RowId = (Int32)colVal; | ||
break; | ||
} | ||
row.Properties.Add(colName, colVal); | ||
} | ||
CryptographyUtils.ReleaseCom(dbColumn); | ||
} | ||
static void postProcessRow(AdcsDbRow row) { | ||
if (row.Properties.ContainsKey("CertificateTemplate")) { | ||
row.Properties.Add("CertificateTemplateOid", new Oid((String)row.Properties["CertificateTemplate"])); | ||
} | ||
if (row.Properties.ContainsKey("ExtensionName")) { | ||
row.Properties.Add("ExtensionNameOid", new Oid((String)row.Properties["ExtensionName"])); | ||
} | ||
} | ||
|
||
public IEnumerable<AdcsDbRow> EnumRows(Int32 skipRows, Int32 takeRows) { | ||
Int32 rowsTaken = 0; | ||
_dbRow.Skip(skipRows); | ||
while (_dbRow.Next() != -1 && rowsTaken < takeRows) { | ||
rowsTaken++; | ||
var row = new AdcsDbRow { | ||
ConfigString = _configString, | ||
Table = _table | ||
}; | ||
enumColumnView(_dbRow, row); | ||
postProcessRow(row); | ||
yield return row; | ||
} | ||
} | ||
void ReleaseUnmanagedResources() { | ||
CryptographyUtils.ReleaseCom(_dbRow); | ||
} | ||
/// <inheritdoc /> | ||
public void Dispose() { | ||
ReleaseUnmanagedResources(); | ||
GC.SuppressFinalize(this); | ||
} | ||
/// <inheritdoc /> | ||
~AdcsDbInternalEnumerator() { | ||
ReleaseUnmanagedResources(); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
PKI/Management/CertificateServices/Database/AdcsDbQueryFilterEntry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
|
||
namespace SysadminsLV.PKI.Management.CertificateServices.Database { | ||
/// <summary> | ||
/// A valid column index number for the view or a predefined column specifier | ||
/// </summary> | ||
public class AdcsDbQueryFilterEntry { | ||
|
||
public AdcsDbQueryFilterEntry(String columnName, AdcsDbSeekOperator op, Object value) { | ||
if (String.IsNullOrEmpty(columnName)) { | ||
throw new ArgumentNullException(nameof(columnName)); | ||
} | ||
|
||
ColumnName = columnName; | ||
LogicalOperator = op; | ||
QualifierValue = value ?? throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
internal Int32 ColumnID { get; set; } | ||
/// <summary> | ||
/// A valid column name for the view or a predefined column specifier. | ||
/// </summary> | ||
public String ColumnName { get; } | ||
/// <summary> | ||
/// Specifies the logical operator of the data-query qualifier for the column. This parameter | ||
/// is used with the <see cref="QualifierValue"/> property to define the data-query qualifier. | ||
/// </summary> | ||
public AdcsDbSeekOperator LogicalOperator { get; } | ||
/// <summary> | ||
/// Specifies the data query qualifier applied to this column. This parameter, along with the | ||
/// <see cref="LogicalOperator"/> parameter, determines which data is returned to the Certificate Services view. | ||
/// </summary> | ||
public Object QualifierValue { get; } | ||
|
||
/// <inheritdoc /> | ||
public override Boolean Equals(Object obj) { | ||
return !(obj is null) | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is AdcsDbQueryFilterEntry other && Equals(other)); | ||
} | ||
protected Boolean Equals(AdcsDbQueryFilterEntry other) { | ||
return String.Equals(ColumnName, other.ColumnName, StringComparison.OrdinalIgnoreCase) | ||
&& LogicalOperator == other.LogicalOperator | ||
&& Equals(QualifierValue, other.QualifierValue); | ||
} | ||
/// <inheritdoc /> | ||
public override Int32 GetHashCode() { | ||
unchecked { | ||
Int32 hashCode = ColumnName != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(ColumnName) : 0; | ||
hashCode = (hashCode * 397) ^ (Int32) LogicalOperator; | ||
hashCode = (hashCode * 397) ^ (QualifierValue != null ? QualifierValue.GetHashCode() : 0); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.