Java Code Examples for org.bouncycastle.asn1.ASN1TaggedObject#getObject()

The following examples show how to use org.bouncycastle.asn1.ASN1TaggedObject#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CAdESWithContentTimestampTest.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected DSSDocument getSignedDocument() {
	FileDocument fileDocument = new FileDocument("src/test/resources/validation/Signature-C-BES-4.p7m");
	
	try (InputStream is = fileDocument.openStream(); ASN1InputStream asn1sInput = new ASN1InputStream(is)) {
		ASN1Sequence asn1Seq = (ASN1Sequence) asn1sInput.readObject();

		ASN1TaggedObject taggedObj = ASN1TaggedObject.getInstance(asn1Seq.getObjectAt(1));
		ASN1Primitive object = taggedObj.getObject();
		SignedData signedData = SignedData.getInstance(object);

		ASN1Set signerInfosAsn1 = signedData.getSignerInfos();
		ASN1Sequence seqSignedInfo = ASN1Sequence.getInstance(signerInfosAsn1.getObjectAt(0));

		SignerInfo signedInfo = SignerInfo.getInstance(seqSignedInfo);
		ASN1Set authenticatedAttributes = signedInfo.getAuthenticatedAttributes();

		boolean found = false;
		for (int i = 0; i < authenticatedAttributes.size(); i++) {
			ASN1Sequence authAttrSeq = ASN1Sequence.getInstance(authenticatedAttributes.getObjectAt(i));
			ASN1ObjectIdentifier attrOid = ASN1ObjectIdentifier.getInstance(authAttrSeq.getObjectAt(0));
			if (PKCSObjectIdentifiers.id_aa_ets_contentTimestamp.equals(attrOid)) {
				found = true;
			}
		}
		assertTrue(found);
	} catch (Exception e) {
		fail(e);
	}
	
	return fileDocument;
}
 
Example 2
Source File: RevocationInfoArchival.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private RevocationInfoArchival(ASN1Sequence seq)
{
    if (seq.size() > 3)
    {
        throw new IllegalArgumentException("Bad sequence size: "
            + seq.size());
    }
    Enumeration e = seq.getObjects();
    while (e.hasMoreElements())
    {
        ASN1TaggedObject o = (ASN1TaggedObject)e.nextElement();
        switch (o.getTagNo())
        {
            case 0:
                ASN1Sequence crlValsSeq = (ASN1Sequence)o.getObject();
                Enumeration crlValsEnum = crlValsSeq.getObjects();
                while (crlValsEnum.hasMoreElements())
                {
                    CertificateList.getInstance(crlValsEnum.nextElement());
                }
                this.crlVals = crlValsSeq;
                break;
            case 1:
                ASN1Sequence ocspValsSeq = (ASN1Sequence)o.getObject();
                Enumeration ocspValsEnum = ocspValsSeq.getObjects();
                while (ocspValsEnum.hasMoreElements())
                {
                    OCSPResponse.getInstance(ocspValsEnum.nextElement());
                }
                this.ocspVals = ocspValsSeq;
                break;
            case 2:
                this.otherRevVals = OtherRevVals.getInstance(o.getObject());
                break;
            default:
                throw new IllegalArgumentException("invalid tag: "
                    + o.getTagNo());
        }
    }
}
 
Example 3
Source File: UserIdentityExtractor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private ASN1Encodable unwrap(ASN1Encodable encodable) {
    while (encodable instanceof ASN1TaggedObject) {
        ASN1TaggedObject taggedObj = (ASN1TaggedObject) encodable;
        encodable = taggedObj.getObject();
    }

    return encodable;
}
 
Example 4
Source File: ExtensionSyntaxChecker.java    From xipki with Apache License 2.0 4 votes vote down vote up
private static ASN1Encodable getParsedImplicitValue(String name, ASN1TaggedObject taggedObject,
    FieldType fieldType) throws BadCertTemplateException {
  try {
    switch (fieldType) {
      case BIT_STRING:
        return DERBitString.getInstance(taggedObject, false);
      case BMPString:
        return DERBMPString.getInstance(taggedObject, false);
      case BOOLEAN:
        return ASN1Boolean.getInstance(taggedObject, false);
      case ENUMERATED:
        return ASN1Enumerated.getInstance(taggedObject, false);
      case GeneralizedTime:
        return DERGeneralizedTime.getInstance(taggedObject, false);
      case IA5String:
        return DERIA5String.getInstance(taggedObject, false);
      case INTEGER:
        return ASN1Integer.getInstance(taggedObject, false);
      case Name:
        return X500Name.getInstance(taggedObject, false);
      case NULL:
        if (!(taggedObject.getObject() instanceof ASN1OctetString
            && ((ASN1OctetString) taggedObject.getObject()).getOctets().length == 0)) {
          throw new BadCertTemplateException("invalid " + name);
        }
        return DERNull.INSTANCE;
      case OCTET_STRING:
        return DEROctetString.getInstance(taggedObject, false);
      case OID:
        return ASN1ObjectIdentifier.getInstance(taggedObject, false);
      case PrintableString:
        return DERPrintableString.getInstance(taggedObject, false);
      case RAW:
        return taggedObject.getObject();
      case SEQUENCE:
      case SEQUENCE_OF:
        return ASN1Sequence.getInstance(taggedObject, false);
      case SET:
      case SET_OF:
        return ASN1Set.getInstance(taggedObject, false);
      case TeletexString:
        return DERT61String.getInstance(taggedObject, false);
      case UTCTime:
        return DERUTCTime.getInstance(taggedObject, false);
      case UTF8String:
        return DERUTF8String.getInstance(taggedObject, false);
      default:
        throw new RuntimeException("Unknown FieldType " + fieldType);
    }
  } catch (IllegalArgumentException ex) {
    throw new BadCertTemplateException("invalid " + name, ex);
  }
}
 
Example 5
Source File: ProxyMessage.java    From xipki with Apache License 2.0 4 votes vote down vote up
private P11Params(ASN1TaggedObject taggedObject) throws BadAsn1ObjectException {
  this.tagNo = taggedObject.getTagNo();
  this.p11Params = taggedObject.getObject();
}