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