Java Code Examples for org.bouncycastle.asn1.x509.qualified.QCStatement

The following examples show how to use org.bouncycastle.asn1.x509.qualified.QCStatement. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: dss   Source File: DSSASN1Utils.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Get the list of all QCStatement Ids that are present in the certificate.
 * (As per ETSI EN 319 412-5 V2.1.1)
 * 
 * @param certToken
 *            the certificate
 * @return the list of QC Statements oids
 */
public static List<String> getQCStatementsIdList(final CertificateToken certToken) {
	final List<String> extensionIdList = new ArrayList<>();
	final byte[] qcStatement = certToken.getCertificate().getExtensionValue(Extension.qCStatements.getId());
	if (Utils.isArrayNotEmpty(qcStatement)) {
		try {
			final ASN1Sequence seq = getAsn1SequenceFromDerOctetString(qcStatement);
			// Sequence of QCStatement
			for (int ii = 0; ii < seq.size(); ii++) {
				final QCStatement statement = QCStatement.getInstance(seq.getObjectAt(ii));
				extensionIdList.add(statement.getStatementId().getId());
			}
		} catch (Exception e) {
			LOG.warn("Unable to parse the qCStatements extension '{}' : {}", Utils.toBase64(qcStatement), e.getMessage(), e);
		}
	}
	return extensionIdList;
}
 
Example 2
Source Project: dss   Source File: DSSASN1Utils.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static List<String> getQCLegislations(CertificateToken certToken) {
	final List<String> result = new ArrayList<>();
	final byte[] qcStatement = certToken.getCertificate().getExtensionValue(Extension.qCStatements.getId());
	if (Utils.isArrayNotEmpty(qcStatement)) {
		try {
			final ASN1Sequence seq = getAsn1SequenceFromDerOctetString(qcStatement);
			// Sequence of QCStatement
			for (int ii = 0; ii < seq.size(); ii++) {
				final QCStatement statement = QCStatement.getInstance(seq.getObjectAt(ii));
				if (QC_LEGISLATION_OID.equals(statement.getStatementId().getId())) {
					ASN1Sequence sequenceLegislation = ASN1Sequence.getInstance(statement.getStatementInfo());
					for (int jj = 0; jj < sequenceLegislation.size(); jj++) {
						result.add(getString(sequenceLegislation.getObjectAt(jj)));
					}
					
				}
			}
		} catch (Exception e) {
			LOG.warn("Unable to parse the qCStatements extension '{}' : {}", Utils.toBase64(qcStatement), e.getMessage(), e);
		}
	}
	return result;
}
 
Example 3
Source Project: dss   Source File: DSSASN1Utils.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static SemanticsIdentifier getSemanticsIdentifier(CertificateToken certToken) {
	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 (RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v2.equals(statement.getStatementId())) {
					SemanticsInformation semanticsInfo = SemanticsInformation.getInstance(statement.getStatementInfo());
					if (semanticsInfo != null && semanticsInfo.getSemanticsIdentifier() != null) {
						return SemanticsIdentifier.fromOid(semanticsInfo.getSemanticsIdentifier().getId());
					}
				}
			}
		} catch (Exception e) {
			LOG.warn("Unable to extract the SemanticsIdentifier", e);
		}
	}
	return null;
}
 
Example 4
Source Project: XS2A-Sandbox   Source File: CertificateService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new base64 encoded X509 certificate for authentication at the XS2A API with the
 * corresponding private key and meta data.
 *
 * @param certificateRequest data needed for certificate generation
 * @return CertificateResponse base64 encoded cert + private key
 */
public CertificateResponse newCertificate(CertificateRequest certificateRequest) {
    SubjectData subjectData = generateSubjectData(certificateRequest);
    QCStatement qcStatement = generateQcStatement(certificateRequest);

    X509Certificate cert = generateCertificate(subjectData, qcStatement);

    return CertificateResponse.builder()
               .privateKey(exportToString(subjectData.getPrivateKey()))
               .encodedCert(exportToString(cert))
               .build();
}
 
Example 5
Source Project: XS2A-Sandbox   Source File: CertificateService.java    License: Apache License 2.0 5 votes vote down vote up
private QCStatement generateQcStatement(CertificateRequest certificateRequest) {
    NcaName ncaName = getNcaNameFromIssuerData();
    NcaId ncaId = getNcaIdFromIssuerData();
    ASN1Encodable qcStatementInfo = createQcInfo(
        RolesOfPsp.fromCertificateRequest(certificateRequest), ncaName, ncaId
    );

    return new QCStatement(ETSI_QC_STATEMENT, qcStatementInfo);
}
 
Example 6
Source Project: dss   Source File: DSSASN1Utils.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the list of all QCType Ids that are present in the certificate.
 * (As per ETSI EN 319 412-5 V2.1.1)
 * 
 * @param certToken
 *            the certificate
 * @return the list of QCTypes oids
 */
public static List<String> getQCTypesIdList(final CertificateToken certToken) {
	final List<String> qcTypesIdList = new ArrayList<>();
	final byte[] qcStatement = certToken.getCertificate().getExtensionValue(Extension.qCStatements.getId());
	if (Utils.isArrayNotEmpty(qcStatement)) {
		try {
			final ASN1Sequence seq = getAsn1SequenceFromDerOctetString(qcStatement);
			// Sequence of QCStatement
			for (int ii = 0; ii < seq.size(); ii++) {
				final QCStatement statement = QCStatement.getInstance(seq.getObjectAt(ii));
				if (QC_TYPE_STATEMENT_OID.equals(statement.getStatementId().getId())) {
					final ASN1Encodable qcTypeInfo1 = statement.getStatementInfo();
					if (qcTypeInfo1 instanceof ASN1Sequence) {
						final ASN1Sequence qcTypeInfo = (ASN1Sequence) qcTypeInfo1;
						for (int jj = 0; jj < qcTypeInfo.size(); jj++) {
							final ASN1Encodable e1 = qcTypeInfo.getObjectAt(jj);
							if (e1 instanceof ASN1ObjectIdentifier) {
								final ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e1;
								qcTypesIdList.add(oid.getId());
							} else {
								LOG.warn("ASN1Sequence in QcTypes does not contain ASN1ObjectIdentifer, but {}",
										e1.getClass().getName());
							}
						}
					} else {
						LOG.warn("QcTypes not an ASN1Sequence, but {}", qcTypeInfo1.getClass().getName());
					}
				}
			}
		} catch (Exception e) {
			LOG.warn("Unable to parse the qCStatements extension '{}' : {}", Utils.toBase64(qcStatement), e.getMessage(), e);
		}
	}

	return qcTypesIdList;
}
 
Example 7
Source Project: dss   Source File: DSSASN1Utils.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extract the PSD2 QcStatement informations for a given certificate
 * 
 * @param certToken the certificate
 * @return an instance of {@code PSD2QcType} or null
 */
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;
}
 
Example 8
Source Project: xipki   Source File: QcStatementOption.java    License: Apache License 2.0 4 votes vote down vote up
public QcStatementOption(QCStatement statement) {
  this.statement = Args.notNull(statement, "statement");
  this.statementId = null;
  this.monetaryValueOption = null;
}
 
Example 9
Source Project: xipki   Source File: QcStatementOption.java    License: Apache License 2.0 4 votes vote down vote up
public QCStatement getStatement() {
  return statement;
}