PkixAttrCertPathValidator.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Pkix
  7. {
  8. /**
  9. * CertPathValidatorSpi implementation for X.509 Attribute Certificates la RFC 3281.
  10. *
  11. * @see org.bouncycastle.x509.ExtendedPkixParameters
  12. */
  13. public class PkixAttrCertPathValidator
  14. // extends CertPathValidatorSpi
  15. {
  16. /**
  17. * Validates an attribute certificate with the given certificate path.
  18. *
  19. * <p>
  20. * <code>params</code> must be an instance of
  21. * <code>ExtendedPkixParameters</code>.
  22. * </p><p>
  23. * The target constraints in the <code>params</code> must be an
  24. * <code>X509AttrCertStoreSelector</code> with at least the attribute
  25. * certificate criterion set. Obey that also target informations may be
  26. * necessary to correctly validate this attribute certificate.
  27. * </p><p>
  28. * The attribute certificate issuer must be added to the trusted attribute
  29. * issuers with {@link ExtendedPkixParameters#setTrustedACIssuers(Set)}.
  30. * </p>
  31. * @param certPath The certificate path which belongs to the attribute
  32. * certificate issuer public key certificate.
  33. * @param params The PKIX parameters.
  34. * @return A <code>PKIXCertPathValidatorResult</code> of the result of
  35. * validating the <code>certPath</code>.
  36. * @throws InvalidAlgorithmParameterException if <code>params</code> is
  37. * inappropriate for this validator.
  38. * @throws CertPathValidatorException if the verification fails.
  39. */
  40. public virtual PkixCertPathValidatorResult Validate(
  41. PkixCertPath certPath,
  42. PkixParameters pkixParams)
  43. {
  44. IX509Selector certSelect = pkixParams.GetTargetConstraints();
  45. if (!(certSelect is X509AttrCertStoreSelector))
  46. {
  47. throw new ArgumentException(
  48. "TargetConstraints must be an instance of " + typeof(X509AttrCertStoreSelector).FullName,
  49. "pkixParams");
  50. }
  51. IX509AttributeCertificate attrCert = ((X509AttrCertStoreSelector) certSelect).AttributeCert;
  52. PkixCertPath holderCertPath = Rfc3281CertPathUtilities.ProcessAttrCert1(attrCert, pkixParams);
  53. PkixCertPathValidatorResult result = Rfc3281CertPathUtilities.ProcessAttrCert2(certPath, pkixParams);
  54. X509Certificate issuerCert = (X509Certificate)certPath.Certificates[0];
  55. Rfc3281CertPathUtilities.ProcessAttrCert3(issuerCert, pkixParams);
  56. Rfc3281CertPathUtilities.ProcessAttrCert4(issuerCert, pkixParams);
  57. Rfc3281CertPathUtilities.ProcessAttrCert5(attrCert, pkixParams);
  58. // 6 already done in X509AttrCertStoreSelector
  59. Rfc3281CertPathUtilities.ProcessAttrCert7(attrCert, certPath, holderCertPath, pkixParams);
  60. Rfc3281CertPathUtilities.AdditionalChecks(attrCert, pkixParams);
  61. DateTime date;
  62. try
  63. {
  64. date = PkixCertPathValidatorUtilities.GetValidCertDateFromValidityModel(pkixParams, null, -1);
  65. }
  66. catch (Exception e)
  67. {
  68. throw new PkixCertPathValidatorException(
  69. "Could not get validity date from attribute certificate.", e);
  70. }
  71. Rfc3281CertPathUtilities.CheckCrls(attrCert, pkixParams, issuerCert, date, certPath.Certificates);
  72. return result;
  73. }
  74. }
  75. }
  76. #pragma warning restore
  77. #endif