Skip to content

Commit

Permalink
Version 1.0 commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lare96 committed Sep 27, 2018
1 parent f47b2ea commit ac637f4
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
out/
rsakeygen.iml
/rsapriv.toml
/rsapub.toml
/log.err
27 changes: 27 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
The MIT License (MIT)

Copyright (c) 2018 Cliven Mitchell



Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:



The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.



THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
rsakeygen
# RSAKeyGen

A tool that generates 1024-bit RSA keys. It currently runs on Java 8 and was developed specifically for the Luna ecosystem.

# Usage

Simply download the latest .JAR file from the [releases]() section, and in the Luna server files put it in the RSA (./data/rsa) directory. Once that is done, double click the JAR file and it will generate new keys automatically!

# License

Like all software for Luna, RSAKeyGen is licensed under MIT (see LICENSE).
61 changes: 61 additions & 0 deletions src/io/luna/net/rsa/AlertWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.luna.net.rsa;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
* A Javafx application that opens an alert window detailing the result of the key computation.
*
* @author lare96 <http://github.com/lare96>
*/
public final class AlertWindow extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
// Dummy scene, never actually displayed.
primaryStage.setScene(new Scene(new HBox(), 300, 300));

List<String> parameters = getParameters().getRaw();
if (parameters.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.INFORMATION,
"RSA Keys have successfully been generated.", ButtonType.OK);
alert.setTitle("RSAKeyGen");
alert.setHeaderText("Success!");
alert.showAndWait();
} else {
writeError(parameters.get(0));

Alert alert = new Alert(Alert.AlertType.ERROR,
"RSA Keys could not be generated. Please see log.err for more info.",
ButtonType.OK);
alert.setTitle("RSAKeyGen");
alert.setHeaderText("Warning!");
alert.showAndWait();
}
}

/**
* Writes an error to the error log.
*
* @param e The error to write.
*/
private void writeError(String e) {
Path errorLog = Paths.get("log.err");
try {
Files.deleteIfExists(errorLog);
Files.write(errorLog, e.getBytes());
} catch (IOException ignored) {

}
}
}
38 changes: 0 additions & 38 deletions src/io/luna/net/rsa/RSAKeyGen.java

This file was deleted.

51 changes: 40 additions & 11 deletions src/io/luna/net/rsa/RSAKeyGenMain.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package io.luna.net.rsa;

import javafx.application.Application;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* The main class that will launch the terminal.
*
Expand All @@ -11,23 +18,45 @@ public final class RSAKeyGenMain {
* The main method, the point of initialization.
*/
public static void main(String[] args) {
System.out.println("RSAKeyGen v1.0");
System.out.println("Type (y) to generate new keys.");
System.out.println("Keep in mind that doing this will overwrite existing keys.");
doKeys();
}

TerminalReader terminal = new TerminalReader();
terminal.awaitNextInputMatching("y", new RSAKeyGen());
/**
* Attempts to generate and publish new RSA keys.
*/
private static void doKeys() {
Path privateFile = Paths.get("rsapriv.toml");
Path publicFile = Paths.get("rsapub.toml");

try {
RSAKeyPair keyPair = RSAKeyPair.newKeyPair();
keyPair.writeToFile(privateFile, publicFile);
} catch (Exception e) {
exit(e);
return;
}
exit();
}

/**
* Causes the application to gracefully exit.
*/
static void exit() {
System.out.println("The application will now exit.");
try {
Thread.sleep(3000);
} catch (InterruptedException ignored) {
private static void exit() {
exit(null);
}

/**
* Causes the application to exit because of an error.
*
* @param e The error that caused the exit.
*/
private static void exit(Exception e) {
if (e == null) {
Application.launch(AlertWindow.class);
} else {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
Application.launch(AlertWindow.class, sw.toString());
}
System.exit(0);
}
}
2 changes: 0 additions & 2 deletions src/io/luna/net/rsa/RSAKeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ void writeToFile(Path privateFile, Path publicFile) throws IOException {
byte[] publicBytes = getBytes(publicKey.getModulus(), publicKey.getPublicExponent());
Files.write(privateFile, privateBytes);
Files.write(publicFile, publicBytes);

System.out.println("RSA private and public keys successfully generated.");
}

/**
Expand Down
42 changes: 0 additions & 42 deletions src/io/luna/net/rsa/TerminalReader.java

This file was deleted.

0 comments on commit ac637f4

Please sign in to comment.