use of com.github.games647.craftapi.model.auth.Account in project CraftAPI by games647.
the class MojangResolver method authenticate.
@Override
public Account authenticate(String email, String password) throws IOException, InvalidCredentialsException {
HttpURLConnection conn = getConnection(AUTH_URL);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
try (OutputStream out = conn.getOutputStream();
OutputStreamWriter outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
BufferedWriter writer = new BufferedWriter(outWriter)) {
writer.append(gson.toJson(new AuthRequest(email, password)));
}
AuthResponse authResponse = parseRequest(conn, in -> readJson(in, AuthResponse.class));
return new Account(authResponse.getSelectedProfile(), authResponse.getAccessToken());
}
use of com.github.games647.craftapi.model.auth.Account in project ChangeSkin by games647.
the class UploadCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
plugin.sendMessage(sender, "upload-noargs");
} else {
String url = args[0];
if (url.startsWith("http://") || url.startsWith("https://")) {
List<Account> accounts = plugin.getCore().getUploadAccounts();
if (accounts.isEmpty()) {
plugin.sendMessage(sender, "no-accounts");
} else {
Account uploadAccount = accounts.get(0);
Runnable skinUploader = new SkinUploader(plugin, uploadAccount, url, sender);
Bukkit.getScheduler().runTaskAsynchronously(plugin, skinUploader);
}
} else {
plugin.sendMessage(sender, "no-valid-url");
}
}
return true;
}
use of com.github.games647.craftapi.model.auth.Account in project FastLogin by games647.
the class NameCheckTask method requestPremiumLogin.
// Minecraft server implementation
// https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
@Override
public void requestPremiumLogin(ProtocolLibLoginSource source, StoredProfile profile, String username, boolean registered) {
try {
source.enableOnlinemode();
} catch (Exception ex) {
plugin.getLog().error("Cannot send encryption packet. Falling back to cracked login for: {}", profile, ex);
return;
}
String ip = player.getAddress().getAddress().getHostAddress();
core.getPendingLogin().put(ip + username, new Object());
byte[] verify = source.getVerifyToken();
BukkitLoginSession playerSession = new BukkitLoginSession(username, verify, registered, profile);
plugin.putSession(player.getAddress(), playerSession);
// cancel only if the player has a paid account otherwise login as normal offline player
synchronized (packetEvent.getAsyncMarker().getProcessingLock()) {
packetEvent.setCancelled(true);
}
}
use of com.github.games647.craftapi.model.auth.Account in project FastLogin by games647.
the class VerifyResponseTask method verifyResponse.
private void verifyResponse(BukkitLoginSession session) {
PrivateKey privateKey = serverKey.getPrivate();
SecretKey loginKey;
try {
loginKey = EncryptionUtil.decryptSharedKey(privateKey, sharedSecret);
} catch (GeneralSecurityException securityEx) {
disconnect("error-kick", false, "Cannot decrypt received contents", securityEx);
return;
}
try {
if (!checkVerifyToken(session) || !enableEncryption(loginKey)) {
return;
}
} catch (Exception ex) {
disconnect("error-kick", false, "Cannot decrypt received contents", ex);
return;
}
String serverId = EncryptionUtil.getServerIdHashString("", loginKey, serverKey.getPublic());
String requestedUsername = session.getRequestUsername();
InetSocketAddress socketAddress = player.getAddress();
try {
MojangResolver resolver = plugin.getCore().getResolver();
InetAddress address = socketAddress.getAddress();
Optional<Verification> response = resolver.hasJoined(requestedUsername, serverId, address);
if (response.isPresent()) {
Verification verification = response.get();
plugin.getLog().info("Profile {} has a verified premium account", requestedUsername);
String realUsername = verification.getName();
if (realUsername == null) {
disconnect("invalid-session", true, "Username field null for {}", requestedUsername);
return;
}
SkinProperty[] properties = verification.getProperties();
if (properties.length > 0) {
session.setSkinProperty(properties[0]);
}
session.setVerifiedUsername(realUsername);
session.setUuid(verification.getId());
session.setVerified(true);
setPremiumUUID(session.getUuid());
receiveFakeStartPacket(realUsername);
} else {
// user tried to fake an authentication
disconnect("invalid-session", true, "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}", session.getRequestUsername(), socketAddress, serverId);
}
} catch (IOException ioEx) {
disconnect("error-kick", false, "Failed to connect to session server", ioEx);
}
}
use of com.github.games647.craftapi.model.auth.Account in project ChangeSkin by games647.
the class MojangAuthApi method authenticate.
public Optional<Account> authenticate(String email, String password) {
try {
HttpURLConnection httpConnection = CommonUtil.getConnection(AUTH_URL);
httpConnection.setRequestMethod("POST");
httpConnection.setDoOutput(true);
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(httpConnection.getOutputStream(), StandardCharsets.UTF_8))) {
writer.append(gson.toJson(new AuthRequest(email, password)));
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
AuthResponse authResponse = gson.fromJson(reader, AuthResponse.class);
return Optional.of(new Account(authResponse.getSelectedProfile(), authResponse.getAccessToken()));
}
} catch (IOException ex) {
logger.error("Failed to authenticate user: {}", email, ex);
}
return Optional.empty();
}
Aggregations