Search in sources :

Example 1 with RDNAttribute

use of de.trustable.ca3s.core.domain.RDNAttribute in project ca3sCore by kuehne-trustable-de.

the class RDNAttributeResourceIT method createRDNAttribute.

@Test
@Transactional
public void createRDNAttribute() throws Exception {
    int databaseSizeBeforeCreate = rDNAttributeRepository.findAll().size();
    // Create the RDNAttribute
    restRDNAttributeMockMvc.perform(post("/api/rdn-attributes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(rDNAttribute))).andExpect(status().isCreated());
    // Validate the RDNAttribute in the database
    List<RDNAttribute> rDNAttributeList = rDNAttributeRepository.findAll();
    assertThat(rDNAttributeList).hasSize(databaseSizeBeforeCreate + 1);
    RDNAttribute testRDNAttribute = rDNAttributeList.get(rDNAttributeList.size() - 1);
    assertThat(testRDNAttribute.getAttributeType()).isEqualTo(DEFAULT_ATTRIBUTE_TYPE);
    assertThat(testRDNAttribute.getAttributeValue()).isEqualTo(DEFAULT_ATTRIBUTE_VALUE);
}
Also used : RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RDNAttribute

use of de.trustable.ca3s.core.domain.RDNAttribute in project ca3sCore by kuehne-trustable-de.

the class CaCmpConnector method buildCertRequest.

/**
 * @param certReqId
 * @param csr
 * @param hmacSecret
 * @return PKIMessage
 * @throws GeneralSecurityException
 */
public PKIMessage buildCertRequest(long certReqId, final CSR csr, final String hmacSecret) throws GeneralSecurityException {
    // read the pem csr and verify the signature
    PKCS10CertificationRequest p10Req;
    try {
        p10Req = cryptoUtil.parseCertificateRequest(csr.getCsrBase64()).getP10Req();
    } catch (IOException e) {
        LOGGER.error("parsing csr", e);
        throw new GeneralSecurityException(e.getMessage());
    }
    List<RDN> rdnList = new ArrayList<>();
    for (de.trustable.ca3s.core.domain.RDN rdnDao : csr.getRdns()) {
        LOGGER.debug("rdnDao : " + rdnDao.getRdnAttributes());
        List<AttributeTypeAndValue> attrTVList = new ArrayList<AttributeTypeAndValue>();
        if (rdnDao != null && rdnDao.getRdnAttributes() != null) {
            for (RDNAttribute rdnAttr : rdnDao.getRdnAttributes()) {
                ASN1ObjectIdentifier aoi = new ASN1ObjectIdentifier(rdnAttr.getAttributeType());
                ASN1Encodable ae = new DERUTF8String(rdnAttr.getAttributeValue());
                AttributeTypeAndValue attrTV = new AttributeTypeAndValue(aoi, ae);
                attrTVList.add(attrTV);
            }
        }
        RDN rdn = new RDN(attrTVList.toArray(new AttributeTypeAndValue[attrTVList.size()]));
        LOGGER.debug("rdn : " + rdn.size() + " elements");
        rdnList.add(rdn);
    }
    X500Name subjectDN = new X500Name(rdnList.toArray(new RDN[rdnList.size()]));
    LOGGER.debug("subjectDN : " + subjectDN);
    Collection<Extension> certExtList = new ArrayList<>();
    // copy CSR attributes to Extension list
    for (Attribute attribute : p10Req.getAttributes()) {
        for (ASN1Encodable asn1Encodable : attribute.getAttributeValues()) {
            if (asn1Encodable != null) {
                try {
                    Extensions extensions = Extensions.getInstance(asn1Encodable);
                    for (ASN1ObjectIdentifier oid : extensions.getExtensionOIDs()) {
                        LOGGER.debug("copying oid '" + oid.toString() + "' from csr to PKIMessage");
                        certExtList.add(extensions.getExtension(oid));
                    }
                } catch (IllegalArgumentException iae) {
                    LOGGER.debug("processing asn1 value  '" + asn1Encodable + "' caused exception", iae);
                }
            }
        }
    }
    final SubjectPublicKeyInfo keyInfo = p10Req.getSubjectPublicKeyInfo();
    return cryptoUtil.buildCertRequest(certReqId, subjectDN, certExtList, keyInfo, hmacSecret);
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute) CsrAttribute(de.trustable.ca3s.core.domain.CsrAttribute) Attribute(org.bouncycastle.asn1.pkcs.Attribute) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) X500Name(org.bouncycastle.asn1.x500.X500Name) Extensions(org.bouncycastle.asn1.x509.Extensions) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue) Extension(org.bouncycastle.asn1.x509.Extension) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) RDN(org.bouncycastle.asn1.x500.RDN) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 3 with RDNAttribute

use of de.trustable.ca3s.core.domain.RDNAttribute in project ca3sCore by kuehne-trustable-de.

the class RDNAttributeResourceIT method updateRDNAttribute.

