X509Store.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // System.Security.Cryptography.X509Certificates.X509Store class
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using Mono.Security.X509;
  31. namespace System.Security.Cryptography.X509Certificates {
  32. public sealed class X509Store {
  33. private string _name;
  34. private StoreLocation _location;
  35. private X509Certificate2Collection _certs;
  36. private OpenFlags _flags;
  37. // constructors
  38. // BUG: MY when using this constructor - My when using StoreName.My
  39. public X509Store ()
  40. : this ("MY", StoreLocation.CurrentUser)
  41. {
  42. }
  43. public X509Store (string storeName)
  44. : this (storeName, StoreLocation.CurrentUser)
  45. {
  46. }
  47. public X509Store (StoreName storeName)
  48. : this (StoreNameToString (storeName), StoreLocation.CurrentUser)
  49. {
  50. }
  51. public X509Store (StoreLocation storeLocation)
  52. : this ("MY", storeLocation)
  53. {
  54. }
  55. public X509Store (StoreName storeName, StoreLocation storeLocation)
  56. : this (StoreNameToString (storeName), StoreLocation.CurrentUser)
  57. {
  58. }
  59. public X509Store (IntPtr storeHandle)
  60. {
  61. // CryptoAPI compatibility (unmanaged handle)
  62. throw new NotSupportedException ();
  63. }
  64. [MonoTODO ("call Mono.Security.X509.X509Store*")]
  65. public X509Store (string storeName, StoreLocation storeLocation)
  66. {
  67. if (storeName == null)
  68. throw new ArgumentNullException ("storeName");
  69. _name = storeName;
  70. _location = storeLocation;
  71. }
  72. // properties
  73. public X509Certificate2Collection Certificates {
  74. get {
  75. if (_certs == null)
  76. _certs = new X509Certificate2Collection ();
  77. return _certs;
  78. }
  79. }
  80. public StoreLocation Location {
  81. get { return _location; }
  82. }
  83. public string Name {
  84. get { return _name; }
  85. }
  86. private bool ReadOnly {
  87. get { return ((_flags & OpenFlags.ReadOnly) != OpenFlags.ReadOnly); }
  88. }
  89. public IntPtr StoreHandle {
  90. get { return IntPtr.Zero; }
  91. }
  92. // methods
  93. private static string StoreNameToString (StoreName sn)
  94. {
  95. switch (sn) {
  96. case StoreName.CertificateAuthority:
  97. return "CA";
  98. default:
  99. return sn.ToString ();
  100. }
  101. }
  102. [MonoTODO ("call Mono.Security.X509.X509Store*")]
  103. public void Add (X509Certificate2 certificate)
  104. {
  105. if (certificate == null)
  106. throw new ArgumentNullException ("certificate");
  107. if (!ReadOnly) {
  108. try {
  109. // Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
  110. // TODO
  111. }
  112. catch {
  113. throw new CryptographicException ("couldn't add certificate");
  114. }
  115. }
  116. }
  117. public void AddRange (X509Certificate2Collection certificates)
  118. {
  119. if (certificates == null)
  120. throw new ArgumentNullException ("certificates");
  121. if (!ReadOnly) {
  122. foreach (X509Certificate2 certificate in certificates) {
  123. Add (certificate);
  124. }
  125. }
  126. }
  127. [MonoTODO ("call Mono.Security.X509.X509Store*")]
  128. public void Close ()
  129. {
  130. }
  131. [MonoTODO ("call Mono.Security.X509.X509Store*")]
  132. public void Open (OpenFlags flags)
  133. {
  134. _flags = flags;
  135. /*bool readOnly = ((flags & OpenFlags.ReadOnly) == OpenFlags.ReadOnly);
  136. bool create = !((flags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly);
  137. bool archive = ((flags & OpenFlags.IncludeArchived) == OpenFlags.IncludeArchived);*/
  138. // TODO
  139. }
  140. [MonoTODO ("call Mono.Security.X509.X509Store*")]
  141. public void Remove (X509Certificate2 certificate)
  142. {
  143. if (certificate == null)
  144. throw new ArgumentNullException ("certificate");
  145. if (!ReadOnly) {
  146. try {
  147. //Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
  148. // TODO
  149. }
  150. catch {
  151. throw new CryptographicException ("couldn't remove certificate");
  152. }
  153. }
  154. }
  155. public void RemoveRange (X509Certificate2Collection certificates)
  156. {
  157. if (certificates == null)
  158. throw new ArgumentNullException ("certificates");
  159. if (!this.ReadOnly) {
  160. foreach (X509Certificate2 certificate in certificates) {
  161. Remove (certificate);
  162. }
  163. }
  164. }
  165. }
  166. }
  167. #endif