use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class TrustBundleCommands method listBundleAnchors.
@Command(name = "ListTrustBundleAnchors", usage = LIST_BUNDLE_ANCHORS)
public void listBundleAnchors(String[] args) {
final long bundleId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
try {
final TrustBundle bundle = proxy.getTrustBundleById(bundleId);
if (bundle == null) {
System.out.println("Bundle with id " + bundleId + " does not exist.");
return;
}
if (bundle.getLastSuccessfulRefresh() == null) {
System.out.println("Bundle has never been successfully downloaded.");
return;
}
final TrustBundleAnchor[] anchors = bundle.getTrustBundleAnchors();
if (anchors == null || anchors.length == 0) {
System.out.println("Bundle has not anchors.");
return;
}
anchorPrinter.printRecords(Arrays.asList(anchors));
} catch (Exception e) {
System.out.println("Error deleting trust bundle: " + e.getMessage());
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class TrustBundleCommands method addTrustBundle.
@Command(name = "AddTrustBundle", usage = ADD_TRUST_BUNDLE)
public void addTrustBundle(String[] args) {
final String bundleName = StringArrayUtil.getRequiredValue(args, 0);
final String url = StringArrayUtil.getRequiredValue(args, 1);
// convert minutes to seconds
final int refreshInterval = Integer.parseInt(StringArrayUtil.getRequiredValue(args, 2)) * 60;
final String signingCertFile = StringArrayUtil.getOptionalValue(args, 3, "");
try {
final TrustBundle exBundle = proxy.getTrustBundleByName(bundleName);
if (exBundle != null) {
System.out.println("Bundle with name " + bundleName + " already exists.");
} else {
final TrustBundle newBundle = new TrustBundle();
newBundle.setBundleName(bundleName);
newBundle.setBundleURL(url);
newBundle.setRefreshInterval(refreshInterval);
if (!StringUtils.isEmpty(signingCertFile)) {
final byte[] signCertData = FileUtils.readFileToByteArray(new File(signingCertFile));
newBundle.setSigningCertificateData(signCertData);
}
proxy.addTrustBundle(newBundle);
System.out.println("Trust bundle " + bundleName + " added to the system.");
}
} catch (Exception e) {
System.out.println("Error adding trust bundle " + bundleName + " : " + e.getMessage());
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class TrustBundleCommands method removeTrustBundle.
@Command(name = "DeleteTrustBundle", usage = REMOVE_TRUST_BUNDLE)
public void removeTrustBundle(String[] args) {
final long bundleId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
try {
final TrustBundle bundle = proxy.getTrustBundleById(bundleId);
if (bundle == null) {
System.out.println("Bundle with id " + bundleId + " does not exist.");
return;
}
proxy.deleteTrustBundles(new Long[] { bundleId });
System.out.println("Trust bundle " + bundle.getBundleName() + " deleted");
} catch (Exception e) {
System.out.println("Error deleting trust bundle: " + e.getMessage());
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class TrustBundleCommands method addTrustBundleToDomain.
@Command(name = "AddTrustBundleToDomain", usage = ADD_BUNDLE_TO_DOMAIN)
public void addTrustBundleToDomain(String[] args) {
final long bundleId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
final long domainId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 1));
final boolean trustIncoming = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 2));
final boolean trustOutgoing = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 3));
try {
final TrustBundle bundle = proxy.getTrustBundleById(bundleId);
if (bundle == null) {
System.out.println("Bundle with id " + bundleId + " does not exist.");
return;
}
final Domain domain = proxy.getDomain(domainId);
if (domain == null) {
System.out.println("Domain with id " + domainId + " does not exist.");
return;
}
// make sure there isn't already an association
final TrustBundleDomainReltn[] reltns = proxy.getTrustBundlesByDomain(domainId, false);
if (reltns != null && reltns.length > 0) {
for (TrustBundleDomainReltn reltn : reltns) {
if (reltn.getTrustBundle().getId() == bundleId) {
System.out.println("Bundle " + bundle.getBundleName() + " is already associated with domain " + domain.getDomainName());
return;
}
}
}
proxy.associateTrustBundleToDomain(domainId, bundleId, trustIncoming, trustOutgoing);
System.out.println("Trust bundle " + bundle.getBundleName() + " added to domain " + domain.getDomainName());
} catch (Exception e) {
System.out.println("Error associating bundle to domain : " + e.getMessage());
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class CertCommands method importPrivateCertWithWrappedKey.
@Command(name = "AddPrivateCertWithWrappedKey", usage = IMPORT_PRIVATE_CERT_W_WRAPPEDKEY_USAGE)
public void importPrivateCertWithWrappedKey(String[] args) {
final String certFileLoc = StringArrayUtil.getRequiredValue(args, 0);
final String keyFileLoc = StringArrayUtil.getRequiredValue(args, 1);
try {
final byte[] certFileBytes = FileUtils.readFileToByteArray(new File(certFileLoc));
final byte[] keyFileBytes = FileUtils.readFileToByteArray(new File(keyFileLoc));
final X509Certificate cert = CertUtils.toX509Certificate(certFileBytes);
byte[] certBytes = org.nhindirect.config.model.utils.CertUtils.certAndWrappedKeyToRawByteFormat(keyFileBytes, cert);
org.nhind.config.Certificate addCert = new org.nhind.config.Certificate();
addCert.setData(certBytes);
addCert.setOwner(CryptoExtensions.getSubjectAddress(cert));
addCert.setPrivateKey(cert instanceof X509CertificateEx);
addCert.setStatus(EntityStatus.ENABLED);
proxy.addCertificates(new org.nhind.config.Certificate[] { addCert });
System.out.println("Successfully imported certificate.");
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
return;
} catch (Exception e) {
System.out.println("Error importing certificate " + e.getMessage());
}
}
Aggregations