@Test
@Transactional
public void updateRDNAttribute() throws Exception {
    // Initialize the database
    rDNAttributeService.save(rDNAttribute);
    int databaseSizeBeforeUpdate = rDNAttributeRepository.findAll().size();
    // Update the rDNAttribute
    RDNAttribute updatedRDNAttribute = rDNAttributeRepository.findById(rDNAttribute.getId()).get();
    // Disconnect from session so that the updates on updatedRDNAttribute are not directly saved in db
    em.detach(updatedRDNAttribute);
    updatedRDNAttribute.attributeType(UPDATED_ATTRIBUTE_TYPE).attributeValue(UPDATED_ATTRIBUTE_VALUE);
    restRDNAttributeMockMvc.perform(put("/api/rdn-attributes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedRDNAttribute))).andExpect(status().isOk());
    // Validate the RDNAttribute in the database
    List<RDNAttribute> rDNAttributeList = rDNAttributeRepository.findAll();
    assertThat(rDNAttributeList).hasSize(databaseSizeBeforeUpdate);
    RDNAttribute testRDNAttribute = rDNAttributeList.get(rDNAttributeList.size() - 1);
    assertThat(testRDNAttribute.getAttributeType()).isEqualTo(UPDATED_ATTRIBUTE_TYPE);
    assertThat(testRDNAttribute.getAttributeValue()).isEqualTo(UPDATED_ATTRIBUTE_VALUE);
}
Also used : RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with RDNAttribute

use of de.trustable.ca3s.core.domain.RDNAttribute in project ca3sCore by kuehne-trustable-de.

the class RDNAttributeResource method createRDNAttribute.

/**
 * {@code POST  /rdn-attributes} : Create a new rDNAttribute.
 *
 * @param rDNAttribute the rDNAttribute to create.
 * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new rDNAttribute, or with status {@code 400 (Bad Request)} if the rDNAttribute has already an ID.
 * @throws URISyntaxException if the Location URI syntax is incorrect.
 */
@PostMapping("/rdn-attributes")
public ResponseEntity<RDNAttribute> createRDNAttribute(@Valid @RequestBody RDNAttribute rDNAttribute) throws URISyntaxException {
    log.debug("REST request to save RDNAttribute : {}", rDNAttribute);
    if (rDNAttribute.getId() != null) {
        throw new BadRequestAlertException("A new rDNAttribute cannot already have an ID", ENTITY_NAME, "idexists");
    }
    RDNAttribute result = rDNAttributeService.save(rDNAttribute);
    return ResponseEntity.created(new URI("/api/rdn-attributes/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(de.trustable.ca3s.core.web.rest.errors.BadRequestAlertException) RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute) URI(java.net.URI)

Example 5 with RDNAttribute

use of de.trustable.ca3s.core.domain.RDNAttribute in project ca3sCore by kuehne-trustable-de.

the class RDNAttributeResource method updateRDNAttribute.

/**
 * {@code PUT  /rdn-attributes} : Updates an existing rDNAttribute.
 *
 * @param rDNAttribute the rDNAttribute to update.
 * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated rDNAttribute,
 * or with status {@code 400 (Bad Request)} if the rDNAttribute is not valid,
 * or with status {@code 500 (Internal Server Error)} if the rDNAttribute couldn't be updated.
 * @throws URISyntaxException if the Location URI syntax is incorrect.
 */
@PutMapping("/rdn-attributes")
public ResponseEntity<RDNAttribute> updateRDNAttribute(@Valid @RequestBody RDNAttribute rDNAttribute) throws URISyntaxException {
    log.debug("REST request to update RDNAttribute : {}", rDNAttribute);
    if (rDNAttribute.getId() == null) {
        throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
    }
    RDNAttribute result = rDNAttributeService.save(rDNAttribute);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, rDNAttribute.getId().toString())).body(result);
}
Also used : BadRequestAlertException(de.trustable.ca3s.core.web.rest.errors.BadRequestAlertException) RDNAttribute(de.trustable.ca3s.core.domain.RDNAttribute)

Aggregations

RDNAttribute (de.trustable.ca3s.core.domain.RDNAttribute)5 BadRequestAlertException (de.trustable.ca3s.core.web.rest.errors.BadRequestAlertException)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CsrAttribute (de.trustable.ca3s.core.domain.CsrAttribute)1 IOException (java.io.IOException)1 URI (java.net.URI)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)1 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)1 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)1 Attribute (org.bouncycastle.asn1.pkcs.Attribute)1 AttributeTypeAndValue (org.bouncycastle.asn1.x500.AttributeTypeAndValue)1 RDN (org.bouncycastle.asn1.x500.RDN)1 X500Name (org.bouncycastle.asn1.x500.X500Name)1 Extension (org.bouncycastle.asn1.x509.Extension)1 Extensions (org.bouncycastle.asn1.x509.Extensions)1 SubjectPublicKeyInfo (org.bouncycastle.asn1.x509.SubjectPublicKeyInfo)1