You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RevocationData.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. /* ====================================================================
  16. This product contains an ASLv2 licensed version of the OOXML signer
  17. package from the eID Applet project
  18. http://code.google.com/p/eid-applet/source/browse/trunk/README.txt
  19. Copyright (C) 2008-2014 FedICT.
  20. ================================================================= */
  21. package org.apache.poi.poifs.crypt.dsig.services;
  22. import java.security.cert.CRLException;
  23. import java.security.cert.X509CRL;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. /**
  27. * Container class for PKI revocation data.
  28. */
  29. public class RevocationData {
  30. private final List<byte[]> crls;
  31. private final List<byte[]> ocsps;
  32. /**
  33. * Default constructor.
  34. */
  35. public RevocationData() {
  36. this.crls = new ArrayList<>();
  37. this.ocsps = new ArrayList<>();
  38. }
  39. /**
  40. * Adds a CRL to this revocation data set.
  41. */
  42. public void addCRL(byte[] encodedCrl) {
  43. this.crls.add(encodedCrl);
  44. }
  45. /**
  46. * Adds a CRL to this revocation data set.
  47. */
  48. public void addCRL(X509CRL crl) {
  49. byte[] encodedCrl;
  50. try {
  51. encodedCrl = crl.getEncoded();
  52. } catch (CRLException e) {
  53. throw new IllegalArgumentException("CRL coding error: "
  54. + e.getMessage(), e);
  55. }
  56. addCRL(encodedCrl);
  57. }
  58. /**
  59. * Adds an OCSP response to this revocation data set.
  60. */
  61. public void addOCSP(byte[] encodedOcsp) {
  62. this.ocsps.add(encodedOcsp);
  63. }
  64. /**
  65. * Gives back a list of all CRLs.
  66. *
  67. * @return a list of all CRLs
  68. */
  69. public List<byte[]> getCRLs() {
  70. return this.crls;
  71. }
  72. /**
  73. * Gives back a list of all OCSP responses.
  74. *
  75. * @return a list of all OCSP response
  76. */
  77. public List<byte[]> getOCSPs() {
  78. return this.ocsps;
  79. }
  80. /**
  81. * Returns {@code true} if this revocation data set holds OCSP
  82. * responses.
  83. *
  84. * @return {@code true} if this revocation data set holds OCSP
  85. * responses.
  86. */
  87. public boolean hasOCSPs() {
  88. return !this.ocsps.isEmpty();
  89. }
  90. /**
  91. * Returns {@code true} if this revocation data set holds CRLs.
  92. *
  93. * @return {@code true} if this revocation data set holds CRLs.
  94. */
  95. public boolean hasCRLs() {
  96. return !this.crls.isEmpty();
  97. }
  98. /**
  99. * Returns {@code true} if this revocation data is not empty.
  100. *
  101. * @return {@code true} if this revocation data is not empty.
  102. */
  103. public boolean hasRevocationDataEntries() {
  104. return hasOCSPs() || hasCRLs();
  105. }
  106. }