DSSASN1Utils { public static PSD2QcType getPSD2QcStatement(CertificateToken certToken) { PSD2QcType result = null; final byte[] qcStatement = certToken.getCertificate().getExtensionValue(Extension.qCStatements.getId()); if (Utils.isArrayNotEmpty(qcStatement)) { try { final ASN1Sequence seq = getAsn1SequenceFromDerOctetString(qcStatement); for (int i = 0; i < seq.size(); i++) { final QCStatement statement = QCStatement.getInstance(seq.getObjectAt(i)); if (OID.psd2_qcStatement.equals(statement.getStatementId())) { result = new PSD2QcType(); ASN1Sequence psd2Seq = ASN1Sequence.getInstance(statement.getStatementInfo()); ASN1Sequence rolesSeq = ASN1Sequence.getInstance(psd2Seq.getObjectAt(0)); List<RoleOfPSP> rolesOfPSP = new ArrayList<>(); for (int ii = 0; ii < rolesSeq.size(); ii++) { ASN1Sequence oneRoleSeq = ASN1Sequence.getInstance(rolesSeq.getObjectAt(ii)); RoleOfPSP roleOfPSP = new RoleOfPSP(); ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) oneRoleSeq.getObjectAt(0); roleOfPSP.setPspOid(RoleOfPspOid.fromOid(oid.getId())); roleOfPSP.setPspName(getString(oneRoleSeq.getObjectAt(1))); rolesOfPSP.add(roleOfPSP); } result.setRolesOfPSP(rolesOfPSP); result.setNcaName(getString(psd2Seq.getObjectAt(1))); result.setNcaId(getString(psd2Seq.getObjectAt(2))); } } } catch (Exception e) { LOG.warn("Unable to read QCStatement", e); } } return result; } private  DSSASN1Utils(); @SuppressWarnings("unchecked") static T toASN1Primitive(final byte[] bytes); static byte[] getDEREncoded(ASN1Encodable asn1Encodable); static byte[] getBEREncoded(ASN1Encodable asn1Encodable); static byte[] getEncoded(BasicOCSPResp basicOCSPResp); static Date toDate(final ASN1GeneralizedTime asn1Date); static String toString(final ASN1OctetString value); static byte[] getEncoded(final TimeStampToken timeStampToken); static byte[] getEncoded(final CMSSignedData cmsSignedData); static byte[] getDEREncoded(final TimeStampToken timeStampToken); static byte[] getDEREncoded(final CMSSignedData data); static byte[] getDEREncoded(final TimestampBinary timestampBinary); static byte[] getDEREncoded(final byte[] bytes); static ASN1Sequence getAsn1SequenceFromDerOctetString(byte[] bytes); static byte[] getAsn1SignaturePolicyDigest(DigestAlgorithm digestAlgorithm, byte[] policyBytes); static AlgorithmIdentifier getAlgorithmIdentifier(final ASN1Sequence atsHashIndexValue); static AlgorithmIdentifier getAlgorithmIdentifier(DigestAlgorithm digestAlgorithm); static ASN1Sequence getCertificatesHashIndex(final ASN1Sequence atsHashIndexValue); static ASN1Sequence getCRLHashIndex(final ASN1Sequence atsHashIndexValue); static ASN1Sequence getUnsignedAttributesHashIndex(final ASN1Sequence atsHashIndexValue); @SuppressWarnings("unchecked") static List<DEROctetString> getDEROctetStrings(final ASN1Sequence asn1Sequence); static boolean hasIdPkixOcspNoCheckExtension(CertificateToken token); static List<CertificatePolicy> getCertificatePolicies(final CertificateToken certToken); static List<String> getQCStatementsIdList(final CertificateToken certToken); static List<String> getQCTypesIdList(final CertificateToken certToken); static List<String> getQCLegislations(CertificateToken certToken); static byte[] getSki(final CertificateToken certificateToken); static byte[] getSki(final CertificateToken certificateToken, boolean computeIfMissing); static byte[] getAuthorityKeyIdentifier(CertificateToken certificateToken); static byte[] computeSkiFromCert(final CertificateToken certificateToken); static byte[] computeSkiFromCertPublicKey(final PublicKey publicKey); static boolean isSkiEqual(final byte[] ski, final CertificateToken certificateToken); static List<String> getCAAccessLocations(final CertificateToken certificate); static List<String> getOCSPAccessLocations(final CertificateToken certificate); static List<String> getCrlUrls(final CertificateToken certificateToken); static boolean isOCSPSigning(CertificateToken certToken); static boolean isExtendedKeyUsagePresent(CertificateToken certToken, ASN1ObjectIdentifier oid); static X509CertificateHolder getX509CertificateHolder(CertificateToken certToken); static CertificateToken getCertificate(final X509CertificateHolder x509CertificateHolder); static CertificateIdentifier toIssuerSerialInfo(SignerId signerId); static X500Principal toX500Principal(X500Name x500Name); static CertificateIdentifier toCertificateIdentifier(final X500Principal issuerX500Principal, final BigInteger serialNumber, final byte[] ski); static IssuerSerial getIssuerSerial(final CertificateToken certToken); static boolean x500PrincipalAreEquals(final X500Principal firstX500Principal, final X500Principal secondX500Principal); static Map<String, String> get(final X500Principal x500Principal); static X500Principal getNormalizedX500Principal(final X500Principal x500Principal); static String getUtf8String(final X500Principal x500Principal); static String getString(ASN1Encodable attributeValue); static String extractAttributeFromX500Principal(ASN1ObjectIdentifier identifier, X500PrincipalHelper principal); static String getSubjectCommonName(CertificateToken cert); static String getHumanReadableName(CertificateToken cert); static SignerInformation getFirstSignerInformation(final CMSSignedData cms); static boolean isASN1SequenceTag(byte tagByte); static Date getDate(ASN1Encodable encodable); static boolean isEmpty(AttributeTable attributeTable); static AttributeTable emptyIfNull(AttributeTable original); static List<String> getExtendedKeyUsage(CertificateToken certToken); static IssuerSerial getIssuerSerial(byte[] binaries); static CertificateIdentifier toCertificateIdentifier(IssuerSerial issuerAndSerial); static ASN1Sequence getAtsHashIndex(AttributeTable timestampUnsignedAttributes); static ASN1Sequence getAtsHashIndexByVersion(AttributeTable timestampUnsignedAttributes, 
			ASN1ObjectIdentifier atsHashIndexVersionIdentifier); static ASN1ObjectIdentifier getAtsHashIndexVersionIdentifier(AttributeTable timestampUnsignedAttributes); static List<byte[]> getOctetStringForAtsHashIndex(Attribute attribute, ASN1ObjectIdentifier atsHashIndexVersionIdentifier); static ASN1Encodable getAsn1Encodable(AttributeTable unsignedAttributes, ASN1ObjectIdentifier oid); static ASN1Set getAsn1AttributeSet(AttributeTable unsignedAttributes, ASN1ObjectIdentifier oid); static Attribute[] getAsn1Attributes(AttributeTable unsignedAttributes, ASN1ObjectIdentifier oid); static List<TimeStampToken> findArchiveTimeStampTokens(AttributeTable unsignedAttributes); static boolean isArchiveTimeStampToken(Attribute attribute); static boolean isAttributeOfType(Attribute attribute, ASN1ObjectIdentifier asn1ObjectIdentifier); static TimeStampToken getTimeStampToken(Attribute attribute); static CMSSignedData getCMSSignedData(Attribute attribute); static ASN1Encodable getAsn1Encodable(Attribute attribute); static Date getTimeStampTokenGenerationTime(TimeStampToken timeStampToken); static RevocationValues getRevocationValues(ASN1Encodable encodable); static CertificateRef getCertificateRef(OtherCertID otherCertId); static PSD2QcType getPSD2QcStatement(CertificateToken certToken); static List<String> getSubjectAlternativeNames(CertificateToken certToken); static SemanticsIdentifier getSemanticsIdentifier(CertificateToken certToken);  }
