ProcurationSyntax.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X500;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  8. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509
  9. {
  10. /**
  11. * Attribute to indicate that the certificate holder may sign in the name of a
  12. * third person.
  13. * <p>
  14. * ISIS-MTT PROFILE: The corresponding ProcurationSyntax contains either the
  15. * name of the person who is represented (subcomponent thirdPerson) or a
  16. * reference to his/her base certificate (in the component signingFor,
  17. * subcomponent certRef), furthermore the optional components country and
  18. * typeSubstitution to indicate the country whose laws apply, and respectively
  19. * the type of procuration (e.g. manager, procuration, custody).
  20. * </p>
  21. * <p>
  22. * ISIS-MTT PROFILE: The GeneralName MUST be of type directoryName and MAY only
  23. * contain: - RFC3039 attributes, except pseudonym (countryName, commonName,
  24. * surname, givenName, serialNumber, organizationName, organizationalUnitName,
  25. * stateOrProvincename, localityName, postalAddress) and - SubjectDirectoryName
  26. * attributes (title, dateOfBirth, placeOfBirth, gender, countryOfCitizenship,
  27. * countryOfResidence and NameAtBirth).
  28. * </p>
  29. * <pre>
  30. * ProcurationSyntax ::= SEQUENCE {
  31. * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
  32. * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
  33. * signingFor [3] EXPLICIT SigningFor
  34. * }
  35. *
  36. * SigningFor ::= CHOICE
  37. * {
  38. * thirdPerson GeneralName,
  39. * certRef IssuerSerial
  40. * }
  41. * </pre>
  42. *
  43. */
  44. public class ProcurationSyntax
  45. : Asn1Encodable
  46. {
  47. private readonly string country;
  48. private readonly DirectoryString typeOfSubstitution;
  49. private readonly GeneralName thirdPerson;
  50. private readonly IssuerSerial certRef;
  51. public static ProcurationSyntax GetInstance(
  52. object obj)
  53. {
  54. if (obj == null || obj is ProcurationSyntax)
  55. {
  56. return (ProcurationSyntax) obj;
  57. }
  58. if (obj is Asn1Sequence)
  59. {
  60. return new ProcurationSyntax((Asn1Sequence) obj);
  61. }
  62. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  63. }
  64. /**
  65. * Constructor from Asn1Sequence.
  66. * <p/>
  67. * The sequence is of type ProcurationSyntax:
  68. * <p/>
  69. * <pre>
  70. * ProcurationSyntax ::= SEQUENCE {
  71. * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
  72. * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
  73. * signingFor [3] EXPLICIT SigningFor
  74. * }
  75. * <p/>
  76. * SigningFor ::= CHOICE
  77. * {
  78. * thirdPerson GeneralName,
  79. * certRef IssuerSerial
  80. * }
  81. * </pre>
  82. *
  83. * @param seq The ASN.1 sequence.
  84. */
  85. private ProcurationSyntax(
  86. Asn1Sequence seq)
  87. {
  88. if (seq.Count < 1 || seq.Count > 3)
  89. throw new ArgumentException("Bad sequence size: " + seq.Count);
  90. IEnumerator e = seq.GetEnumerator();
  91. while (e.MoveNext())
  92. {
  93. Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
  94. switch (o.TagNo)
  95. {
  96. case 1:
  97. country = DerPrintableString.GetInstance(o, true).GetString();
  98. break;
  99. case 2:
  100. typeOfSubstitution = DirectoryString.GetInstance(o, true);
  101. break;
  102. case 3:
  103. Asn1Object signingFor = o.GetObject();
  104. if (signingFor is Asn1TaggedObject)
  105. {
  106. thirdPerson = GeneralName.GetInstance(signingFor);
  107. }
  108. else
  109. {
  110. certRef = IssuerSerial.GetInstance(signingFor);
  111. }
  112. break;
  113. default:
  114. throw new ArgumentException("Bad tag number: " + o.TagNo);
  115. }
  116. }
  117. }
  118. /**
  119. * Constructor from a given details.
  120. * <p/>
  121. * <p/>
  122. * Either <code>generalName</code> or <code>certRef</code> MUST be
  123. * <code>null</code>.
  124. *
  125. * @param country The country code whose laws apply.
  126. * @param typeOfSubstitution The type of procuration.
  127. * @param certRef Reference to certificate of the person who is represented.
  128. */
  129. public ProcurationSyntax(
  130. string country,
  131. DirectoryString typeOfSubstitution,
  132. IssuerSerial certRef)
  133. {
  134. this.country = country;
  135. this.typeOfSubstitution = typeOfSubstitution;
  136. this.thirdPerson = null;
  137. this.certRef = certRef;
  138. }
  139. /**
  140. * Constructor from a given details.
  141. * <p/>
  142. * <p/>
  143. * Either <code>generalName</code> or <code>certRef</code> MUST be
  144. * <code>null</code>.
  145. *
  146. * @param country The country code whose laws apply.
  147. * @param typeOfSubstitution The type of procuration.
  148. * @param thirdPerson The GeneralName of the person who is represented.
  149. */
  150. public ProcurationSyntax(
  151. string country,
  152. DirectoryString typeOfSubstitution,
  153. GeneralName thirdPerson)
  154. {
  155. this.country = country;
  156. this.typeOfSubstitution = typeOfSubstitution;
  157. this.thirdPerson = thirdPerson;
  158. this.certRef = null;
  159. }
  160. public virtual string Country
  161. {
  162. get { return country; }
  163. }
  164. public virtual DirectoryString TypeOfSubstitution
  165. {
  166. get { return typeOfSubstitution; }
  167. }
  168. public virtual GeneralName ThirdPerson
  169. {
  170. get { return thirdPerson; }
  171. }
  172. public virtual IssuerSerial CertRef
  173. {
  174. get { return certRef; }
  175. }
  176. /**
  177. * Produce an object suitable for an Asn1OutputStream.
  178. * <p/>
  179. * Returns:
  180. * <p/>
  181. * <pre>
  182. * ProcurationSyntax ::= SEQUENCE {
  183. * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
  184. * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
  185. * signingFor [3] EXPLICIT SigningFor
  186. * }
  187. * <p/>
  188. * SigningFor ::= CHOICE
  189. * {
  190. * thirdPerson GeneralName,
  191. * certRef IssuerSerial
  192. * }
  193. * </pre>
  194. *
  195. * @return an Asn1Object
  196. */
  197. public override Asn1Object ToAsn1Object()
  198. {
  199. Asn1EncodableVector v = new Asn1EncodableVector();
  200. if (country != null)
  201. {
  202. v.Add(new DerTaggedObject(true, 1, new DerPrintableString(country, true)));
  203. }
  204. v.AddOptionalTagged(true, 2, typeOfSubstitution);
  205. if (thirdPerson != null)
  206. {
  207. v.Add(new DerTaggedObject(true, 3, thirdPerson));
  208. }
  209. else
  210. {
  211. v.Add(new DerTaggedObject(true, 3, certRef));
  212. }
  213. return new DerSequence(v);
  214. }
  215. }
  216. }
  217. #pragma warning restore
  218. #endif