Search in sources :

Example 91 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project Signal-Android by WhisperSystems.

the class GroupsV2AuthorizationSignalStoreCache method read.

@Override
@NonNull
public Map<Integer, AuthCredentialResponse> read() {
    byte[] credentialBlob = store.getBlob(KEY, null);
    if (credentialBlob == null) {
        Log.i(TAG, "No credentials responses are cached locally");
        return Collections.emptyMap();
    }
    try {
        TemporalAuthCredentialResponses temporalCredentials = TemporalAuthCredentialResponses.parseFrom(credentialBlob);
        HashMap<Integer, AuthCredentialResponse> result = new HashMap<>(temporalCredentials.getCredentialResponseCount());
        for (TemporalAuthCredentialResponse credential : temporalCredentials.getCredentialResponseList()) {
            result.put(credential.getDate(), new AuthCredentialResponse(credential.getAuthCredentialResponse().toByteArray()));
        }
        Log.i(TAG, String.format(Locale.US, "Loaded %d credentials from local storage", result.size()));
        return result;
    } catch (InvalidProtocolBufferException | InvalidInputException e) {
        throw new AssertionError(e);
    }
}
Also used : TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) InvalidInputException(org.signal.zkgroup.InvalidInputException) HashMap(java.util.HashMap) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TemporalAuthCredentialResponses(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponses) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse) TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) NonNull(androidx.annotation.NonNull)

Example 92 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project Signal-Android by WhisperSystems.

the class WebSocketConnection method onMessage.

