Search in sources :

Example 1 with X509ByteExtensionWrapper

use of org.candlepin.pki.X509ByteExtensionWrapper in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testContentExtension.

@Test
public void testContentExtension() throws IOException {
    Set<Product> products = new HashSet<>();
    products.add(product);
    product.setProductContent(null);
    for (Content content : superContent) {
        product.addContent(content, false);
    }
    consumer.setFact("system.certificate_version", "3.3");
    consumer.setFact("uname.machine", "x86_64");
    Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(product, getProductModels(product, products, "prefix", entitlement), "prefix", null);
    Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
    for (X509ByteExtensionWrapper ext : byteExtensions) {
        byteMap.put(ext.getOid(), ext);
    }
    assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
    List<String> contentSetList = new ArrayList<>();
    try {
        contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEquals(7, contentSetList.size());
    for (String url : testUrls) {
        assertTrue(contentSetList.contains("/prefix" + url));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with X509ByteExtensionWrapper

use of org.candlepin.pki.X509ByteExtensionWrapper in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testContentExtensionLargeSet.

@Test
public void testContentExtensionLargeSet() throws IOException {
    Set<Product> products = new HashSet<>();
    Product extremeProduct = TestUtil.createProduct("12345", "a product");
    extremeProduct.setAttribute(Product.Attributes.VERSION, "version");
    extremeProduct.setAttribute(Product.Attributes.VARIANT, "variant");
    extremeProduct.setAttribute(Product.Attributes.TYPE, "SVC");
    extremeProduct.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
    products.add(extremeProduct);
    for (int i = 0; i < 550; i++) {
        String url = "/content/dist" + i + "/jboss/source" + i;
        Content content = createContent(CONTENT_NAME + i, CONTENT_ID + i, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, url, CONTENT_GPG_URL, ARCH_LABEL);
        extremeProduct.addContent(content, false);
    }
    consumer.setUuid("test-consumer");
    consumer.setFact("system.certificate_version", "3.3");
    consumer.setFact("uname.machine", "x86_64");
    certServiceAdapter.prepareV3Extensions();
    Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(extremeProduct, getProductModels(extremeProduct, products, "prefix", entitlement), "prefix", null);
    Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
    for (X509ByteExtensionWrapper ext : byteExtensions) {
        byteMap.put(ext.getOid(), ext);
    }
    assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
    List<String> contentSetList = new ArrayList<>();
    try {
        contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEquals(550, contentSetList.size());
    for (int i = 0; i < 550; i++) {
        String url = "/content/dist" + i + "/jboss/source" + i;
        assertTrue(contentSetList.contains("/prefix" + url));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with X509ByteExtensionWrapper

use of org.candlepin.pki.X509ByteExtensionWrapper in project candlepin by candlepin.

the class DefaultEntitlementCertServiceAdapterTest method testContentExtensionConsumerNoArchFact.

@Test
public void testContentExtensionConsumerNoArchFact() throws IOException {
    Set<Product> products = new HashSet<>();
    products.add(product);
    // set of content for an incompatible arch, which should
    // be in the cert, since this consumer has no arch fact therefore
    // should match everything
    String wrongArches = "s390";
    String noArchUrl = "/some/place/nice";
    Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, noArchUrl, CONTENT_GPG_URL, wrongArches);
    product.setProductContent(null);
    for (Content content : superContent) {
        product.addContent(content, false);
    }
    product.addContent(wrongArchContent, false);
    consumer.setFact("system.certificate_version", "3.3");
    Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(product, getProductModels(product, products, "prefix", entitlement), "prefix", null);
    Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
    for (X509ByteExtensionWrapper ext : byteExtensions) {
        byteMap.put(ext.getOid(), ext);
    }
    assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
    List<String> contentSetList = new ArrayList<>();
    try {
        contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEquals(8, contentSetList.size());
    for (String url : testUrls) {
        assertTrue(contentSetList.contains("/prefix" + url));
    }
    // verify our new wrong arch url is in there
    assertTrue(contentSetList.contains("/prefix" + noArchUrl));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with X509ByteExtensionWrapper

use of org.candlepin.pki.X509ByteExtensionWrapper in project candlepin by candlepin.

the class X509V3ExtensionUtil method getByteExtensions.

public Set<X509ByteExtensionWrapper> getByteExtensions(Product sku, List<org.candlepin.model.dto.Product> productModels, String contentPrefix, Map<String, EnvironmentContent> promotedContent) throws IOException {
    Set<X509ByteExtensionWrapper> toReturn = new LinkedHashSet<>();
    EntitlementBody eb = createEntitlementBodyContent(sku, productModels, contentPrefix, promotedContent);
    X509ByteExtensionWrapper bodyExtension = new X509ByteExtensionWrapper(OIDUtil.REDHAT_OID + "." + OIDUtil.TOPLEVEL_NAMESPACES.get(OIDUtil.ENTITLEMENT_DATA_KEY), false, retrieveContentValue(eb));
    toReturn.add(bodyExtension);
    return toReturn;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) EntitlementBody(org.candlepin.model.dto.EntitlementBody)

Example 5 with X509ByteExtensionWrapper

use of org.candlepin.pki.X509ByteExtensionWrapper in project candlepin by candlepin.

the class UeberCertificateGenerator method createX509Certificate.

private X509Certificate createX509Certificate(UeberCertData data, BigInteger serialNumber, KeyPair keyPair) throws GeneralSecurityException, IOException {
    Set<X509ByteExtensionWrapper> byteExtensions = new LinkedHashSet<>();
    Set<X509ExtensionWrapper> extensions = new LinkedHashSet<>();
    extensions.addAll(extensionUtil.productExtensions(data.getProduct()));
    extensions.addAll(extensionUtil.contentExtensions(data.getProduct().getProductContent(), null, new HashMap<>(), new Consumer(), data.getProduct()));
    extensions.addAll(extensionUtil.subscriptionExtensions(data.getEntitlement().getPool()));
    extensions.addAll(extensionUtil.entitlementExtensions(data.getEntitlement().getQuantity()));
    extensions.addAll(extensionUtil.consumerExtensions(data.getConsumer()));
    if (log.isDebugEnabled()) {
        log.debug("Ueber certificate extensions for Owner: {}", data.getOwner().getKey());
        for (X509ExtensionWrapper eWrapper : extensions) {
            log.debug("Extension {} with value {}", eWrapper.getOid(), eWrapper.getValue());
        }
    }
    String dn = "O=" + data.getOwner().getKey();
    return this.pki.createX509Certificate(dn, extensions, byteExtensions, data.getStartDate(), data.getEndDate(), keyPair, serialNumber, null);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper)

Aggregations

X509ByteExtensionWrapper (org.candlepin.pki.X509ByteExtensionWrapper)10 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 EnvironmentContent (org.candlepin.model.EnvironmentContent)6 Product (org.candlepin.model.Product)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 GeneralSecurityException (java.security.GeneralSecurityException)5 CertificateExpiredException (java.security.cert.CertificateExpiredException)5 HashSet (java.util.HashSet)5 Content (org.candlepin.model.Content)5 CertificateSizeException (org.candlepin.util.CertificateSizeException)5 Test (org.junit.Test)5 ExpectedException (org.junit.rules.ExpectedException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ProductContent (org.candlepin.model.ProductContent)4 X509ExtensionWrapper (org.candlepin.pki.X509ExtensionWrapper)4 X509Certificate (java.security.cert.X509Certificate)3 LinkedHashSet (java.util.LinkedHashSet)3 Calendar (java.util.Calendar)1