Search in sources :

Example 6 with Command

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());
    }
}
Also used : TrustBundle(org.nhind.config.TrustBundle) TrustBundleAnchor(org.nhind.config.TrustBundleAnchor) Command(org.nhindirect.dns.tools.utils.Command)

Example 7 with Command

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());
    }
}
Also used : TrustBundle(org.nhind.config.TrustBundle) File(java.io.File) Command(org.nhindirect.dns.tools.utils.Command)

Example 8 with Command

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());
    }
}
Also used : TrustBundle(org.nhind.config.TrustBundle) Command(org.nhindirect.dns.tools.utils.Command)

Example 9 with Command

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());
    }
}
Also used : TrustBundle(org.nhind.config.TrustBundle) Domain(org.nhind.config.Domain) TrustBundleDomainReltn(org.nhind.config.TrustBundleDomainReltn) Command(org.nhindirect.dns.tools.utils.Command)

Example 10 with Command

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());
    }
}
Also used : X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) IOException(java.io.IOException) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) Command(org.nhindirect.dns.tools.utils.Command)

Aggregations

Command (org.nhindirect.dns.tools.utils.Command)33 DnsRecord (org.nhind.config.DnsRecord)14 IOException (java.io.IOException)11 Domain (org.nhind.config.Domain)9 File (java.io.File)7 X509Certificate (java.security.cert.X509Certificate)6 TrustBundle (org.nhind.config.TrustBundle)6 ArrayList (java.util.ArrayList)4 PolicyParseException (org.nhindirect.policy.PolicyParseException)4 CertPolicyGroupDomainReltn (org.nhind.config.CertPolicyGroupDomainReltn)3 TrustBundleDomainReltn (org.nhind.config.TrustBundleDomainReltn)3 X509CertificateEx (org.nhindirect.stagent.cert.X509CertificateEx)3 RemoteException (java.rmi.RemoteException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Anchor (org.nhind.config.Anchor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PolicyLexicon (org.nhind.config.PolicyLexicon)1 TrustBundleAnchor (org.nhind.config.TrustBundleAnchor)1