Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

<repositories>
<repository>
<id>bukkit</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<!-- Bukkit Dependency -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.9-R0.2</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand All @@ -36,8 +36,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<!-- Jar Plugin -->
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vexsoftware/votifier/Votifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onEnable() {
File config = new File(getDataFolder() + "/config.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config);
File rsaDirectory = new File(getDataFolder() + "/rsa");
// Replace to remove a bug with Windows paths - SmilingDevil
// Replace it to remove a bug with Windows paths - SmilingDevil
String listenerDirectory = getDataFolder().toString()
.replace("\\", "/") + "/listeners";

Expand All @@ -100,7 +100,7 @@ public void onEnable() {
hostAddr = "0.0.0.0";

/*
* Create configuration file if it does not exists; otherwise, load it
* Create a configuration file if it does not exist; otherwise, load it
*/
if (!config.exists()) {
try {
Expand Down
112 changes: 46 additions & 66 deletions src/main/java/com/vexsoftware/votifier/crypto/RSAIO.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
/*
* Copyright (C) 2011 Vex Software LLC
* This file is part of Votifier.
*
* Votifier is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Votifier is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Votifier. If not, see <http://www.gnu.org/licenses/>.
*/

package com.vexsoftware.votifier.crypto;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand All @@ -27,85 +10,82 @@
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

import javax.xml.bind.DatatypeConverter;
import java.util.Base64;

/**
* Static utility methods for saving and loading RSA key pairs.
*
* @author Blake Beaupain
*
* @author Blake Beaupain, mzcy_ (Recode, don't use javax classes)
*/
public class RSAIO {

/**
* Saves the key pair to the disk.
*
* @param directory
* The directory to save to
* @param keyPair
* The key pair to save
* @throws Exception
* If an error occurs
*
* @param directory The directory to save to
* @param keyPair The key pair to save
* @throws Exception If an error occurs
*/
public static void save(File directory, KeyPair keyPair) throws Exception {
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();

// Store the public key.
X509EncodedKeySpec publicSpec = new X509EncodedKeySpec(
publicKey.getEncoded());
FileOutputStream out = new FileOutputStream(directory + "/public.key");
out.write(DatatypeConverter.printBase64Binary(publicSpec.getEncoded())
.getBytes());
out.close();
X509EncodedKeySpec publicSpec = new X509EncodedKeySpec(publicKey.getEncoded());
try (FileOutputStream out = new FileOutputStream(new File(directory, "public.key"))) {
out.write(Base64.getEncoder().encode(publicSpec.getEncoded()));
}

// Store the private key.
PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(
privateKey.getEncoded());
out = new FileOutputStream(directory + "/private.key");
out.write(DatatypeConverter.printBase64Binary(privateSpec.getEncoded())
.getBytes());
out.close();
PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
try (FileOutputStream out = new FileOutputStream(new File(directory, "private.key"))) {
out.write(Base64.getEncoder().encode(privateSpec.getEncoded()));
}
}

/**
* Loads an RSA key pair from a directory. The directory must have the files
* "public.key" and "private.key".
*
* @param directory
* The directory to load from
*
* @param directory The directory to load from
* @return The key pair
* @throws Exception
* If an error occurs
* @throws Exception If an error occurs
*/
public static KeyPair load(File directory) throws Exception {
// Read the public key file.
File publicKeyFile = new File(directory + "/public.key");
FileInputStream in = new FileInputStream(directory + "/public.key");
byte[] encodedPublicKey = new byte[(int) publicKeyFile.length()];
in.read(encodedPublicKey);
encodedPublicKey = DatatypeConverter.parseBase64Binary(new String(
encodedPublicKey));
in.close();
File publicKeyFile = new File(directory, "public.key");
byte[] encodedPublicKey;
try (FileInputStream in = new FileInputStream(publicKeyFile)) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = in.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
encodedPublicKey = buffer.toByteArray();
}
byte[] decodedPublicKey = Base64.getDecoder().decode(encodedPublicKey);

// Read the private key file.
File privateKeyFile = new File(directory + "/private.key");
in = new FileInputStream(directory + "/private.key");
byte[] encodedPrivateKey = new byte[(int) privateKeyFile.length()];
in.read(encodedPrivateKey);
encodedPrivateKey = DatatypeConverter.parseBase64Binary(new String(
encodedPrivateKey));
in.close();
File privateKeyFile = new File(directory, "private.key");
byte[] encodedPrivateKey;
try (FileInputStream in = new FileInputStream(privateKeyFile)) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = in.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
encodedPrivateKey = buffer.toByteArray();
}
byte[] decodedPrivateKey = Base64.getDecoder().decode(encodedPrivateKey);

// Instantiate and return the key pair.
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(
encodedPublicKey);
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(decodedPublicKey);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(
encodedPrivateKey);
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(decodedPrivateKey);
PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
return new KeyPair(publicKey, privateKey);
}

}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Votifier
main: com.vexsoftware.votifier.Votifier
version: maven-version-number
description: A plugin that gets notified when votes are made for the server on toplists.
authors: [blakeman8192, Kramer]
authors: [blakeman8192, Kramer, mzcy_]