first stab add project addition
[jSite2.git] / src / net / pterodactylus / jsite / core / NodeManager.java
index 1e61980..f772dc2 100644 (file)
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.fcp.highlevel.HighLevelClient;
 import net.pterodactylus.fcp.highlevel.HighLevelClientListener;
+import net.pterodactylus.fcp.highlevel.KeyGenerationResult;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
 
@@ -421,6 +422,28 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                return clientNodes.get(highLevelClient);
        }
 
+       /**
+        * Generates a new SSK key pair.
+        * 
+        * @return An array with the private key at index <code>0</code> and the
+        *         public key at index <code>1</code>
+        * @throws IOException
+        *             if an I/O error occurs communicating with the node
+        */
+       public String[] generateKeyPair() throws IOException {
+               if (!nodes.isEmpty()) {
+                       Node node = nodes.get(0);
+                       HighLevelClient highLevelClient = nodeClients.get(node);
+                       try {
+                               KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
+                               return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+                       } catch (InterruptedException e) {
+                               /* ignore. */
+                       }
+               }
+               return null;
+       }
+
        //
        // PRIVATE METHODS
        //