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;
}
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;
}
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"));
}
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"));
}
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()));
}
}
}
}
Aggregations