Search in sources :

Example 1 with Account

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());
}
Also used : AuthRequest(com.github.games647.craftapi.model.auth.AuthRequest) Account(com.github.games647.craftapi.model.auth.Account) HttpURLConnection(java.net.HttpURLConnection) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) AuthResponse(com.github.games647.craftapi.model.auth.AuthResponse)

Example 2 with Account

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;
}
Also used : Account(com.github.games647.changeskin.core.model.auth.Account) SkinUploader(com.github.games647.changeskin.bukkit.task.SkinUploader)

Example 3 with Account

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);
    }
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 4 with Account

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);
    }
}
Also used : PrivateKey(java.security.PrivateKey) InetSocketAddress(java.net.InetSocketAddress) GeneralSecurityException(java.security.GeneralSecurityException) Verification(com.github.games647.craftapi.model.auth.Verification) IOException(java.io.IOException) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) MojangResolver(com.github.games647.craftapi.resolver.MojangResolver) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecretKey(javax.crypto.SecretKey) InetAddress(java.net.InetAddress)

Example 5 with Account

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();
}
Also used : AuthRequest(com.github.games647.changeskin.core.model.auth.AuthRequest) Account(com.github.games647.changeskin.core.model.auth.Account) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AuthResponse(com.github.games647.changeskin.core.model.auth.AuthResponse)

Aggregations

Account (com.github.games647.changeskin.core.model.auth.Account)4 IOException (java.io.IOException)3 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 HttpURLConnection (java.net.HttpURLConnection)2 SkinUploader (com.github.games647.changeskin.bukkit.task.SkinUploader)1 SkinUploader (com.github.games647.changeskin.bungee.task.SkinUploader)1 AuthRequest (com.github.games647.changeskin.core.model.auth.AuthRequest)1 AuthResponse (com.github.games647.changeskin.core.model.auth.AuthResponse)1 SkinUploader (com.github.games647.changeskin.sponge.task.SkinUploader)1 Profile (com.github.games647.craftapi.model.Profile)1 Account (com.github.games647.craftapi.model.auth.Account)1 AuthRequest (com.github.games647.craftapi.model.auth.AuthRequest)1 AuthResponse (com.github.games647.craftapi.model.auth.AuthResponse)1 Verification (com.github.games647.craftapi.model.auth.Verification)1 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)1 MojangResolver (com.github.games647.craftapi.resolver.MojangResolver)1 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)1 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)1 StoredProfile (com.github.games647.fastlogin.core.StoredProfile)1