Search in sources :

Example 1 with Verification

use of com.github.games647.craftapi.model.auth.Verification 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 2 with Verification

use of com.github.games647.craftapi.model.auth.Verification in project CraftAPI by games647.

the class MojangResolver method hasJoined.

// todo: implement custom rate limiter that cleans up on size checking
// private final Map<Object, Object> requests = SafeCacheBuilder.newBuilder()
// .expireAfterWrite(10, TimeUnit.MINUTES)
// .build(CacheLoader.from(() -> {
// throw new UnsupportedOperationException();
// }));
@Override
public Optional<Verification> hasJoined(String username, String serverHash, InetAddress hostIp) throws IOException {
    String url;
    if (hostIp instanceof Inet6Address) {
        // Mojang currently doesn't check the IPv6 address correct. The prevent-proxy even doesn't work with
        // a vanilla server
        url = String.format(HAS_JOINED_URL_RAW, username, serverHash);
    } else {
        String encodedIP = URLEncoder.encode(hostIp.getHostAddress(), StandardCharsets.UTF_8.name());
        url = String.format(HAS_JOINED_URL_PROXY_CHECK, username, serverHash, encodedIP);
    }
    HttpURLConnection conn = getConnection(url);
    int responseCode = conn.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
        return Optional.empty();
    }
    return Optional.of(parseRequest(conn, in -> readJson(in, Verification.class)));
}
Also used : Account(com.github.games647.craftapi.model.auth.Account) HttpURLConnection(java.net.HttpURLConnection) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) URL(java.net.URL) UUIDAdapter(com.github.games647.craftapi.UUIDAdapter) Textures(com.github.games647.craftapi.model.skin.Textures) InetAddress(java.net.InetAddress) ProxySelector(java.net.ProxySelector) ImmutableList(com.google.common.collect.ImmutableList) Verification(com.github.games647.craftapi.model.auth.Verification) Proxy(java.net.Proxy) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) OutputStream(java.io.OutputStream) ImmutableSet(com.google.common.collect.ImmutableSet) AuthResponse(com.github.games647.craftapi.model.auth.AuthResponse) BufferedWriter(java.io.BufferedWriter) RenderedImage(java.awt.image.RenderedImage) IOException(java.io.IOException) UUID(java.util.UUID) Instant(java.time.Instant) Model(com.github.games647.craftapi.model.skin.Model) StandardCharsets(java.nio.charset.StandardCharsets) Profile(com.github.games647.craftapi.model.Profile) Inet6Address(java.net.Inet6Address) URLEncoder(java.net.URLEncoder) AuthRequest(com.github.games647.craftapi.model.auth.AuthRequest) Optional(java.util.Optional) Type(java.net.Proxy.Type) NameHistory(com.github.games647.craftapi.model.NameHistory) HttpURLConnection(java.net.HttpURLConnection) Inet6Address(java.net.Inet6Address)

Aggregations

Verification (com.github.games647.craftapi.model.auth.Verification)2 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 UUIDAdapter (com.github.games647.craftapi.UUIDAdapter)1 NameHistory (com.github.games647.craftapi.model.NameHistory)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 Model (com.github.games647.craftapi.model.skin.Model)1 Textures (com.github.games647.craftapi.model.skin.Textures)1 MojangResolver (com.github.games647.craftapi.resolver.MojangResolver)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 RenderedImage (java.awt.image.RenderedImage)1 BufferedWriter (java.io.BufferedWriter)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1