Search in sources :

Example 1 with X509ExtensionWrapper

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

the class DefaultEntitlementCertServiceAdapter method prepareV3Extensions.

public Set<X509ExtensionWrapper> prepareV3Extensions() {
    Set<X509ExtensionWrapper> result = v3extensionUtil.getExtensions();
    X509ExtensionWrapper typeExtension = new X509ExtensionWrapper(OIDUtil.REDHAT_OID + "." + OIDUtil.TOPLEVEL_NAMESPACES.get(OIDUtil.ENTITLEMENT_TYPE_KEY), false, "Basic");
    result.add(typeExtension);
    return result;
}
Also used : X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper)

Example 2 with X509ExtensionWrapper

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

the class DefaultContentAccessCertServiceAdapter method prepareV3Extensions.

public Set<X509ExtensionWrapper> prepareV3Extensions() {
    Set<X509ExtensionWrapper> result = v3extensionUtil.getExtensions();
    X509ExtensionWrapper typeExtension = new X509ExtensionWrapper(OIDUtil.REDHAT_OID + "." + OIDUtil.TOPLEVEL_NAMESPACES.get(OIDUtil.ENTITLEMENT_TYPE_KEY), false, "OrgLevel");
    result.add(typeExtension);
    return result;
}
Also used : X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper)

Example 3 with X509ExtensionWrapper

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

the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsNoCompatibleArch.

@Test
public void testPrepareV1ExtensionsNoCompatibleArch() throws IOException, GeneralSecurityException {
    Set<Product> products = new HashSet<>();
    // product with no compatible content, but marked as 'ALL' arch
    Product wrongArchProduct = TestUtil.createProduct("12345", "a product");
    wrongArchProduct.setAttribute(Product.Attributes.VERSION, "version");
    wrongArchProduct.setAttribute(Product.Attributes.VARIANT, "variant");
    wrongArchProduct.setAttribute(Product.Attributes.TYPE, "SVC");
    wrongArchProduct.setAttribute(Product.Attributes.ARCHITECTURE, "ALL");
    // no x86_64, ie ARCH_LABEL
    String wrongArches = "s390x,s390,ppc64,ia64";
    Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, CONTENT_URL, CONTENT_GPG_URL, wrongArches);
    wrongArchProduct.addContent(wrongArchContent, false);
    products.add(wrongArchProduct);
    setupEntitlements(ARCH_LABEL, "1.0");
    Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null);
    Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions);
    Map<String, String> extMap = getEncodedContentMap(extensions);
    assertFalse(isEncodedContentValid(map));
    assertFalse(map.containsKey(CONTENT_URL));
    // make sure we don't set content type to "null"
    assertFalse(extMapHasContentType(kickstartContent, extMap, "null"));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) Product(org.candlepin.model.Product) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with X509ExtensionWrapper

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

the class DefaultEntitlementCertServiceAdapterTest method testPrepareV1ExtensionsKnownAndUnknownContentTypes.

@Test
public void testPrepareV1ExtensionsKnownAndUnknownContentTypes() throws IOException, GeneralSecurityException {
    Set<Product> products = new HashSet<>();
    // product with a kickstart content
    Product product = TestUtil.createProduct("12345", "a product");
    product.setAttribute(Product.Attributes.VERSION, "version");
    product.setAttribute(Product.Attributes.VARIANT, "variant");
    product.setAttribute(Product.Attributes.TYPE, "SVC");
    product.setAttribute(Product.Attributes.ARCHITECTURE, ARCH_LABEL);
    product.addContent(content, false);
    product.addContent(fileContent, false);
    product.addContent(kickstartContent, false);
    product.addContent(unknownTypeContent, false);
    products.add(product);
    setupEntitlements(ARCH_LABEL, "1.0");
    Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV1Extensions(products, pool, consumer, entitlement.getQuantity(), "", null);
    Map<String, X509ExtensionWrapper> map = getEncodedContent(extensions);
    Map<String, String> extMap = getEncodedContentMap(extensions);
    // we skip content of unknown type for v1 certs, but other
    // content should still get added
    assertTrue(isEncodedContentValid(map));
    // other contents are in there
    assertTrue(map.containsKey(CONTENT_URL));
    // unknown is not
    assertFalse(map.containsKey(CONTENT_TYPE_UNKNOWN));
    assertFalse(map.containsKey(CONTENT_URL_UNKNOWN_TYPE));
    // we have a yum,file, and kickstart content and
    // we do not have any unknown content types
    assertTrue(extMapHasContentType(content, extMap, "1"));
    assertTrue(extMapHasContentType(fileContent, extMap, "2"));
    assertTrue(extMapHasContentType(kickstartContent, extMap, "3"));
    assertFalse(extMapHasContentType(unknownTypeContent, extMap, "1"));
    assertFalse(extMapHasContentType(unknownTypeContent, extMap, "2"));
    assertFalse(extMapHasContentType(unknownTypeContent, extMap, "3"));
    // make sure we don't set content type to "null"
    assertFalse(extMapHasContentType(unknownTypeContent, extMap, "null"));
}
Also used : Product(org.candlepin.model.Product) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with X509ExtensionWrapper

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

the class DefaultEntitlementCertServiceAdapterTest method testPrepareV3EntitlementData.

