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