@Test public void getPSD2QcStatement() { CertificateToken cert = DSSUtils.loadCertificateFromBase64EncodedString( "MIII2TCCBsGgAwIBAgIJAqog3++ziaB0MA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNVBAYTAkNaMSMwIQYDVQQDDBpJLkNBIFNTTCBFViBDQS9SU0EgMTAvMjAxNzEtMCsGA1UECgwkUHJ2bsOtIGNlcnRpZmlrYcSNbsOtIGF1dG9yaXRhLCBhLnMuMRcwFQYDVQRhDA5OVFJDWi0yNjQzOTM5NTAeFw0xOTEyMTcxNDA0MDNaFw0yMDEyMTYxNDA0MDNaMIIBBTEUMBIGA1UEAwwLY3JlZGl0YXMuY3oxETAPBgNVBAUTCDYzNDkyNTU1MRkwFwYDVQQHDBBQcmFoYSA4LCBLYXJsw61uMR0wGwYDVQQIDBRIbGF2bsOtIG3Em3N0byBQcmFoYTELMAkGA1UEBhMCQ1oxHDAaBgNVBAoME0JhbmthIENSRURJVEFTIGEucy4xFDASBgNVBAkMC1Nva29sb3Zza8OhMQ4wDAYDVQQRDAUxODYwMDEbMBkGA1UEYQwSUFNEQ1otQ05CLTYzNDkyNTU1MR0wGwYDVQQPDBRQcml2YXRlIE9yZ2FuaXphdGlvbjETMBEGCysGAQQBgjc8AgEDEwJDWjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOKZv4JkbWxjAaB/jkoQ/BS5WvItruLmQAF47D6AOZ1q6L958HmtjlXvmocttMh6f6iSOruwI9IFGOOtPvzFHOjZEcnE2L8pSyDRlV5eaLAi9JSVWYar48QrOkJWwbnX8W6LclBppU4ELPsrFS+wR2KabKOF0FffelUTtzUF9PPATElvMQlXaf0Mf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mNt311tk62YoKn6P5FBCi7uIbg7zv0o+RdLXhg=="); assertNotNull(cert); PSD2QcType psd2QcType = DSSASN1Utils.getPSD2QcStatement(cert); assertNotNull(psd2QcType); List<RoleOfPSP> rolesOfPSP = psd2QcType.getRolesOfPSP(); assertNotNull(rolesOfPSP); for (RoleOfPSP roleOfPSP : rolesOfPSP) { assertNotNull(roleOfPSP); assertNotNull(roleOfPSP.getPspOid()); assertNotNull(roleOfPSP.getPspName()); } assertNotNull(psd2QcType.getNcaName()); assertNotNull(psd2QcType.getNcaId()); CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/ec.europa.eu.crt")); assertNotNull(certificate); assertNull(DSSASN1Utils.getPSD2QcStatement(certificate)); }