-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sign certificate functionality of PKI secret engine. #192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,17 @@ public async Task<Secret<CertificateCredentials>> GetCredentialsAsync(string pki | |
|
||
return result; | ||
} | ||
|
||
public async Task<Secret<SignedCertificateData>> SignCertificateAsync(string pkiRoleName, SignCertificatesRequestOptions signCertificatesRequestOptions, string pkiBackendMountPoint = null, string wrapTimeToLive = null) | ||
{ | ||
Checker.NotNull(pkiRoleName, "pkiRoleName"); | ||
Checker.NotNull(signCertificatesRequestOptions, "signCertificatesRequestOptions"); | ||
|
||
var result = await _polymath.MakeVaultApiRequest<Secret<SignedCertificateData>>(pkiBackendMountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.PKI, "/sign/" + pkiRoleName, HttpMethod.Post, signCertificatesRequestOptions, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext); | ||
result.Data.CertificateFormat = signCertificatesRequestOptions.CertificateFormat; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property is not marked with JsonIgnore... Either we should let json set it, or if we are explicitly setting it, it should be marked with json-ignore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CertificateFormat property is marked as JsonIgnore in AbstractCertificateData class. Or maybe I am referring to wrong property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it. i was looking at the request poco by mistake. |
||
|
||
return result; | ||
} | ||
|
||
public async Task<Secret<RevokeCertificateResponse>> RevokeCertificateAsync(string serialNumber, string pkiBackendMountPoint = null) | ||
{ | ||
|
@@ -54,5 +65,6 @@ public async Task<RawCertificateData> ReadCACertificateAsync(CertificateFormat c | |
EncodedCertificateFormat = outputFormat | ||
}; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace VaultSharp.V1.SecretsEngines.PKI | ||
{ | ||
/// <summary> | ||
/// Represents the Sign Certificate request options. | ||
/// </summary> | ||
public class SignCertificatesRequestOptions | ||
{ | ||
/// <summary> | ||
/// <para>[required]</para> | ||
/// Specifies the PEM-encoded CSR | ||
/// </summary> | ||
/// <value> | ||
/// Encoded CSR. | ||
/// </value> | ||
[JsonProperty("csr")] | ||
public string Csr { get; set; } | ||
|
||
/// <summary> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this. redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you right. Removed Abstract class and created separate classes for both endpoints so this one is fixed too. |
||
/// <para>[required]</para> | ||
/// Gets or sets the requested CN for the certificate. | ||
/// If the CN is allowed by role policy, it will be issued. | ||
/// </summary> | ||
/// <value> | ||
/// The name of the common. | ||
/// </value> | ||
[JsonProperty("common_name")] | ||
public string CommonName { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the requested Subject Alternative Names, in a comma-delimited list. | ||
/// These can be host names or email addresses; they will be parsed into their respective fields. | ||
/// If any requested names do not match role policy, the entire request will be denied. | ||
/// </summary> | ||
/// <value> | ||
/// The subject alternative names. | ||
/// </value> | ||
[JsonProperty("alt_names")] | ||
public string SubjectAlternativeNames { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the requested IP Subject Alternative Names, in a comma-delimited list. | ||
/// Only valid if the role allows IP SANs (which is the default). | ||
/// </summary> | ||
/// <value> | ||
/// The ip subject alternative names. | ||
/// </value> | ||
[JsonProperty("ip_sans")] | ||
public string IPSubjectAlternativeNames { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the requested URI Subject Alternative Names, in a comma-delimited list. | ||
/// </summary> | ||
/// <value> | ||
/// The uri subject alternative names. | ||
/// </value> | ||
[JsonProperty("uri_sans")] | ||
public string URISubjectAlternativeNames { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the custom OID/UTF8-string SANs. | ||
/// These must match values specified on the role in allowed_other_sans (globbing allowed). | ||
/// The format is the same as OpenSSL: [oid];[type]:[value] where the only current valid type is UTF8. | ||
/// This can be a comma-delimited list or a JSON string slice. | ||
/// </summary> | ||
/// <value> | ||
/// The other subject alternative names. | ||
/// </value> | ||
[JsonProperty("other_sans")] | ||
public string OtherSubjectAlternativeNames { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the requested Time To Live. | ||
/// Cannot be greater than the role's max_ttl value. | ||
/// If not provided, the role's ttl value will be used. | ||
/// Note that the role values default to system values if not explicitly set. | ||
/// </summary> | ||
/// <value> | ||
/// The time to live. | ||
/// </value> | ||
[JsonProperty("ttl")] | ||
public string TimeToLive { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets the certificate format for returned data. | ||
/// Can be pem or der; defaults to pem. | ||
/// If der, the output is base64 encoded.. | ||
/// </summary> | ||
/// <value> | ||
/// The certificate format. | ||
/// </value> | ||
[JsonProperty("format")] | ||
public CertificateFormat CertificateFormat { get; set; } | ||
|
||
/// <summary> | ||
/// <para>[optional]</para> | ||
/// Gets or sets a value indicating whether [exclude common name from subject alternative names]. | ||
/// If set, the given common name will not be included in DNS or Email Subject Alternate Names (as appropriate). | ||
/// Useful if the CN is not a hostname or email address, but is instead some human-readable identifier. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if [exclude common name from subject alternative names]; otherwise, <c>false</c>. | ||
/// </value> | ||
[JsonProperty("exclude_cn_from_sans")] | ||
public bool ExcludeCommonNameFromSubjectAlternativeNames { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SignCertificatesRequestOptions"/> class. | ||
/// </summary> | ||
public SignCertificatesRequestOptions() | ||
{ | ||
CertificateFormat = CertificateFormat.pem; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace VaultSharp.V1.SecretsEngines.PKI | ||
{ | ||
/// <summary> | ||
/// Represents the signed Certificate. | ||
/// </summary> | ||
public class SignedCertificateData : AbstractCertificateData | ||
{ | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a null check on result.Data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's assigned as in GetCredentialsAsync function. Thought that there will be some exception, error code from Api if there will be no data send. For my purpose i don't even need that CertificateFormat Assigned cause as a caller you already know it.