use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class KeyLookup method parse.
@Override
public void parse(String commandText) throws Exception {
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
String alias;
switch(st.countTokens()) {
case 0:
if (!module.isCurrentGuidSetAndVerified()) {
return;
} else {
alias = module.getCurrentGuid().getEntityName();
}
break;
case 1:
alias = st.nextToken();
break;
default:
wrongArguments();
return;
}
GNSClientCommands gnsClient = module.getGnsClient();
PublicKey pk;
if (!StringUtil.isValidGuidString(alias)) {
pk = gnsClient.publicKeyLookupFromAlias(alias);
} else {
pk = gnsClient.publicKeyLookupFromGuid(alias);
}
console.printString(alias + " public key is " + DatatypeConverter.printHexBinary(pk.getEncoded()));
//console.printString(alias + " public key is " + ByteUtils.toHex(pk.getEncoded()));
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class PrivateKeyImport method parse.
@Override
public void parse(String commandText) throws Exception {
GNSClientCommands gnsClient = module.getGnsClient();
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
String filename = st.nextToken();
PrivateKey privateKey = KeyPairUtils.getPrivateKeyFromPKCS8File(filename);
String guid = gnsClient.lookupGuid(aliasName);
if (guid == null) {
console.printString("Alias " + aliasName + " is not in the GNS");
console.printNewline();
return;
}
PublicKey publicKey = gnsClient.publicKeyLookupFromGuid(guid);
GuidEntry guidEntry = new GuidEntry(aliasName, guid, publicKey, privateKey);
KeyPairUtils.saveKeyPair(module.getGnsInstance(), guidEntry.getEntityName(), guidEntry.getGuid(), new KeyPair(guidEntry.getPublicKey(), guidEntry.getPrivateKey()));
console.printString("Private key for " + guidEntry.getEntityName() + " read from " + filename + " and saved in local preferences.");
} catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException | ClientException e) {
console.printString("Failed to save keys ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class GuidCreate method parse.
@Override
public void parse(String commandText) throws Exception {
GuidEntry accountGuid = module.getCurrentGuid();
StringTokenizer st = new StringTokenizer(commandText.trim());
if ((st.countTokens() != 1)) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
try {
GNSClientCommands gnsClient = module.getGnsClient();
try {
gnsClient.lookupGuid(aliasName);
printString("Alias " + aliasName + " already exists.\n");
return;
} catch (ClientException expected) {
// The alias does not exists, that's good, let's create it
}
if (!module.isSilent()) {
printString("Looking for alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid != null) {
try {
PublicKey pk = gnsClient.publicKeyLookupFromGuid(myGuid.getGuid());
if (myGuid.getPublicKey().equals(pk)) {
// We already have the key but the alias is missing in the GNS,
// re-add the alias
printString("Alias info found locally but missing in GNS, re-adding alias to the GNS\n");
gnsClient.guidCreate(myGuid, aliasName);
} else {
printString("Old certificates found locally and not matching key in GNS, deleting local keys\n");
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
} catch (InvalidGuidException e) {
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
}
if (!module.isSilent()) {
printString("Generating new GUID and keys for account " + accountGuid.getEntityName() + " \n");
}
myGuid = gnsClient.guidCreate(accountGuid, aliasName);
if (!module.isSilent()) {
printString("Created GUID " + myGuid.getGuid() + "\n");
}
if (module.getCurrentGuid() == null) {
module.setCurrentGuidAndCheckForVerified(myGuid);
module.setPromptString(ConsoleModule.CONSOLE_PROMPT + aliasName + ">");
}
} catch (IOException | ClientException e) {
printString("Failed to create new guid ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class CreateDnsRecord method main.
/**
*
* @param args
* @throws IOException
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws ClientException
* @throws InvalidKeyException
* @throws SignatureException
* @throws Exception
*/
public static void main(String[] args) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, ClientException, InvalidKeyException, SignatureException, Exception {
if (args.length != 2) {
System.out.println("Usage: edu.umass.cs.gnsclient.examples.CreateDnsRecord <host> <address>");
System.exit(0);
}
client = new GNSClientCommands();
try {
accountGuid = GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT_ALIAS, "password", true);
} catch (Exception e) {
System.out.println("Exception during accountGuid creation: " + e);
System.exit(1);
}
System.out.println("Client connected to GNS");
createAnARecord(args[0], args[1]);
client.close();
System.exit(0);
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class CreateSomeRecordsForDns method main.
/**
*
* @param args
* @throws IOException
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws ClientException
* @throws InvalidKeyException
* @throws SignatureException
* @throws Exception
*/
public static void main(String[] args) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, ClientException, InvalidKeyException, SignatureException, Exception {
client = new GNSClientCommands();
try {
accountGuid = GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT_ALIAS, "password", true);
} catch (Exception e) {
System.out.println("Exception during accountGuid creation: " + e);
System.exit(1);
}
System.out.println("Client connected to GNS");
createAnARecord("westy.gns.", "173.236.153.191");
createAnARecord("mobilityfirst.gns.", "128.119.240.104");
client.close();
System.exit(0);
}
Aggregations