1- using System . Security . Cryptography . X509Certificates ;
2-
3- using AdvancedSystems . Security . Abstractions . Exceptions ;
1+ using System . Collections . Generic ;
2+ using System . Security . Cryptography . X509Certificates ;
43
54namespace AdvancedSystems . Security . Abstractions ;
65
76/// <summary>
8- /// Defines a service for managing and retrieving X.509 certificates.
7+ /// Defines a contract for managing and retrieving X.509 certificates.
98/// </summary>
9+ /// <remarks>
10+ /// See also: <seealso href="https://datatracker.ietf.org/doc/rfc5280/"/>.
11+ /// </remarks>
12+ /// <seealso cref="ICertificateStore"/>
1013public interface ICertificateService
1114{
1215 #region Methods
1316
1417 /// <summary>
15- /// Retrieves an X.509 certificate from the specified store using the provided
16- /// <paramref name="thumbprint"/>.
18+ /// Adds a certificate to a certificate store.
1719 /// </summary>
18- /// <param name="thumbprint">
19- /// The thumbprint of the certificate to locate.
20+ /// <param name="storeService">
21+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
22+ /// </param>
23+ /// <param name="certificate">
24+ /// The certificate to add.
25+ /// </param>
26+ /// <returns>
27+ /// Returns <see langword="true"/> if the <paramref name="certificate"/> was added
28+ /// successfully to the certificate store, else <see langword="false"/>.
29+ /// </returns>
30+ bool AddCertificate ( string storeService , X509Certificate2 certificate ) ;
31+
32+ /// <summary>
33+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/summary"/>
34+ /// </summary>
35+ /// <param name="storeService">
36+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/param[@name='storeService']"/>
37+ /// </param>
38+ /// <param name="certificatePath">
39+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/param[@name='certificatePath']"/>
40+ /// </param>
41+ /// <param name="privateKeyPath">
42+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/param[@name='privateKeyPath']"/>
43+ /// </param>
44+ /// <param name="certificate">
45+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/param[@name='certificate']"/>
46+ /// </param>
47+ /// <returns>
48+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/returns"/>
49+ /// </returns>
50+ /// <remarks>
51+ /// <inheritdoc cref="TryImportPemCertificate(string, string, string, string, out X509Certificate2?)" path="/remarks"/>
52+ /// </remarks>
53+ bool TryImportPemCertificate ( string storeService , string certificatePath , string privateKeyPath , out X509Certificate2 ? certificate ) ;
54+
55+ /// <summary>
56+ /// Tries to import a PEM certificate file into a certificate store.
57+ /// </summary>
58+ /// <param name="storeService">
59+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
60+ /// </param>
61+ /// <param name="certificatePath">
62+ /// The file path to the PEM certificate.
63+ /// </param>
64+ /// <param name="privateKeyPath">
65+ /// The file path to the PKCS#8 (encrypted) private key associated with the specified certificate.
66+ /// </param>
67+ /// <param name="password">
68+ /// The password required to decrypt the private key (if specified).
69+ /// </param>
70+ /// <param name="certificate">
71+ /// An output parameter that will contain the imported <see cref="X509Certificate2"/> instance if the operation succeeds;
72+ /// otherwise, it will be <see langword="null"/>.
73+ /// </param>
74+ /// <returns>
75+ /// <see langword="true"/> if the certificate was imported to the certificate store successfully, else <see langword="false"/>.
76+ /// </returns>
77+ /// <remarks>
78+ /// See also: <seealso href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail"/>.
79+ /// </remarks>
80+ bool TryImportPemCertificate ( string storeService , string certificatePath , string privateKeyPath , string password , out X509Certificate2 ? certificate ) ;
81+
82+ /// <summary>
83+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/summary"/>
84+ /// </summary>
85+ /// <param name="storeService">
86+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/param[@name='storeService']"/>
2087 /// </param>
21- /// <param name="storeName ">
22- /// The certificate store from which to retrieve the certificate.
88+ /// <param name="certificatePath ">
89+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/param[@name='certificatePath']"/>
2390 /// </param>
24- /// <param name="storeLocation">
25- /// The location of the certificate store, such as <see cref="StoreLocation.CurrentUser"/>
26- /// or <see cref="StoreLocation.LocalMachine"/>.
91+ /// <param name="certificate">
92+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/param[@name='certificate']"/>
2793 /// </param>
2894 /// <returns>
29- /// The <see cref="X509Certificate2"/> object if the certificate is found, else <c>null</c>.
95+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/returns"/>
3096 /// </returns>
31- /// <exception cref="CertificateNotFoundException" >
32- /// Thrown when no certificate with the specified thumbprint is found in the store.
33- /// </exception >
34- X509Certificate2 ? GetStoreCertificate ( string thumbprint , StoreName storeName , StoreLocation storeLocation ) ;
97+ /// <remarks >
98+ /// <inheritdoc cref="TryImportPfxCertificate(string, string, string, out X509Certificate2?)" path="/remarks"/>
99+ /// </remarks >
100+ bool TryImportPfxCertificate ( string storeService , string certificatePath , out X509Certificate2 ? certificate ) ;
35101
36102 /// <summary>
37- /// Retrieves an application-configured X.509 certificate.
103+ /// Tries to import a PFX certificate file into a certificate store .
38104 /// </summary>
105+ /// <param name="storeService">
106+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
107+ /// </param>
108+ /// <param name="certificatePath">
109+ /// The file path to the PFX certificate file that needs to be imported.
110+ /// </param>
111+ /// <param name="password">
112+ /// The password required to access the PFX file's private key.
113+ /// </param>
114+ /// <param name="certificate">
115+ /// An output parameter that will contain the imported <see cref="X509Certificate2"/> instance if the operation succeeds;
116+ /// otherwise, it will be <see langword="null"/>.
117+ /// </param>
118+ /// <returns>
119+ /// <see langword="true"/> if the certificate was imported to the certificate store successfully, else <see langword="false"/>.
120+ /// </returns>
121+ /// <remarks>
122+ /// See also: <seealso href="https://en.wikipedia.org/wiki/PKCS_12"/>.
123+ /// </remarks>
124+ bool TryImportPfxCertificate ( string storeService , string certificatePath , string password , out X509Certificate2 ? certificate ) ;
125+
126+ /// <summary>
127+ /// Retrieves all certificates from the certificate store.
128+ /// </summary>
129+ /// <param name="storeService">
130+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
131+ /// </param>
132+ /// <returns>
133+ /// Returns a collection of <seealso cref="X509Certificate2"/> certificates.
134+ /// </returns>
135+ IEnumerable < X509Certificate2 > GetCertificate ( string storeService ) ;
136+
137+ /// <summary>
138+ /// Retrieves a certificate from the certificate store by using the <paramref name="thumbprint"/>.
139+ /// </summary>
140+ /// <param name="storeService">
141+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
142+ /// </param>
143+ /// <param name="thumbprint">
144+ /// The string representing the thumbprint of the certificate to retrieve.
145+ /// </param>
146+ /// <param name="validOnly">
147+ /// <see langword="true"/> to allow only valid certificates to be returned from the search;
148+ /// otherwise, <see langword="false"/>.
149+ /// </param>
150+ /// <returns>
151+ /// A <seealso cref="X509Certificate2"/> object if a certificate in the certificate store
152+ /// matches the search criteria, else <see langword="null"/>.
153+ /// </returns>
154+ X509Certificate2 ? GetCertificate ( string storeService , string thumbprint , bool validOnly = true ) ;
155+
156+ /// <summary>
157+ /// Removes a certificate from the certificate store by using the <paramref name="thumbprint"/>.
158+ /// </summary>
159+ /// <param name="storeService">
160+ /// The name of the keyed <seealso cref="ICertificateStore"/> service to use.
161+ /// </param>
162+ /// <param name="thumbprint">
163+ /// The string representing the thumbprint of the certificate to remove.
164+ /// </param>
39165 /// <returns>
40- /// The <see cref="X509Certificate2"/> object if the certificate is found, else <c>null</c>.
166+ /// Returns <see langword="true"/> if a certificate with the specified <paramref name="thumbprint"/>
167+ /// was removed from the certificate store, else <see langword="false"/>.
41168 /// </returns>
42- X509Certificate2 ? GetConfiguredCertificate ( ) ;
169+ bool RemoveCertificate ( string storeService , string thumbprint ) ;
43170
44171 #endregion
45172}
0 commit comments