Challenge.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  7. {
  8. public class Challenge
  9. : Asn1Encodable
  10. {
  11. private readonly AlgorithmIdentifier owf;
  12. private readonly Asn1OctetString witness;
  13. private readonly Asn1OctetString challenge;
  14. private Challenge(Asn1Sequence seq)
  15. {
  16. int index = 0;
  17. if (seq.Count == 3)
  18. {
  19. owf = AlgorithmIdentifier.GetInstance(seq[index++]);
  20. }
  21. witness = Asn1OctetString.GetInstance(seq[index++]);
  22. challenge = Asn1OctetString.GetInstance(seq[index]);
  23. }
  24. public static Challenge GetInstance(object obj)
  25. {
  26. if (obj is Challenge)
  27. return (Challenge)obj;
  28. if (obj is Asn1Sequence)
  29. return new Challenge((Asn1Sequence)obj);
  30. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  31. }
  32. public virtual AlgorithmIdentifier Owf
  33. {
  34. get { return owf; }
  35. }
  36. /**
  37. * <pre>
  38. * Challenge ::= SEQUENCE {
  39. * owf AlgorithmIdentifier OPTIONAL,
  40. *
  41. * -- MUST be present in the first Challenge; MAY be omitted in
  42. * -- any subsequent Challenge in POPODecKeyChallContent (if
  43. * -- omitted, then the owf used in the immediately preceding
  44. * -- Challenge is to be used).
  45. *
  46. * witness OCTET STRING,
  47. * -- the result of applying the one-way function (owf) to a
  48. * -- randomly-generated INTEGER, A. [Note that a different
  49. * -- INTEGER MUST be used for each Challenge.]
  50. * challenge OCTET STRING
  51. * -- the encryption (under the public key for which the cert.
  52. * -- request is being made) of Rand, where Rand is specified as
  53. * -- Rand ::= SEQUENCE {
  54. * -- int INTEGER,
  55. * -- - the randomly-generated INTEGER A (above)
  56. * -- sender GeneralName
  57. * -- - the sender's name (as included in PKIHeader)
  58. * -- }
  59. * }
  60. * </pre>
  61. * @return a basic ASN.1 object representation.
  62. */
  63. public override Asn1Object ToAsn1Object()
  64. {
  65. Asn1EncodableVector v = new Asn1EncodableVector();
  66. v.AddOptional(owf);
  67. v.Add(witness, challenge);
  68. return new DerSequence(v);
  69. }
  70. }
  71. }
  72. #pragma warning restore
  73. #endif