Search in sources :

Example 31 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class DNSRecordCommands method addSOA.

/**
	 * Adds an SOA records to the configuration service.
	 * @param args Contains the SOA record attributes.
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_SOA_Add", usage = ADD_SOA_USAGE)
public void addSOA(String[] args) {
    DnsRecord record = fromRecord(parser.parseSOA(args));
    addDNS(record);
}
Also used : DnsRecord(org.nhind.config.DnsRecord) Command(org.nhindirect.dns.tools.utils.Command)

Example 32 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class AnchorCommands method exportAnchor.

@Command(name = "ExportAnchor", usage = EXPORT_ANCHOR_USAGE)
public void exportAnchor(String[] args) {
    final String id = StringArrayUtil.getRequiredValue(args, 0);
    try {
        // make sure the anchor exists
        long[] ids = new long[] { Long.parseLong(id) };
        final Anchor[] anchors = proxy.getAnchors(ids, null);
        if (anchors == null || anchors.length == 0) {
            System.out.println("Anchor does not exists.");
            return;
        } else {
            for (Anchor anchor : anchors) {
                final X509Certificate cert = CertUtils.toX509Certificate(anchor.getData());
                final String certFileHold = CryptoExtensions.getSubjectAddress(cert) + ".der";
                File certFile = new File(certFileHold);
                if (certFile.exists())
                    certFile.delete();
                System.out.println("Writing anchor file: " + certFile.getAbsolutePath());
                try {
                    FileUtils.writeByteArrayToFile(certFile, cert.getEncoded());
                } catch (Exception e) {
                    System.err.println("Failed to write anchor to file: " + e.getMessage());
                }
            }
        }
    } catch (Exception e) {
        System.err.println("Error exporting anchor: " + e.getMessage());
    }
}
Also used : Anchor(org.nhind.config.Anchor) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) Command(org.nhindirect.dns.tools.utils.Command)

Example 33 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class AnchorCommands method importAnchor.

@Command(name = "ImportAnchor", usage = IMPORT_ANCHOR_USAGE)
public void importAnchor(String[] args) {
    final String fileLoc = StringArrayUtil.getRequiredValue(args, 0);
    final String domainId = StringArrayUtil.getRequiredValue(args, 1);
    final boolean incoming = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 2));
    final boolean outgoing = Boolean.parseBoolean(StringArrayUtil.getRequiredValue(args, 3));
    try {
        // makes sure the domain exists
        final Domain exDomain = proxy.getDomain(Long.parseLong(domainId));
        if (exDomain == null) {
            System.out.println("The domain with the id " + domainId + " does not exists in the system");
            return;
        }
        byte[] certBytes = FileUtils.readFileToByteArray(new File(fileLoc));
        if (certBytes != null) {
            Anchor anchor = new Anchor();
            anchor.setData(certBytes);
            anchor.setIncoming(incoming);
            anchor.setOutgoing(outgoing);
            anchor.setOwner(exDomain.getDomainName());
            proxy.addAnchor(new Anchor[] { anchor });
            System.out.println("Successfully imported trust anchor.");
        }
    } catch (IOException e) {
        System.out.println("Error reading file " + fileLoc + " : " + e.getMessage());
    } catch (Exception e) {
        System.out.println("Error importing trust anchor " + fileLoc + " : " + e.getMessage());
    }
}
Also used : Anchor(org.nhind.config.Anchor) IOException(java.io.IOException) Domain(org.nhind.config.Domain) File(java.io.File) IOException(java.io.IOException) 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