Skip to content

Commit

Permalink
1.4.10: Hypixel Cert Reversion (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
symt authored May 5, 2022
1 parent 497540e commit 2f7b63d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
version = "1.4.9"
version = "1.4.10"
group = "dev.meyi.bn"
archivesBaseName = "BazaarNotifier"

Expand Down
38 changes: 2 additions & 36 deletions src/main/java/dev/meyi/bn/BazaarNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.text.DecimalFormat;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -38,10 +28,9 @@
public class BazaarNotifier {

public static final String MODID = "BazaarNotifier";
public static final String VERSION = "1.4.9";
public static final String VERSION = "1.4.10";
public static final String prefix =
EnumChatFormatting.GOLD + "[" + EnumChatFormatting.YELLOW + "BN" + EnumChatFormatting.GOLD
+ "] " + EnumChatFormatting.RESET;
EnumChatFormatting.GOLD + "[" + EnumChatFormatting.YELLOW + "BN" + EnumChatFormatting.GOLD + "] " + EnumChatFormatting.RESET;
public static String apiKey = "";

public static DecimalFormat df = new DecimalFormat("#,###.0");
Expand All @@ -67,8 +56,6 @@ public class BazaarNotifier {

public static ModuleList modules;

public static SSLSocketFactory sslSocketFactory;

public static void resetMod() {
modules.resetAll();
orders = Defaults.DEFAULT_ORDERS_LAYOUT();
Expand Down Expand Up @@ -97,27 +84,6 @@ public void preInit(FMLPreInitializationEvent event) {

@Mod.EventHandler
public void init(FMLInitializationEvent event) {

try {
Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(
this.getClass().getClassLoader().getResourceAsStream("api-hypixel.crt"));
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("api-hypixel-bz", certificate);

TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);

BazaarNotifier.sslSocketFactory = sslContext.getSocketFactory();

} catch (CertificateException | KeyStoreException | IOException | NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}

MinecraftForge.EVENT_BUS.register(new EventHandler());
MinecraftForge.EVENT_BUS.register(new ChestTickHandler());
MinecraftForge.EVENT_BUS.register(new MouseHandler());
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/dev/meyi/bn/utilities/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.net.ssl.HttpsURLConnection;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
Expand All @@ -25,7 +23,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -34,19 +31,18 @@
public class Utils {

public static JSONObject getBazaarData() throws IOException {
HttpClient client = HttpClientBuilder.create().build();
String apiBit = "";
if (!BazaarNotifier.apiKeyDisabled) {
apiBit = "?key=" + BazaarNotifier.apiKey;
}

HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.hypixel.net/skyblock/bazaar" + apiBit).openConnection();
connection.setSSLSocketFactory(BazaarNotifier.sslSocketFactory);
connection.connect();
HttpGet request = new HttpGet(
"https://api.hypixel.net/skyblock/bazaar" + apiBit);
HttpResponse response = client.execute(request);

String result = IOUtils.toString(new BufferedReader
(new InputStreamReader(
connection.getInputStream())));

response.getEntity().getContent())));

return new JSONObject(result).getJSONObject("products");
}
Expand Down
23 changes: 0 additions & 23 deletions src/main/resources/api-hypixel.crt

This file was deleted.

0 comments on commit 2f7b63d

Please sign in to comment.