Search in sources :

Example 1 with RequestType

use of POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType in project PokeGOAPI-Java by Grover-c13.

the class Signature method setSignature.

/**
 * Given a fully built request, set the signature correctly.
 *
 * @param api the api
 * @param builder the RequestEnvelope builder
 * @throws RequestFailedException if an invalid request is sent
 */
public static void setSignature(PokemonGo api, RequestEnvelope.Builder builder) throws RequestFailedException {
    boolean usePtr8 = false;
    byte[][] requestData = new byte[builder.getRequestsCount()][];
    for (int i = 0; i < builder.getRequestsCount(); i++) {
        requestData[i] = builder.getRequests(i).toByteArray();
        RequestType requestType = builder.getRequests(i).getRequestType();
        if (requestType == RequestType.GET_PLAYER) {
            usePtr8 |= api.firstGP;
            api.firstGP = false;
        } else if (requestType == RequestType.GET_MAP_OBJECTS) {
            usePtr8 |= !api.firstGMO;
            api.firstGMO = false;
        }
    }
    double latitude = api.latitude;
    double longitude = api.longitude;
    double accuracy = api.accuracy;
    if (Double.isNaN(latitude)) {
        latitude = 0.0;
    }
    if (Double.isNaN(longitude)) {
        longitude = 0.0;
    }
    if (Double.isNaN(accuracy)) {
        accuracy = 0.0;
    }
    byte[] authTicket;
    if (builder.hasAuthTicket()) {
        authTicket = builder.getAuthTicket().toByteArray();
    } else {
        authTicket = builder.getAuthInfo().toByteArray();
    }
    long currentTimeMillis = api.currentTimeMillis();
    byte[] sessionHash = api.sessionHash;
    HashProvider provider = api.hashProvider;
    Hash hash = provider.provide(currentTimeMillis, latitude, longitude, accuracy, authTicket, sessionHash, requestData);
    long timeSinceStart = currentTimeMillis - api.startTime;
    SignatureOuterClass.Signature.Builder signatureBuilder = SignatureOuterClass.Signature.newBuilder().setLocationHash1(hash.locationAuthHash).setLocationHash2(hash.locationHash).setSessionHash(ByteString.copyFrom(sessionHash)).setTimestamp(currentTimeMillis).setTimestampSinceStart(timeSinceStart).setDeviceInfo(api.getDeviceInfo()).addAllLocationFix(LocationFixes.getDefault(api, builder, currentTimeMillis, RANDOM)).setActivityStatus(api.getActivitySignature(RANDOM)).setUnknown25(provider.getUNK25()).setUnknown27(// Currently random, generation is unknown
    RANDOM.nextInt(59000) + 1000);
    final SignatureOuterClass.Signature.SensorInfo sensorInfo = SensorInfo.getDefault(api, currentTimeMillis, RANDOM);
    if (sensorInfo != null)
        signatureBuilder.addSensorInfo(sensorInfo);
    List<Long> requestHashes = hash.requestHashes;
    for (int i = 0; i < builder.getRequestsCount(); i++) signatureBuilder.addRequestHash(requestHashes.get(i));
    Crypto crypto = new Crypto();
    SignatureOuterClass.Signature signature = signatureBuilder.build();
    byte[] signatureByteArray = signature.toByteArray();
    byte[] encrypted = crypto.encrypt(signatureByteArray, timeSinceStart);
    ByteString signatureBytes = SendEncryptedSignatureRequest.newBuilder().setEncryptedSignature(ByteString.copyFrom(encrypted)).build().toByteString();
    RequestEnvelope.PlatformRequest signatureRequest = RequestEnvelope.PlatformRequest.newBuilder().setType(PlatformRequestType.SEND_ENCRYPTED_SIGNATURE).setRequestMessage(signatureBytes).build();
    builder.addPlatformRequests(signatureRequest);
    if (usePtr8) {
        ByteString ptr8 = UnknownPtr8RequestOuterClass.UnknownPtr8Request.newBuilder().setMessage("15c79df0558009a4242518d2ab65de2a59e09499").build().toByteString();
        builder.addPlatformRequests(RequestEnvelope.PlatformRequest.newBuilder().setType(PlatformRequestType.UNKNOWN_PTR_8).setRequestMessage(ptr8).build());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) Hash(com.pokegoapi.util.hash.Hash) Crypto(com.pokegoapi.util.hash.crypto.Crypto) HashProvider(com.pokegoapi.util.hash.HashProvider) SignatureOuterClass(POGOProtos.Networking.Envelopes.SignatureOuterClass) RequestEnvelope(POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope) RequestType(POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType) PlatformRequestType(POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType)

Aggregations

RequestEnvelope (POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope)1 SignatureOuterClass (POGOProtos.Networking.Envelopes.SignatureOuterClass)1 PlatformRequestType (POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType)1 RequestType (POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType)1 ByteString (com.google.protobuf.ByteString)1 Hash (com.pokegoapi.util.hash.Hash)1 HashProvider (com.pokegoapi.util.hash.HashProvider)1 Crypto (com.pokegoapi.util.hash.crypto.Crypto)1