@Test
public void testPrepareV3EntitlementData() throws IOException, GeneralSecurityException {
    Set<Product> products = new HashSet<>();
    products.add(product);
    consumer.setFact("system.certificate_version", "3.3");
    consumer.setFact("uname.machine", "x86_64");
    Product product = pool.getProduct();
    product.setAttribute(Product.Attributes.WARNING_PERIOD, "20");
    product.setAttribute(Product.Attributes.SOCKETS, "4");
    product.setAttribute(Product.Attributes.RAM, "8");
    product.setAttribute(Product.Attributes.CORES, "4");
    product.setAttribute(Product.Attributes.MANAGEMENT_ENABLED, "true");
    product.setAttribute(Product.Attributes.STACKING_ID, "45678");
    pool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    product.setAttribute(Product.Attributes.SUPPORT_LEVEL, "slevel");
    product.setAttribute(Product.Attributes.SUPPORT_TYPE, "stype");
    pool.setAccountNumber("account1");
    pool.setContractNumber("contract1");
    pool.setOrderNumber("order1");
    for (ProductContent pc : product.getProductContent()) {
        pc.setEnabled(false);
    }
    Set<X509ExtensionWrapper> extensions = certServiceAdapter.prepareV3Extensions();
    Map<String, X509ExtensionWrapper> map = new HashMap<>();
    for (X509ExtensionWrapper ext : extensions) {
        map.put(ext.getOid(), ext);
    }
    assertTrue(map.containsKey("1.3.6.1.4.1.2312.9.6"));
    assertEquals(map.get("1.3.6.1.4.1.2312.9.6").getValue(), ("3.3"));
    byte[] payload = v3extensionUtil.createEntitlementDataPayload(getProductModels(product, products, "prefix", entitlement), consumer, pool, entitlement.getQuantity());
    String stringValue = "";
    try {
        stringValue = processPayload(payload);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Map<String, Object> data = (Map<String, Object>) Util.fromJson(stringValue, Map.class);
    assertEquals(data.get("consumer"), "test-consumer");
    assertEquals(data.get("quantity"), 10);
    Map<String, Object> subs = (Map<String, Object>) data.get("subscription");
    assertEquals(subs.get("sku"), subscription.getProduct().getId());
    assertEquals(subs.get("name"), subscription.getProduct().getName());
    assertEquals(subs.get("warning"), 20);
    assertEquals(subs.get("sockets"), 4);
    assertEquals(subs.get("ram"), 8);
    assertEquals(subs.get("cores"), 4);
    assertTrue((Boolean) subs.get("management"));
    assertEquals(subs.get("stacking_id"), "45678");
    assertTrue((Boolean) subs.get("virt_only"));
    Map<String, Object> service = (Map<String, Object>) subs.get("service");
    assertEquals(service.get("level"), "slevel");
    assertEquals(service.get("type"), "stype");
    Map<String, Object> order = (Map<String, Object>) data.get("order");
    assertEquals(order.get("number"), pool.getOrderNumber());
    assertTrue(((Integer) order.get("quantity")).intValue() == subscription.getQuantity());
    assertNotNull(order.get("start"));
    assertNotNull(order.get("end"));
    // assertEquals(order.get("contract"), subscription.getContractNumber());
    // assertEquals(order.get("account"), subscription.getAccountNumber());
    List<Map<String, Object>> prods = (List<Map<String, Object>>) data.get("products");
    List<Map<String, Object>> contents = null;
    for (Map<String, Object> prod : prods) {
        assertEquals(prod.get("id"), product.getId());
        assertEquals(prod.get("name"), product.getName());
        assertEquals(prod.get("version"), product.getAttributeValue(Product.Attributes.VERSION));
        String arch = product.hasAttribute(Product.Attributes.ARCHITECTURE) ? product.getAttributeValue(Product.Attributes.ARCHITECTURE) : "";
        StringTokenizer st = new StringTokenizer(arch, ",");
        while (st.hasMoreElements()) {
            assertTrue(((List) prod.get("architectures")).contains(st.nextElement()));
        }
        contents = (List<Map<String, Object>>) prod.get("content");
        for (Map<String, Object> cont : contents) {
            assertEquals(cont.get("id"), CONTENT_ID);
            assertEquals(cont.get("name"), CONTENT_NAME);
            assertEquals(cont.get("type"), CONTENT_TYPE);
            assertEquals(cont.get("label"), CONTENT_LABEL);
            assertEquals(cont.get("vendor"), CONTENT_VENDOR);
            assertEquals(cont.get("gpg_url"), CONTENT_GPG_URL);
            assertEquals(cont.get("path"), "prefix" + CONTENT_URL);
            assertFalse((Boolean) cont.get("enabled"));
            assertEquals(cont.get("metadata_expire"), 3200);
            List<String> arches = new ArrayList<>();
            arches.add(ARCH_LABEL);
            assertEquals(cont.get("arches"), arches);
            String rTags = content.getRequiredTags();
            st = new StringTokenizer(rTags, ",");
            while (st.hasMoreElements()) {
                assertTrue(((List) cont.get("required_tags")).contains(st.nextElement()));
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) ProductContent(org.candlepin.model.ProductContent) 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) BigInteger(java.math.BigInteger) StringTokenizer(java.util.StringTokenizer) X509ExtensionWrapper(org.candlepin.pki.X509ExtensionWrapper) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

X509ExtensionWrapper (org.candlepin.pki.X509ExtensionWrapper)25 Product (org.candlepin.model.Product)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)12 HashMap (java.util.HashMap)8 LinkedHashSet (java.util.LinkedHashSet)8 IOException (java.io.IOException)7 CertificateSizeException (org.candlepin.util.CertificateSizeException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 GeneralSecurityException (java.security.GeneralSecurityException)6 CertificateExpiredException (java.security.cert.CertificateExpiredException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ProductContent (org.candlepin.model.ProductContent)6 ExpectedException (org.junit.rules.ExpectedException)6 Matchers.anyMap (org.mockito.Matchers.anyMap)6 List (java.util.List)5 EnvironmentContent (org.candlepin.model.EnvironmentContent)5 X509Certificate (java.security.cert.X509Certificate)4