ManagedSecretKey.class);
List<ManagedSecretKey> matchingTag = Lists.newArrayList();
for (ProviderOf<ManagedSecretKey> keyProvider : keyProviders) {
ItemBase item = keyProvider.getItem();
if (!item.getTags().hasTag(TAG_KEY_ID, keyId)) {
continue;
}
matchingTag.add(keyProvider.get());
}
if (matchingTag.size() > 1) {
// TODO: Pick the longest time-to-expiry key
log.warn("Found multiple keys as children of {}", owner);
}
// Return existing key
for (ManagedSecretKey key : matchingTag) {
return key;
}
}
ManagedSecretKey ca;
{
ItemBase sslKeyItem = (ItemBase) platformLayer.getItem(sslKey);
ManagedSecretKey key = providers.toInterface(sslKeyItem, ManagedSecretKey.class);
if (!key.isCaKey()) {
// Easy case - we just want to use this key
return key;
}
ca = key;
}
if (!OpsContext.isConfigure()) {
log.info("No SSL key found; not in configure mode; won't create");
return null;
}
// No key found; let's create a new key
log.info("No SSL key found; creating a new one under {}", owner);
{
X500Principal subject = buildX500(keyId, owner);
KeyPair keyPair = RsaUtils.generateRsaKeyPair();
PlatformLayerKey createdPath = ca.createSignedKey(owner, keyId, subject, keyPair);
ItemBase createdModel = platformLayer.getItem(createdPath);
ManagedSecretKey created = providers.toInterface(createdModel, ManagedSecretKey.class);
return created;
}
}