@@ -108,8 +108,11 @@ public class LukittuLicenseVerify {
108108 * production)
109109 * @param publicKey The public key used to verify the server's signature
110110 * (should be hardcoded in production)
111+ * @throws IOException If a network or server error occurs
112+ * @throws Exception If validation fails for any reason
111113 */
112- public static void verifyKey (String licenseKey , String teamId , String productId , String publicKey ) {
114+ public static void verifyKey (String licenseKey , String teamId , String productId , String publicKey )
115+ throws Exception {
113116 DEVICE_IDENTIFIER = getHardwareIdentifier ();
114117
115118 // Generate a random challenge
@@ -127,7 +130,13 @@ public static void verifyKey(String licenseKey, String teamId, String productId,
127130 "deviceIdentifier": "%s"
128131 }""" , licenseKey , productId , challenge , VERSION , DEVICE_IDENTIFIER );
129132
130- fetchAndHandleResponse (url , jsonBody , publicKey , challenge );
133+ boolean verificationSuccess = fetchAndHandleResponse (url , jsonBody , publicKey , challenge );
134+
135+ // Throw exception if verification failed to ensure it's caught in Simple's
136+ // onEnable
137+ if (!verificationSuccess ) {
138+ throw new Exception ("License verification failed" );
139+ }
131140 }
132141
133142 /**
@@ -165,10 +174,13 @@ public static String bytesToHex(byte[] bytes) {
165174 * @param publicKeyBase64 The public key to verify the response
166175 * @param challenge The challenge string that should be signed in the
167176 * response
177+ * @return true if verification succeeded, false if it failed
178+ * @throws IOException If a network error occurs
168179 */
169- public static void fetchAndHandleResponse (String urlString , String jsonBody , String publicKeyBase64 ,
170- String challenge ) {
180+ public static boolean fetchAndHandleResponse (String urlString , String jsonBody , String publicKeyBase64 ,
181+ String challenge ) throws IOException {
171182 HttpURLConnection connection = null ;
183+ boolean success = false ;
172184
173185 try {
174186 var url = URI .create (urlString ).toURL ();
@@ -189,7 +201,7 @@ public static void fetchAndHandleResponse(String urlString, String jsonBody, Str
189201
190202 if (responseCode == HttpURLConnection .HTTP_OK ) {
191203 try (var inputStream = connection .getInputStream ()) {
192- handleJsonResponse (inputStream , publicKeyBase64 , challenge );
204+ success = handleJsonResponse (inputStream , publicKeyBase64 , challenge );
193205 }
194206 } else {
195207 try (var errorStream = connection .getErrorStream ()) {
@@ -214,11 +226,14 @@ public static void fetchAndHandleResponse(String urlString, String jsonBody, Str
214226 } catch (IOException e1 ) {
215227 Simple .INSTANCE .getLogger ().log (Level .SEVERE , "Failed to parse error response" , e1 );
216228 }
229+ throw new IOException ("Connection to license server failed" , e );
217230 } finally {
218231 if (connection != null ) {
219232 connection .disconnect ();
220233 }
221234 }
235+
236+ return success ;
222237 }
223238
224239 /**
0 commit comments