Search in sources :

Example 26 with CertificateSerial

use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.

the class CrlResource method unrevoke.

@ApiOperation(notes = "Deletes a Certificate from the Revocation List", value = "unrevoke")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void unrevoke(@QueryParam("serial") String[] serialIds) throws CRLException, IOException {
    String filePath = getCrlFilePath();
    File crlFile = new File(filePath);
    try {
        List<BigInteger> serials = new LinkedList<>();
        for (CertificateSerial serial : certificateSerialCurator.listBySerialIds(serialIds)) {
            serials.add(serial.getSerial());
        }
        if (serials.size() > 0) {
            this.crlFileUtil.updateCRLFile(crlFile, null, serials);
        }
    } catch (IOException e) {
        throw new IseException(e.getMessage(), e);
    }
}
Also used : IseException(org.candlepin.common.exceptions.IseException) BigInteger(java.math.BigInteger) CertificateSerial(org.candlepin.model.CertificateSerial) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 27 with CertificateSerial

use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.

the class CdnResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO.
 * This method will not set the ID field.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
private void populateEntity(Cdn entity, CdnDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the Cdn model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the Cdn dto is null");
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getUrl() != null) {
        entity.setUrl(dto.getUrl());
    }
    if (dto.getCertificate() != null) {
        CertificateDTO certDTO = dto.getCertificate();
        CdnCertificate cdnCert;
        if (certDTO.getKey() != null && certDTO.getCert() != null) {
            cdnCert = new CdnCertificate();
            cdnCert.setCert(certDTO.getCert());
            cdnCert.setKey(certDTO.getKey());
            if (certDTO.getSerial() != null) {
                CertificateSerialDTO certSerialDTO = certDTO.getSerial();
                CertificateSerial certSerial = new CertificateSerial();
                certSerial.setExpiration(certSerialDTO.getExpiration());
                if (certSerialDTO.getSerial() != null) {
                    certSerial.setSerial(certSerialDTO.getSerial().longValue());
                }
                if (certSerialDTO.isCollected() != null) {
                    certSerial.setCollected(certSerialDTO.isCollected());
                }
                if (certSerialDTO.isRevoked() != null) {
                    certSerial.setRevoked(certSerialDTO.isRevoked());
                }
                cdnCert.setSerial(certSerial);
            }
            entity.setCertificate(cdnCert);
        } else {
            throw new BadRequestException(i18n.tr("cdn certificate has null key or cert."));
        }
    }
}
Also used : CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CertificateSerial(org.candlepin.model.CertificateSerial) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Example 28 with CertificateSerial

use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.

the class EntitlementTranslatorTest method initSourceObject.

@Override
protected Entitlement initSourceObject() {
    Entitlement source = new Entitlement();
    source.setId("ent-id");
    source.setQuantity(1);
    source.setDeletedFromPool(false);
    source.setOwner(this.ownerTranslatorTest.initSourceObject());
    source.setPool(this.poolTranslatorTest.initSourceObject());
    HashSet<EntitlementCertificate> certs = new HashSet<>();
    EntitlementCertificate entCert = new EntitlementCertificate();
    entCert.setId("ent-cert-id");
    entCert.setEntitlement(source);
    entCert.setKey("ent-cert-key");
    entCert.setCert("ent-cert-cert");
    entCert.setSerial(new CertificateSerial());
    certs.add(entCert);
    source.setCertificates(certs);
    Consumer consumer = new Consumer();
    consumer.setUuid("consumer-uuid");
    source.setConsumer(consumer);
    source.setEndDate(new Date());
    source.setStartDate(new Date());
    return source;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) CertificateSerial(org.candlepin.model.CertificateSerial) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet)

Example 29 with CertificateSerial

use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.

the class StubEntitlementCertServiceAdapter method generateEntitlementCerts.