@Override
public synchronized void onMessage(WebSocket webSocket, ByteString payload) {
    try {
        WebSocketMessage message = WebSocketMessage.parseFrom(payload.toByteArray());
        if (message.getType().getNumber() == WebSocketMessage.Type.REQUEST_VALUE) {
            incomingRequests.add(message.getRequest());
        } else if (message.getType().getNumber() == WebSocketMessage.Type.RESPONSE_VALUE) {
            OutgoingRequest listener = outgoingRequests.remove(message.getResponse().getId());
            if (listener != null) {
                listener.onSuccess(new WebsocketResponse(message.getResponse().getStatus(), new String(message.getResponse().getBody().toByteArray()), message.getResponse().getHeadersList(), !credentialsProvider.isPresent()));
                if (message.getResponse().getStatus() >= 400) {
                    healthMonitor.onMessageError(message.getResponse().getStatus(), credentialsProvider.isPresent());
                }
            } else if (keepAlives.remove(message.getResponse().getId())) {
                healthMonitor.onKeepAliveResponse(message.getResponse().getId(), credentialsProvider.isPresent());
            }
        }
        notifyAll();
    } catch (InvalidProtocolBufferException e) {
        warn(e);
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) WebSocketMessage(org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage) ByteString(okio.ByteString)

Example 93 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project Signal-Android by WhisperSystems.

the class SignalServiceCipher method decrypt.

/**
 * Decrypt a received {@link SignalServiceEnvelope}
 *
 * @param envelope The received SignalServiceEnvelope
 *
 * @return a decrypted SignalServiceContent
 */
public SignalServiceContent decrypt(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, InvalidMetadataVersionException, ProtocolInvalidKeyIdException, ProtocolLegacyMessageException, ProtocolUntrustedIdentityException, ProtocolNoSessionException, ProtocolInvalidVersionException, ProtocolInvalidMessageException, ProtocolInvalidKeyException, ProtocolDuplicateMessageException, SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException {
    try {
        if (envelope.hasLegacyMessage()) {
            Plaintext plaintext = decrypt(envelope, envelope.getLegacyMessage());
            SignalServiceProtos.DataMessage dataMessage = SignalServiceProtos.DataMessage.parseFrom(plaintext.getData());
            SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setLegacyDataMessage(dataMessage).build();
            return SignalServiceContent.createFromProto(contentProto);
        } else if (envelope.hasContent()) {
            Plaintext plaintext = decrypt(envelope, envelope.getContent());
            SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData());
            SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setContent(content).build();
            return SignalServiceContent.createFromProto(contentProto);
        }
        return null;
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidMetadataMessageException(e);
    }
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) UnidentifiedSenderMessageContent(org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SignalServiceContentProto(org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto) InvalidMetadataMessageException(org.signal.libsignal.metadata.InvalidMetadataMessageException)

Example 94 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project dubbo by alibaba.

the class ProtobufUtils method deserializeJson.

/* Protobuf json */
static <T> T deserializeJson(String json, Class<T> requestClass) throws InvalidProtocolBufferException {
    Builder builder;
    try {
        builder = getMessageBuilder(requestClass);
    } catch (Exception e) {
        throw new IllegalArgumentException("Get google protobuf message builder from " + requestClass.getName() + "failed", e);
    }
    JsonFormat.parser().merge(json, builder);
    return (T) builder.build();
}
Also used : MessageOrBuilder(com.google.protobuf.MessageOrBuilder) Builder(com.google.protobuf.GeneratedMessageV3.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException)

Example 95 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project bagheera by mozilla-metrics.

the class KafkaConsumer method poll.

@Override
public void poll() {
    final CountDownLatch latch = new CountDownLatch(streams.size());
    for (final KafkaStream<Message> stream : streams) {
        workers.add(executor.submit(new Callable<Void>() {

            @Override
            public Void call() {
                try {
                    for (MessageAndMetadata<Message> mam : stream) {
                        BagheeraMessage bmsg = BagheeraMessage.parseFrom(ByteString.copyFrom(mam.message().payload()));
                        // get the sink for this message's namespace
                        // (typically only one sink unless a regex pattern was used to listen to multiple topics)
                        KeyValueSink sink = sinkFactory.getSink(bmsg.getNamespace());
                        if (sink == null) {
                            LOG.error("Could not obtain sink for namespace: " + bmsg.getNamespace());
                            break;
                        }
                        if (bmsg.getOperation() == Operation.CREATE_UPDATE && bmsg.hasId() && bmsg.hasPayload()) {
                            if (validationPipeline == null || validationPipeline.isValid(bmsg.getPayload().toByteArray())) {
                                if (bmsg.hasTimestamp()) {
                                    sink.store(bmsg.getId(), bmsg.getPayload().toByteArray(), bmsg.getTimestamp());
                                } else {
                                    sink.store(bmsg.getId(), bmsg.getPayload().toByteArray());
                                }
                            } else {
                                invalidMessageMeter.mark();
                                // TODO: sample out an example payload
                                LOG.warn("Invalid payload for namespace: " + bmsg.getNamespace());
                            }
                        } else if (bmsg.getOperation() == Operation.DELETE && bmsg.hasId()) {
                            sink.delete(bmsg.getId());
                        }
                        consumed.mark();
                    }
                } catch (InvalidProtocolBufferException e) {
                    LOG.error("Invalid protocol buffer in data stream", e);
                } catch (UnsupportedEncodingException e) {
                    LOG.error("Message ID was not in UTF-8 encoding", e);
                } catch (IOException e) {
                    LOG.error("IO error while storing to data sink", e);
                } finally {
                    latch.countDown();
                }
                return null;
            }
        }));
    }
    // run indefinitely unless we detect that a thread exited
    try {
        while (true) {
            latch.await(10, TimeUnit.SECONDS);
            if (latch.getCount() != streams.size()) {
                // we have a dead thread and should exit
                break;
            }
        }
    } catch (InterruptedException e) {
        LOG.info("Interrupted during polling", e);
    }
    // Spit out errors if there were any
    for (Future<Void> worker : workers) {
        try {
            if (worker.isDone() && !worker.isCancelled()) {
                worker.get(1, TimeUnit.SECONDS);
            }
        } catch (InterruptedException e) {
            LOG.error("Thread was interrupted:", e);
        } catch (ExecutionException e) {
            LOG.error("Exception occured in thread:", e);
        } catch (TimeoutException e) {
            LOG.error("Timed out waiting for thread result:", e);
        } catch (CancellationException e) {
            LOG.error("Thread has been canceled: ", e);
        }
    }
}
Also used : BagheeraMessage(com.mozilla.bagheera.BagheeraProto.BagheeraMessage) Message(kafka.message.Message) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) KeyValueSink(com.mozilla.bagheera.sink.KeyValueSink) CancellationException(java.util.concurrent.CancellationException) BagheeraMessage(com.mozilla.bagheera.BagheeraProto.BagheeraMessage) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)260 ServerRequest (com.pokegoapi.main.ServerRequest)46 ByteString (com.google.protobuf.ByteString)42 IOException (java.io.IOException)41 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)39 InvalidProtocolBufferException (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException)22 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)19 List (java.util.List)18 Map (java.util.Map)17 Any (com.google.protobuf.Any)16 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)15 HashSet (java.util.HashSet)11 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)10 Status (org.apache.accumulo.server.replication.proto.Replication.Status)10 Text (org.apache.hadoop.io.Text)10 JsonToken (com.fasterxml.jackson.core.JsonToken)9 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)9 ContractExeException (org.tron.core.exception.ContractExeException)9