@Override
public Map<String, EntitlementCertificate> generateEntitlementCerts(Consumer consumer, Map<String, PoolQuantity> poolQuantityMap, Map<String, Entitlement> entitlements, Map<String, Product> products, boolean save) throws GeneralSecurityException, IOException {
    Map<String, EntitlementCertificate> result = new HashMap<>();
    for (Entry<String, Entitlement> entry : entitlements.entrySet()) {
        Entitlement entitlement = entry.getValue();
        Product product = products.get(entry.getKey());
        log.debug("Generating entitlement cert for:");
        log.debug("   consumer: " + consumer.getUuid());
        log.debug("   product: " + product.getUuid());
        log.debug("   end date: " + entitlement.getEndDate());
        EntitlementCertificate cert = new EntitlementCertificate();
        CertificateSerial serial = new CertificateSerial(entitlement.getEndDate());
        serialCurator.create(serial);
        cert.setSerial(serial);
        cert.setKeyAsBytes(("---- STUB KEY -----" + Math.random()).getBytes());
        cert.setCertAsBytes(("---- STUB CERT -----" + Math.random()).getBytes());
        cert.setEntitlement(entitlement);
        entitlement.getCertificates().add(cert);
        log.debug("Generated cert: " + serial.getId());
        log.debug("Key: " + cert.getKey());
        log.debug("Cert: " + cert.getCert());
        if (save) {
            cert = entCertCurator.create(cert);
        }
        result.put(entry.getKey(), cert);
    }
    return result;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) CertificateSerial(org.candlepin.model.CertificateSerial) Entitlement(org.candlepin.model.Entitlement)

Example 30 with CertificateSerial

use of org.candlepin.model.CertificateSerial in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testDetachedEntitlementDataNotAddedToCertV1.

@Test
public void testDetachedEntitlementDataNotAddedToCertV1() throws Exception {
    KeyPair keyPair = new BouncyCastlePKIUtility(null, null, null).generateNewKeyPair();
    when(keyPairCurator.getConsumerKeyPair(any(Consumer.class))).thenReturn(keyPair);
    when(mockedPKI.getPemEncoded(any(X509Certificate.class))).thenReturn("".getBytes());
    when(mockedPKI.getPemEncoded(any(Key.class))).thenReturn("".getBytes());
    final CertificateSerial serial = mock(CertificateSerial.class);
    when(serial.getId()).thenReturn(1L);
    pool.setId("poolId");
    doAnswer(new Answer<Map<String, CertificateSerial>>() {

        @Override
        public Map<String, CertificateSerial> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            Map<String, CertificateSerial> map = (Map<String, CertificateSerial>) args[0];
            map.put("poolId", serial);
            return null;
        }
    }).when(serialCurator).saveOrUpdateAll(anyMap());
    EntitlementCertificate cert = certServiceAdapter.generateEntitlementCert(entitlement, product);
    assertTrue(!cert.getCert().contains("ENTITLEMENT DATA"));
}
Also used : KeyPair(java.security.KeyPair) PEMKeyPair(org.bouncycastle.openssl.PEMKeyPair) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Matchers.anyString(org.mockito.Matchers.anyString) BouncyCastlePKIUtility(org.candlepin.pki.impl.BouncyCastlePKIUtility) X509Certificate(java.security.cert.X509Certificate) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Key(java.security.Key) Test(org.junit.Test)

Aggregations

CertificateSerial (org.candlepin.model.CertificateSerial)46 Date (java.util.Date)23 Test (org.junit.Test)21 Consumer (org.candlepin.model.Consumer)16 IdentityCertificate (org.candlepin.model.IdentityCertificate)16 Entitlement (org.candlepin.model.Entitlement)11 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)11 HashSet (java.util.HashSet)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)9 Owner (org.candlepin.model.Owner)9 File (java.io.File)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 KeyPair (java.security.KeyPair)7 X509Certificate (java.security.cert.X509Certificate)7 ZipInputStream (java.util.zip.ZipInputStream)7 Principal (org.candlepin.auth.Principal)7 ConsumerType (org.candlepin.model.ConsumerType)7 HashMap (java.util.HashMap)6 KeyPair (org.candlepin.model.KeyPair)6