diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000000..211ea0c2102 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,3 @@ +# examples has its own WORKSPACE. Ignore as part of this root WORKSPACE so that +# we don't need to repeat dependencies. +examples/ diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000000..53485cb9743 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 diff --git a/.gemini/config.yaml b/.gemini/config.yaml new file mode 100644 index 00000000000..71adf793964 --- /dev/null +++ b/.gemini/config.yaml @@ -0,0 +1,13 @@ +have_fun: false +memory_config: + disabled: false +code_review: + disable: false + comment_severity_threshold: MEDIUM + max_review_comments: -1 + pull_request_opened: + help: false + summary: false + code_review: false + include_drafts: false +ignore_patterns: [] diff --git a/.gitattributes b/.gitattributes index 6754557eab6..4343b9bd8ec 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ -TestService.java.txt binary -TestServiceLite.java.txt binary -TestServiceNano.java.txt binary +TestService.java.txt -text +TestServiceLite.java.txt -text +TestDeprecatedService.java.txt -text +TestDeprecatedServiceLite.java.txt -text diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE deleted file mode 100644 index 431fcb1f09c..00000000000 --- a/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1,8 +0,0 @@ -Please answer these questions before submitting your issue. - -### What version of gRPC are you using? - - -### What did you expect to see? - - diff --git a/.github/ISSUE_TEMPLATE/ask_question.md b/.github/ISSUE_TEMPLATE/ask_question.md new file mode 100644 index 00000000000..c384031e347 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ask_question.md @@ -0,0 +1,12 @@ +--- +name: Ask a question +about: Asking a question related gRPC-Java +labels: question +--- + + + + diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000000..b6998dde7c2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,19 @@ +--- +name: Report a bug +about: Create a bug report to help us improve +--- + + + +### What version of gRPC-Java are you using? + +### What is your environment? + + +### What did you expect to see? + +### What did you see instead? + +### Steps to reproduce the bug + + diff --git a/.github/ISSUE_TEMPLATE/feature_report.md b/.github/ISSUE_TEMPLATE/feature_report.md new file mode 100644 index 00000000000..ddc60838148 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_report.md @@ -0,0 +1,19 @@ +--- +name: Request a feature +about: Suggest an enhancement for gRPC +labels: enhancement +--- + + + +### Is your feature request related to a problem? + + +### Describe the solution you'd like + + +### Describe alternatives you've considered + + +### Additional context + diff --git a/.github/workflows/branch-testing.yml b/.github/workflows/branch-testing.yml new file mode 100644 index 00000000000..ece8ec4cd58 --- /dev/null +++ b/.github/workflows/branch-testing.yml @@ -0,0 +1,41 @@ +name: GitHub Actions Branch Testing + +on: + push: + branches: + - master + - 'v1.*' + schedule: + - cron: '54 19 * * SUN' # weekly at a "random" time + +permissions: + contents: read + +jobs: + arm64: + runs-on: ubuntu-24.04-arm + strategy: + matrix: + jre: [17] + fail-fast: false # Should swap to true if we grow a large matrix + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.jre }} + distribution: 'temurin' + + - name: Gradle cache + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build + run: ./gradlew -Dorg.gradle.parallel=true -Dorg.gradle.jvmargs='-Xmx1g' -PskipAndroid=true -PskipCodegen=true -PerrorProne=false test + diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml new file mode 100644 index 00000000000..da1e2fed114 --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -0,0 +1,13 @@ +name: "Validate Gradle Wrapper" +on: [push, pull_request] + +permissions: + contents: read + +jobs: + validation: + name: "Gradle wrapper validation" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: gradle/actions/wrapper-validation@v4 diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml new file mode 100644 index 00000000000..3070a1a2f7c --- /dev/null +++ b/.github/workflows/lock.yml @@ -0,0 +1,20 @@ +name: 'Lock Threads' + +on: + workflow_dispatch: + schedule: + - cron: '37 3 * * *' + +permissions: + issues: write + pull-requests: write + +jobs: + lock: + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v5 + with: + github-token: ${{ github.token }} + issue-inactive-days: 90 + pr-inactive-days: 90 diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000000..ccabd9be79f --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,110 @@ +name: GitHub Actions Linux Testing + +on: + push: + branches: + - master + - 'v1.*' + pull_request: + schedule: + - cron: '54 19 * * SUN' # weekly at a "random" time + +permissions: + contents: read + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + jre: [8, 11, 17, 21] + fail-fast: false # Should swap to true if we grow a large matrix + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.jre }} + distribution: 'temurin' + + - name: Gradle cache + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Maven cache + uses: actions/cache@v4 + with: + path: | + ~/.m2/repository + !~/.m2/repository/io/grpc + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', 'build.gradle') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Protobuf cache + uses: actions/cache@v4 + with: + path: /tmp/protobuf-cache + key: ${{ runner.os }}-maven-${{ hashFiles('buildscripts/make_dependencies.sh') }} + + - name: Build + run: buildscripts/kokoro/unix.sh + - name: Post Failure Upload Test Reports to Artifacts + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: Test Reports (JRE ${{ matrix.jre }}) + path: | + ./*/build/reports/tests/** + ./*/*/build/reports/tests/** + retention-days: 14 + - name: Check for modified codegen + run: test -z "$(git status --porcelain)" || (git status && echo Error Working directory is not clean. Forget to commit generated files? && false) + + - name: Coveralls + if: matrix.jre == 8 # Upload once, instead of for each job in the matrix + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + run: ./gradlew :grpc-all:coveralls -PskipAndroid=true -x compileJava + - name: Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + bazel: + runs-on: ubuntu-latest + strategy: + matrix: + bzlmod: [true, false] + env: + USE_BAZEL_VERSION: 7.7.1 + + steps: + - uses: actions/checkout@v4 + + - name: Check versions match in MODULE.bazel and repositories.bzl + run: | + diff -u <(sed -n '/GRPC_DEPS_START/,/GRPC_DEPS_END/ {/GRPC_DEPS_/! p}' MODULE.bazel) \ + <(sed -n '/GRPC_DEPS_START/,/GRPC_DEPS_END/ {/GRPC_DEPS_/! p}' repositories.bzl) + + - name: Bazel cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/bazel/*/cache + ~/.cache/bazelisk/downloads + key: ${{ runner.os }}-bazel-${{ env.USE_BAZEL_VERSION }}-${{ hashFiles('WORKSPACE', 'repositories.bzl') }} + + - name: Run bazel build + run: bazelisk build //... --enable_bzlmod=${{ matrix.bzlmod }} + + - name: Run bazel test + run: bazelisk test //... --enable_bzlmod=${{ matrix.bzlmod }} + + - name: Run example bazel build + run: bazelisk build //... --enable_bzlmod=${{ matrix.bzlmod }} + working-directory: ./examples diff --git a/.gitignore b/.gitignore index e82cb67ccfc..b078d891adf 100644 --- a/.gitignore +++ b/.gitignore @@ -15,10 +15,14 @@ bazel-genfiles bazel-grpc-java bazel-out bazel-testlogs +MODULE.bazel.lock # IntelliJ IDEA .idea *.iml +*.ipr +*.iws +.ijwb # Eclipse .classpath @@ -27,9 +31,18 @@ bazel-testlogs .gitignore bin +# VsCode +.vscode + # OS X .DS_Store # Emacs *~ \#*\# + +# ARM tests +qemu-arm-static + +# Temporary output dir for artifacts +mvn-artifacts diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index aa15eea7b71..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,57 +0,0 @@ -sudo: false - -language: java - -env: - global: - - GRADLE_OPTS=-Xmx512m - - PROTOBUF_VERSION=3.5.1 - - LDFLAGS=-L/tmp/protobuf/lib - - CXXFLAGS=-I/tmp/protobuf/include - - LD_LIBRARY_PATH=/tmp/protobuf/lib - -before_install: - - mkdir -p $HOME/.gradle/caches && - ln -s /tmp/gradle-caches-modules-2 $HOME/.gradle/caches/modules-2 - - mkdir -p $HOME/.gradle && - ln -s /tmp/gradle-wrapper $HOME/.gradle/wrapper - # Work around https://github.com/travis-ci/travis-ci/issues/2317 - - if \[ "$TRAVIS_OS_NAME" = linux \]; then jdk_switcher use oraclejdk8; fi - - buildscripts/make_dependencies.sh # build protoc into /tmp/protobuf-${PROTOBUF_VERSION} - - ln -s "/tmp/protobuf-${PROTOBUF_VERSION}/$(uname -s)-$(uname -p)" /tmp/protobuf - - mkdir -p $HOME/.gradle - - echo "checkstyle.ignoreFailures=false" >> $HOME/.gradle/gradle.properties - - echo "failOnWarnings=true" >> $HOME/.gradle/gradle.properties - - echo "errorProne=true" >> $HOME/.gradle/gradle.properties - -install: - - ./gradlew assemble generateTestProto install - - pushd examples && ./gradlew build && popd - - pushd examples && mvn verify && popd - -before_script: - - test -z "$(git status --porcelain)" || (git status && echo Error Working directory is not clean. Forget to commit generated files? && false) - -script: - - ./gradlew check :grpc-all:jacocoTestReport - -after_success: - - if \[ "$TRAVIS_OS_NAME" = linux \]; then ./gradlew :grpc-all:coveralls; fi - - bash <(curl -s https://codecov.io/bash) - -os: - - linux - -notifications: - email: false - -cache: - directories: - - /tmp/protobuf-${PROTOBUF_VERSION} - - /tmp/gradle-caches-modules-2 - - /tmp/gradle-wrapper - -before_cache: - # The lock changes based on folder name; normally $HOME/.gradle/caches/modules-2/modules-2.lock - - rm /tmp/gradle-caches-modules-2/gradle-caches-modules-2.lock - - find $HOME/.gradle/wrapper -not -name "*-all.zip" -and -not -name "*-bin.zip" -delete diff --git a/BUILD.bazel b/BUILD.bazel index b30a6bdc05b..27a99fb62eb 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,4 @@ -# Copyright 2017 gRPC authors. +# Copyright 2017 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library") +load("@rules_java//java:defs.bzl", "java_library", "java_plugin") +load("@rules_jvm_external//:defs.bzl", "artifact") load(":java_grpc_library.bzl", "java_grpc_library") java_proto_library( @@ -24,3 +27,45 @@ java_grpc_library( srcs = ["@com_google_protobuf//:api_proto"], deps = [":api_proto_java"], ) + +java_library( + name = "java_grpc_library_deps__do_not_reference", + visibility = ["//visibility:public"], + exports = [ + "//api", + "//protobuf", + "//stub", + "@com_google_protobuf//:protobuf_java", + artifact("com.google.code.findbugs:jsr305"), + artifact("com.google.guava:guava"), + ], +) + +java_library( + name = "java_lite_grpc_library_deps__do_not_reference", + visibility = ["//visibility:public"], + exports = [ + "//api", + "//protobuf-lite", + "//stub", + artifact("com.google.code.findbugs:jsr305"), + artifact("com.google.guava:guava"), + ], +) + +java_plugin( + name = "auto_value", + generates_api = 1, + processor_class = "com.google.auto.value.processor.AutoValueProcessor", + deps = [artifact("com.google.auto.value:auto-value")], +) + +java_library( + name = "auto_value_annotations", + exported_plugins = [":auto_value"], + neverlink = 1, + visibility = ["//:__subpackages__"], + exports = [ + artifact("com.google.auto.value:auto-value-annotations"), + ], +) diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md new file mode 100644 index 00000000000..9d4213ebca7 --- /dev/null +++ b/CODE-OF-CONDUCT.md @@ -0,0 +1,3 @@ +## Community Code of Conduct + +gRPC follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). diff --git a/COMPILING.md b/COMPILING.md index f75023cde27..b7df1319beb 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -1,15 +1,22 @@ Building gRPC-Java ================== -Building is only necessary if you are making changes to gRPC-Java. +Building is only necessary if you are making changes to gRPC-Java or testing/using a non-released + version (e.g. master HEAD) of gRPC-Java library. Building requires JDK 8, as our tests use TLS. grpc-java has a C++ code generation plugin for protoc. Since many Java -developers don't have C compilers installed and don't need to modify the +developers don't have C compilers installed and don't need to run or modify the codegen, the build can skip it. To skip, create the file `/gradle.properties` and add `skipCodegen=true`. +Some parts of grpc-java depend on Android. Since many Java developers don't have +the Android SDK installed and don't need to run or modify the Android +components, the build can skip it. To skip, create the file +`/gradle.properties` and add `skipAndroid=true`. +Otherwise, create the file `/gradle.properties` and add `android.useAndroidX=true`. + Then, to build, run: ``` $ ./gradlew build @@ -18,11 +25,11 @@ $ ./gradlew build To install the artifacts to your Maven local repository for use in your own project, run: ``` -$ ./gradlew install +$ ./gradlew publishToMavenLocal ``` ### Notes for IntelliJ -Building in IntelliJ works best when you import the project as a Gradle project and delegate IDE +Building in IntelliJ works best when you import the project as a Gradle project and delegate IDE build/run actions to Gradle. You can find this setting at: @@ -37,23 +44,22 @@ This section is only necessary if you are making changes to the code generation. Most users only need to use `skipCodegen=true` as discussed above. ### Build Protobuf -The codegen plugin is C++ code and requires protobuf 3.0.0 or later. +The codegen plugin is C++ code and requires protobuf 22.5 or later. For Linux, Mac and MinGW: ``` -$ git clone https://github.com/google/protobuf.git -$ cd protobuf -$ git checkout v3.5.1 -$ ./autogen.sh -$ ./configure -$ make -$ make check +$ PROTOBUF_VERSION=22.5 +$ curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz +$ tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz +$ cd protobuf-$PROTOBUF_VERSION +$ ./configure --disable-shared +$ make # You may want to pass -j to make this run faster; see make --help $ sudo make install ``` If you are comfortable with C++ compilation and autotools, you can specify a ``--prefix`` for Protobuf and use ``-I`` in ``CXXFLAGS``, ``-L`` in -``LDFLAGS``, ``LD_LIBRARY_PATH``, and ``PATH`` to reference it. The +``LDFLAGS`` to reference it. The environment variables will be used when building grpc-java. Protobuf installs to ``/usr/local`` by default. @@ -61,15 +67,8 @@ Protobuf installs to ``/usr/local`` by default. For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/cmake/README.md) for how to compile Protobuf. gRPC-java assumes a Release build. -#### Linux and MinGW -If ``/usr/local/lib`` is not in your library search path, you can add it by running: -``` -$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf' -$ sudo ldconfig -``` - #### Mac -Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the +Some versions of Mac OS X (e.g., 10.10) don't have ``/usr/local`` in the default search paths for header files and libraries. It will fail the build of the codegen. To work around this, you will need to set environment variables: ``` @@ -81,17 +80,17 @@ $ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" When building on Windows and VC++, you need to specify project properties for Gradle to find protobuf: ``` -.\gradlew install ^ - -PvcProtobufInclude=C:\path\to\protobuf-3.5.1\src ^ - -PvcProtobufLibs=C:\path\to\protobuf-3.5.1\vsprojects\Release ^ +.\gradlew publishToMavenLocal ^ + -PvcProtobufInclude=C:\path\to\protobuf\src ^ + -PvcProtobufLibs=C:\path\to\protobuf\vsprojects\Release ^ -PtargetArch=x86_32 ``` Since specifying those properties every build is bothersome, you can instead create ``\gradle.properties`` with contents like: ``` -vcProtobufInclude=C:\\path\\to\\protobuf-3.5.1\\src -vcProtobufLibs=C:\\path\\to\\protobuf-3.5.1\\vsprojects\\Release +vcProtobufInclude=C:\\path\\to\\protobuf\\src +vcProtobufLibs=C:\\path\\to\\protobuf\\vsprojects\\Release targetArch=x86_32 ``` @@ -115,3 +114,39 @@ use the one that has been built by your own, by adding this property to ``` protoc=/path/to/protoc ``` + +How to install Android SDK +--------------------------- +This section is only necessary if you are building modules depending on Android +(e.g., `cronet`). Non-Android users only need to use `skipAndroid=true` as +discussed above. + +### Install via Android Studio (GUI) +Download and install Android Studio from [Android Developer site](https://developer.android.com/studio). +You can find the configuration for Android SDK at: +``` +Preferences -> System Settings -> Android SDK +``` +Select the version of Android SDK to be installed and click `apply`. The location +of Android SDK being installed is shown at `Android SDK Location` at the same panel. +The default is `$HOME/Library/Android/sdk` for Mac OS and `$HOME/Android/Sdk` for Linux. +You can change this to a custom location. + +### Install via Command line tools only +Go to [Android SDK](https://developer.android.com/studio#command-tools) and +download the commandlinetools package for your build machine OS. Decide where +you want the Android SDK to be stored. `$HOME/Library/Android/sdk` is typical on +Mac OS and `$HOME/Android/Sdk` for Linux. + +```sh +export ANDROID_HOME=$HOME/Android/Sdk # Adjust to your liking +mkdir $HOME/Android +mkdir $ANDROID_HOME +mkdir $ANDROID_HOME/cmdline-tools +unzip -d $ANDROID_HOME/cmdline-tools DOWNLOADS/commandlinetools-*.zip +mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest +# Android SDK is now ready. Now accept licenses so the build can auto-download packages +$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses + +# Add 'export ANDROID_HOME=$HOME/Android/Sdk' to your .bashrc or equivalent +``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0fc610c5101..646a7d986fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,27 @@ # How to contribute -We definitely welcome your patches and contributions to gRPC! +We definitely welcome your patches and contributions to gRPC! Please read the gRPC +organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md) +and [contribution guidelines](https://github.com/grpc/grpc-community/blob/master/CONTRIBUTING.md) before proceeding. + If you are new to github, please start by reading [Pull Request howto](https://help.github.com/articles/about-pull-requests/) ## Legal requirements In order to protect both you and ourselves, you will need to sign the -[Contributor License Agreement](https://identity.linuxfoundation.org/projects/cncf). +[Contributor License Agreement](https://easycla.lfx.linuxfoundation.org/). When +you make a PR, a CLA bot will provide a link for the process. + +## Compiling + +See [COMPILING.md](COMPILING.md). Specifically, you'll generally want to set +`skipCodegen=true` so you don't need to deal with the C++ compilation. ## Code style We follow the [Google Java Style -Guide](https://google-styleguide.googlecode.com/svn/trunk/javaguide.html). Our +Guide](https://google.github.io/styleguide/javaguide.html). Our build automatically will provide warnings for style issues. [Eclipse](https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml) and @@ -21,56 +30,36 @@ style configurations are commonly useful. For IntelliJ 14, copy the style to `~/.IdeaIC14/config/codestyles/`, start IntelliJ, go to File > Settings > Code Style, and set the Scheme to `GoogleStyle`. -## Maintaining clean commit history - -We have few conventions for keeping history clean and making code reviews easier -for reviewers: - -* First line of commit messages should be in format of - - `package-name: summary of change` - - where the summary finishes the sentence: `This commit improves gRPC to ____________.` - - for example: - - `core,netty,interop-testing: add capacitive duractance to turbo encabulators` - -* Every time you receive a feedback on your pull request, push changes that - address it as a separate one or multiple commits with a descriptive commit - message (try avoid using vauge `addressed pr feedback` type of messages). - - Project maintainers are obligated to squash those commits into one when - merging. - -## Running tests - -### Jetty ALPN setup for IntelliJ - -The tests in interop-testing project require jetty-alpn agent running in the background -otherwise they'll fail. Here are instructions on how to setup IntellJ IDEA to enable running -those tests in IDE: - -* Settings -> Build Tools -> Gradle -> Runner -> select Gradle Test Runner -* View -> Tool Windows -> Gradle -> Edit Run Configuration -> Defaults -> JUnit -> Before lauch -> + -> Run Gradle task, enter the task in the build.gradle that sets the javaagent. - -Step 1 must be taken, otherwise by the default JUnit Test Runner running a single test in IDE will trigger all the tests. - ## Guidelines for Pull Requests How to get your contributions merged smoothly and quickly. - Create **small PRs** that are narrowly focused on **addressing a single concern**. We often times receive PRs that are trying to fix several things at a time, but only one fix is considered acceptable, nothing gets merged and both author's & review's time is wasted. Create more PRs to address different concerns and everyone will be happy. -- For speculative changes, consider opening an issue and discussing it first. If you are suggesting a behavioral or API change, consider starting with a [gRFC proposal](https://github.com/grpc/proposal). - -- Provide a good **PR description** as a record of **what** change is being made and **why** it was made. Link to a github issue if it exists. - -- Don't fix code style and formatting unless you are already changing that line to address an issue. PRs with irrelevant changes won't be merged. If you do want to fix formatting or style, do that in a separate PR. - -- Unless your PR is trivial, you should expect there will be reviewer comments that you'll need to address before merging. We expect you to be reasonably responsive to those comments, otherwise the PR will be closed after 2-3 weeks of inactivity. - -- Maintain **clean commit history** and use **meaningful commit messages**. See [maintaining clean commit history](#maintaining-clean-commit-history) for details. - +- For speculative changes, consider opening an issue and discussing it to avoid + wasting time on an inappropriate approach. If you are suggesting a behavioral + or API change, consider starting with a [gRFC + proposal](https://github.com/grpc/proposal). + +- Follow [typical Git commit message](https://cbea.ms/git-commit/#seven-rules) + structure. Have a good **commit description** as a record of **what** and + **why** the change is being made. Link to a GitHub issue if it exists. The + commit description makes a good PR description and is auto-copied by GitHub if + you have a single commit when creating the PR. + + If your change is mostly for a single module (e.g., other module changes are + trivial), prefix your commit summary with the module name changed. Instead of + "Add HTTP/2 faster-than-light support to gRPC Netty" it is more terse as + "netty: Add faster-than-light support". + +- Don't fix code style and formatting unless you are already changing that line + to address an issue. If you do want to fix formatting or style, do that in a + separate PR. + +- Unless your PR is trivial, you should expect there will be reviewer comments + that you'll need to address before merging. Address comments with additional + commits so the reviewer can review just the changes; do not squash reviewed + commits unless the reviewer agrees. PRs are squashed when merging. + - Keep your PR up to date with upstream/master (if there are merge conflicts, we can't really merge your change). - **All tests need to be passing** before your change can be merged. We recommend you **run tests locally** before creating your PR to catch breakages early on. Also, `./gradlew build` (`gradlew build` on Windows) **must not introduce any new warnings**. diff --git a/GOVERNANCE.md b/GOVERNANCE.md new file mode 100644 index 00000000000..d6ff2674710 --- /dev/null +++ b/GOVERNANCE.md @@ -0,0 +1 @@ +This repository is governed by the gRPC organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md). diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 00000000000..5048c7c5aca --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,35 @@ +This page lists all active maintainers of this repository. If you were a +maintainer and would like to add your name to the Emeritus list, please send us a +PR. + +See [GOVERNANCE.md](https://github.com/grpc/grpc-community/blob/master/governance.md) +for governance guidelines and how to become a maintainer. +See [CONTRIBUTING.md](https://github.com/grpc/grpc-community/blob/master/CONTRIBUTING.md) +for general contribution guidelines. + +## Maintainers (in alphabetical order) +- [ejona86](https://github.com/ejona86), Google LLC +- [jdcormie](https://github.com/jdcormie), Google LLC +- [kannanjgithub](https://github.com/kannanjgithub), Google LLC +- [ran-su](https://github.com/ran-su), Google LLC +- [sergiitk](https://github.com/sergiitk), Google LLC +- [temawi](https://github.com/temawi), Google LLC +- [YifeiZhuang](https://github.com/YifeiZhuang), Google LLC +- [zhangkun83](https://github.com/zhangkun83), Google LLC + +## Emeritus Maintainers (in alphabetical order) +- [carl-mastrangelo](https://github.com/carl-mastrangelo) +- [creamsoup](https://github.com/creamsoup) +- [dapengzhang0](https://github.com/dapengzhang0) +- [ericgribkoff](https://github.com/ericgribkoff) +- [jiangtaoli2016](https://github.com/jiangtaoli2016) +- [jtattermusch](https://github.com/jtattermusch) +- [larry-safran](https://github.com/larry-safran) +- [louiscryan](https://github.com/louiscryan) +- [markb74](https://github.com/markb74) +- [nicolasnoble](https://github.com/nicolasnoble) +- [nmittler](https://github.com/nmittler) +- [sanjaypujare](https://github.com/sanjaypujare) +- [srini100](https://github.com/srini100) +- [voidzcy](https://github.com/voidzcy) +- [zpencer](https://github.com/zpencer) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000000..42c3ed23e03 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,161 @@ +module( + name = "grpc-java", + version = "1.82.0-SNAPSHOT", # CURRENT_GRPC_VERSION + compatibility_level = 0, + repo_name = "io_grpc_grpc_java", +) + +# GRPC_DEPS_START +IO_GRPC_GRPC_JAVA_ARTIFACTS = [ + "com.google.android:annotations:4.1.1.4", + "com.google.api.grpc:proto-google-common-protos:2.64.1", + "com.google.auth:google-auth-library-credentials:1.42.1", + "com.google.auth:google-auth-library-oauth2-http:1.42.1", + "com.google.auto.value:auto-value-annotations:1.11.0", + "com.google.auto.value:auto-value:1.11.0", + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.code.gson:gson:2.13.2", + "com.google.errorprone:error_prone_annotations:2.48.0", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:guava:33.5.0-android", + "com.google.re2j:re2j:1.8", + "com.google.s2a.proto.v2:s2a-proto:0.1.3", + "com.google.truth:truth:1.4.5", + "com.squareup.okhttp:okhttp:2.7.5", + "com.squareup.okio:okio:2.10.0", # 3.0+ needs swapping to -jvm; need work to avoid flag-day + "io.netty:netty-buffer:4.1.132.Final", + "io.netty:netty-codec-http2:4.1.132.Final", + "io.netty:netty-codec-http:4.1.132.Final", + "io.netty:netty-codec-socks:4.1.132.Final", + "io.netty:netty-codec:4.1.132.Final", + "io.netty:netty-common:4.1.132.Final", + "io.netty:netty-handler-proxy:4.1.132.Final", + "io.netty:netty-handler:4.1.132.Final", + "io.netty:netty-resolver:4.1.132.Final", + "io.netty:netty-tcnative-boringssl-static:2.0.75.Final", + "io.netty:netty-tcnative-classes:2.0.75.Final", + "io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.132.Final", + "io.netty:netty-transport-native-unix-common:4.1.132.Final", + "io.netty:netty-transport:4.1.132.Final", + "io.opencensus:opencensus-api:0.31.0", + "io.opencensus:opencensus-contrib-grpc-metrics:0.31.0", + "io.perfmark:perfmark-api:0.27.0", + "junit:junit:4.13.2", + "org.mockito:mockito-core:4.4.0", + "org.checkerframework:checker-qual:3.49.5", + "org.codehaus.mojo:animal-sniffer-annotations:1.27", +] +# GRPC_DEPS_END + +bazel_dep(name = "abseil-cpp", version = "20250512.1") +bazel_dep(name = "bazel_jar_jar", version = "0.1.11.bcr.1") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis") +bazel_dep(name = "grpc-proto", version = "0.0.0-20240627-ec30f58.bcr.1", repo_name = "io_grpc_grpc_proto") +bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_java", version = "9.1.0") +bazel_dep(name = "rules_jvm_external", version = "6.0") + +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") +maven.install( + artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS, + repositories = [ + "https://repo.maven.apache.org/maven2/", + ], + strict_visibility = True, +) +use_repo(maven, "maven") + +maven.override( + coordinates = "com.google.protobuf:protobuf-java", + target = "@com_google_protobuf//:protobuf_java", +) +maven.override( + coordinates = "com.google.protobuf:protobuf-java-util", + target = "@com_google_protobuf//:protobuf_java_util", +) +maven.override( + coordinates = "com.google.protobuf:protobuf-javalite", + target = "@com_google_protobuf//:protobuf_javalite", +) +maven.override( + coordinates = "io.grpc:grpc-alts", + target = "@io_grpc_grpc_java//alts", +) +maven.override( + coordinates = "io.grpc:grpc-api", + target = "@io_grpc_grpc_java//api", +) +maven.override( + coordinates = "io.grpc:grpc-auth", + target = "@io_grpc_grpc_java//auth", +) +maven.override( + coordinates = "io.grpc:grpc-census", + target = "@io_grpc_grpc_java//census", +) +maven.override( + coordinates = "io.grpc:grpc-context", + target = "@io_grpc_grpc_java//context", +) +maven.override( + coordinates = "io.grpc:grpc-core", + target = "@io_grpc_grpc_java//core:core_maven", +) +maven.override( + coordinates = "io.grpc:grpc-googleapis", + target = "@io_grpc_grpc_java//googleapis", +) +maven.override( + coordinates = "io.grpc:grpc-grpclb", + target = "@io_grpc_grpc_java//grpclb", +) +maven.override( + coordinates = "io.grpc:grpc-inprocess", + target = "@io_grpc_grpc_java//inprocess", +) +maven.override( + coordinates = "io.grpc:grpc-netty", + target = "@io_grpc_grpc_java//netty", +) +maven.override( + coordinates = "io.grpc:grpc-netty-shaded", + target = "@io_grpc_grpc_java//netty:shaded_maven", +) +maven.override( + coordinates = "io.grpc:grpc-okhttp", + target = "@io_grpc_grpc_java//okhttp", +) +maven.override( + coordinates = "io.grpc:grpc-protobuf", + target = "@io_grpc_grpc_java//protobuf", +) +maven.override( + coordinates = "io.grpc:grpc-protobuf-lite", + target = "@io_grpc_grpc_java//protobuf-lite", +) +maven.override( + coordinates = "io.grpc:grpc-rls", + target = "@io_grpc_grpc_java//rls", +) +maven.override( + coordinates = "io.grpc:grpc-services", + target = "@io_grpc_grpc_java//services:services_maven", +) +maven.override( + coordinates = "io.grpc:grpc-stub", + target = "@io_grpc_grpc_java//stub", +) +maven.override( + coordinates = "io.grpc:grpc-testing", + target = "@io_grpc_grpc_java//testing", +) +maven.override( + coordinates = "io.grpc:grpc-xds", + target = "@io_grpc_grpc_java//xds:xds_maven", +) +maven.override( + coordinates = "io.grpc:grpc-util", + target = "@io_grpc_grpc_java//util", +) diff --git a/NOTICE.txt b/NOTICE.txt index e4be9bf96bd..f70c5620cf7 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,4 +1,4 @@ -Copyright 2014, gRPC Authors All rights reserved. +Copyright 2014 The gRPC Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,12 +25,38 @@ at: * LOCATION_IN_GRPC: * okhttp/third_party/okhttp -This product contains a modified portion of 'Netty', an open source -networking library, which can be obtained at: +This product contains a modified portion of 'Envoy', an open source +cloud-native high-performance edge/middle/service proxy, which can be +obtained at: * LICENSE: - * netty/third_party/netty/LICENSE.txt (Apache License 2.0) + * xds/third_party/envoy/LICENSE (Apache License 2.0) + * NOTICE: + * xds/third_party/envoy/NOTICE * HOMEPAGE: - * https://netty.io + * https://www.envoyproxy.io * LOCATION_IN_GRPC: - * netty/third_party/netty + * xds/third_party/envoy + +This product contains a modified portion of 'protoc-gen-validate (PGV)', +an open source protoc plugin to generate polyglot message validators, +which can be obtained at: + + * LICENSE: + * xds/third_party/protoc-gen-validate/LICENSE (Apache License 2.0) + * NOTICE: + * xds/third_party/protoc-gen-validate/NOTICE + * HOMEPAGE: + * https://github.com/envoyproxy/protoc-gen-validate + * LOCATION_IN_GRPC: + * xds/third_party/protoc-gen-validate + +This product contains a modified portion of 'udpa', +an open source universal data plane API, which can be obtained at: + + * LICENSE: + * xds/third_party/udpa/LICENSE (Apache License 2.0) + * HOMEPAGE: + * https://github.com/cncf/udpa + * LOCATION_IN_GRPC: + * xds/third_party/udpa diff --git a/README.md b/README.md index 85f4c46507a..8e6620c927e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,6 @@ gRPC-Java - An RPC library and framework ======================================== -gRPC-Java works with JDK 6. On Android, gRPC-Java supports Android API levels -14 and up (Ice Cream Sandwich and later). - -TLS usage typically requires using Java 8, or Play Services Dynamic Security -Provider on Android. Please see the [Security Readme](SECURITY.md). - @@ -19,8 +13,40 @@ Provider on Android. Please see the [Security Readme](SECURITY.md).
Homepage:
[![Join the chat at https://gitter.im/grpc/grpc](https://badges.gitter.im/grpc/grpc.svg)](https://gitter.im/grpc/grpc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/grpc/grpc-java.svg?branch=master)](https://travis-ci.org/grpc/grpc-java) -[![Coverage Status](https://coveralls.io/repos/grpc/grpc-java/badge.svg?branch=master&service=github)](https://coveralls.io/github/grpc/grpc-java?branch=master) +[![GitHub Actions Linux Testing](https://github.com/grpc/grpc-java/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/grpc/grpc-java/actions/workflows/testing.yml?branch=master) +[![Line Coverage Status](https://coveralls.io/repos/grpc/grpc-java/badge.svg?branch=master&service=github)](https://coveralls.io/github/grpc/grpc-java?branch=master) +[![Branch-adjusted Line Coverage Status](https://codecov.io/gh/grpc/grpc-java/branch/master/graph/badge.svg)](https://codecov.io/gh/grpc/grpc-java) + +Supported Platforms +------------------- + +gRPC-Java supports Java 8 and later. Android minSdkVersion 23 (Marshmallow) and +later are supported with [Java 8 language desugaring][android-java-8]. + +TLS usage on Android typically requires Play Services Dynamic Security Provider. +Please see the [Security Readme](SECURITY.md). + +Older Java versions are not directly supported, but a branch remains available +for fixes and releases. See [gRFC P5 JDK Version Support +Policy][P5-jdk-version-support]. + +Java version | gRPC Branch +------------ | ----------- +7 | 1.41.x + +[android-java-8]: https://developer.android.com/studio/write/java8-support#supported_features +[P5-jdk-version-support]: https://github.com/grpc/proposal/blob/master/P5-jdk-version-support.md#proposal + +Getting Started +--------------- + +For a guided tour, take a look at the [quick start +guide](https://grpc.io/docs/languages/java/quickstart) or the more explanatory [gRPC +basics](https://grpc.io/docs/languages/java/basics). + +The [examples](https://github.com/grpc/grpc-java/tree/v1.81.0/examples) and the +[Android example](https://github.com/grpc/grpc-java/tree/v1.81.0/examples/android) +are standalone projects that showcase the usage of gRPC. Download -------- @@ -29,41 +55,49 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: ```xml io.grpc - grpc-netty - 1.10.0 + grpc-netty-shaded + 1.81.0 + runtime io.grpc grpc-protobuf - 1.10.0 + 1.81.0 io.grpc grpc-stub - 1.10.0 + 1.81.0 ``` Or for Gradle with non-Android, add to your dependencies: ```gradle -compile 'io.grpc:grpc-netty:1.10.0' -compile 'io.grpc:grpc-protobuf:1.10.0' -compile 'io.grpc:grpc-stub:1.10.0' +runtimeOnly 'io.grpc:grpc-netty-shaded:1.81.0' +implementation 'io.grpc:grpc-protobuf:1.81.0' +implementation 'io.grpc:grpc-stub:1.81.0' ``` -For Android client, use `grpc-okhttp` instead of `grpc-netty` and -`grpc-protobuf-lite` or `grpc-protobuf-nano` instead of `grpc-protobuf`: +For Android client, use `grpc-okhttp` instead of `grpc-netty-shaded` and +`grpc-protobuf-lite` instead of `grpc-protobuf`: ```gradle -compile 'io.grpc:grpc-okhttp:1.10.0' -compile 'io.grpc:grpc-protobuf-lite:1.10.0' -compile 'io.grpc:grpc-stub:1.10.0' +implementation 'io.grpc:grpc-okhttp:1.81.0' +implementation 'io.grpc:grpc-protobuf-lite:1.81.0' +implementation 'io.grpc:grpc-stub:1.81.0' ``` +For [Bazel](https://bazel.build), you can either +[use Maven](https://github.com/bazelbuild/rules_jvm_external) +(with the GAVs from above), or use `@io_grpc_grpc_java//api` et al (see below). + [the JARs]: -http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.grpc%22%20AND%20v%3A%221.9.0%22 +https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.81.0 Development snapshots are available in [Sonatypes's snapshot -repository](https://oss.sonatype.org/content/repositories/snapshots/). +repository](https://central.sonatype.com/repository/maven-snapshots/). + +Generated Code +-------------- For protobuf-based codegen, you can put your proto files in the `src/main/proto` and `src/test/proto` directories along with an appropriate plugin. @@ -78,18 +112,18 @@ For protobuf-based codegen integrated with the Maven build system, you can use kr.motd.maven os-maven-plugin - 1.5.0.Final + 1.7.1 org.xolstice.maven.plugins protobuf-maven-plugin - 0.5.0 + 0.6.1 - com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier} + com.google.protobuf:protoc:3.25.8:exe:${os.detected.classifier} grpc-java - io.grpc:protoc-gen-grpc-java:1.10.0:exe:${os.detected.classifier} + io.grpc:protoc-gen-grpc-java:1.81.0:exe:${os.detected.classifier} @@ -106,30 +140,20 @@ For protobuf-based codegen integrated with the Maven build system, you can use [protobuf-maven-plugin]: https://www.xolstice.org/protobuf-maven-plugin/ -For protobuf-based codegen integrated with the Gradle build system, you can use -[protobuf-gradle-plugin][]: +For non-Android protobuf-based codegen integrated with the Gradle build system, +you can use [protobuf-gradle-plugin][]: ```gradle -apply plugin: 'java' -apply plugin: 'com.google.protobuf' - -buildscript { - repositories { - mavenCentral() - } - dependencies { - // ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier - // gradle versions - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3' - } +plugins { + id 'com.google.protobuf' version '0.9.5' } protobuf { protoc { - artifact = "com.google.protobuf:protoc:3.5.1-1" + artifact = "com.google.protobuf:protoc:3.25.8" } plugins { grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.10.0' + artifact = 'io.grpc:protoc-gen-grpc-java:1.81.0' } } generateProtoTasks { @@ -142,18 +166,74 @@ protobuf { [protobuf-gradle-plugin]: https://github.com/google/protobuf-gradle-plugin +The prebuilt protoc-gen-grpc-java binary uses glibc on Linux. If you are +compiling on Alpine Linux, you may want to use the [Alpine grpc-java package][] +which uses musl instead. + +[Alpine grpc-java package]: https://pkgs.alpinelinux.org/package/edge/community/x86_64/grpc-java + +For Android protobuf-based codegen integrated with the Gradle build system, also +use protobuf-gradle-plugin but specify the 'lite' options: + +```gradle +plugins { + id 'com.google.protobuf' version '0.9.5' +} + +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:3.25.8" + } + plugins { + grpc { + artifact = 'io.grpc:protoc-gen-grpc-java:1.81.0' + } + } + generateProtoTasks { + all().each { task -> + task.builtins { + java { option 'lite' } + } + task.plugins { + grpc { option 'lite' } + } + } + } +} + +``` + +For [Bazel](https://bazel.build), use the [`proto_library`](https://github.com/bazelbuild/rules_proto) +and the [`java_proto_library`](https://bazel.build/reference/be/java#java_proto_library) (no `load()` required) +and `load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")` (from this project), as in +[this example `BUILD.bazel`](https://github.com/grpc/grpc-java/blob/master/examples/BUILD.bazel). + +API Stability +------------- + +APIs annotated with `@Internal` are for internal use by the gRPC library and +should not be used by gRPC users. APIs annotated with `@ExperimentalApi` are +subject to change in future releases, and library code that other projects +may depend on should not use these APIs. + +We recommend using the +[grpc-java-api-checker](https://github.com/grpc/grpc-java-api-checker) +(an [Error Prone](https://github.com/google/error-prone) plugin) +to check for usages of `@ExperimentalApi` and `@Internal` in any library code +that depends on gRPC. It may also be used to check for `@Internal` usage or +unintended `@ExperimentalApi` consumption in non-library code. + How to Build ------------ If you are making changes to gRPC-Java, see the [compiling instructions](COMPILING.md). -Navigating Around the Source ----------------------------- +High-level Components +--------------------- -Here's a quick readers' guide to the code to help folks get started. At a high -level there are three distinct layers to the library: __Stub__, __Channel__ & -__Transport__. +At a high level there are three distinct layers to the library: *Stub*, +*Channel*, and *Transport*. ### Stub @@ -161,81 +241,34 @@ The Stub layer is what is exposed to most developers and provides type-safe bindings to whatever datamodel/IDL/interface you are adapting. gRPC comes with a [plugin](https://github.com/google/grpc-java/blob/master/compiler) to the protocol-buffers compiler that generates Stub interfaces out of `.proto` files, -but bindings to other datamodel/IDL should be trivial to add and are welcome. - -#### Key Interfaces - -[Stream Observer](https://github.com/google/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java) +but bindings to other datamodel/IDL are easy and encouraged. ### Channel The Channel layer is an abstraction over Transport handling that is suitable for interception/decoration and exposes more behavior to the application than the Stub layer. It is intended to be easy for application frameworks to use this -layer to address cross-cutting concerns such as logging, monitoring, auth etc. -Flow-control is also exposed at this layer to allow more sophisticated -applications to interact with it directly. - -#### Common - -* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java) -* [Status - error code namespace & handling](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java) - -#### Client -* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java) -* [Client Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientCall.java) -* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java) - -#### Server -* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java) -* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java) - +layer to address cross-cutting concerns such as logging, monitoring, auth, etc. ### Transport The Transport layer does the heavy lifting of putting and taking bytes off the wire. The interfaces to it are abstract just enough to allow plugging in of -different implementations. Transports are modeled as `Stream` factories. The -variation in interface between a server Stream and a client Stream exists to -codify their differing semantics for cancellation and error reporting. - -Note the transport layer API is considered internal to gRPC and has weaker API -guarantees than the core API under package `io.grpc`. - -gRPC comes with three Transport implementations: - -1. The [Netty-based](https://github.com/google/grpc-java/blob/master/netty) - transport is the main transport implementation based on - [Netty](http://netty.io). It is for both the client and the server. -2. The [OkHttp-based](https://github.com/google/grpc-java/blob/master/okhttp) - transport is a lightweight transport based on - [OkHttp](http://square.github.io/okhttp/). It is mainly for use on Android - and is for client only. -3. The - [inProcess](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/inprocess) - transport is for when a server is in the same process as the client. It is - useful for testing. - -#### Common - -* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/Stream.java) -* [Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/StreamListener.java) - -#### Client - -* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ClientStream.java) -* [Client Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ClientStreamListener.java) - -#### Server - -* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ServerStream.java) -* [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ServerStreamListener.java) - - -Examples --------- - -The [examples](https://github.com/grpc/grpc-java/tree/master/examples) -and the -[Android example](https://github.com/grpc/grpc-java/tree/master/examples/android) are standalone projects that -showcase the usage of gRPC. +different implementations. Note the transport layer API is considered internal +to gRPC and has weaker API guarantees than the core API under package `io.grpc`. + +gRPC comes with multiple Transport implementations: + +1. The Netty-based HTTP/2 transport is the main transport implementation based + on [Netty](https://netty.io). It is not officially supported on Android. + There is a "grpc-netty-shaded" version of this transport. It is generally + preferred over using the Netty-based transport directly as it requires less + dependency management and is easier to upgrade within many applications. +2. The OkHttp-based HTTP/2 transport is a lightweight transport based on + [Okio](https://square.github.io/okio/) and forked low-level parts of + [OkHttp](https://square.github.io/okhttp/). It is mainly for use on Android. +3. The in-process transport is for when a server is in the same process as the + client. It is used frequently for testing, while also being safe for + production use. +4. The Binder transport is for Android cross-process communication on a single + device. diff --git a/RELEASING.md b/RELEASING.md index 451c67ab683..c57829b8c25 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -4,73 +4,32 @@ How to Create a Release of GRPC Java (for Maintainers Only) Build Environments ------------------ We deploy GRPC to Maven Central under the following systems: -- Ubuntu 14.04 with Docker 1.6.1 that runs CentOS 6.6 -- Windows 7 64-bit with MSYS2 with mingw32 and mingw64 -- Mac OS X 10.9.5 +- Ubuntu 14.04 with Docker 13.03.0 that runs CentOS 7 +- Windows 7 64-bit with Visual Studio +- Mac OS X 10.14.6 Other systems may also work, but we haven't verified them. -Prerequisites -------------- - -### Setup OSSRH and Signing - -If you haven't deployed artifacts to Maven Central before, you need to setup -your OSSRH (OSS Repository Hosting) account and signing keys. -- Follow the instructions on [this - page](http://central.sonatype.org/pages/ossrh-guide.html) to set up an - account with OSSRH. - - You only need to create the account, not set up a new project - - Contact a gRPC maintainer to add your account after you have created it. -- (For release deployment only) Install GnuPG and [generate your key - pair](https://www.gnupg.org/documentation/howtos.html). You'll also - need to [publish your public key](https://www.gnupg.org/gph/en/manual.html#AEN464) - to make it visible to the Sonatype servers - (e.g. `gpg --keyserver pgp.mit.edu --send-key `). -- Put your GnuPG key password and OSSRH account information in - `/.gradle/gradle.properties`. - -``` -# You need the signing properties only if you are making release deployment -signing.keyId=<8-character-public-key-id> -signing.password= -signing.secretKeyRingFile=/.gnupg/secring.gpg - -ossrhUsername= -ossrhPassword= -checkstyle.ignoreFailures=false -``` - -### Build Protobuf -Protobuf libraries are needed for compiling the GRPC codegen. Despite that you -may have installed Protobuf on your system, you may want to build Protobuf -separately and install it under your personal directory, because - -1. The Protobuf version installed on your system may be different from what - GRPC requires. You may not want to pollute your system installation. -2. We will deploy both 32-bit and 64-bit versions of the codegen, thus require - both variants of Protobuf libraries. You don't want to mix them in your - system paths. - -Please see the [Main Readme](README.md) for details on building protobuf. - Common Variables ---------------- Many of the following commands expect release-specific variables to be set. Set them before continuing, and set them again when resuming. ```bash -$ MAJOR=1 MINOR=7 PATCH=0 # Set appropriately for new release -$ VERSION_FILES=( +MAJOR=1 MINOR=7 PATCH=0 # Set appropriately for new release +VERSION_FILES=( + MODULE.bazel build.gradle - android-interop-testing/app/build.gradle core/src/main/java/io/grpc/internal/GrpcUtil.java - cronet/build.gradle + examples/MODULE.bazel examples/build.gradle examples/pom.xml examples/android/clientcache/app/build.gradle examples/android/helloworld/app/build.gradle examples/android/routeguide/app/build.gradle + examples/android/strictmode/app/build.gradle + examples/example-*/build.gradle + examples/example-*/pom.xml ) ``` @@ -83,328 +42,211 @@ convention of `v..x`, while the tags include the patch version `v..`. For example, the same branch `v1.7.x` would be used to create all `v1.7` tags (e.g. `v1.7.0`, `v1.7.1`). -1. For `master`, change root build files to the next minor snapshot (e.g. +1. Review the issues in the current release [milestone](https://github.com/grpc/grpc-java/milestones) + for issues that won't make the cut. Check if any of them can be + closed. Be aware of the issues with the [TODO:release blocker][] label. + Consider reaching out to the assignee for the status update. +2. For `master`, change root build files to the next minor snapshot (e.g. ``1.8.0-SNAPSHOT``). ```bash - $ git checkout -b bump-version master + git checkout -b bump-version master # Change version to next minor (and keep -SNAPSHOT) - $ sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$((MINOR+1)).0'\1/' \ + sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$((MINOR+1)).0'\1/' \ "${VERSION_FILES[@]}" - $ sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$((MINOR+1)).0/ \ - compiler/src/test{,Lite,Nano}/golden/TestService.java.txt - $ ./gradlew build - $ git commit -a -m "Start $MAJOR.$((MINOR+1)).0 development cycle" + sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$((MINOR+1)).0/ \ + compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt + ./gradlew build + git commit -a -m "Start $MAJOR.$((MINOR+1)).0 development cycle" ``` -2. Go through PR review and submit. -3. Create the release branch starting just before your commit and push it to GitHub: +3. Go through PR review and submit. +4. Create the release branch starting just before your commit and push it to GitHub: ```bash - $ git fetch upstream - $ git checkout -b v$MAJOR.$MINOR.x \ - $(git log --pretty=format:%H --grep "^Start $MAJOR.$((MINOR+1)).0 development cycle$" upstream/master)^ - $ git push upstream v$MAJOR.$MINOR.x + git fetch upstream + git checkout -b v$MAJOR.$MINOR.x \ + $(git log --pretty=format:%H --grep "^Start $MAJOR.$((MINOR+1)).0 development cycle" upstream/master)^ + git push upstream v$MAJOR.$MINOR.x ``` -4. Go to [Travis CI settings](https://travis-ci.org/grpc/grpc-java/settings) and - add a _Cron Job_: - * Branch: `v$MAJOR.$MINOR.x` - * Interval: `weekly` - * Options: `Do not run if there has been a build in the last 24h` - * Click _Add_ button -5. Continue with Google-internal steps at go/grpc/java/releasing. +5. Continue with Google-internal steps at go/grpc-java/releasing, but stop + before `Auto releasing using kokoro`. 6. Create a milestone for the next release. 7. Move items out of the release milestone that didn't make the cut. Issues that may be backported should stay in the release milestone. Treat issues with the 'release blocker' label with special care. +8. Begin compiling release notes. This produces a starting point: + + ```bash + echo "## gRPC Java $MAJOR.$MINOR.0 Release Notes" && echo && \ + git shortlog -e --format='%s (%h)' "$(git merge-base upstream/v$MAJOR.$((MINOR-1)).x upstream/v$MAJOR.$MINOR.x)"..upstream/v$MAJOR.$MINOR.x | cat && \ + echo && echo && echo "Backported commits in previous release:" && \ + git log --oneline "$(git merge-base v$MAJOR.$((MINOR-1)).0 upstream/v$MAJOR.$MINOR.x)"..v$MAJOR.$((MINOR-1)).0^ + ``` + +[TODO:release blocker]: https://github.com/grpc/grpc-java/issues?q=label%3A%22TODO%3Arelease+blocker%22 +[TODO:backport]: https://github.com/grpc/grpc-java/issues?q=label%3ATODO%3Abackport Tagging the Release ------------------- 1. Verify there are no open issues in the release milestone. Open issues should - either be deferred or resolved and the fix backported. -2. For vMajor.Minor.x branch, change `README.md` to refer to the next release + either be deferred or resolved and the fix backported. Verify there are no + [TODO:release blocker][] nor [TODO:backport][] issues (open or closed), or + that they are tracking an issue for a different branch. +2. Ensure that the Google-internal steps + at go/grpc-java/releasing#before-tagging-a-release are completed. +3. For vMajor.Minor.x branch, change `README.md` to refer to the next release version. _Also_ update the version numbers for protoc if the protobuf library version was updated since the last release. ```bash - $ git checkout -b release v$MAJOR.$MINOR.x - # Bump documented versions. Don't forget protobuf version - $ ${EDITOR:-nano -w} README.md - $ git commit -a -m "Update README to reference $MAJOR.$MINOR.$PATCH" + git checkout v$MAJOR.$MINOR.x + git pull upstream v$MAJOR.$MINOR.x + git checkout -b release-v$MAJOR.$MINOR.$PATCH + + # Bump documented gRPC versions. + # Also update protoc version to match protobuf version in gradle/libs.versions.toml. + ${EDITOR:-nano -w} README.md + + git commit -a -m "Update README etc to reference $MAJOR.$MINOR.$PATCH" ``` -3. Change root build files to remove "-SNAPSHOT" for the next release version +4. Change root build files to remove "-SNAPSHOT" for the next release version (e.g. `0.7.0`). Commit the result and make a tag: ```bash # Change version to remove -SNAPSHOT - $ sed -i 's/-SNAPSHOT\(.*CURRENT_GRPC_VERSION\)/\1/' "${VERSION_FILES[@]}" - $ sed -i s/-SNAPSHOT// compiler/src/test{,Lite,Nano}/golden/TestService.java.txt - $ ./gradlew build - $ git commit -a -m "Bump version to $MAJOR.$MINOR.$PATCH" - $ git tag -a v$MAJOR.$MINOR.$PATCH -m "Version $MAJOR.$MINOR.$PATCH" + sed -i 's/-SNAPSHOT\(.*CURRENT_GRPC_VERSION\)/\1/' "${VERSION_FILES[@]}" + sed -i s/-SNAPSHOT// compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt + ./gradlew build + git commit -a -m "Bump version to $MAJOR.$MINOR.$PATCH" + git tag -a v$MAJOR.$MINOR.$PATCH -m "Version $MAJOR.$MINOR.$PATCH" ``` -4. Change root build files to the next snapshot version (e.g. `0.7.1-SNAPSHOT`). +5. Change root build files to the next snapshot version (e.g. `0.7.1-SNAPSHOT`). Commit the result: ```bash # Change version to next patch and add -SNAPSHOT - $ sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT'\1/' \ + sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT'\1/' \ "${VERSION_FILES[@]}" - $ sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT/ compiler/src/test{,Lite,Nano}/golden/TestService.java.txt - $ ./gradlew build - $ git commit -a -m "Bump version to $MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT" - ``` -5. Go through PR review and push the release tag and updated release branch to - GitHub: - - ```bash - $ git checkout v$MAJOR.$MINOR.x - $ git merge --ff-only release - $ git push upstream v$MAJOR.$MINOR.$PATCH - $ git push upstream v$MAJOR.$MINOR.x - ``` -6. Close the release milestone. - -Setup Build Environment ---------------------------- - -### Linux -The deployment for Linux uses [Docker](https://www.docker.com/) running -CentOS 6.6 in order to ensure that we have a consistent deployment environment -on Linux. You'll first need to install Docker if not already installed on your -system. Make sure to have at least version 1.7.1 or later. - -1. Under the [Protobuf source directory](https://github.com/google/protobuf), - build the `protoc-artifacts` image: - - ```bash - protobuf$ docker build -t protoc-artifacts protoc-artifacts - ``` -2. Under the grpc-java source directory, build the `grpc-java-deploy` image: - - ```bash - grpc-java$ docker build -t grpc-java-deploy compiler - ``` -3. Start a Docker container that has the deploy environment set up for you. The - GRPC source is cloned into `/grpc-java`. - - ```bash - $ docker run -it --rm=true grpc-java-deploy - ``` - - Note that the container will be deleted after you exit. Any changes you have - made (e.g., copied configuration files) will be lost. If you want to keep the - container, remove `--rm=true` from the command line. -4. Next, you'll need to copy your OSSRH credentials and GnuPG keys to your docker container. - In Docker: - ``` - # mkdir /root/.gradle - ``` - Find the container ID in your bash prompt, which is shown as `[root@ ...]`. - In host: - ``` - $ docker cp ~/.gnupg :/root/ - $ docker cp ~/.gradle/gradle.properties :/root/.gradle/ - ``` - - You'll also need to update `signing.secretKeyRingFile` in - `/root/.gradle/gradle.properties` to point to `/root/.gnupg/secring.gpg`. - -### Windows - -#### Windows 64-bit with MSYS2 (Recommended for Windows) -Because the gcc shipped with MSYS2 doesn't support multilib, you have to -compile and deploy 32-bit and 64-bit binaries in separate steps. - -##### Under MinGW-w64 Win32 Shell -1. Compile and install 32-bit protobuf: - - ```bash - protobuf$ ./configure --disable-shared --prefix=$HOME/protobuf-32 - protobuf$ make clean && make && make install - ``` -2. Configure CXXFLAGS needed by the protoc plugin when building. - - ```bash - grpc-java$ export CXXFLAGS="-I$HOME/protobuf-32/include" \ - LDFLAGS="-L$HOME/protobuf-32/lib" - ``` - -##### Under MinGW-w64 Win64 Shell -1. Compile and install 64-bit protobuf: - - ```bash - protobuf$ ./configure --disable-shared --prefix=$HOME/protobuf-64 - protobuf$ make clean && make && make install - ``` -2. Configure CXXFLAGS needed by the protoc plugin when building. - - ```bash - grpc-java$ export CXXFLAGS="-I$HOME/protobuf-64/include" \ - LDFLAGS="-L$HOME/protobuf-64/lib" - ``` - -#### Windows 64-bit with Cygwin64 (TODO: incomplete) -Because the MinGW gcc shipped with Cygwin64 doesn't support multilib, you have -to compile and deploy 32-bit and 64-bit binaries in separate steps. - -1. Compile and install 32-bit protobuf. `-static-libgcc -static-libstdc++` are - needed for `protoc` to be successfully run in the unit test. - - ```bash - protobuf$ LDFLAGS="-static-libgcc -static-libstdc++" ./configure --host=i686-w64-mingw32 --disable-shared --prefix=$HOME/protobuf-32 - protobuf$ make clean && make && make install - ``` - -2. Compile and install 64-bit protobuf: - - ```bash - protobuf$ ./configure --host=x86_64-w64-mingw32 --disable-shared --prefix=$HOME/protobuf-64 - protobuf$ make clean && make && make install - ``` - -### Mac -Please refer to [Protobuf -README](https://github.com/google/protobuf/blob/master/README.md) for how to -set up GCC and Unix tools on Mac. - -Mac OS X has been 64-bit-only since 10.7 and we are compiling for 10.7 and up. -We only build 64-bit artifact for Mac. - -1. Compile and install protobuf: - - ```bash - protobuf$ CXXFLAGS="-m64" ./configure --disable-shared --prefix=$HOME/protobuf - protobuf$ make clean && make && make install - ``` -2. Configure CXXFLAGS needed by the protoc plugin when building. - - ```bash - grpc-java$ export CXXFLAGS="-I$HOME/protobuf/include" \ - LDFLAGS="$HOME/protobuf/lib/libprotobuf.a $HOME/protobuf/lib/libprotoc.a" - ``` - -Build and Deploy ----------------- -We currently distribute the following OSes and architectures: - -| OS | x86_32 | x86_64 | -| --- | --- | --- | -| Linux | X | X | -| Windows | X | X | -| Mac | | X | - -Deployment to Maven Central (or the snapshot repo) is a two-step process. The only -artifact that is platform-specific is codegen, so we only need to deploy the other -jars once. So the first deployment is for all of the artifacts from one of the selected -OS/architectures. After that, we then deploy the codegen artifacts for the remaining -OS/architectures. - -**NOTE: _Before building/deploying, be sure to switch to the appropriate branch or tag in -the grpc-java source directory._** - -### First Deployment - -As stated above, this only needs to be done once for one of the selected OS/architectures. -The following command will build the whole project and upload it to Maven -Central. Parallel building [is not safe during -uploadArchives](https://issues.gradle.org/browse/GRADLE-3420). -```bash -grpc-java$ ./gradlew clean build && ./gradlew -Dorg.gradle.parallel=false uploadArchives -``` - -If the version has the `-SNAPSHOT` suffix, the artifacts will automatically -go to the snapshot repository. Otherwise it's a release deployment and the -artifacts will go to a freshly created staging repository. - -### Deploy GRPC Codegen for Additional Platforms -The previous step will only deploy the codegen artifacts for the OS you run on -it and the architecture of your JVM. For a fully fledged deployment, you will -need to deploy the codegen for all other supported OSes and architectures. + sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT/ \ + compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt + ./gradlew build + git commit -a -m "Bump version to $MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT" + git push -u origin release-v$MAJOR.$MINOR.$PATCH + ``` + Raise a PR and set the base branch of the PR to v$MAJOR.$MINOR.x of the upstream grpc-java repo. +6. Go through PR review and push the release tag and updated release branch to + GitHub (DO NOT click the merge button on the GitHub page): + + ```bash + git checkout v$MAJOR.$MINOR.x + git merge --ff-only release-v$MAJOR.$MINOR.$PATCH + git push upstream v$MAJOR.$MINOR.x + git push upstream v$MAJOR.$MINOR.$PATCH + ``` +7. Close the release milestone. + +8. Trigger build as described in "Auto releasing using kokoro" at + go/grpc-java/releasing. + + It runs three jobs on Kokoro, one on each platform. See their scripts: + `linux_artifacts.sh`, `windows.bat`, and `macos.sh`. The mvn-artifacts/ + outputs of each script is combined into a single folder and then processed + by `upload_artifacts.sh`, which signs the files and uploads to Sonatype. + +9. Once all of the artifacts have been pushed to the staging repository, the + repository should have been closed by `upload_artifacts.sh`. Closing triggers + several sanity checks on the repository. If this completes successfully, the + repository can then be `released`, which will begin the process of pushing + the new artifacts to Maven Central (the staging repository will be destroyed + in the process). You can see the complete process for releasing to Maven + Central on the [OSSRH site](https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#deploying). + +10. We have containers for each release to detect compatibility regressions with + old releases. Generate one for the new release by following the [GCR image + generation instructions][gcr-image]. Summary: + ```bash + # If you haven't previously configured docker: + gcloud auth configure-docker us-docker.pkg.dev + + # In main grpc repo, add the new version to matrix + ${EDITOR:-nano -w} tools/interop_matrix/client_matrix.py + tools/interop_matrix/create_matrix_images.py --git_checkout --release=v$MAJOR.$MINOR.$PATCH \ + --upload_images --language java + docker pull us-docker.pkg.dev/grpc-testing/testing-images-public/grpc_interop_java:v$MAJOR.$MINOR.$PATCH + docker_image=us-docker.pkg.dev/grpc-testing/testing-images-public/grpc_interop_java:v$MAJOR.$MINOR.$PATCH \ + tools/interop_matrix/testcases/java__master + + # Commit the changes + git commit --all -m "[interop] Add grpc-java $MAJOR.$MINOR.$PATCH to client_matrix.py" + + # Create a PR with the `release notes: no` label and run ad-hoc test against your PR + ``` +[gcr-image]: https://github.com/grpc/grpc/blob/master/tools/interop_matrix/README.md#step-by-step-instructions-for-adding-a-gcr-image-for-a-new-release-for-compatibility-test + +11. Update gh-pages with the new Javadoc. Generally the file is on repo1 + 15 minutes after publishing: + + ```bash + git checkout gh-pages + git pull --ff-only upstream gh-pages + rm -r javadoc/ + wget -O grpc-all-javadoc.jar "https://repo1.maven.org/maven2/io/grpc/grpc-all/$MAJOR.$MINOR.$PATCH/grpc-all-$MAJOR.$MINOR.$PATCH-javadoc.jar" + unzip -d javadoc grpc-all-javadoc.jar + patch -p1 < ga.patch + rm grpc-all-javadoc.jar + rm -r javadoc/META-INF/ + git add -A javadoc + git commit -m "Javadoc for $MAJOR.$MINOR.$PATCH" + git push upstream gh-pages + ``` + + Verify the current version is [live on grpc.io](https://grpc.io/grpc-java/javadoc/). + +12. Add [Release Notes](https://github.com/grpc/grpc-java/releases) for the new tag. + *Make sure that any backports are reflected in the release notes.* + +13. Notify the Community. Post a release announcement to + [grpc-io](https://groups.google.com/forum/#!forum/grpc-io) + (`grpc-io@googlegroups.com`) with the title `gRPC-Java v$MAJOR.$MINOR.$PATCH + Released`. The email content should link to the GitHub release notes and + include a copy of them. + +14. Update README.md. Cherry-pick the commit that updated the README.md into the + master branch. + + ```bash + git checkout -b bump-readme master + git cherry-pick v$MAJOR.$MINOR.$PATCH^ + git push --set-upstream origin bump-readme + ``` + + Create a PR and go through the review process + +15. Update version referenced by tutorials. Update `params.grpc_vers.java` in + [config.yaml](https://github.com/grpc/grpc.io/blob/master/config.yaml) of + the grpc.io repository. Create a PR and go through the review process. + +Post-release upgrades +--------------------- +Upgrade dependencies after the release so they can be well-tested before the +next release. -To deploy the codegen for an OS and architecture, you must run the following -commands on that OS and specify the architecture by the flag `-PtargetArch=`. +Upgrade the Gradle plugins in `settings.gradle` and the Gradle version in +`gradle/wrapper/gradle-wrapper.properties`. Make sure to read the release notes +for each dependency upgraded. Test by doing a regular build. -If you are doing a snapshot deployment: +Upgrade the regular dependencies in `gradle/libs.versions.toml`, except for +Netty and netty-tcnative. To find available upgrades: ```bash -grpc-java$ ./gradlew clean grpc-compiler:build grpc-compiler:uploadArchives \ - -PtargetArch= -Dorg.gradle.parallel=false +./gradlew checkForUpdates ``` -When deploying a Release, the first deployment will create -[a new staging repository](https://oss.sonatype.org/#stagingRepositories). You'll need -to look up the ID in the OSSRH UI (usually in the form of `iogrpc-*`). Codegen -deployment commands should include `-PrepositoryId=` in order to -ensure that the artifacts are pushed to the same staging repository. - -```bash -grpc-java$ ./gradlew clean grpc-compiler:build grpc-compiler:uploadArchives -PtargetArch= \ - -PrepositoryId= -Dorg.gradle.parallel=false -``` - -Releasing on Maven Central --------------------------- -Once all of the artifacts have been pushed to the staging repository, the -repository must first be `closed`, which will trigger several sanity checks -on the repository. If this completes successfully, the repository can then -be `released`, which will begin the process of pushing the new artifacts to -Maven Central (the staging repository will be destroyed in the process). You can -see the complete process for releasing to Maven Central on the [OSSRH -site](http://central.sonatype.org/pages/releasing-the-deployment.html). - -Build interop container image ------------------------------ - -We have containers for each release to detect compatibility regressions with old -releases. Generate one for the new release by following the -[GCR image generation instructions](https://github.com/grpc/grpc/blob/master/tools/interop_matrix/README.md#step-by-step-instructions-for-adding-a-gcr-image-for-a-new-release-for-compatibility-test). - -Update README.md ----------------- -After waiting ~1 day and verifying that the release appears on [Maven -Central](http://mvnrepository.com/), cherry-pick the commit that updated the -README into the master branch and go through review process. - -``` -$ git checkout -b bump-readme master -$ git cherry-pick v$MAJOR.$MINOR.$PATCH^ -``` - -Update version referenced by tutorials --------------------------------------- - -Update the `grpc_java_release_tag` in -[\_data/config.yml](https://github.com/grpc/grpc.github.io/blob/master/_data/config.yml) -of the grpc.github.io repository. - -Notify the Community --------------------- -Finally, document and publicize the release. - -1. Add [Release Notes](https://github.com/grpc/grpc-java/releases) for the new tag. - The description should include any major fixes or features since the last release. - You may choose to add links to bugs, PRs, or commits if appropriate. -2. Post a release announcement to [grpc-io](https://groups.google.com/forum/#!forum/grpc-io) - (`grpc-io@googlegroups.com`). The title should be something that clearly identifies - the release (e.g.`GRPC-Java Released`). - -Update Hosted Javadoc ---------------------- - -Now we need to update gh-pages with the new Javadoc: - -```bash -git checkout gh-pages -rm -r javadoc/ -wget -O grpc-all-javadoc.jar "http://search.maven.org/remotecontent?filepath=io/grpc/grpc-all/$MAJOR.$MINOR.$PATCH/grpc-all-$MAJOR.$MINOR.$PATCH-javadoc.jar" -unzip -d javadoc grpc-all-javadoc.jar -patch -p1 < ga.patch -rm grpc-all-javadoc.jar -rm -r javadoc/META-INF/ -git add -A javadoc -git commit -m "Javadoc for $MAJOR.$MINOR.$PATCH" -``` +Test by doing a regular build. For each step, if a dependency cannot be +upgraded, add a comment. Create issues in other projects for breakages, and in +gRPC for things that will need a migration effort. -Push gh-pages to the main repository and verify the current version is [live -on grpc.io](https://grpc.io/grpc-java/javadoc/). +When happy with the dependency upgrades, update the versions in `MODULE.bazel`, +`repositories.bzl`, and the various `pom.xml` and `build.gradle` files in +`examples/`. diff --git a/SECURITY.md b/SECURITY.md index 24b2cb142a0..e710ceaabe1 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,35 +1,52 @@ +# Security Policy + +For information on gRPC Security Policy and reporting potentional security +issues, please see [gRPC CVE Process][]. + +[gRPC CVE Process]: https://github.com/grpc/proposal/blob/master/P4-grpc-cve-process.md + # Authentication -gRPC supports a number of different mechanisms for asserting identity between an client and server. This document provides code samples demonstrating how to provide SSL/TLS encryption support and identity assertions in Java, as well as passing OAuth2 tokens to services that support it. +gRPC supports a number of different mechanisms for asserting identity between an +client and server. This document provides code samples demonstrating how to +provide SSL/TLS encryption support and identity assertions in Java, as well as +passing OAuth2 tokens to services that support it. # Transport Security (TLS) -HTTP/2 over TLS mandates the use of [ALPN](https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-05) to negotiate the use of the h2 protocol. ALPN is a fairly new standard and (where possible) gRPC also supports protocol negotiation via [NPN](https://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04) for systems that do not yet support ALPN. +HTTP/2 over TLS mandates the use of [ALPN](https://tools.ietf.org/html/rfc7301) +to negotiate the use of the h2 protocol and support for the GCM mode of AES. -On Android, use the [Play Services Provider](#tls-on-android). For non-Android systems, use [OpenSSL](#tls-with-openssl). +There are multiple options available, but on Android we recommend using the +[Play Services Provider](#tls-on-android) and for non-Android systems we +recommend [netty-tcnative with +BoringSSL](#tls-with-netty-tcnative-on-boringssl). ## TLS on Android On Android we recommend the use of the [Play Services Dynamic Security -Provider](https://www.appfoundry.be/blog/2014/11/18/Google-Play-Services-Dynamic-Security-Provider/) -to ensure your application has an up-to-date OpenSSL library with the necessary -ciper-suites and a reliable ALPN implementation. This requires [updating the -security provider at -runtime](https://developer.android.com/training/articles/security-gms-provider.html). +Provider][] to ensure your application has an up-to-date OpenSSL library with +the necessary cipher-suites and a reliable ALPN implementation. This requires +[updating the security provider at runtime][config-psdsp]. Although ALPN mostly works on newer Android releases (especially since 5.0), there are bugs and discovered security vulnerabilities that are only fixed by upgrading the security provider. Thus, we recommend using the Play Service Dynamic Security Provider for all Android versions. -*Note: The Dynamic Security Provider must be installed **before** creating a gRPC OkHttp channel. gRPC's OkHttpProtocolNegotiator statically initializes the security protocol(s) available to gRPC, which means that changes to the security provider after the first channel is created will not be picked up by gRPC.* +*Note: The Dynamic Security Provider must be installed **before** creating a +gRPC OkHttp channel. gRPC statically initializes the security protocol(s) +available, which means that changes to the security provider after the first +channel is created will not be noticed by gRPC.* + +[Play Services Dynamic Security Provider]: https://www.appfoundry.be/blog/2014/11/18/Google-Play-Services-Dynamic-Security-Provider/ +[config-psdsp]: https://developer.android.com/training/articles/security-gms-provider.html ### Bundling Conscrypt If depending on Play Services is not an option for your app, then you may bundle [Conscrypt](https://conscrypt.org) with your application. Binaries are available -on [Maven -Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.conscrypt%20a%3Aconscrypt-android). +on [Maven Central][conscrypt-maven]. Like the Play Services Dynamic Security Provider, you must still "install" Conscrypt before use. @@ -42,100 +59,98 @@ import java.security.Security; Security.insertProviderAt(Conscrypt.newProvider(), 1); ``` -## TLS with OpenSSL +[conscrypt-maven]: https://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.conscrypt%20a%3Aconscrypt-android -This is currently the recommended approach for using gRPC over TLS (on non-Android systems). +## TLS on non-Android -The main benefits of using OpenSSL are: +OpenJDK versions prior to Java 8u252 do not support ALPN. Java 8 has 10% the +performance of OpenSSL. -1. **Speed**: In local testing, we've seen performance improvements of 3x over the JDK. GCM, which is used by the only cipher suite required by the HTTP/2 spec, is 10-500x faster. -2. **Ciphers**: OpenSSL has its own ciphers and is not dependent on the limitations of the JDK. This allows supporting GCM on Java 7. -3. **ALPN to NPN Fallback**: if the remote endpoint doesn't support ALPN. -4. **Version Independence**: does not require using a different library version depending on the JDK update. +We recommend most users use grpc-netty-shaded, which includes netty-tcnative on +BoringSSL. It includes pre-built libraries for 64 bit Windows, OS X, and 64 bit +Linux. For 32 bit Windows, Conscrypt is an option. For all other platforms, Java +9+ is required. -Support for OpenSSL is only provided for the Netty transport via [netty-tcnative](https://github.com/netty/netty-tcnative), which is a fork of -[Apache Tomcat's tcnative](http://tomcat.apache.org/native-doc/), a JNI wrapper around OpenSSL. +For users of xDS management protocol, the grpc-netty-shaded transport is +particularly appropriate since it is already used internally for the xDS +protocol and is a runtime dependency of grpc-xds. -### OpenSSL: Dynamic vs Static (which to use?) +For users of grpc-netty we recommend [netty-tcnative with +BoringSSL](#tls-with-netty-tcnative-on-boringssl), although using the built-in +JDK support in Java 9+, [Conscrypt](#tls-with-conscrypt), and [netty-tcnative +with OpenSSL](#tls-with-netty-tcnative-on-openssl) are other valid options. -As of version `1.1.33.Fork14`, netty-tcnative provides two options for usage: statically or dynamically linked. For simplification of initial setup, -we recommend that users first look at `netty-tcnative-boringssl-static`, which is statically linked against BoringSSL and Apache APR. Using this artifact requires no extra installation and guarantees that ALPN and the ciphers required for -HTTP/2 are available. In addition, starting with `1.1.33.Fork16` binaries for -all supported platforms can be included at compile time and the correct binary -for the platform can be selected at runtime. +[Netty TCNative](https://github.com/netty/netty-tcnative) is a fork of +[Apache Tomcat's tcnative](https://tomcat.apache.org/native-doc/) and is a JNI +wrapper around OpenSSL/BoringSSL/LibreSSL. -Production systems, however, may require an easy upgrade path for OpenSSL security patches. In this case, relying on the statically linked artifact also implies waiting for the Netty team -to release the new artifact to Maven Central, which can take some time. A better solution in this case is to use the dynamically linked `netty-tcnative` artifact, which allows the site administrator -to easily upgrade OpenSSL in the standard way (e.g. apt-get) without relying on any new builds from Netty. +We recommend BoringSSL for its simplicity and low occurrence of security +vulnerabilities relative to OpenSSL. BoringSSL is used by Conscrypt as well. -### OpenSSL: Statically Linked (netty-tcnative-boringssl-static) +### TLS with netty-tcnative on BoringSSL -This is the simplest way to configure the Netty transport for OpenSSL. You just need to add the appropriate `netty-tcnative-boringssl-static` artifact to your application's classpath. +Netty-tcnative with BoringSSL includes BoringSSL statically linked in the +binary. This means the system's pre-installed TLS libraries will not be used. +Production systems that have centralized upgrade agility in the face of +security vulnerabilities may want to use [netty-tcnative on +OpenSSL](#tls-with-netty-tcnative-on-openssl) instead. -Artifacts are available on [Maven Central](http://repo1.maven.org/maven2/io/netty/netty-tcnative-boringssl-static/) for the following platforms: +Users of grpc-netty-shaded will automatically use netty-tcnative with +BoringSSL. -Maven Classifier | Description ----------------- | ----------- -windows-x86_64 | Windows distribution -osx-x86_64 | Mac distribution -linux-x86_64 | Linux distribution +grpc-netty users will need to add the appropriate +`netty-tcnative-boringssl-static` artifact to the application's classpath. +Artifacts are available for 64 bit Windows, OS X, and 64 bit Linux. -##### Getting netty-tcnative-boringssl-static from Maven - -In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-plugin) to help simplify the dependency. +Depending on netty-tcnative-boringssl-static will include binaries for all +supported platforms. For Maven: ```xml - io.netty netty-tcnative-boringssl-static - 2.0.6.Final + 2.0.20.Final + runtime - ``` -##### Getting netty-tcnative-boringssl-static from Gradle - -Gradle you can use the [osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin), which is a wrapper around the os-maven-plugin. +And for Gradle: ```gradle -buildscript { - repositories { - mavenCentral() - } -} - dependencies { - compile 'io.netty:netty-tcnative-boringssl-static:2.0.6.Final' + // See table for correct version + runtime 'io.netty:netty-tcnative-boringssl-static:2.0.20.Final' } ``` -### OpenSSL: Dynamically Linked (netty-tcnative) - -If for any reason you need to dynamically link against OpenSSL (e.g. you need control over the version of OpenSSL), you can instead use the `netty-tcnative` artifact. - -Requirements: +For projects sensitive to binary size, specify the classifier for the precise +platform you need: `windows-x86_64`, `osx-x86_64`, `linux-x86_64`. You can also +use [os-maven-plugin](https://github.com/trustin/os-maven-plugin) or +[osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin), +to choose the classifier for the platform running the build. -1. [OpenSSL](https://www.openssl.org/) version >= 1.0.2 for ALPN support, or version >= 1.0.1 for NPN. -2. [Apache APR library (libapr-1)](https://apr.apache.org/) version >= 1.5.2. -3. [netty-tcnative](https://github.com/netty/netty-tcnative) version >= 1.1.33.Fork7 must be on classpath. Prior versions only supported NPN and only Fedora-derivatives were supported for Linux. +### TLS with netty-tcnative on OpenSSL -Artifacts are available on [Maven Central](http://repo1.maven.org/maven2/io/netty/netty-tcnative/) for the following platforms: +Using OpenSSL can have more initial configuration issues, but can be useful if +your OS's OpenSSL version is recent and kept up-to-date with security fixes. +OpenSSL is not included with tcnative, but instead is dynamically linked using +your operating system's OpenSSL. -Classifier | Description ----------------- | ----------- -windows-x86_64 | Windows distribution -osx-x86_64 | Mac distribution -linux-x86_64 | Used for non-Fedora derivatives of Linux -linux-x86_64-fedora | Used for Fedora derivatives +To use OpenSSL you will use the `netty-tcnative` artifact. It requires: -On Linux it should be noted that OpenSSL uses a different soname for Fedora derivatives than other Linux releases. To work around this limitation, netty-tcnative deploys two separate versions for linux. +1. [OpenSSL](https://www.openssl.org/) version >= 1.0.2 for ALPN support. +2. [Apache APR library (libapr-1)](https://apr.apache.org/) version >= 1.5.2. -##### Getting netty-tcnative from Maven +You must specify a classifier for the correct netty-tcnative binary: +`windows-x86_64`, `osx-x86_64`, `linux-x86_64`, or `linux-x86_64-fedora`. +Fedora derivatives use a different soname from other Linux distributations, so +you must select the "fedora" version on those distributions. -In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-plugin) to help simplify the dependency. +In Maven, you can use the +[os-maven-plugin](https://github.com/trustin/os-maven-plugin) to help simplify +the dependency. ```xml @@ -143,8 +158,9 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven- io.netty netty-tcnative - 2.0.6.Final + 2.0.20.Final ${tcnative.classifier} + runtime @@ -154,7 +170,7 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven- kr.motd.maven os-maven-plugin - 1.5.0.Final + 1.7.1 @@ -186,9 +202,8 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven- ``` -##### Getting netty-tcnative from Gradle - -Gradle you can use the [osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin), which is a wrapper around the os-maven-plugin. +And in Gradle you can use the +[osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin). ```gradle buildscript { @@ -211,58 +226,34 @@ if (osdetector.os == "linux" && osdetector.release.isLike("fedora")) { } dependencies { - compile 'io.netty:netty-tcnative:2.0.6.Final:' + tcnative_classifier + runtime 'io.netty:netty-tcnative:2.0.20.Final:' + tcnative_classifier } ``` -## TLS with JDK (Jetty ALPN/NPN) +### TLS with Conscrypt -**WARNING: DON'T DO THIS!!** +[Conscrypt](https://conscrypt.org) provides an implementation of the JSSE +security APIs based on BoringSSL. Pre-built binaries are available for 32 and +64 bit Windows, OS X, and 64 bit Linux. -*For non-Android systems, the recommended approach is to use [OpenSSL](#tls-with-openssl). Using the JDK for ALPN is generally much slower and may not support the necessary ciphers for HTTP2.* +Depend on `conscrypt-openjdk-uber` for binaries of all supported JRE platforms. +For projects sensitive to binary size, depend on `conscrypt-openjdk` and +specify the appropriate classifier. `os-maven-plugin` and +`osdetector-gradle-plugin` may also be used. See the documentation for +[netty-tcnative-boringssl-static](#tls-with-netty-tcnative-on-boringssl) for +example usage of the plugins. -*Jetty ALPN brings its own baggage in that the Java bootclasspath needs to be modified, which may not be an option for some environments. In addition, a specific version of Jetty ALPN has to be used for a given version of the JRE. If the versions don't match the negotiation will fail, but you won't really know why. And since there is such a tight coupling between Jetty ALPN and the JRE, there are no guarantees that Jetty ALPN will support every JRE out in the wild.* - -*The moral of the story is: Don't use the JDK for ALPN! But if you absolutely have to, here's how you do it... :)* - ---- - -If not using the Netty transport (or you are unable to use OpenSSL for some reason) another alternative is to use the JDK for TLS. - -No standard Java release has built-in support for ALPN today ([there is a tracking issue](https://bugs.openjdk.java.net/browse/JDK-8051498) so go upvote it!) so we need to use the [Jetty-ALPN](https://github.com/jetty-project/jetty-alpn) (or [Jetty-NPN](https://github.com/jetty-project/jetty-npn) if on Java < 8) bootclasspath extension for OpenJDK. To do this, add an `Xbootclasspath` JVM option referencing the path to the Jetty `alpn-boot` jar. - -```sh -java -Xbootclasspath/p:/path/to/jetty/alpn/extension.jar ... -``` +Generally you will "install" Conscrypt before use, for gRPC to find. -Note that you must use the [release of the Jetty-ALPN jar](http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions) specific to the version of Java you are using. However, you can use the JVM agent [Jetty-ALPN-Agent](https://github.com/jetty-project/jetty-alpn-agent) to load the correct Jetty `alpn-boot` jar file for the current Java version. To do this, instead of adding an `Xbootclasspath` option, add a `javaagent` JVM option referencing the path to the Jetty `alpn-agent` jar. +```java +import org.conscrypt.Conscrypt; +import java.security.Security; +... -```sh -java -javaagent:/path/to/jetty-alpn-agent.jar ... +// Somewhere in main() +Security.insertProviderAt(Conscrypt.newProvider(), 1); ``` -### JDK Ciphers - -Java 7 does not support [the cipher suites recommended](https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-9.2.2) by the HTTP2 specification. To address this we suggest servers use Java 8 where possible or use an alternative JCE implementation such as [Bouncy Castle](https://www.bouncycastle.org/java.html). If this is not practical it is possible to use other ciphers but you need to ensure that the services you intend to call have [allowed out-of-spec ciphers](https://github.com/grpc/grpc/issues/681) and have evaluated the security risks of doing so. - -Users should be aware that GCM is [_very_ slow (1 MB/s)](https://bugzilla.redhat.com/show_bug.cgi?id=1135504) before Java 8u60. With Java 8u60 GCM is 10x faster (10-20 MB/s), but that is still slow compared to OpenSSL (~200 MB/s), especially with AES-NI support (~1 GB/s). GCM cipher suites are the only suites available that comply with HTTP2's cipher requirements. - -### Configuring Jetty ALPN in Web Containers - -Some web containers, such as [Jetty](http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html) restrict access to server classes for web applications. A gRPC client running within such a container must be properly configured to allow access to the ALPN classes. In Jetty, this is done by including a `WEB-INF/jetty-env.xml` file containing the following: - -```xml - - - - - - - - -org.eclipse.jetty.alpn. - - -``` ## Enabling TLS on a server To use TLS on the server, a certificate chain and private key need to be @@ -270,44 +261,50 @@ specified in PEM format. The standard TLS port is 443, but we use 8443 below to avoid needing extra permissions from the OS. ```java -Server server = ServerBuilder.forPort(8443) - // Enable TLS - .useTransportSecurity(certChainFile, privateKeyFile) +ServerCredentials creds = TlsServerCredentials.create(certChainFile, privateKeyFile); +Server server = Grpc.newServerBuilderForPort(8443, creds) .addService(serviceImplementation) - .build(); -server.start(); + .build() + .start(); ``` If the issuing certificate authority is not known to the client then a properly -configured SslContext or SSLSocketFactory should be provided to the -NettyChannelBuilder or OkHttpChannelBuilder, respectively. +configured trust manager should be provided to TlsChannelCredentials and used to +construct the channel. ## Mutual TLS [Mutual authentication][] (or "client-side authentication") configuration is similar to the server by providing truststores, a client certificate and private key to the client channel. The server must also be configured to request a certificate from clients, as well as truststores for which client certificates it should allow. ```java -Server server = NettyServerBuilder.forPort(8443) - .sslContext(GrpcSslContexts.forServer(certChainFile, privateKeyFile) - .trustManager(clientCertChainFile) - .clientAuth(ClientAuth.OPTIONAL) - .build()); +ServerCredentials creds = TlsServerCredentials.newBuilder() + .keyManager(certChainFile, privateKeyFile) + .trustManager(clientCAsFile) + .clientAuth(TlsServerCredentials.ClientAuth.REQUIRE) + .build(); ``` -Negotiated client certificates are available in the SSLSession, which is found in the `TRANSPORT_ATTR_SSL_SESSION` attribute of Grpc. A server interceptor can provide details in the current Context. +Negotiated client certificates are available in the SSLSession, which is found +in the `Grpc.TRANSPORT_ATTR_SSL_SESSION` attribute of the call. A server +interceptor can provide details in the current Context. ```java -public final static Context.Key SSL_SESSION_CONTEXT = Context.key("SSLSession"); +// The application uses this in its handlers. +public static final Context.Key SECURITY_INFO = Context.key("my.security.Info"); @Override -public ServerCall.Listener interceptCall(ServerCall call, +public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler next) { - SSLSession sslSession = call.attributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION); + SSLSession sslSession = call.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION); if (sslSession == null) { - return next.startCall(call, headers) + return next.startCall(call, headers); } + // This interceptor can provide a centralized policy to process the client's + // certificate. Avoid exposing low-level details (like SSLSession) and + // instead provide a higher-level concept like "authenticated user." + MySecurityInfo info = process(sslSession); return Contexts.interceptCall( - Context.current().withValue(SSL_SESSION_CONTEXT, clientContext), call, headers, next); + Context.current().withValue(SECURITY_INFO, info), call, headers, next); } ``` @@ -318,13 +315,36 @@ public ServerCall.Listener interceptCall(ServerCall c If you received an error message "ALPN is not configured properly" or "Jetty ALPN/NPN has not been properly configured", it most likely means that: - ALPN related dependencies are either not present in the classpath - or that there is a classpath conflict - - or that a wrong version is used due to dependency management. + - or that a wrong version is used due to dependency management + - or you are on an unsupported platform (e.g., 32-bit OS). See [Transport + Security](#transport-security-tls) for supported platforms. ### Netty If you aren't using gRPC on Android devices, you are most likely using `grpc-netty` transport. If you are developing for Android and have a dependency on `grpc-netty`, you should remove it as `grpc-netty` is unsupported on Android. Use `grpc-okhttp` instead. +If you are on a 32-bit operating system, using Java 11+ may be the easiest +solution, as ALPN was added to Java in Java 9. If on 32-bit Windows, [Conscrypt +is an option](#tls-with-conscrypt). Otherwise you need to [build your own 32-bit +version of +`netty-tcnative`](https://netty.io/wiki/forked-tomcat-native.html#wiki-h2-6). + +If on Alpine Linux, depending on your specific JDK you may see a crash in +netty_tcnative. This is generally caused by a missing symbol. Run `apk install +gcompat` and use the environment variable `LD_PRELOAD=/lib/libgcompat.so.0` when +executing Java. + +If on Fedora 30 or later and you see "libcrypt.so.1: cannot open shared object +file: No such file or directory". Run `dnf -y install libxcrypt-compat` to +install the necessary dependency. + +Most dependency versioning problems can be solved by using +`io.grpc:grpc-netty-shaded` instead of `io.grpc:grpc-netty`, although this also +limits your usage of the Netty-specific APIs. `io.grpc:grpc-netty-shaded` +includes the proper version of Netty and `netty-tcnative-boringssl-static` in a +way that won't conflict with other Netty usages. + Find the dependency tree (e.g., `mvn dependency:tree`), and look for versions of: - `io.grpc:grpc-netty` - `io.netty:netty-handler` (really, make sure all of io.netty except for @@ -337,16 +357,14 @@ If you have both `netty-handler` and `netty-tcnative-boringssl-static` dependenc If you have other `netty` dependencies, such as `netty-all`, that are pulled in from other libraries, then ultimately you should make sure only one `netty` dependency is used to avoid classpath conflict. The easiest way is to exclude transitive Netty dependencies from all the immediate dependencies, e.g., in Maven use ``, and then add an explict Netty dependency in your project along with the corresponding `tcnative` versions. See the versions table below. -If you are using `musl` libc (e.g., with Alpine Linux), then `netty-tcnative-boringssl-static` won't work. There are several alternatives: - - Use [netty-tcnative-alpine] (https://github.com/pires/netty-tcnative-alpine) - - Use a distribution with `glibc` - -If you are running inside of an embedded Tomcat runtime (e.g., Spring Boot), then some versions of `netty-tcnative-boringssl-static` will have conflicts and won't work. You must use gRPC 1.4.0 or later. +If you are running in a runtime environment that also uses Netty (e.g., Hadoop, Spark, Spring Boot 2) and you have no control over the Netty version at all, then you should use a shaded gRPC Netty dependency to avoid classpath conflicts with other Netty versions in runtime the classpath: + - Remove `io.grpc:grpc-netty` dependency + - Add `io.grpc:grpc-netty-shaded` dependency Below are known to work version combinations: grpc-netty version | netty-handler version | netty-tcnative-boringssl-static version ------------------- | --------------------- | --------------------------------------- +------------------ |-----------------------| --------------------------------------- 1.0.0-1.0.1 | 4.1.3.Final | 1.1.33.Fork19 1.0.2-1.0.3 | 4.1.6.Final | 1.1.33.Fork23 1.1.x-1.3.x | 4.1.8.Final | 1.1.33.Fork26 @@ -355,22 +373,44 @@ grpc-netty version | netty-handler version | netty-tcnative-boringssl-static ver 1.6.x | 4.1.14.Final | 2.0.5.Final 1.7.x-1.8.x | 4.1.16.Final | 2.0.6.Final 1.9.x-1.10.x | 4.1.17.Final | 2.0.7.Final -1.11.x- | 4.1.22.Final | 2.0.7.Final +1.11.x-1.12.x | 4.1.22.Final | 2.0.7.Final +1.13.x | 4.1.25.Final | 2.0.8.Final +1.14.x-1.15.x | 4.1.27.Final | 2.0.12.Final +1.16.x-1.17.x | 4.1.30.Final | 2.0.17.Final +1.18.x-1.19.x | 4.1.32.Final | 2.0.20.Final +1.20.x-1.21.x | 4.1.34.Final | 2.0.22.Final +1.22.x | 4.1.35.Final | 2.0.25.Final +1.23.x-1.24.x | 4.1.38.Final | 2.0.25.Final +1.25.x-1.27.x | 4.1.42.Final | 2.0.26.Final +1.28.x | 4.1.45.Final | 2.0.28.Final +1.29.x-1.31.x | 4.1.48.Final | 2.0.30.Final +1.32.x-1.34.x | 4.1.51.Final | 2.0.31.Final +1.35.x-1.41.x | 4.1.52.Final | 2.0.34.Final +1.42.x-1.43.x | 4.1.63.Final | 2.0.38.Final +1.44.x-1.47.x | 4.1.72.Final | 2.0.46.Final +1.48.x-1.49.x | 4.1.77.Final | 2.0.53.Final +1.50.x-1.53.x | 4.1.79.Final | 2.0.54.Final +1.54.x-1.55.x | 4.1.87.Final | 2.0.56.Final +1.56.x | 4.1.87.Final | 2.0.61.Final +1.57.x-1.58.x | 4.1.93.Final | 2.0.61.Final +1.59.x | 4.1.97.Final | 2.0.61.Final +1.60.x-1.66.x | 4.1.100.Final | 2.0.61.Final +1.67.x-1.70.x | 4.1.110.Final | 2.0.65.Final +1.71.x-1.74.x | 4.1.110.Final | 2.0.70.Final +1.75.x-1.76.x | 4.1.124.Final | 2.0.72.Final +1.77.x-1.78.x | 4.1.127.Final | 2.0.74.Final +1.79.x-1.80.x | 4.1.130.Final | 2.0.74.Final +1.81.x- | 4.1.132.Final | 2.0.75.Final + +_(grpc-netty-shaded avoids issues with keeping these versions in sync.)_ ### OkHttp -If you are using gRPC on Android devices, you are most likely using `grpc-okhttp` transport. - -Find the dependency tree (e.g., `mvn dependency:tree`), and look for versions of: - - `io.grpc:grpc-okhttp` - - `com.squareup.okhttp:okhttp` - -If you don't have `grpc-okhttp`, you should add it as a dependency. - -If you have both `io.grpc:grpc-netty` and `io.grpc:grpc-okhttp`, you may also have issues. Remove `grpc-netty` if you are on Android. - -If you have `okhttp` version below 2.5.0, then it may not work with gRPC. +If you are using gRPC on Android devices, you are most likely using +`grpc-okhttp` transport. -It is OK to have both `okhttp` 2.x and 3.x since they have different group name and under different packages. +Find the dependency tree (e.g., `mvn dependency:tree`), and look for +`io.grpc:grpc-okhttp`. If you don't have `grpc-okhttp`, you should add it as a +dependency. # gRPC over plaintext @@ -381,17 +421,12 @@ An option is provided to use gRPC over plaintext without TLS. While this is conv The following code snippet shows how you can call the Google Cloud PubSub API using gRPC with a service account. The credentials are loaded from a key stored in a well-known location or by detecting that the application is running in an environment that can provide one automatically, e.g. Google Compute Engine. While this example is specific to Google and it's services, similar patterns can be followed for other service providers. ```java -// Create a channel to the test service. -ManagedChannel channel = ManagedChannelBuilder.forTarget("pubsub.googleapis.com") +// Use the default credentials from the environment +ChannelCredentials creds = GoogleDefaultChannelCredentials.create(); +// Create a channel to the service +ManagedChannel channel = Grpc.newChannelBuilder("dns:///pubsub.googleapis.com", creds) .build(); -// Get the default credentials from the environment -GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); -// Down-scope the credential to just the scopes required by the service -creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub")); -// Create an instance of {@link io.grpc.CallCredentials} -CallCredentials callCreds = MoreCallCredentials.from(creds); -// Create a stub with credential -PublisherGrpc.PublisherBlockingStub publisherStub = - PublisherGrpc.newBlockingStub(channel).withCallCredentials(callCreds); +// Create a stub and send an RPC +PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel); publisherStub.publish(someMessage); ``` diff --git a/WORKSPACE b/WORKSPACE index 65bf26a8b25..1efdf2793a8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1,58 @@ workspace(name = "io_grpc_grpc_java") -load("//:repositories.bzl", "grpc_java_repositories") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS", "grpc_java_repositories") grpc_java_repositories() + +http_archive( + name = "rules_java", + sha256 = "47632cc506c858011853073449801d648e10483d4b50e080ec2549a4b2398960", + urls = [ + "https://github.com/bazelbuild/rules_java/releases/download/8.15.2/rules_java-8.15.2.tar.gz", + ], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps") + +protobuf_deps() + +load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies") + +rules_java_dependencies() + +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +bazel_features_deps() + +load("@bazel_jar_jar//:jar_jar.bzl", "jar_jar_repositories") + +jar_jar_repositories() + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") + +switched_rules_by_language( + name = "com_google_googleapis_imports", +) + +http_archive( + name = "rules_jvm_external", + sha256 = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac", + strip_prefix = "rules_jvm_external-5.3", + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.3/rules_jvm_external-5.3.tar.gz", +) + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_install( + artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS + PROTOBUF_MAVEN_ARTIFACTS, + override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS, + repositories = [ + "https://repo.maven.apache.org/maven2/", + ], + strict_visibility = True, +) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000000..4ecb9e5d985 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1 @@ +# When using bzlmod this makes sure nothing from the legacy WORKSPACE is loaded diff --git a/all/build.gradle b/all/build.gradle index 95942b4ddae..11eec4b7ff8 100644 --- a/all/build.gradle +++ b/all/build.gradle @@ -1,44 +1,48 @@ -apply plugin: 'com.github.kt3k.coveralls' +plugins { + id "java-library" + id "maven-publish" -description = "gRPC: All" - -buildscript { - repositories { - maven { - // The google mirror is less flaky than mavenCentral() - url "https://maven-central.storage-download.googleapis.com/repos/central/data/" - } - } - dependencies { - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1' - } + id "com.github.kt3k.coveralls" } +description = "gRPC: All" + def subprojects = [ - project(':grpc-auth'), - project(':grpc-core'), - project(':grpc-context'), - project(':grpc-netty'), - project(':grpc-okhttp'), - project(':grpc-protobuf'), - project(':grpc-protobuf-lite'), - project(':grpc-protobuf-nano'), - project(':grpc-stub'), - project(':grpc-testing'), + project(':grpc-api'), + project(':grpc-auth'), + project(':grpc-core'), + project(':grpc-grpclb'), + project(':grpc-gcp-csm-observability'), + project(':grpc-inprocess'), + project(':grpc-netty'), + project(':grpc-okhttp'), + project(':grpc-opentelemetry'), + project(':grpc-protobuf'), + project(':grpc-protobuf-lite'), + project(':grpc-rls'), + project(':grpc-services'), + project(':grpc-servlet'), + project(':grpc-servlet-jakarta'), + project(':grpc-stub'), + project(':grpc-testing'), + project(':grpc-util'), + project(':grpc-xds'), ] -for (subproject in rootProject.subprojects) { +for (subproject in subprojects) { if (subproject == project) { continue } evaluationDependsOn(subproject.path) } +evaluationDependsOn(':grpc-interop-testing') dependencies { - compile subprojects.minus(project(':grpc-protobuf-lite')) + api subprojects.minus([project(':grpc-protobuf-lite')]) + implementation libraries.guava.jre // JRE required by transitive protobuf-java-util } -javadoc { +tasks.named("javadoc").configure { classpath = files(subprojects.collect { subproject -> subproject.javadoc.classpath }) @@ -47,39 +51,29 @@ javadoc { continue; } source subproject.javadoc.source - options.links subproject.javadoc.options.links.toArray(new String[0]) + options.linksOffline.addAll subproject.javadoc.options.linksOffline } } -task jacocoMerge(type: JacocoMerge) { - dependsOn(subprojects.jacocoTestReport.dependsOn) +tasks.named("jacocoTestReport").configure { mustRunAfter(subprojects.jacocoTestReport.mustRunAfter) - destinationFile = file("${buildDir}/jacoco/test.exec") - executionData = files(subprojects.jacocoTestReport.executionData) - .plus(project(':grpc-interop-testing').jacocoTestReport.executionData) - .filter { f -> f.exists() } -} - -jacocoTestReport { - dependsOn(jacocoMerge) + mustRunAfter(project(':grpc-interop-testing').jacocoTestReport.mustRunAfter) + executionData.from files(subprojects.jacocoTestReport.executionData) + .plus(project(':grpc-interop-testing').jacocoTestReport.executionData) reports { - xml.enabled = true - html.enabled = true + xml.required = true + html.required = true } - additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs) - sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories = files(subprojects.sourceSets.main.output) - classDirectories = files(classDirectories.files.collect { - fileTree(dir: it, - exclude: ['**/io/grpc/okhttp/internal/**']) - }) + subprojects.each { subproject -> + additionalSourceDirs.from(subproject.jacocoTestReport.additionalSourceDirs) + sourceDirectories.from(subproject.jacocoTestReport.sourceDirectories) + classDirectories.from(subproject.jacocoTestReport.classDirectories) + } } coveralls { sourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten() } -tasks.coveralls { - dependsOn(jacocoTestReport) -} +tasks.named("coveralls").configure { dependsOn tasks.named("jacocoTestReport") } diff --git a/alts/BUILD.bazel b/alts/BUILD.bazel index ca72e1d6cea..f29df303fbe 100644 --- a/alts/BUILD.bazel +++ b/alts/BUILD.bazel @@ -1,3 +1,7 @@ +load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_jvm_external//:defs.bzl", "artifact") load("//:java_grpc_library.bzl", "java_grpc_library") java_library( @@ -8,17 +12,20 @@ java_library( deps = [ ":handshaker_java_grpc", ":handshaker_java_proto", - "//core", + "//api", + "//core:internal", "//netty", "//stub", - "@com_google_code_findbugs_jsr305//jar", - "@com_google_guava_guava//jar", "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", - "@io_netty_netty_buffer//jar", - "@io_netty_netty_codec//jar", - "@io_netty_netty_common//jar", - "@io_netty_netty_transport//jar", + artifact("com.google.code.findbugs:jsr305"), + artifact("com.google.errorprone:error_prone_annotations"), + artifact("com.google.guava:guava"), + artifact("io.netty:netty-buffer"), + artifact("io.netty:netty-codec"), + artifact("io.netty:netty-common"), + artifact("io.netty:netty-handler"), + artifact("io.netty:netty-transport"), ], ) @@ -31,37 +38,40 @@ java_library( deps = [ ":alts_internal", ":handshaker_java_grpc", - "//core", + ":handshaker_java_proto", + "//api", + "//auth", "//core:internal", "//netty", - "@com_google_code_findbugs_jsr305//jar", - "@com_google_guava_guava//jar", - "@io_netty_netty_common//jar", - "@io_netty_netty_transport//jar", - "@org_apache_commons_commons_lang3//jar", + artifact("com.google.auth:google-auth-library-oauth2-http"), + artifact("com.google.code.findbugs:jsr305"), + artifact("com.google.guava:guava"), + artifact("io.netty:netty-common"), + artifact("io.netty:netty-handler"), + artifact("io.netty:netty-transport"), ], ) # bazel only accepts proto import with absolute path. genrule( name = "protobuf_imports", - srcs = glob(["src/main/proto/*.proto"]), + srcs = glob(["src/main/proto/grpc/gcp/*.proto"]), outs = [ - "protobuf_out/altscontext.proto", - "protobuf_out/handshaker.proto", - "protobuf_out/transport_security_common.proto", + "protobuf_out/grpc/gcp/altscontext.proto", + "protobuf_out/grpc/gcp/handshaker.proto", + "protobuf_out/grpc/gcp/transport_security_common.proto", ], cmd = "for fname in $(SRCS); do " + "sed 's,import \",import \"alts/protobuf_out/,g' $$fname > " + - "$(@D)/protobuf_out/$$(basename $$fname); done", + "$(@D)/protobuf_out/grpc/gcp/$$(basename $$fname); done", ) proto_library( name = "handshaker_proto", srcs = [ - "protobuf_out/altscontext.proto", - "protobuf_out/handshaker.proto", - "protobuf_out/transport_security_common.proto", + "protobuf_out/grpc/gcp/altscontext.proto", + "protobuf_out/grpc/gcp/handshaker.proto", + "protobuf_out/grpc/gcp/transport_security_common.proto", ], ) diff --git a/alts/build.gradle b/alts/build.gradle index 64cee9aa55e..c206a37bcef 100644 --- a/alts/build.gradle +++ b/alts/build.gradle @@ -1,50 +1,104 @@ -description = "gRPC: ALTS" - -sourceCompatibility = 1.7 -targetCompatibility = 1.7 +plugins { + id "java-library" + id "maven-publish" -buildscript { - repositories { - maven { - // The google mirror is less flaky than mavenCentral() - url "https://maven-central.storage-download.googleapis.com/repos/central/data/" - } - } - dependencies { - classpath libraries.protobuf_plugin - } + id "com.google.protobuf" + id "com.gradleup.shadow" + id "ru.vyarus.animalsniffer" } +description = "gRPC: ALTS" + dependencies { - compile project(':grpc-core'), - project(':grpc-netty'), + api project(':grpc-api') + implementation project(':grpc-auth'), + project(':grpc-core'), + project(":grpc-context"), // Override google-auth dependency with our newer version project(':grpc-protobuf'), project(':grpc-stub'), - libraries.lang, - libraries.protobuf - testCompile libraries.guava, - libraries.guava_testlib, - libraries.junit, - libraries.mockito, - libraries.truth - signature 'org.codehaus.mojo.signature:java17:1.0@signature' + libraries.protobuf.java, + libraries.conscrypt, + libraries.google.auth.oauth2Http + def nettyDependency = implementation project(':grpc-netty') + + shadow configurations.implementation.getDependencies().minus(nettyDependency) + shadow project(path: ':grpc-netty-shaded', configuration: 'shadow') + + testImplementation project(':grpc-testing'), + testFixtures(project(':grpc-core')), + project(':grpc-inprocess'), + project(':grpc-testing-proto'), + libraries.guava, + libraries.junit, + libraries.mockito.core, + libraries.truth + + testImplementation libraries.guava.testlib + testRuntimeOnly libraries.netty.tcnative, + libraries.netty.tcnative.classes + testRuntimeOnly (libraries.netty.transport.epoll) { + artifact { + classifier = "linux-x86_64" + } + } + signature (libraries.signature.java) { + artifact { + extension = "signature" + } + } } configureProtoCompilation() -[compileJava, compileTestJava].each() { - // ALTS retuns a lot of futures that we mostly don't care about. - // protobuf calls valueof. Will be fixed in next release (google/protobuf#4046) - it.options.compilerArgs += ["-Xlint:-deprecation", "-Xep:FutureReturnValueIgnored:OFF"] +import net.ltgt.gradle.errorprone.CheckSeverity + +[tasks.named("compileJava"), tasks.named("compileTestJava")]*.configure { + // ALTS returns a lot of futures that we mostly don't care about. + options.errorprone.check("FutureReturnValueIgnored", CheckSeverity.OFF) } -javadoc { +tasks.named("javadoc").configure { exclude 'io/grpc/alts/internal/**' + exclude 'io/grpc/alts/Internal*' +} + +tasks.named("jar").configure { + // Must use a different archiveClassifier to avoid conflicting with shadowJar + archiveClassifier = 'original' + manifest { + attributes('Automatic-Module-Name': 'io.grpc.alts') + } } -idea { - module { - sourceDirs += file("${projectDir}/src/generated/main/grpc"); - sourceDirs += file("${projectDir}/src/generated/main/java"); +// We want to use grpc-netty-shaded instead of grpc-netty. But we also want our +// source to work with Bazel, so we rewrite the code as part of the build. +tasks.named("shadowJar").configure { + archiveClassifier = null + dependencies { + exclude(dependency {true}) + } + relocate 'io.grpc.netty', 'io.grpc.netty.shaded.io.grpc.netty' + relocate 'io.netty', 'io.grpc.netty.shaded.io.netty' +} + +publishing { + publications { + maven(MavenPublication) { + // We want this to throw an exception if it isn't working + def originalJar = artifacts.find { dep -> dep.classifier == 'original'} + artifacts.remove(originalJar) + + pom.withXml { + def dependenciesNode = new Node(null, 'dependencies') + project.configurations.shadow.allDependencies.each { dep -> + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', dep.group) + dependencyNode.appendNode('artifactId', dep.name) + dependencyNode.appendNode('version', dep.version) + dependencyNode.appendNode('scope', 'compile') + } + asNode().dependencies[0].replaceNode(dependenciesNode) + } + } } } diff --git a/alts/src/generated/main/grpc/io/grpc/alts/internal/HandshakerServiceGrpc.java b/alts/src/generated/main/grpc/io/grpc/alts/internal/HandshakerServiceGrpc.java index 58789fb4472..07e4256eb75 100644 --- a/alts/src/generated/main/grpc/io/grpc/alts/internal/HandshakerServiceGrpc.java +++ b/alts/src/generated/main/grpc/io/grpc/alts/internal/HandshakerServiceGrpc.java @@ -1,75 +1,75 @@ package io.grpc.alts.internal; import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; /** */ -@javax.annotation.Generated( - value = "by gRPC proto compiler", - comments = "Source: handshaker.proto") +@io.grpc.stub.annotations.GrpcGenerated public final class HandshakerServiceGrpc { private HandshakerServiceGrpc() {} - public static final String SERVICE_NAME = "grpc.gcp.HandshakerService"; + public static final java.lang.String SERVICE_NAME = "grpc.gcp.HandshakerService"; // Static method descriptors that strictly reflect the proto. - @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") - @java.lang.Deprecated // Use {@link #getDoHandshakeMethod()} instead. - public static final io.grpc.MethodDescriptor METHOD_DO_HANDSHAKE = getDoHandshakeMethodHelper(); - - private static volatile io.grpc.MethodDescriptor getDoHandshakeMethod; - - @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") - public static io.grpc.MethodDescriptor getDoHandshakeMethod() { - return getDoHandshakeMethodHelper(); - } - - private static io.grpc.MethodDescriptor getDoHandshakeMethodHelper() { - io.grpc.MethodDescriptor getDoHandshakeMethod; + private static volatile io.grpc.MethodDescriptor getDoHandshakeMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "DoHandshake", + requestType = io.grpc.alts.internal.HandshakerReq.class, + responseType = io.grpc.alts.internal.HandshakerResp.class, + methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) + public static io.grpc.MethodDescriptor getDoHandshakeMethod() { + io.grpc.MethodDescriptor getDoHandshakeMethod; if ((getDoHandshakeMethod = HandshakerServiceGrpc.getDoHandshakeMethod) == null) { synchronized (HandshakerServiceGrpc.class) { if ((getDoHandshakeMethod = HandshakerServiceGrpc.getDoHandshakeMethod) == null) { - HandshakerServiceGrpc.getDoHandshakeMethod = getDoHandshakeMethod = - io.grpc.MethodDescriptor.newBuilder() + HandshakerServiceGrpc.getDoHandshakeMethod = getDoHandshakeMethod = + io.grpc.MethodDescriptor.newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.gcp.HandshakerService", "DoHandshake")) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "DoHandshake")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.grpc.alts.internal.Handshaker.HandshakerReq.getDefaultInstance())) + io.grpc.alts.internal.HandshakerReq.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.grpc.alts.internal.Handshaker.HandshakerResp.getDefaultInstance())) - .setSchemaDescriptor(new HandshakerServiceMethodDescriptorSupplier("DoHandshake")) - .build(); - } + io.grpc.alts.internal.HandshakerResp.getDefaultInstance())) + .setSchemaDescriptor(new HandshakerServiceMethodDescriptorSupplier("DoHandshake")) + .build(); } - } - return getDoHandshakeMethod; + } + } + return getDoHandshakeMethod; } /** * Creates a new async stub that supports all call types for the service */ public static HandshakerServiceStub newStub(io.grpc.Channel channel) { - return new HandshakerServiceStub(channel); + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public HandshakerServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new HandshakerServiceStub(channel, callOptions); + } + }; + return HandshakerServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports all types of calls on the service + */ + public static HandshakerServiceBlockingV2Stub newBlockingV2Stub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public HandshakerServiceBlockingV2Stub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new HandshakerServiceBlockingV2Stub(channel, callOptions); + } + }; + return HandshakerServiceBlockingV2Stub.newStub(factory, channel); } /** @@ -77,7 +77,14 @@ public static HandshakerServiceStub newStub(io.grpc.Channel channel) { */ public static HandshakerServiceBlockingStub newBlockingStub( io.grpc.Channel channel) { - return new HandshakerServiceBlockingStub(channel); + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public HandshakerServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new HandshakerServiceBlockingStub(channel, callOptions); + } + }; + return HandshakerServiceBlockingStub.newStub(factory, channel); } /** @@ -85,12 +92,19 @@ public static HandshakerServiceBlockingStub newBlockingStub( */ public static HandshakerServiceFutureStub newFutureStub( io.grpc.Channel channel) { - return new HandshakerServiceFutureStub(channel); + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public HandshakerServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new HandshakerServiceFutureStub(channel, callOptions); + } + }; + return HandshakerServiceFutureStub.newStub(factory, channel); } /** */ - public static abstract class HandshakerServiceImplBase implements io.grpc.BindableService { + public interface AsyncService { /** *
@@ -102,39 +116,36 @@ public static abstract class HandshakerServiceImplBase implements io.grpc.Bindab
      * response before sending next request.
      * 
*/ - public io.grpc.stub.StreamObserver doHandshake( - io.grpc.stub.StreamObserver responseObserver) { - return asyncUnimplementedStreamingCall(getDoHandshakeMethodHelper(), responseObserver); + default io.grpc.stub.StreamObserver doHandshake( + io.grpc.stub.StreamObserver responseObserver) { + return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(getDoHandshakeMethod(), responseObserver); } + } + + /** + * Base class for the server implementation of the service HandshakerService. + */ + public static abstract class HandshakerServiceImplBase + implements io.grpc.BindableService, AsyncService { @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getDoHandshakeMethodHelper(), - asyncBidiStreamingCall( - new MethodHandlers< - io.grpc.alts.internal.Handshaker.HandshakerReq, - io.grpc.alts.internal.Handshaker.HandshakerResp>( - this, METHODID_DO_HANDSHAKE))) - .build(); + return HandshakerServiceGrpc.bindService(this); } } /** + * A stub to allow clients to do asynchronous rpc calls to service HandshakerService. */ - public static final class HandshakerServiceStub extends io.grpc.stub.AbstractStub { - private HandshakerServiceStub(io.grpc.Channel channel) { - super(channel); - } - - private HandshakerServiceStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + public static final class HandshakerServiceStub + extends io.grpc.stub.AbstractAsyncStub { + private HandshakerServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { super(channel, callOptions); } @java.lang.Override - protected HandshakerServiceStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + protected HandshakerServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new HandshakerServiceStub(channel, callOptions); } @@ -148,47 +159,77 @@ protected HandshakerServiceStub build(io.grpc.Channel channel, * response before sending next request. * */ - public io.grpc.stub.StreamObserver doHandshake( - io.grpc.stub.StreamObserver responseObserver) { - return asyncBidiStreamingCall( - getChannel().newCall(getDoHandshakeMethodHelper(), getCallOptions()), responseObserver); + public io.grpc.stub.StreamObserver doHandshake( + io.grpc.stub.StreamObserver responseObserver) { + return io.grpc.stub.ClientCalls.asyncBidiStreamingCall( + getChannel().newCall(getDoHandshakeMethod(), getCallOptions()), responseObserver); } } /** + * A stub to allow clients to do synchronous rpc calls to service HandshakerService. */ - public static final class HandshakerServiceBlockingStub extends io.grpc.stub.AbstractStub { - private HandshakerServiceBlockingStub(io.grpc.Channel channel) { - super(channel); + public static final class HandshakerServiceBlockingV2Stub + extends io.grpc.stub.AbstractBlockingStub { + private HandshakerServiceBlockingV2Stub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); } - private HandshakerServiceBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + @java.lang.Override + protected HandshakerServiceBlockingV2Stub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new HandshakerServiceBlockingV2Stub(channel, callOptions); + } + + /** + *
+     * Handshaker service accepts a stream of handshaker request, returning a
+     * stream of handshaker response. Client is expected to send exactly one
+     * message with either client_start or server_start followed by one or more
+     * messages with next. Each time client sends a request, the handshaker
+     * service expects to respond. Client does not have to wait for service's
+     * response before sending next request.
+     * 
+ */ + @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/10918") + public io.grpc.stub.BlockingClientCall + doHandshake() { + return io.grpc.stub.ClientCalls.blockingBidiStreamingCall( + getChannel(), getDoHandshakeMethod(), getCallOptions()); + } + } + + /** + * A stub to allow clients to do limited synchronous rpc calls to service HandshakerService. + */ + public static final class HandshakerServiceBlockingStub + extends io.grpc.stub.AbstractBlockingStub { + private HandshakerServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { super(channel, callOptions); } @java.lang.Override - protected HandshakerServiceBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + protected HandshakerServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new HandshakerServiceBlockingStub(channel, callOptions); } } /** + * A stub to allow clients to do ListenableFuture-style rpc calls to service HandshakerService. */ - public static final class HandshakerServiceFutureStub extends io.grpc.stub.AbstractStub { - private HandshakerServiceFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private HandshakerServiceFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + public static final class HandshakerServiceFutureStub + extends io.grpc.stub.AbstractFutureStub { + private HandshakerServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { super(channel, callOptions); } @java.lang.Override - protected HandshakerServiceFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { + protected HandshakerServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new HandshakerServiceFutureStub(channel, callOptions); } } @@ -200,10 +241,10 @@ private static final class MethodHandlers implements io.grpc.stub.ServerCalls.ServerStreamingMethod, io.grpc.stub.ServerCalls.ClientStreamingMethod, io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final HandshakerServiceImplBase serviceImpl; + private final AsyncService serviceImpl; private final int methodId; - MethodHandlers(HandshakerServiceImplBase serviceImpl, int methodId) { + MethodHandlers(AsyncService serviceImpl, int methodId) { this.serviceImpl = serviceImpl; this.methodId = methodId; } @@ -224,20 +265,32 @@ public io.grpc.stub.StreamObserver invoke( switch (methodId) { case METHODID_DO_HANDSHAKE: return (io.grpc.stub.StreamObserver) serviceImpl.doHandshake( - (io.grpc.stub.StreamObserver) responseObserver); + (io.grpc.stub.StreamObserver) responseObserver); default: throw new AssertionError(); } } } + public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getDoHandshakeMethod(), + io.grpc.stub.ServerCalls.asyncBidiStreamingCall( + new MethodHandlers< + io.grpc.alts.internal.HandshakerReq, + io.grpc.alts.internal.HandshakerResp>( + service, METHODID_DO_HANDSHAKE))) + .build(); + } + private static abstract class HandshakerServiceBaseDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { HandshakerServiceBaseDescriptorSupplier() {} @java.lang.Override public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return io.grpc.alts.internal.Handshaker.getDescriptor(); + return io.grpc.alts.internal.HandshakerProto.getDescriptor(); } @java.lang.Override @@ -254,9 +307,9 @@ private static final class HandshakerServiceFileDescriptorSupplier private static final class HandshakerServiceMethodDescriptorSupplier extends HandshakerServiceBaseDescriptorSupplier implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final String methodName; + private final java.lang.String methodName; - HandshakerServiceMethodDescriptorSupplier(String methodName) { + HandshakerServiceMethodDescriptorSupplier(java.lang.String methodName) { this.methodName = methodName; } @@ -276,7 +329,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() { if (result == null) { serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) .setSchemaDescriptor(new HandshakerServiceFileDescriptorSupplier()) - .addMethod(getDoHandshakeMethodHelper()) + .addMethod(getDoHandshakeMethod()) .build(); } } diff --git a/alts/src/generated/main/java/io/grpc/alts/internal/Altscontext.java b/alts/src/generated/main/java/io/grpc/alts/internal/Altscontext.java deleted file mode 100644 index a6451710320..00000000000 --- a/alts/src/generated/main/java/io/grpc/alts/internal/Altscontext.java +++ /dev/null @@ -1,1526 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: altscontext.proto - -package io.grpc.alts.internal; - -public final class Altscontext { - private Altscontext() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface AltsContextOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.AltsContext) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - java.lang.String getApplicationProtocol(); - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - com.google.protobuf.ByteString - getApplicationProtocolBytes(); - - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - java.lang.String getRecordProtocol(); - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - com.google.protobuf.ByteString - getRecordProtocolBytes(); - - /** - *
-     * The security level of the created secure channel.
-     * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - int getSecurityLevelValue(); - /** - *
-     * The security level of the created secure channel.
-     * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel getSecurityLevel(); - - /** - *
-     * The peer service account.
-     * 
- * - * string peer_service_account = 4; - */ - java.lang.String getPeerServiceAccount(); - /** - *
-     * The peer service account.
-     * 
- * - * string peer_service_account = 4; - */ - com.google.protobuf.ByteString - getPeerServiceAccountBytes(); - - /** - *
-     * The local service account.
-     * 
- * - * string local_service_account = 5; - */ - java.lang.String getLocalServiceAccount(); - /** - *
-     * The local service account.
-     * 
- * - * string local_service_account = 5; - */ - com.google.protobuf.ByteString - getLocalServiceAccountBytes(); - - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - boolean hasPeerRpcVersions(); - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions(); - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder(); - } - /** - * Protobuf type {@code grpc.gcp.AltsContext} - */ - public static final class AltsContext extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.AltsContext) - AltsContextOrBuilder { - private static final long serialVersionUID = 0L; - // Use AltsContext.newBuilder() to construct. - private AltsContext(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private AltsContext() { - applicationProtocol_ = ""; - recordProtocol_ = ""; - securityLevel_ = 0; - peerServiceAccount_ = ""; - localServiceAccount_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private AltsContext( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - applicationProtocol_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - recordProtocol_ = s; - break; - } - case 24: { - int rawValue = input.readEnum(); - - securityLevel_ = rawValue; - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); - - peerServiceAccount_ = s; - break; - } - case 42: { - java.lang.String s = input.readStringRequireUtf8(); - - localServiceAccount_ = s; - break; - } - case 50: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder subBuilder = null; - if (peerRpcVersions_ != null) { - subBuilder = peerRpcVersions_.toBuilder(); - } - peerRpcVersions_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(peerRpcVersions_); - peerRpcVersions_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Altscontext.internal_static_grpc_gcp_AltsContext_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Altscontext.internal_static_grpc_gcp_AltsContext_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Altscontext.AltsContext.class, io.grpc.alts.internal.Altscontext.AltsContext.Builder.class); - } - - public static final int APPLICATION_PROTOCOL_FIELD_NUMBER = 1; - private volatile java.lang.Object applicationProtocol_; - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - public java.lang.String getApplicationProtocol() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - applicationProtocol_ = s; - return s; - } - } - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolBytes() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - applicationProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RECORD_PROTOCOL_FIELD_NUMBER = 2; - private volatile java.lang.Object recordProtocol_; - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - public java.lang.String getRecordProtocol() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - recordProtocol_ = s; - return s; - } - } - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - public com.google.protobuf.ByteString - getRecordProtocolBytes() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - recordProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int SECURITY_LEVEL_FIELD_NUMBER = 3; - private int securityLevel_; - /** - *
-     * The security level of the created secure channel.
-     * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public int getSecurityLevelValue() { - return securityLevel_; - } - /** - *
-     * The security level of the created secure channel.
-     * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel getSecurityLevel() { - io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel result = io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.valueOf(securityLevel_); - return result == null ? io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.UNRECOGNIZED : result; - } - - public static final int PEER_SERVICE_ACCOUNT_FIELD_NUMBER = 4; - private volatile java.lang.Object peerServiceAccount_; - /** - *
-     * The peer service account.
-     * 
- * - * string peer_service_account = 4; - */ - public java.lang.String getPeerServiceAccount() { - java.lang.Object ref = peerServiceAccount_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - peerServiceAccount_ = s; - return s; - } - } - /** - *
-     * The peer service account.
-     * 
- * - * string peer_service_account = 4; - */ - public com.google.protobuf.ByteString - getPeerServiceAccountBytes() { - java.lang.Object ref = peerServiceAccount_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - peerServiceAccount_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int LOCAL_SERVICE_ACCOUNT_FIELD_NUMBER = 5; - private volatile java.lang.Object localServiceAccount_; - /** - *
-     * The local service account.
-     * 
- * - * string local_service_account = 5; - */ - public java.lang.String getLocalServiceAccount() { - java.lang.Object ref = localServiceAccount_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - localServiceAccount_ = s; - return s; - } - } - /** - *
-     * The local service account.
-     * 
- * - * string local_service_account = 5; - */ - public com.google.protobuf.ByteString - getLocalServiceAccountBytes() { - java.lang.Object ref = localServiceAccount_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - localServiceAccount_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int PEER_RPC_VERSIONS_FIELD_NUMBER = 6; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions peerRpcVersions_; - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public boolean hasPeerRpcVersions() { - return peerRpcVersions_ != null; - } - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions() { - return peerRpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder() { - return getPeerRpcVersions(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getApplicationProtocolBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, applicationProtocol_); - } - if (!getRecordProtocolBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, recordProtocol_); - } - if (securityLevel_ != io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.SECURITY_NONE.getNumber()) { - output.writeEnum(3, securityLevel_); - } - if (!getPeerServiceAccountBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, peerServiceAccount_); - } - if (!getLocalServiceAccountBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, localServiceAccount_); - } - if (peerRpcVersions_ != null) { - output.writeMessage(6, getPeerRpcVersions()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getApplicationProtocolBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, applicationProtocol_); - } - if (!getRecordProtocolBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, recordProtocol_); - } - if (securityLevel_ != io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.SECURITY_NONE.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(3, securityLevel_); - } - if (!getPeerServiceAccountBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, peerServiceAccount_); - } - if (!getLocalServiceAccountBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, localServiceAccount_); - } - if (peerRpcVersions_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(6, getPeerRpcVersions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Altscontext.AltsContext)) { - return super.equals(obj); - } - io.grpc.alts.internal.Altscontext.AltsContext other = (io.grpc.alts.internal.Altscontext.AltsContext) obj; - - boolean result = true; - result = result && getApplicationProtocol() - .equals(other.getApplicationProtocol()); - result = result && getRecordProtocol() - .equals(other.getRecordProtocol()); - result = result && securityLevel_ == other.securityLevel_; - result = result && getPeerServiceAccount() - .equals(other.getPeerServiceAccount()); - result = result && getLocalServiceAccount() - .equals(other.getLocalServiceAccount()); - result = result && (hasPeerRpcVersions() == other.hasPeerRpcVersions()); - if (hasPeerRpcVersions()) { - result = result && getPeerRpcVersions() - .equals(other.getPeerRpcVersions()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + APPLICATION_PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + getApplicationProtocol().hashCode(); - hash = (37 * hash) + RECORD_PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + getRecordProtocol().hashCode(); - hash = (37 * hash) + SECURITY_LEVEL_FIELD_NUMBER; - hash = (53 * hash) + securityLevel_; - hash = (37 * hash) + PEER_SERVICE_ACCOUNT_FIELD_NUMBER; - hash = (53 * hash) + getPeerServiceAccount().hashCode(); - hash = (37 * hash) + LOCAL_SERVICE_ACCOUNT_FIELD_NUMBER; - hash = (53 * hash) + getLocalServiceAccount().hashCode(); - if (hasPeerRpcVersions()) { - hash = (37 * hash) + PEER_RPC_VERSIONS_FIELD_NUMBER; - hash = (53 * hash) + getPeerRpcVersions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Altscontext.AltsContext parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Altscontext.AltsContext prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.AltsContext} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.AltsContext) - io.grpc.alts.internal.Altscontext.AltsContextOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Altscontext.internal_static_grpc_gcp_AltsContext_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Altscontext.internal_static_grpc_gcp_AltsContext_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Altscontext.AltsContext.class, io.grpc.alts.internal.Altscontext.AltsContext.Builder.class); - } - - // Construct using io.grpc.alts.internal.Altscontext.AltsContext.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - applicationProtocol_ = ""; - - recordProtocol_ = ""; - - securityLevel_ = 0; - - peerServiceAccount_ = ""; - - localServiceAccount_ = ""; - - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = null; - } else { - peerRpcVersions_ = null; - peerRpcVersionsBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Altscontext.internal_static_grpc_gcp_AltsContext_descriptor; - } - - public io.grpc.alts.internal.Altscontext.AltsContext getDefaultInstanceForType() { - return io.grpc.alts.internal.Altscontext.AltsContext.getDefaultInstance(); - } - - public io.grpc.alts.internal.Altscontext.AltsContext build() { - io.grpc.alts.internal.Altscontext.AltsContext result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Altscontext.AltsContext buildPartial() { - io.grpc.alts.internal.Altscontext.AltsContext result = new io.grpc.alts.internal.Altscontext.AltsContext(this); - result.applicationProtocol_ = applicationProtocol_; - result.recordProtocol_ = recordProtocol_; - result.securityLevel_ = securityLevel_; - result.peerServiceAccount_ = peerServiceAccount_; - result.localServiceAccount_ = localServiceAccount_; - if (peerRpcVersionsBuilder_ == null) { - result.peerRpcVersions_ = peerRpcVersions_; - } else { - result.peerRpcVersions_ = peerRpcVersionsBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Altscontext.AltsContext) { - return mergeFrom((io.grpc.alts.internal.Altscontext.AltsContext)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Altscontext.AltsContext other) { - if (other == io.grpc.alts.internal.Altscontext.AltsContext.getDefaultInstance()) return this; - if (!other.getApplicationProtocol().isEmpty()) { - applicationProtocol_ = other.applicationProtocol_; - onChanged(); - } - if (!other.getRecordProtocol().isEmpty()) { - recordProtocol_ = other.recordProtocol_; - onChanged(); - } - if (other.securityLevel_ != 0) { - setSecurityLevelValue(other.getSecurityLevelValue()); - } - if (!other.getPeerServiceAccount().isEmpty()) { - peerServiceAccount_ = other.peerServiceAccount_; - onChanged(); - } - if (!other.getLocalServiceAccount().isEmpty()) { - localServiceAccount_ = other.localServiceAccount_; - onChanged(); - } - if (other.hasPeerRpcVersions()) { - mergePeerRpcVersions(other.getPeerRpcVersions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Altscontext.AltsContext parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Altscontext.AltsContext) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object applicationProtocol_ = ""; - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public java.lang.String getApplicationProtocol() { - java.lang.Object ref = applicationProtocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - applicationProtocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolBytes() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - applicationProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder setApplicationProtocol( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - applicationProtocol_ = value; - onChanged(); - return this; - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder clearApplicationProtocol() { - - applicationProtocol_ = getDefaultInstance().getApplicationProtocol(); - onChanged(); - return this; - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder setApplicationProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - applicationProtocol_ = value; - onChanged(); - return this; - } - - private java.lang.Object recordProtocol_ = ""; - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public java.lang.String getRecordProtocol() { - java.lang.Object ref = recordProtocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - recordProtocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public com.google.protobuf.ByteString - getRecordProtocolBytes() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - recordProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder setRecordProtocol( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - recordProtocol_ = value; - onChanged(); - return this; - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder clearRecordProtocol() { - - recordProtocol_ = getDefaultInstance().getRecordProtocol(); - onChanged(); - return this; - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder setRecordProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - recordProtocol_ = value; - onChanged(); - return this; - } - - private int securityLevel_ = 0; - /** - *
-       * The security level of the created secure channel.
-       * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public int getSecurityLevelValue() { - return securityLevel_; - } - /** - *
-       * The security level of the created secure channel.
-       * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public Builder setSecurityLevelValue(int value) { - securityLevel_ = value; - onChanged(); - return this; - } - /** - *
-       * The security level of the created secure channel.
-       * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel getSecurityLevel() { - io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel result = io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.valueOf(securityLevel_); - return result == null ? io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel.UNRECOGNIZED : result; - } - /** - *
-       * The security level of the created secure channel.
-       * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public Builder setSecurityLevel(io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel value) { - if (value == null) { - throw new NullPointerException(); - } - - securityLevel_ = value.getNumber(); - onChanged(); - return this; - } - /** - *
-       * The security level of the created secure channel.
-       * 
- * - * .grpc.gcp.SecurityLevel security_level = 3; - */ - public Builder clearSecurityLevel() { - - securityLevel_ = 0; - onChanged(); - return this; - } - - private java.lang.Object peerServiceAccount_ = ""; - /** - *
-       * The peer service account.
-       * 
- * - * string peer_service_account = 4; - */ - public java.lang.String getPeerServiceAccount() { - java.lang.Object ref = peerServiceAccount_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - peerServiceAccount_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The peer service account.
-       * 
- * - * string peer_service_account = 4; - */ - public com.google.protobuf.ByteString - getPeerServiceAccountBytes() { - java.lang.Object ref = peerServiceAccount_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - peerServiceAccount_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The peer service account.
-       * 
- * - * string peer_service_account = 4; - */ - public Builder setPeerServiceAccount( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - peerServiceAccount_ = value; - onChanged(); - return this; - } - /** - *
-       * The peer service account.
-       * 
- * - * string peer_service_account = 4; - */ - public Builder clearPeerServiceAccount() { - - peerServiceAccount_ = getDefaultInstance().getPeerServiceAccount(); - onChanged(); - return this; - } - /** - *
-       * The peer service account.
-       * 
- * - * string peer_service_account = 4; - */ - public Builder setPeerServiceAccountBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - peerServiceAccount_ = value; - onChanged(); - return this; - } - - private java.lang.Object localServiceAccount_ = ""; - /** - *
-       * The local service account.
-       * 
- * - * string local_service_account = 5; - */ - public java.lang.String getLocalServiceAccount() { - java.lang.Object ref = localServiceAccount_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - localServiceAccount_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The local service account.
-       * 
- * - * string local_service_account = 5; - */ - public com.google.protobuf.ByteString - getLocalServiceAccountBytes() { - java.lang.Object ref = localServiceAccount_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - localServiceAccount_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The local service account.
-       * 
- * - * string local_service_account = 5; - */ - public Builder setLocalServiceAccount( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - localServiceAccount_ = value; - onChanged(); - return this; - } - /** - *
-       * The local service account.
-       * 
- * - * string local_service_account = 5; - */ - public Builder clearLocalServiceAccount() { - - localServiceAccount_ = getDefaultInstance().getLocalServiceAccount(); - onChanged(); - return this; - } - /** - *
-       * The local service account.
-       * 
- * - * string local_service_account = 5; - */ - public Builder setLocalServiceAccountBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - localServiceAccount_ = value; - onChanged(); - return this; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions peerRpcVersions_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> peerRpcVersionsBuilder_; - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public boolean hasPeerRpcVersions() { - return peerRpcVersionsBuilder_ != null || peerRpcVersions_ != null; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions() { - if (peerRpcVersionsBuilder_ == null) { - return peerRpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } else { - return peerRpcVersionsBuilder_.getMessage(); - } - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public Builder setPeerRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (peerRpcVersionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - peerRpcVersions_ = value; - onChanged(); - } else { - peerRpcVersionsBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public Builder setPeerRpcVersions( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder builderForValue) { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = builderForValue.build(); - onChanged(); - } else { - peerRpcVersionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public Builder mergePeerRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (peerRpcVersionsBuilder_ == null) { - if (peerRpcVersions_ != null) { - peerRpcVersions_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.newBuilder(peerRpcVersions_).mergeFrom(value).buildPartial(); - } else { - peerRpcVersions_ = value; - } - onChanged(); - } else { - peerRpcVersionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public Builder clearPeerRpcVersions() { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = null; - onChanged(); - } else { - peerRpcVersions_ = null; - peerRpcVersionsBuilder_ = null; - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder getPeerRpcVersionsBuilder() { - - onChanged(); - return getPeerRpcVersionsFieldBuilder().getBuilder(); - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder() { - if (peerRpcVersionsBuilder_ != null) { - return peerRpcVersionsBuilder_.getMessageOrBuilder(); - } else { - return peerRpcVersions_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 6; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> - getPeerRpcVersionsFieldBuilder() { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder>( - getPeerRpcVersions(), - getParentForChildren(), - isClean()); - peerRpcVersions_ = null; - } - return peerRpcVersionsBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.AltsContext) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.AltsContext) - private static final io.grpc.alts.internal.Altscontext.AltsContext DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Altscontext.AltsContext(); - } - - public static io.grpc.alts.internal.Altscontext.AltsContext getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public AltsContext parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new AltsContext(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Altscontext.AltsContext getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_AltsContext_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_AltsContext_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\021altscontext.proto\022\010grpc.gcp\032\037transport" + - "_security_common.proto\"\354\001\n\013AltsContext\022\034" + - "\n\024application_protocol\030\001 \001(\t\022\027\n\017record_p" + - "rotocol\030\002 \001(\t\022/\n\016security_level\030\003 \001(\0162\027." + - "grpc.gcp.SecurityLevel\022\034\n\024peer_service_a" + - "ccount\030\004 \001(\t\022\035\n\025local_service_account\030\005 " + - "\001(\t\0228\n\021peer_rpc_versions\030\006 \001(\0132\035.grpc.gc" + - "p.RpcProtocolVersionsB\027\n\025io.grpc.alts.in" + - "ternalb\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - io.grpc.alts.internal.TransportSecurityCommon.getDescriptor(), - }, assigner); - internal_static_grpc_gcp_AltsContext_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_grpc_gcp_AltsContext_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_AltsContext_descriptor, - new java.lang.String[] { "ApplicationProtocol", "RecordProtocol", "SecurityLevel", "PeerServiceAccount", "LocalServiceAccount", "PeerRpcVersions", }); - io.grpc.alts.internal.TransportSecurityCommon.getDescriptor(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/alts/src/generated/main/java/io/grpc/alts/internal/Handshaker.java b/alts/src/generated/main/java/io/grpc/alts/internal/Handshaker.java deleted file mode 100644 index 03d78876871..00000000000 --- a/alts/src/generated/main/java/io/grpc/alts/internal/Handshaker.java +++ /dev/null @@ -1,13320 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: handshaker.proto - -package io.grpc.alts.internal; - -public final class Handshaker { - private Handshaker() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - /** - * Protobuf enum {@code grpc.gcp.HandshakeProtocol} - */ - public enum HandshakeProtocol - implements com.google.protobuf.ProtocolMessageEnum { - /** - *
-     * Default value.
-     * 
- * - * HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; - */ - HANDSHAKE_PROTOCOL_UNSPECIFIED(0), - /** - *
-     * TLS handshake protocol.
-     * 
- * - * TLS = 1; - */ - TLS(1), - /** - *
-     * Application Layer Transport Security handshake protocol.
-     * 
- * - * ALTS = 2; - */ - ALTS(2), - UNRECOGNIZED(-1), - ; - - /** - *
-     * Default value.
-     * 
- * - * HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; - */ - public static final int HANDSHAKE_PROTOCOL_UNSPECIFIED_VALUE = 0; - /** - *
-     * TLS handshake protocol.
-     * 
- * - * TLS = 1; - */ - public static final int TLS_VALUE = 1; - /** - *
-     * Application Layer Transport Security handshake protocol.
-     * 
- * - * ALTS = 2; - */ - public static final int ALTS_VALUE = 2; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static HandshakeProtocol valueOf(int value) { - return forNumber(value); - } - - public static HandshakeProtocol forNumber(int value) { - switch (value) { - case 0: return HANDSHAKE_PROTOCOL_UNSPECIFIED; - case 1: return TLS; - case 2: return ALTS; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - HandshakeProtocol> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public HandshakeProtocol findValueByNumber(int number) { - return HandshakeProtocol.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.getDescriptor().getEnumTypes().get(0); - } - - private static final HandshakeProtocol[] VALUES = values(); - - public static HandshakeProtocol valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private HandshakeProtocol(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:grpc.gcp.HandshakeProtocol) - } - - /** - * Protobuf enum {@code grpc.gcp.NetworkProtocol} - */ - public enum NetworkProtocol - implements com.google.protobuf.ProtocolMessageEnum { - /** - * NETWORK_PROTOCOL_UNSPECIFIED = 0; - */ - NETWORK_PROTOCOL_UNSPECIFIED(0), - /** - * TCP = 1; - */ - TCP(1), - /** - * UDP = 2; - */ - UDP(2), - UNRECOGNIZED(-1), - ; - - /** - * NETWORK_PROTOCOL_UNSPECIFIED = 0; - */ - public static final int NETWORK_PROTOCOL_UNSPECIFIED_VALUE = 0; - /** - * TCP = 1; - */ - public static final int TCP_VALUE = 1; - /** - * UDP = 2; - */ - public static final int UDP_VALUE = 2; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static NetworkProtocol valueOf(int value) { - return forNumber(value); - } - - public static NetworkProtocol forNumber(int value) { - switch (value) { - case 0: return NETWORK_PROTOCOL_UNSPECIFIED; - case 1: return TCP; - case 2: return UDP; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - NetworkProtocol> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public NetworkProtocol findValueByNumber(int number) { - return NetworkProtocol.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.getDescriptor().getEnumTypes().get(1); - } - - private static final NetworkProtocol[] VALUES = values(); - - public static NetworkProtocol valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private NetworkProtocol(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:grpc.gcp.NetworkProtocol) - } - - public interface EndpointOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.Endpoint) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-     * "192.168.0.1" or "2001:db8::1".
-     * 
- * - * string ip_address = 1; - */ - java.lang.String getIpAddress(); - /** - *
-     * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-     * "192.168.0.1" or "2001:db8::1".
-     * 
- * - * string ip_address = 1; - */ - com.google.protobuf.ByteString - getIpAddressBytes(); - - /** - *
-     * Port number.
-     * 
- * - * int32 port = 2; - */ - int getPort(); - - /** - *
-     * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-     * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - int getProtocolValue(); - /** - *
-     * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-     * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - io.grpc.alts.internal.Handshaker.NetworkProtocol getProtocol(); - } - /** - * Protobuf type {@code grpc.gcp.Endpoint} - */ - public static final class Endpoint extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.Endpoint) - EndpointOrBuilder { - private static final long serialVersionUID = 0L; - // Use Endpoint.newBuilder() to construct. - private Endpoint(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private Endpoint() { - ipAddress_ = ""; - port_ = 0; - protocol_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private Endpoint( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - ipAddress_ = s; - break; - } - case 16: { - - port_ = input.readInt32(); - break; - } - case 24: { - int rawValue = input.readEnum(); - - protocol_ = rawValue; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Endpoint_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Endpoint_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.Endpoint.class, io.grpc.alts.internal.Handshaker.Endpoint.Builder.class); - } - - public static final int IP_ADDRESS_FIELD_NUMBER = 1; - private volatile java.lang.Object ipAddress_; - /** - *
-     * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-     * "192.168.0.1" or "2001:db8::1".
-     * 
- * - * string ip_address = 1; - */ - public java.lang.String getIpAddress() { - java.lang.Object ref = ipAddress_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - ipAddress_ = s; - return s; - } - } - /** - *
-     * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-     * "192.168.0.1" or "2001:db8::1".
-     * 
- * - * string ip_address = 1; - */ - public com.google.protobuf.ByteString - getIpAddressBytes() { - java.lang.Object ref = ipAddress_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - ipAddress_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int PORT_FIELD_NUMBER = 2; - private int port_; - /** - *
-     * Port number.
-     * 
- * - * int32 port = 2; - */ - public int getPort() { - return port_; - } - - public static final int PROTOCOL_FIELD_NUMBER = 3; - private int protocol_; - /** - *
-     * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-     * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public int getProtocolValue() { - return protocol_; - } - /** - *
-     * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-     * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public io.grpc.alts.internal.Handshaker.NetworkProtocol getProtocol() { - io.grpc.alts.internal.Handshaker.NetworkProtocol result = io.grpc.alts.internal.Handshaker.NetworkProtocol.valueOf(protocol_); - return result == null ? io.grpc.alts.internal.Handshaker.NetworkProtocol.UNRECOGNIZED : result; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getIpAddressBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, ipAddress_); - } - if (port_ != 0) { - output.writeInt32(2, port_); - } - if (protocol_ != io.grpc.alts.internal.Handshaker.NetworkProtocol.NETWORK_PROTOCOL_UNSPECIFIED.getNumber()) { - output.writeEnum(3, protocol_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getIpAddressBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, ipAddress_); - } - if (port_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(2, port_); - } - if (protocol_ != io.grpc.alts.internal.Handshaker.NetworkProtocol.NETWORK_PROTOCOL_UNSPECIFIED.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(3, protocol_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.Endpoint)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.Endpoint other = (io.grpc.alts.internal.Handshaker.Endpoint) obj; - - boolean result = true; - result = result && getIpAddress() - .equals(other.getIpAddress()); - result = result && (getPort() - == other.getPort()); - result = result && protocol_ == other.protocol_; - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + IP_ADDRESS_FIELD_NUMBER; - hash = (53 * hash) + getIpAddress().hashCode(); - hash = (37 * hash) + PORT_FIELD_NUMBER; - hash = (53 * hash) + getPort(); - hash = (37 * hash) + PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + protocol_; - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Endpoint parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.Endpoint prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.Endpoint} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.Endpoint) - io.grpc.alts.internal.Handshaker.EndpointOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Endpoint_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Endpoint_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.Endpoint.class, io.grpc.alts.internal.Handshaker.Endpoint.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.Endpoint.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - ipAddress_ = ""; - - port_ = 0; - - protocol_ = 0; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Endpoint_descriptor; - } - - public io.grpc.alts.internal.Handshaker.Endpoint getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.Endpoint build() { - io.grpc.alts.internal.Handshaker.Endpoint result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.Endpoint buildPartial() { - io.grpc.alts.internal.Handshaker.Endpoint result = new io.grpc.alts.internal.Handshaker.Endpoint(this); - result.ipAddress_ = ipAddress_; - result.port_ = port_; - result.protocol_ = protocol_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.Endpoint) { - return mergeFrom((io.grpc.alts.internal.Handshaker.Endpoint)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.Endpoint other) { - if (other == io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance()) return this; - if (!other.getIpAddress().isEmpty()) { - ipAddress_ = other.ipAddress_; - onChanged(); - } - if (other.getPort() != 0) { - setPort(other.getPort()); - } - if (other.protocol_ != 0) { - setProtocolValue(other.getProtocolValue()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.Endpoint parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.Endpoint) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object ipAddress_ = ""; - /** - *
-       * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-       * "192.168.0.1" or "2001:db8::1".
-       * 
- * - * string ip_address = 1; - */ - public java.lang.String getIpAddress() { - java.lang.Object ref = ipAddress_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - ipAddress_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-       * "192.168.0.1" or "2001:db8::1".
-       * 
- * - * string ip_address = 1; - */ - public com.google.protobuf.ByteString - getIpAddressBytes() { - java.lang.Object ref = ipAddress_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - ipAddress_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-       * "192.168.0.1" or "2001:db8::1".
-       * 
- * - * string ip_address = 1; - */ - public Builder setIpAddress( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - ipAddress_ = value; - onChanged(); - return this; - } - /** - *
-       * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-       * "192.168.0.1" or "2001:db8::1".
-       * 
- * - * string ip_address = 1; - */ - public Builder clearIpAddress() { - - ipAddress_ = getDefaultInstance().getIpAddress(); - onChanged(); - return this; - } - /** - *
-       * IP address. It should contain an IPv4 or IPv6 string literal, e.g.
-       * "192.168.0.1" or "2001:db8::1".
-       * 
- * - * string ip_address = 1; - */ - public Builder setIpAddressBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - ipAddress_ = value; - onChanged(); - return this; - } - - private int port_ ; - /** - *
-       * Port number.
-       * 
- * - * int32 port = 2; - */ - public int getPort() { - return port_; - } - /** - *
-       * Port number.
-       * 
- * - * int32 port = 2; - */ - public Builder setPort(int value) { - - port_ = value; - onChanged(); - return this; - } - /** - *
-       * Port number.
-       * 
- * - * int32 port = 2; - */ - public Builder clearPort() { - - port_ = 0; - onChanged(); - return this; - } - - private int protocol_ = 0; - /** - *
-       * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-       * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public int getProtocolValue() { - return protocol_; - } - /** - *
-       * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-       * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public Builder setProtocolValue(int value) { - protocol_ = value; - onChanged(); - return this; - } - /** - *
-       * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-       * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public io.grpc.alts.internal.Handshaker.NetworkProtocol getProtocol() { - io.grpc.alts.internal.Handshaker.NetworkProtocol result = io.grpc.alts.internal.Handshaker.NetworkProtocol.valueOf(protocol_); - return result == null ? io.grpc.alts.internal.Handshaker.NetworkProtocol.UNRECOGNIZED : result; - } - /** - *
-       * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-       * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public Builder setProtocol(io.grpc.alts.internal.Handshaker.NetworkProtocol value) { - if (value == null) { - throw new NullPointerException(); - } - - protocol_ = value.getNumber(); - onChanged(); - return this; - } - /** - *
-       * Network protocol (e.g., TCP, UDP) associated with this endpoint.
-       * 
- * - * .grpc.gcp.NetworkProtocol protocol = 3; - */ - public Builder clearProtocol() { - - protocol_ = 0; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.Endpoint) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.Endpoint) - private static final io.grpc.alts.internal.Handshaker.Endpoint DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.Endpoint(); - } - - public static io.grpc.alts.internal.Handshaker.Endpoint getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Endpoint parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Endpoint(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.Endpoint getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface IdentityOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.Identity) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * Service account of a connection endpoint.
-     * 
- * - * string service_account = 1; - */ - java.lang.String getServiceAccount(); - /** - *
-     * Service account of a connection endpoint.
-     * 
- * - * string service_account = 1; - */ - com.google.protobuf.ByteString - getServiceAccountBytes(); - - /** - *
-     * Hostname of a connection endpoint.
-     * 
- * - * string hostname = 2; - */ - java.lang.String getHostname(); - /** - *
-     * Hostname of a connection endpoint.
-     * 
- * - * string hostname = 2; - */ - com.google.protobuf.ByteString - getHostnameBytes(); - - public io.grpc.alts.internal.Handshaker.Identity.IdentityOneofCase getIdentityOneofCase(); - } - /** - * Protobuf type {@code grpc.gcp.Identity} - */ - public static final class Identity extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.Identity) - IdentityOrBuilder { - private static final long serialVersionUID = 0L; - // Use Identity.newBuilder() to construct. - private Identity(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private Identity() { - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private Identity( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - identityOneofCase_ = 1; - identityOneof_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - identityOneofCase_ = 2; - identityOneof_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Identity_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Identity_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.Identity.class, io.grpc.alts.internal.Handshaker.Identity.Builder.class); - } - - private int identityOneofCase_ = 0; - private java.lang.Object identityOneof_; - public enum IdentityOneofCase - implements com.google.protobuf.Internal.EnumLite { - SERVICE_ACCOUNT(1), - HOSTNAME(2), - IDENTITYONEOF_NOT_SET(0); - private final int value; - private IdentityOneofCase(int value) { - this.value = value; - } - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static IdentityOneofCase valueOf(int value) { - return forNumber(value); - } - - public static IdentityOneofCase forNumber(int value) { - switch (value) { - case 1: return SERVICE_ACCOUNT; - case 2: return HOSTNAME; - case 0: return IDENTITYONEOF_NOT_SET; - default: return null; - } - } - public int getNumber() { - return this.value; - } - }; - - public IdentityOneofCase - getIdentityOneofCase() { - return IdentityOneofCase.forNumber( - identityOneofCase_); - } - - public static final int SERVICE_ACCOUNT_FIELD_NUMBER = 1; - /** - *
-     * Service account of a connection endpoint.
-     * 
- * - * string service_account = 1; - */ - public java.lang.String getServiceAccount() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 1) { - ref = identityOneof_; - } - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (identityOneofCase_ == 1) { - identityOneof_ = s; - } - return s; - } - } - /** - *
-     * Service account of a connection endpoint.
-     * 
- * - * string service_account = 1; - */ - public com.google.protobuf.ByteString - getServiceAccountBytes() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 1) { - ref = identityOneof_; - } - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - if (identityOneofCase_ == 1) { - identityOneof_ = b; - } - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int HOSTNAME_FIELD_NUMBER = 2; - /** - *
-     * Hostname of a connection endpoint.
-     * 
- * - * string hostname = 2; - */ - public java.lang.String getHostname() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 2) { - ref = identityOneof_; - } - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (identityOneofCase_ == 2) { - identityOneof_ = s; - } - return s; - } - } - /** - *
-     * Hostname of a connection endpoint.
-     * 
- * - * string hostname = 2; - */ - public com.google.protobuf.ByteString - getHostnameBytes() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 2) { - ref = identityOneof_; - } - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - if (identityOneofCase_ == 2) { - identityOneof_ = b; - } - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (identityOneofCase_ == 1) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, identityOneof_); - } - if (identityOneofCase_ == 2) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, identityOneof_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (identityOneofCase_ == 1) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, identityOneof_); - } - if (identityOneofCase_ == 2) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, identityOneof_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.Identity)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.Identity other = (io.grpc.alts.internal.Handshaker.Identity) obj; - - boolean result = true; - result = result && getIdentityOneofCase().equals( - other.getIdentityOneofCase()); - if (!result) return false; - switch (identityOneofCase_) { - case 1: - result = result && getServiceAccount() - .equals(other.getServiceAccount()); - break; - case 2: - result = result && getHostname() - .equals(other.getHostname()); - break; - case 0: - default: - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - switch (identityOneofCase_) { - case 1: - hash = (37 * hash) + SERVICE_ACCOUNT_FIELD_NUMBER; - hash = (53 * hash) + getServiceAccount().hashCode(); - break; - case 2: - hash = (37 * hash) + HOSTNAME_FIELD_NUMBER; - hash = (53 * hash) + getHostname().hashCode(); - break; - case 0: - default: - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Identity parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Identity parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.Identity parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.Identity prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.Identity} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.Identity) - io.grpc.alts.internal.Handshaker.IdentityOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Identity_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Identity_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.Identity.class, io.grpc.alts.internal.Handshaker.Identity.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.Identity.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - identityOneofCase_ = 0; - identityOneof_ = null; - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_Identity_descriptor; - } - - public io.grpc.alts.internal.Handshaker.Identity getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.Identity build() { - io.grpc.alts.internal.Handshaker.Identity result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.Identity buildPartial() { - io.grpc.alts.internal.Handshaker.Identity result = new io.grpc.alts.internal.Handshaker.Identity(this); - if (identityOneofCase_ == 1) { - result.identityOneof_ = identityOneof_; - } - if (identityOneofCase_ == 2) { - result.identityOneof_ = identityOneof_; - } - result.identityOneofCase_ = identityOneofCase_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.Identity) { - return mergeFrom((io.grpc.alts.internal.Handshaker.Identity)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.Identity other) { - if (other == io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance()) return this; - switch (other.getIdentityOneofCase()) { - case SERVICE_ACCOUNT: { - identityOneofCase_ = 1; - identityOneof_ = other.identityOneof_; - onChanged(); - break; - } - case HOSTNAME: { - identityOneofCase_ = 2; - identityOneof_ = other.identityOneof_; - onChanged(); - break; - } - case IDENTITYONEOF_NOT_SET: { - break; - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.Identity parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.Identity) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int identityOneofCase_ = 0; - private java.lang.Object identityOneof_; - public IdentityOneofCase - getIdentityOneofCase() { - return IdentityOneofCase.forNumber( - identityOneofCase_); - } - - public Builder clearIdentityOneof() { - identityOneofCase_ = 0; - identityOneof_ = null; - onChanged(); - return this; - } - - - /** - *
-       * Service account of a connection endpoint.
-       * 
- * - * string service_account = 1; - */ - public java.lang.String getServiceAccount() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 1) { - ref = identityOneof_; - } - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (identityOneofCase_ == 1) { - identityOneof_ = s; - } - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * Service account of a connection endpoint.
-       * 
- * - * string service_account = 1; - */ - public com.google.protobuf.ByteString - getServiceAccountBytes() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 1) { - ref = identityOneof_; - } - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - if (identityOneofCase_ == 1) { - identityOneof_ = b; - } - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * Service account of a connection endpoint.
-       * 
- * - * string service_account = 1; - */ - public Builder setServiceAccount( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - identityOneofCase_ = 1; - identityOneof_ = value; - onChanged(); - return this; - } - /** - *
-       * Service account of a connection endpoint.
-       * 
- * - * string service_account = 1; - */ - public Builder clearServiceAccount() { - if (identityOneofCase_ == 1) { - identityOneofCase_ = 0; - identityOneof_ = null; - onChanged(); - } - return this; - } - /** - *
-       * Service account of a connection endpoint.
-       * 
- * - * string service_account = 1; - */ - public Builder setServiceAccountBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - identityOneofCase_ = 1; - identityOneof_ = value; - onChanged(); - return this; - } - - /** - *
-       * Hostname of a connection endpoint.
-       * 
- * - * string hostname = 2; - */ - public java.lang.String getHostname() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 2) { - ref = identityOneof_; - } - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (identityOneofCase_ == 2) { - identityOneof_ = s; - } - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * Hostname of a connection endpoint.
-       * 
- * - * string hostname = 2; - */ - public com.google.protobuf.ByteString - getHostnameBytes() { - java.lang.Object ref = ""; - if (identityOneofCase_ == 2) { - ref = identityOneof_; - } - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - if (identityOneofCase_ == 2) { - identityOneof_ = b; - } - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * Hostname of a connection endpoint.
-       * 
- * - * string hostname = 2; - */ - public Builder setHostname( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - identityOneofCase_ = 2; - identityOneof_ = value; - onChanged(); - return this; - } - /** - *
-       * Hostname of a connection endpoint.
-       * 
- * - * string hostname = 2; - */ - public Builder clearHostname() { - if (identityOneofCase_ == 2) { - identityOneofCase_ = 0; - identityOneof_ = null; - onChanged(); - } - return this; - } - /** - *
-       * Hostname of a connection endpoint.
-       * 
- * - * string hostname = 2; - */ - public Builder setHostnameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - identityOneofCase_ = 2; - identityOneof_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.Identity) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.Identity) - private static final io.grpc.alts.internal.Handshaker.Identity DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.Identity(); - } - - public static io.grpc.alts.internal.Handshaker.Identity getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Identity parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Identity(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.Identity getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StartClientHandshakeReqOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.StartClientHandshakeReq) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * Handshake security protocol requested by the client.
-     * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - int getHandshakeSecurityProtocolValue(); - /** - *
-     * Handshake security protocol requested by the client.
-     * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - io.grpc.alts.internal.Handshaker.HandshakeProtocol getHandshakeSecurityProtocol(); - - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - java.util.List - getApplicationProtocolsList(); - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - int getApplicationProtocolsCount(); - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - java.lang.String getApplicationProtocols(int index); - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index); - - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - java.util.List - getRecordProtocolsList(); - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - int getRecordProtocolsCount(); - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - java.lang.String getRecordProtocols(int index); - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - com.google.protobuf.ByteString - getRecordProtocolsBytes(int index); - - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - java.util.List - getTargetIdentitiesList(); - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - io.grpc.alts.internal.Handshaker.Identity getTargetIdentities(int index); - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - int getTargetIdentitiesCount(); - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - java.util.List - getTargetIdentitiesOrBuilderList(); - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - io.grpc.alts.internal.Handshaker.IdentityOrBuilder getTargetIdentitiesOrBuilder( - int index); - - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - boolean hasLocalIdentity(); - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - io.grpc.alts.internal.Handshaker.Identity getLocalIdentity(); - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder(); - - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - boolean hasLocalEndpoint(); - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint(); - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder(); - - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - boolean hasRemoteEndpoint(); - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint(); - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder(); - - /** - *
-     * (Optional) If target name is provided, a secure naming check is performed
-     * to verify that the peer authenticated identity is indeed authorized to run
-     * the target name.
-     * 
- * - * string target_name = 8; - */ - java.lang.String getTargetName(); - /** - *
-     * (Optional) If target name is provided, a secure naming check is performed
-     * to verify that the peer authenticated identity is indeed authorized to run
-     * the target name.
-     * 
- * - * string target_name = 8; - */ - com.google.protobuf.ByteString - getTargetNameBytes(); - - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - boolean hasRpcVersions(); - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions(); - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder(); - } - /** - * Protobuf type {@code grpc.gcp.StartClientHandshakeReq} - */ - public static final class StartClientHandshakeReq extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.StartClientHandshakeReq) - StartClientHandshakeReqOrBuilder { - private static final long serialVersionUID = 0L; - // Use StartClientHandshakeReq.newBuilder() to construct. - private StartClientHandshakeReq(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StartClientHandshakeReq() { - handshakeSecurityProtocol_ = 0; - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - targetIdentities_ = java.util.Collections.emptyList(); - targetName_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StartClientHandshakeReq( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - int rawValue = input.readEnum(); - - handshakeSecurityProtocol_ = rawValue; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - applicationProtocols_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000002; - } - applicationProtocols_.add(s); - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - recordProtocols_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000004; - } - recordProtocols_.add(s); - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { - targetIdentities_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; - } - targetIdentities_.add( - input.readMessage(io.grpc.alts.internal.Handshaker.Identity.parser(), extensionRegistry)); - break; - } - case 42: { - io.grpc.alts.internal.Handshaker.Identity.Builder subBuilder = null; - if (localIdentity_ != null) { - subBuilder = localIdentity_.toBuilder(); - } - localIdentity_ = input.readMessage(io.grpc.alts.internal.Handshaker.Identity.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(localIdentity_); - localIdentity_ = subBuilder.buildPartial(); - } - - break; - } - case 50: { - io.grpc.alts.internal.Handshaker.Endpoint.Builder subBuilder = null; - if (localEndpoint_ != null) { - subBuilder = localEndpoint_.toBuilder(); - } - localEndpoint_ = input.readMessage(io.grpc.alts.internal.Handshaker.Endpoint.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(localEndpoint_); - localEndpoint_ = subBuilder.buildPartial(); - } - - break; - } - case 58: { - io.grpc.alts.internal.Handshaker.Endpoint.Builder subBuilder = null; - if (remoteEndpoint_ != null) { - subBuilder = remoteEndpoint_.toBuilder(); - } - remoteEndpoint_ = input.readMessage(io.grpc.alts.internal.Handshaker.Endpoint.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(remoteEndpoint_); - remoteEndpoint_ = subBuilder.buildPartial(); - } - - break; - } - case 66: { - java.lang.String s = input.readStringRequireUtf8(); - - targetName_ = s; - break; - } - case 74: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder subBuilder = null; - if (rpcVersions_ != null) { - subBuilder = rpcVersions_.toBuilder(); - } - rpcVersions_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(rpcVersions_); - rpcVersions_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - applicationProtocols_ = applicationProtocols_.getUnmodifiableView(); - } - if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - recordProtocols_ = recordProtocols_.getUnmodifiableView(); - } - if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { - targetIdentities_ = java.util.Collections.unmodifiableList(targetIdentities_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartClientHandshakeReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartClientHandshakeReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.class, io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder.class); - } - - private int bitField0_; - public static final int HANDSHAKE_SECURITY_PROTOCOL_FIELD_NUMBER = 1; - private int handshakeSecurityProtocol_; - /** - *
-     * Handshake security protocol requested by the client.
-     * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public int getHandshakeSecurityProtocolValue() { - return handshakeSecurityProtocol_; - } - /** - *
-     * Handshake security protocol requested by the client.
-     * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public io.grpc.alts.internal.Handshaker.HandshakeProtocol getHandshakeSecurityProtocol() { - io.grpc.alts.internal.Handshaker.HandshakeProtocol result = io.grpc.alts.internal.Handshaker.HandshakeProtocol.valueOf(handshakeSecurityProtocol_); - return result == null ? io.grpc.alts.internal.Handshaker.HandshakeProtocol.UNRECOGNIZED : result; - } - - public static final int APPLICATION_PROTOCOLS_FIELD_NUMBER = 2; - private com.google.protobuf.LazyStringList applicationProtocols_; - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - public com.google.protobuf.ProtocolStringList - getApplicationProtocolsList() { - return applicationProtocols_; - } - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - public int getApplicationProtocolsCount() { - return applicationProtocols_.size(); - } - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - public java.lang.String getApplicationProtocols(int index) { - return applicationProtocols_.get(index); - } - /** - *
-     * The application protocols supported by the client, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 2; - */ - public com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index) { - return applicationProtocols_.getByteString(index); - } - - public static final int RECORD_PROTOCOLS_FIELD_NUMBER = 3; - private com.google.protobuf.LazyStringList recordProtocols_; - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - public com.google.protobuf.ProtocolStringList - getRecordProtocolsList() { - return recordProtocols_; - } - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - public int getRecordProtocolsCount() { - return recordProtocols_.size(); - } - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - public java.lang.String getRecordProtocols(int index) { - return recordProtocols_.get(index); - } - /** - *
-     * The record protocols supported by the client, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 3; - */ - public com.google.protobuf.ByteString - getRecordProtocolsBytes(int index) { - return recordProtocols_.getByteString(index); - } - - public static final int TARGET_IDENTITIES_FIELD_NUMBER = 4; - private java.util.List targetIdentities_; - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public java.util.List getTargetIdentitiesList() { - return targetIdentities_; - } - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public java.util.List - getTargetIdentitiesOrBuilderList() { - return targetIdentities_; - } - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public int getTargetIdentitiesCount() { - return targetIdentities_.size(); - } - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity getTargetIdentities(int index) { - return targetIdentities_.get(index); - } - /** - *
-     * (Optional) Describes which server identities are acceptable by the client.
-     * If target identities are provided and none of them matches the peer
-     * identity of the server, handshake will fail.
-     * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getTargetIdentitiesOrBuilder( - int index) { - return targetIdentities_.get(index); - } - - public static final int LOCAL_IDENTITY_FIELD_NUMBER = 5; - private io.grpc.alts.internal.Handshaker.Identity localIdentity_; - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public boolean hasLocalIdentity() { - return localIdentity_ != null; - } - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentity() { - return localIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } - /** - *
-     * (Optional) Application may specify a local identity. Otherwise, the
-     * handshaker chooses a default local identity.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder() { - return getLocalIdentity(); - } - - public static final int LOCAL_ENDPOINT_FIELD_NUMBER = 6; - private io.grpc.alts.internal.Handshaker.Endpoint localEndpoint_; - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public boolean hasLocalEndpoint() { - return localEndpoint_ != null; - } - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint() { - return localEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } - /** - *
-     * (Optional) Local endpoint information of the connection to the server,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder() { - return getLocalEndpoint(); - } - - public static final int REMOTE_ENDPOINT_FIELD_NUMBER = 7; - private io.grpc.alts.internal.Handshaker.Endpoint remoteEndpoint_; - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public boolean hasRemoteEndpoint() { - return remoteEndpoint_ != null; - } - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint() { - return remoteEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } - /** - *
-     * (Optional) Endpoint information of the remote server, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder() { - return getRemoteEndpoint(); - } - - public static final int TARGET_NAME_FIELD_NUMBER = 8; - private volatile java.lang.Object targetName_; - /** - *
-     * (Optional) If target name is provided, a secure naming check is performed
-     * to verify that the peer authenticated identity is indeed authorized to run
-     * the target name.
-     * 
- * - * string target_name = 8; - */ - public java.lang.String getTargetName() { - java.lang.Object ref = targetName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - targetName_ = s; - return s; - } - } - /** - *
-     * (Optional) If target name is provided, a secure naming check is performed
-     * to verify that the peer authenticated identity is indeed authorized to run
-     * the target name.
-     * 
- * - * string target_name = 8; - */ - public com.google.protobuf.ByteString - getTargetNameBytes() { - java.lang.Object ref = targetName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - targetName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RPC_VERSIONS_FIELD_NUMBER = 9; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions rpcVersions_; - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public boolean hasRpcVersions() { - return rpcVersions_ != null; - } - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions() { - return rpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } - /** - *
-     * (Optional) RPC protocol versions supported by the client.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder() { - return getRpcVersions(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (handshakeSecurityProtocol_ != io.grpc.alts.internal.Handshaker.HandshakeProtocol.HANDSHAKE_PROTOCOL_UNSPECIFIED.getNumber()) { - output.writeEnum(1, handshakeSecurityProtocol_); - } - for (int i = 0; i < applicationProtocols_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, applicationProtocols_.getRaw(i)); - } - for (int i = 0; i < recordProtocols_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, recordProtocols_.getRaw(i)); - } - for (int i = 0; i < targetIdentities_.size(); i++) { - output.writeMessage(4, targetIdentities_.get(i)); - } - if (localIdentity_ != null) { - output.writeMessage(5, getLocalIdentity()); - } - if (localEndpoint_ != null) { - output.writeMessage(6, getLocalEndpoint()); - } - if (remoteEndpoint_ != null) { - output.writeMessage(7, getRemoteEndpoint()); - } - if (!getTargetNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 8, targetName_); - } - if (rpcVersions_ != null) { - output.writeMessage(9, getRpcVersions()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (handshakeSecurityProtocol_ != io.grpc.alts.internal.Handshaker.HandshakeProtocol.HANDSHAKE_PROTOCOL_UNSPECIFIED.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(1, handshakeSecurityProtocol_); - } - { - int dataSize = 0; - for (int i = 0; i < applicationProtocols_.size(); i++) { - dataSize += computeStringSizeNoTag(applicationProtocols_.getRaw(i)); - } - size += dataSize; - size += 1 * getApplicationProtocolsList().size(); - } - { - int dataSize = 0; - for (int i = 0; i < recordProtocols_.size(); i++) { - dataSize += computeStringSizeNoTag(recordProtocols_.getRaw(i)); - } - size += dataSize; - size += 1 * getRecordProtocolsList().size(); - } - for (int i = 0; i < targetIdentities_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, targetIdentities_.get(i)); - } - if (localIdentity_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getLocalIdentity()); - } - if (localEndpoint_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(6, getLocalEndpoint()); - } - if (remoteEndpoint_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(7, getRemoteEndpoint()); - } - if (!getTargetNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, targetName_); - } - if (rpcVersions_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(9, getRpcVersions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.StartClientHandshakeReq)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq other = (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) obj; - - boolean result = true; - result = result && handshakeSecurityProtocol_ == other.handshakeSecurityProtocol_; - result = result && getApplicationProtocolsList() - .equals(other.getApplicationProtocolsList()); - result = result && getRecordProtocolsList() - .equals(other.getRecordProtocolsList()); - result = result && getTargetIdentitiesList() - .equals(other.getTargetIdentitiesList()); - result = result && (hasLocalIdentity() == other.hasLocalIdentity()); - if (hasLocalIdentity()) { - result = result && getLocalIdentity() - .equals(other.getLocalIdentity()); - } - result = result && (hasLocalEndpoint() == other.hasLocalEndpoint()); - if (hasLocalEndpoint()) { - result = result && getLocalEndpoint() - .equals(other.getLocalEndpoint()); - } - result = result && (hasRemoteEndpoint() == other.hasRemoteEndpoint()); - if (hasRemoteEndpoint()) { - result = result && getRemoteEndpoint() - .equals(other.getRemoteEndpoint()); - } - result = result && getTargetName() - .equals(other.getTargetName()); - result = result && (hasRpcVersions() == other.hasRpcVersions()); - if (hasRpcVersions()) { - result = result && getRpcVersions() - .equals(other.getRpcVersions()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + HANDSHAKE_SECURITY_PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + handshakeSecurityProtocol_; - if (getApplicationProtocolsCount() > 0) { - hash = (37 * hash) + APPLICATION_PROTOCOLS_FIELD_NUMBER; - hash = (53 * hash) + getApplicationProtocolsList().hashCode(); - } - if (getRecordProtocolsCount() > 0) { - hash = (37 * hash) + RECORD_PROTOCOLS_FIELD_NUMBER; - hash = (53 * hash) + getRecordProtocolsList().hashCode(); - } - if (getTargetIdentitiesCount() > 0) { - hash = (37 * hash) + TARGET_IDENTITIES_FIELD_NUMBER; - hash = (53 * hash) + getTargetIdentitiesList().hashCode(); - } - if (hasLocalIdentity()) { - hash = (37 * hash) + LOCAL_IDENTITY_FIELD_NUMBER; - hash = (53 * hash) + getLocalIdentity().hashCode(); - } - if (hasLocalEndpoint()) { - hash = (37 * hash) + LOCAL_ENDPOINT_FIELD_NUMBER; - hash = (53 * hash) + getLocalEndpoint().hashCode(); - } - if (hasRemoteEndpoint()) { - hash = (37 * hash) + REMOTE_ENDPOINT_FIELD_NUMBER; - hash = (53 * hash) + getRemoteEndpoint().hashCode(); - } - hash = (37 * hash) + TARGET_NAME_FIELD_NUMBER; - hash = (53 * hash) + getTargetName().hashCode(); - if (hasRpcVersions()) { - hash = (37 * hash) + RPC_VERSIONS_FIELD_NUMBER; - hash = (53 * hash) + getRpcVersions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.StartClientHandshakeReq prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.StartClientHandshakeReq} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.StartClientHandshakeReq) - io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartClientHandshakeReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartClientHandshakeReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.class, io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - getTargetIdentitiesFieldBuilder(); - } - } - public Builder clear() { - super.clear(); - handshakeSecurityProtocol_ = 0; - - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); - if (targetIdentitiesBuilder_ == null) { - targetIdentities_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); - } else { - targetIdentitiesBuilder_.clear(); - } - if (localIdentityBuilder_ == null) { - localIdentity_ = null; - } else { - localIdentity_ = null; - localIdentityBuilder_ = null; - } - if (localEndpointBuilder_ == null) { - localEndpoint_ = null; - } else { - localEndpoint_ = null; - localEndpointBuilder_ = null; - } - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = null; - } else { - remoteEndpoint_ = null; - remoteEndpointBuilder_ = null; - } - targetName_ = ""; - - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = null; - } else { - rpcVersions_ = null; - rpcVersionsBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartClientHandshakeReq_descriptor; - } - - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq build() { - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq buildPartial() { - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq result = new io.grpc.alts.internal.Handshaker.StartClientHandshakeReq(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - result.handshakeSecurityProtocol_ = handshakeSecurityProtocol_; - if (((bitField0_ & 0x00000002) == 0x00000002)) { - applicationProtocols_ = applicationProtocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000002); - } - result.applicationProtocols_ = applicationProtocols_; - if (((bitField0_ & 0x00000004) == 0x00000004)) { - recordProtocols_ = recordProtocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000004); - } - result.recordProtocols_ = recordProtocols_; - if (targetIdentitiesBuilder_ == null) { - if (((bitField0_ & 0x00000008) == 0x00000008)) { - targetIdentities_ = java.util.Collections.unmodifiableList(targetIdentities_); - bitField0_ = (bitField0_ & ~0x00000008); - } - result.targetIdentities_ = targetIdentities_; - } else { - result.targetIdentities_ = targetIdentitiesBuilder_.build(); - } - if (localIdentityBuilder_ == null) { - result.localIdentity_ = localIdentity_; - } else { - result.localIdentity_ = localIdentityBuilder_.build(); - } - if (localEndpointBuilder_ == null) { - result.localEndpoint_ = localEndpoint_; - } else { - result.localEndpoint_ = localEndpointBuilder_.build(); - } - if (remoteEndpointBuilder_ == null) { - result.remoteEndpoint_ = remoteEndpoint_; - } else { - result.remoteEndpoint_ = remoteEndpointBuilder_.build(); - } - result.targetName_ = targetName_; - if (rpcVersionsBuilder_ == null) { - result.rpcVersions_ = rpcVersions_; - } else { - result.rpcVersions_ = rpcVersionsBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) { - return mergeFrom((io.grpc.alts.internal.Handshaker.StartClientHandshakeReq)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.StartClientHandshakeReq other) { - if (other == io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance()) return this; - if (other.handshakeSecurityProtocol_ != 0) { - setHandshakeSecurityProtocolValue(other.getHandshakeSecurityProtocolValue()); - } - if (!other.applicationProtocols_.isEmpty()) { - if (applicationProtocols_.isEmpty()) { - applicationProtocols_ = other.applicationProtocols_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.addAll(other.applicationProtocols_); - } - onChanged(); - } - if (!other.recordProtocols_.isEmpty()) { - if (recordProtocols_.isEmpty()) { - recordProtocols_ = other.recordProtocols_; - bitField0_ = (bitField0_ & ~0x00000004); - } else { - ensureRecordProtocolsIsMutable(); - recordProtocols_.addAll(other.recordProtocols_); - } - onChanged(); - } - if (targetIdentitiesBuilder_ == null) { - if (!other.targetIdentities_.isEmpty()) { - if (targetIdentities_.isEmpty()) { - targetIdentities_ = other.targetIdentities_; - bitField0_ = (bitField0_ & ~0x00000008); - } else { - ensureTargetIdentitiesIsMutable(); - targetIdentities_.addAll(other.targetIdentities_); - } - onChanged(); - } - } else { - if (!other.targetIdentities_.isEmpty()) { - if (targetIdentitiesBuilder_.isEmpty()) { - targetIdentitiesBuilder_.dispose(); - targetIdentitiesBuilder_ = null; - targetIdentities_ = other.targetIdentities_; - bitField0_ = (bitField0_ & ~0x00000008); - targetIdentitiesBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? - getTargetIdentitiesFieldBuilder() : null; - } else { - targetIdentitiesBuilder_.addAllMessages(other.targetIdentities_); - } - } - } - if (other.hasLocalIdentity()) { - mergeLocalIdentity(other.getLocalIdentity()); - } - if (other.hasLocalEndpoint()) { - mergeLocalEndpoint(other.getLocalEndpoint()); - } - if (other.hasRemoteEndpoint()) { - mergeRemoteEndpoint(other.getRemoteEndpoint()); - } - if (!other.getTargetName().isEmpty()) { - targetName_ = other.targetName_; - onChanged(); - } - if (other.hasRpcVersions()) { - mergeRpcVersions(other.getRpcVersions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private int handshakeSecurityProtocol_ = 0; - /** - *
-       * Handshake security protocol requested by the client.
-       * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public int getHandshakeSecurityProtocolValue() { - return handshakeSecurityProtocol_; - } - /** - *
-       * Handshake security protocol requested by the client.
-       * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public Builder setHandshakeSecurityProtocolValue(int value) { - handshakeSecurityProtocol_ = value; - onChanged(); - return this; - } - /** - *
-       * Handshake security protocol requested by the client.
-       * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public io.grpc.alts.internal.Handshaker.HandshakeProtocol getHandshakeSecurityProtocol() { - io.grpc.alts.internal.Handshaker.HandshakeProtocol result = io.grpc.alts.internal.Handshaker.HandshakeProtocol.valueOf(handshakeSecurityProtocol_); - return result == null ? io.grpc.alts.internal.Handshaker.HandshakeProtocol.UNRECOGNIZED : result; - } - /** - *
-       * Handshake security protocol requested by the client.
-       * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public Builder setHandshakeSecurityProtocol(io.grpc.alts.internal.Handshaker.HandshakeProtocol value) { - if (value == null) { - throw new NullPointerException(); - } - - handshakeSecurityProtocol_ = value.getNumber(); - onChanged(); - return this; - } - /** - *
-       * Handshake security protocol requested by the client.
-       * 
- * - * .grpc.gcp.HandshakeProtocol handshake_security_protocol = 1; - */ - public Builder clearHandshakeSecurityProtocol() { - - handshakeSecurityProtocol_ = 0; - onChanged(); - return this; - } - - private com.google.protobuf.LazyStringList applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureApplicationProtocolsIsMutable() { - if (!((bitField0_ & 0x00000002) == 0x00000002)) { - applicationProtocols_ = new com.google.protobuf.LazyStringArrayList(applicationProtocols_); - bitField0_ |= 0x00000002; - } - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public com.google.protobuf.ProtocolStringList - getApplicationProtocolsList() { - return applicationProtocols_.getUnmodifiableView(); - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public int getApplicationProtocolsCount() { - return applicationProtocols_.size(); - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public java.lang.String getApplicationProtocols(int index) { - return applicationProtocols_.get(index); - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index) { - return applicationProtocols_.getByteString(index); - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public Builder setApplicationProtocols( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.set(index, value); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public Builder addApplicationProtocols( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.add(value); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public Builder addAllApplicationProtocols( - java.lang.Iterable values) { - ensureApplicationProtocolsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, applicationProtocols_); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public Builder clearApplicationProtocols() { - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the client, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 2; - */ - public Builder addApplicationProtocolsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.add(value); - onChanged(); - return this; - } - - private com.google.protobuf.LazyStringList recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureRecordProtocolsIsMutable() { - if (!((bitField0_ & 0x00000004) == 0x00000004)) { - recordProtocols_ = new com.google.protobuf.LazyStringArrayList(recordProtocols_); - bitField0_ |= 0x00000004; - } - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public com.google.protobuf.ProtocolStringList - getRecordProtocolsList() { - return recordProtocols_.getUnmodifiableView(); - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public int getRecordProtocolsCount() { - return recordProtocols_.size(); - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public java.lang.String getRecordProtocols(int index) { - return recordProtocols_.get(index); - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public com.google.protobuf.ByteString - getRecordProtocolsBytes(int index) { - return recordProtocols_.getByteString(index); - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public Builder setRecordProtocols( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureRecordProtocolsIsMutable(); - recordProtocols_.set(index, value); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public Builder addRecordProtocols( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureRecordProtocolsIsMutable(); - recordProtocols_.add(value); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public Builder addAllRecordProtocols( - java.lang.Iterable values) { - ensureRecordProtocolsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, recordProtocols_); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public Builder clearRecordProtocols() { - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the client, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 3; - */ - public Builder addRecordProtocolsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureRecordProtocolsIsMutable(); - recordProtocols_.add(value); - onChanged(); - return this; - } - - private java.util.List targetIdentities_ = - java.util.Collections.emptyList(); - private void ensureTargetIdentitiesIsMutable() { - if (!((bitField0_ & 0x00000008) == 0x00000008)) { - targetIdentities_ = new java.util.ArrayList(targetIdentities_); - bitField0_ |= 0x00000008; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> targetIdentitiesBuilder_; - - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public java.util.List getTargetIdentitiesList() { - if (targetIdentitiesBuilder_ == null) { - return java.util.Collections.unmodifiableList(targetIdentities_); - } else { - return targetIdentitiesBuilder_.getMessageList(); - } - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public int getTargetIdentitiesCount() { - if (targetIdentitiesBuilder_ == null) { - return targetIdentities_.size(); - } else { - return targetIdentitiesBuilder_.getCount(); - } - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity getTargetIdentities(int index) { - if (targetIdentitiesBuilder_ == null) { - return targetIdentities_.get(index); - } else { - return targetIdentitiesBuilder_.getMessage(index); - } - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder setTargetIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity value) { - if (targetIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTargetIdentitiesIsMutable(); - targetIdentities_.set(index, value); - onChanged(); - } else { - targetIdentitiesBuilder_.setMessage(index, value); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder setTargetIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (targetIdentitiesBuilder_ == null) { - ensureTargetIdentitiesIsMutable(); - targetIdentities_.set(index, builderForValue.build()); - onChanged(); - } else { - targetIdentitiesBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder addTargetIdentities(io.grpc.alts.internal.Handshaker.Identity value) { - if (targetIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTargetIdentitiesIsMutable(); - targetIdentities_.add(value); - onChanged(); - } else { - targetIdentitiesBuilder_.addMessage(value); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder addTargetIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity value) { - if (targetIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTargetIdentitiesIsMutable(); - targetIdentities_.add(index, value); - onChanged(); - } else { - targetIdentitiesBuilder_.addMessage(index, value); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder addTargetIdentities( - io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (targetIdentitiesBuilder_ == null) { - ensureTargetIdentitiesIsMutable(); - targetIdentities_.add(builderForValue.build()); - onChanged(); - } else { - targetIdentitiesBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder addTargetIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (targetIdentitiesBuilder_ == null) { - ensureTargetIdentitiesIsMutable(); - targetIdentities_.add(index, builderForValue.build()); - onChanged(); - } else { - targetIdentitiesBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder addAllTargetIdentities( - java.lang.Iterable values) { - if (targetIdentitiesBuilder_ == null) { - ensureTargetIdentitiesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, targetIdentities_); - onChanged(); - } else { - targetIdentitiesBuilder_.addAllMessages(values); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder clearTargetIdentities() { - if (targetIdentitiesBuilder_ == null) { - targetIdentities_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); - onChanged(); - } else { - targetIdentitiesBuilder_.clear(); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public Builder removeTargetIdentities(int index) { - if (targetIdentitiesBuilder_ == null) { - ensureTargetIdentitiesIsMutable(); - targetIdentities_.remove(index); - onChanged(); - } else { - targetIdentitiesBuilder_.remove(index); - } - return this; - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder getTargetIdentitiesBuilder( - int index) { - return getTargetIdentitiesFieldBuilder().getBuilder(index); - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getTargetIdentitiesOrBuilder( - int index) { - if (targetIdentitiesBuilder_ == null) { - return targetIdentities_.get(index); } else { - return targetIdentitiesBuilder_.getMessageOrBuilder(index); - } - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public java.util.List - getTargetIdentitiesOrBuilderList() { - if (targetIdentitiesBuilder_ != null) { - return targetIdentitiesBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(targetIdentities_); - } - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder addTargetIdentitiesBuilder() { - return getTargetIdentitiesFieldBuilder().addBuilder( - io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance()); - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder addTargetIdentitiesBuilder( - int index) { - return getTargetIdentitiesFieldBuilder().addBuilder( - index, io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance()); - } - /** - *
-       * (Optional) Describes which server identities are acceptable by the client.
-       * If target identities are provided and none of them matches the peer
-       * identity of the server, handshake will fail.
-       * 
- * - * repeated .grpc.gcp.Identity target_identities = 4; - */ - public java.util.List - getTargetIdentitiesBuilderList() { - return getTargetIdentitiesFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> - getTargetIdentitiesFieldBuilder() { - if (targetIdentitiesBuilder_ == null) { - targetIdentitiesBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder>( - targetIdentities_, - ((bitField0_ & 0x00000008) == 0x00000008), - getParentForChildren(), - isClean()); - targetIdentities_ = null; - } - return targetIdentitiesBuilder_; - } - - private io.grpc.alts.internal.Handshaker.Identity localIdentity_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> localIdentityBuilder_; - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public boolean hasLocalIdentity() { - return localIdentityBuilder_ != null || localIdentity_ != null; - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentity() { - if (localIdentityBuilder_ == null) { - return localIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } else { - return localIdentityBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder setLocalIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentityBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - localIdentity_ = value; - onChanged(); - } else { - localIdentityBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder setLocalIdentity( - io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (localIdentityBuilder_ == null) { - localIdentity_ = builderForValue.build(); - onChanged(); - } else { - localIdentityBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder mergeLocalIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentityBuilder_ == null) { - if (localIdentity_ != null) { - localIdentity_ = - io.grpc.alts.internal.Handshaker.Identity.newBuilder(localIdentity_).mergeFrom(value).buildPartial(); - } else { - localIdentity_ = value; - } - onChanged(); - } else { - localIdentityBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder clearLocalIdentity() { - if (localIdentityBuilder_ == null) { - localIdentity_ = null; - onChanged(); - } else { - localIdentity_ = null; - localIdentityBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder getLocalIdentityBuilder() { - - onChanged(); - return getLocalIdentityFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder() { - if (localIdentityBuilder_ != null) { - return localIdentityBuilder_.getMessageOrBuilder(); - } else { - return localIdentity_ == null ? - io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } - } - /** - *
-       * (Optional) Application may specify a local identity. Otherwise, the
-       * handshaker chooses a default local identity.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> - getLocalIdentityFieldBuilder() { - if (localIdentityBuilder_ == null) { - localIdentityBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder>( - getLocalIdentity(), - getParentForChildren(), - isClean()); - localIdentity_ = null; - } - return localIdentityBuilder_; - } - - private io.grpc.alts.internal.Handshaker.Endpoint localEndpoint_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> localEndpointBuilder_; - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public boolean hasLocalEndpoint() { - return localEndpointBuilder_ != null || localEndpoint_ != null; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint() { - if (localEndpointBuilder_ == null) { - return localEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } else { - return localEndpointBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public Builder setLocalEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (localEndpointBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - localEndpoint_ = value; - onChanged(); - } else { - localEndpointBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public Builder setLocalEndpoint( - io.grpc.alts.internal.Handshaker.Endpoint.Builder builderForValue) { - if (localEndpointBuilder_ == null) { - localEndpoint_ = builderForValue.build(); - onChanged(); - } else { - localEndpointBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public Builder mergeLocalEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (localEndpointBuilder_ == null) { - if (localEndpoint_ != null) { - localEndpoint_ = - io.grpc.alts.internal.Handshaker.Endpoint.newBuilder(localEndpoint_).mergeFrom(value).buildPartial(); - } else { - localEndpoint_ = value; - } - onChanged(); - } else { - localEndpointBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public Builder clearLocalEndpoint() { - if (localEndpointBuilder_ == null) { - localEndpoint_ = null; - onChanged(); - } else { - localEndpoint_ = null; - localEndpointBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public io.grpc.alts.internal.Handshaker.Endpoint.Builder getLocalEndpointBuilder() { - - onChanged(); - return getLocalEndpointFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder() { - if (localEndpointBuilder_ != null) { - return localEndpointBuilder_.getMessageOrBuilder(); - } else { - return localEndpoint_ == null ? - io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } - } - /** - *
-       * (Optional) Local endpoint information of the connection to the server,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 6; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> - getLocalEndpointFieldBuilder() { - if (localEndpointBuilder_ == null) { - localEndpointBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder>( - getLocalEndpoint(), - getParentForChildren(), - isClean()); - localEndpoint_ = null; - } - return localEndpointBuilder_; - } - - private io.grpc.alts.internal.Handshaker.Endpoint remoteEndpoint_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> remoteEndpointBuilder_; - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public boolean hasRemoteEndpoint() { - return remoteEndpointBuilder_ != null || remoteEndpoint_ != null; - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint() { - if (remoteEndpointBuilder_ == null) { - return remoteEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } else { - return remoteEndpointBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public Builder setRemoteEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (remoteEndpointBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - remoteEndpoint_ = value; - onChanged(); - } else { - remoteEndpointBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public Builder setRemoteEndpoint( - io.grpc.alts.internal.Handshaker.Endpoint.Builder builderForValue) { - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = builderForValue.build(); - onChanged(); - } else { - remoteEndpointBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public Builder mergeRemoteEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (remoteEndpointBuilder_ == null) { - if (remoteEndpoint_ != null) { - remoteEndpoint_ = - io.grpc.alts.internal.Handshaker.Endpoint.newBuilder(remoteEndpoint_).mergeFrom(value).buildPartial(); - } else { - remoteEndpoint_ = value; - } - onChanged(); - } else { - remoteEndpointBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public Builder clearRemoteEndpoint() { - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = null; - onChanged(); - } else { - remoteEndpoint_ = null; - remoteEndpointBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public io.grpc.alts.internal.Handshaker.Endpoint.Builder getRemoteEndpointBuilder() { - - onChanged(); - return getRemoteEndpointFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder() { - if (remoteEndpointBuilder_ != null) { - return remoteEndpointBuilder_.getMessageOrBuilder(); - } else { - return remoteEndpoint_ == null ? - io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } - } - /** - *
-       * (Optional) Endpoint information of the remote server, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 7; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> - getRemoteEndpointFieldBuilder() { - if (remoteEndpointBuilder_ == null) { - remoteEndpointBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder>( - getRemoteEndpoint(), - getParentForChildren(), - isClean()); - remoteEndpoint_ = null; - } - return remoteEndpointBuilder_; - } - - private java.lang.Object targetName_ = ""; - /** - *
-       * (Optional) If target name is provided, a secure naming check is performed
-       * to verify that the peer authenticated identity is indeed authorized to run
-       * the target name.
-       * 
- * - * string target_name = 8; - */ - public java.lang.String getTargetName() { - java.lang.Object ref = targetName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - targetName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * (Optional) If target name is provided, a secure naming check is performed
-       * to verify that the peer authenticated identity is indeed authorized to run
-       * the target name.
-       * 
- * - * string target_name = 8; - */ - public com.google.protobuf.ByteString - getTargetNameBytes() { - java.lang.Object ref = targetName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - targetName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * (Optional) If target name is provided, a secure naming check is performed
-       * to verify that the peer authenticated identity is indeed authorized to run
-       * the target name.
-       * 
- * - * string target_name = 8; - */ - public Builder setTargetName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - targetName_ = value; - onChanged(); - return this; - } - /** - *
-       * (Optional) If target name is provided, a secure naming check is performed
-       * to verify that the peer authenticated identity is indeed authorized to run
-       * the target name.
-       * 
- * - * string target_name = 8; - */ - public Builder clearTargetName() { - - targetName_ = getDefaultInstance().getTargetName(); - onChanged(); - return this; - } - /** - *
-       * (Optional) If target name is provided, a secure naming check is performed
-       * to verify that the peer authenticated identity is indeed authorized to run
-       * the target name.
-       * 
- * - * string target_name = 8; - */ - public Builder setTargetNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - targetName_ = value; - onChanged(); - return this; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions rpcVersions_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> rpcVersionsBuilder_; - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public boolean hasRpcVersions() { - return rpcVersionsBuilder_ != null || rpcVersions_ != null; - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions() { - if (rpcVersionsBuilder_ == null) { - return rpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } else { - return rpcVersionsBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public Builder setRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (rpcVersionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - rpcVersions_ = value; - onChanged(); - } else { - rpcVersionsBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public Builder setRpcVersions( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder builderForValue) { - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = builderForValue.build(); - onChanged(); - } else { - rpcVersionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public Builder mergeRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (rpcVersionsBuilder_ == null) { - if (rpcVersions_ != null) { - rpcVersions_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.newBuilder(rpcVersions_).mergeFrom(value).buildPartial(); - } else { - rpcVersions_ = value; - } - onChanged(); - } else { - rpcVersionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public Builder clearRpcVersions() { - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = null; - onChanged(); - } else { - rpcVersions_ = null; - rpcVersionsBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder getRpcVersionsBuilder() { - - onChanged(); - return getRpcVersionsFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder() { - if (rpcVersionsBuilder_ != null) { - return rpcVersionsBuilder_.getMessageOrBuilder(); - } else { - return rpcVersions_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } - } - /** - *
-       * (Optional) RPC protocol versions supported by the client.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 9; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> - getRpcVersionsFieldBuilder() { - if (rpcVersionsBuilder_ == null) { - rpcVersionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder>( - getRpcVersions(), - getParentForChildren(), - isClean()); - rpcVersions_ = null; - } - return rpcVersionsBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.StartClientHandshakeReq) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.StartClientHandshakeReq) - private static final io.grpc.alts.internal.Handshaker.StartClientHandshakeReq DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.StartClientHandshakeReq(); - } - - public static io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public StartClientHandshakeReq parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StartClientHandshakeReq(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface ServerHandshakeParametersOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.ServerHandshakeParameters) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - java.util.List - getRecordProtocolsList(); - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - int getRecordProtocolsCount(); - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - java.lang.String getRecordProtocols(int index); - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - com.google.protobuf.ByteString - getRecordProtocolsBytes(int index); - - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - java.util.List - getLocalIdentitiesList(); - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - io.grpc.alts.internal.Handshaker.Identity getLocalIdentities(int index); - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - int getLocalIdentitiesCount(); - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - java.util.List - getLocalIdentitiesOrBuilderList(); - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentitiesOrBuilder( - int index); - } - /** - * Protobuf type {@code grpc.gcp.ServerHandshakeParameters} - */ - public static final class ServerHandshakeParameters extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.ServerHandshakeParameters) - ServerHandshakeParametersOrBuilder { - private static final long serialVersionUID = 0L; - // Use ServerHandshakeParameters.newBuilder() to construct. - private ServerHandshakeParameters(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private ServerHandshakeParameters() { - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - localIdentities_ = java.util.Collections.emptyList(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private ServerHandshakeParameters( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - recordProtocols_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; - } - recordProtocols_.add(s); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - localIdentities_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000002; - } - localIdentities_.add( - input.readMessage(io.grpc.alts.internal.Handshaker.Identity.parser(), extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - recordProtocols_ = recordProtocols_.getUnmodifiableView(); - } - if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - localIdentities_ = java.util.Collections.unmodifiableList(localIdentities_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_ServerHandshakeParameters_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_ServerHandshakeParameters_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.class, io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.Builder.class); - } - - public static final int RECORD_PROTOCOLS_FIELD_NUMBER = 1; - private com.google.protobuf.LazyStringList recordProtocols_; - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - public com.google.protobuf.ProtocolStringList - getRecordProtocolsList() { - return recordProtocols_; - } - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - public int getRecordProtocolsCount() { - return recordProtocols_.size(); - } - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - public java.lang.String getRecordProtocols(int index) { - return recordProtocols_.get(index); - } - /** - *
-     * The record protocols supported by the server, e.g.,
-     * "ALTSRP_GCM_AES128".
-     * 
- * - * repeated string record_protocols = 1; - */ - public com.google.protobuf.ByteString - getRecordProtocolsBytes(int index) { - return recordProtocols_.getByteString(index); - } - - public static final int LOCAL_IDENTITIES_FIELD_NUMBER = 2; - private java.util.List localIdentities_; - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public java.util.List getLocalIdentitiesList() { - return localIdentities_; - } - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public java.util.List - getLocalIdentitiesOrBuilderList() { - return localIdentities_; - } - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public int getLocalIdentitiesCount() { - return localIdentities_.size(); - } - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentities(int index) { - return localIdentities_.get(index); - } - /** - *
-     * (Optional) A list of local identities supported by the server, if
-     * specified. Otherwise, the handshaker chooses a default local identity.
-     * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentitiesOrBuilder( - int index) { - return localIdentities_.get(index); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < recordProtocols_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, recordProtocols_.getRaw(i)); - } - for (int i = 0; i < localIdentities_.size(); i++) { - output.writeMessage(2, localIdentities_.get(i)); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - { - int dataSize = 0; - for (int i = 0; i < recordProtocols_.size(); i++) { - dataSize += computeStringSizeNoTag(recordProtocols_.getRaw(i)); - } - size += dataSize; - size += 1 * getRecordProtocolsList().size(); - } - for (int i = 0; i < localIdentities_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, localIdentities_.get(i)); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.ServerHandshakeParameters)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters other = (io.grpc.alts.internal.Handshaker.ServerHandshakeParameters) obj; - - boolean result = true; - result = result && getRecordProtocolsList() - .equals(other.getRecordProtocolsList()); - result = result && getLocalIdentitiesList() - .equals(other.getLocalIdentitiesList()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (getRecordProtocolsCount() > 0) { - hash = (37 * hash) + RECORD_PROTOCOLS_FIELD_NUMBER; - hash = (53 * hash) + getRecordProtocolsList().hashCode(); - } - if (getLocalIdentitiesCount() > 0) { - hash = (37 * hash) + LOCAL_IDENTITIES_FIELD_NUMBER; - hash = (53 * hash) + getLocalIdentitiesList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.ServerHandshakeParameters prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.ServerHandshakeParameters} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.ServerHandshakeParameters) - io.grpc.alts.internal.Handshaker.ServerHandshakeParametersOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_ServerHandshakeParameters_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_ServerHandshakeParameters_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.class, io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - getLocalIdentitiesFieldBuilder(); - } - } - public Builder clear() { - super.clear(); - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - if (localIdentitiesBuilder_ == null) { - localIdentities_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); - } else { - localIdentitiesBuilder_.clear(); - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_ServerHandshakeParameters_descriptor; - } - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters build() { - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters buildPartial() { - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters result = new io.grpc.alts.internal.Handshaker.ServerHandshakeParameters(this); - int from_bitField0_ = bitField0_; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - recordProtocols_ = recordProtocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.recordProtocols_ = recordProtocols_; - if (localIdentitiesBuilder_ == null) { - if (((bitField0_ & 0x00000002) == 0x00000002)) { - localIdentities_ = java.util.Collections.unmodifiableList(localIdentities_); - bitField0_ = (bitField0_ & ~0x00000002); - } - result.localIdentities_ = localIdentities_; - } else { - result.localIdentities_ = localIdentitiesBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.ServerHandshakeParameters) { - return mergeFrom((io.grpc.alts.internal.Handshaker.ServerHandshakeParameters)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.ServerHandshakeParameters other) { - if (other == io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.getDefaultInstance()) return this; - if (!other.recordProtocols_.isEmpty()) { - if (recordProtocols_.isEmpty()) { - recordProtocols_ = other.recordProtocols_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureRecordProtocolsIsMutable(); - recordProtocols_.addAll(other.recordProtocols_); - } - onChanged(); - } - if (localIdentitiesBuilder_ == null) { - if (!other.localIdentities_.isEmpty()) { - if (localIdentities_.isEmpty()) { - localIdentities_ = other.localIdentities_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureLocalIdentitiesIsMutable(); - localIdentities_.addAll(other.localIdentities_); - } - onChanged(); - } - } else { - if (!other.localIdentities_.isEmpty()) { - if (localIdentitiesBuilder_.isEmpty()) { - localIdentitiesBuilder_.dispose(); - localIdentitiesBuilder_ = null; - localIdentities_ = other.localIdentities_; - bitField0_ = (bitField0_ & ~0x00000002); - localIdentitiesBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? - getLocalIdentitiesFieldBuilder() : null; - } else { - localIdentitiesBuilder_.addAllMessages(other.localIdentities_); - } - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.ServerHandshakeParameters) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.LazyStringList recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureRecordProtocolsIsMutable() { - if (!((bitField0_ & 0x00000001) == 0x00000001)) { - recordProtocols_ = new com.google.protobuf.LazyStringArrayList(recordProtocols_); - bitField0_ |= 0x00000001; - } - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public com.google.protobuf.ProtocolStringList - getRecordProtocolsList() { - return recordProtocols_.getUnmodifiableView(); - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public int getRecordProtocolsCount() { - return recordProtocols_.size(); - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public java.lang.String getRecordProtocols(int index) { - return recordProtocols_.get(index); - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public com.google.protobuf.ByteString - getRecordProtocolsBytes(int index) { - return recordProtocols_.getByteString(index); - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public Builder setRecordProtocols( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureRecordProtocolsIsMutable(); - recordProtocols_.set(index, value); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public Builder addRecordProtocols( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureRecordProtocolsIsMutable(); - recordProtocols_.add(value); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public Builder addAllRecordProtocols( - java.lang.Iterable values) { - ensureRecordProtocolsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, recordProtocols_); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public Builder clearRecordProtocols() { - recordProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - *
-       * The record protocols supported by the server, e.g.,
-       * "ALTSRP_GCM_AES128".
-       * 
- * - * repeated string record_protocols = 1; - */ - public Builder addRecordProtocolsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureRecordProtocolsIsMutable(); - recordProtocols_.add(value); - onChanged(); - return this; - } - - private java.util.List localIdentities_ = - java.util.Collections.emptyList(); - private void ensureLocalIdentitiesIsMutable() { - if (!((bitField0_ & 0x00000002) == 0x00000002)) { - localIdentities_ = new java.util.ArrayList(localIdentities_); - bitField0_ |= 0x00000002; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> localIdentitiesBuilder_; - - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public java.util.List getLocalIdentitiesList() { - if (localIdentitiesBuilder_ == null) { - return java.util.Collections.unmodifiableList(localIdentities_); - } else { - return localIdentitiesBuilder_.getMessageList(); - } - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public int getLocalIdentitiesCount() { - if (localIdentitiesBuilder_ == null) { - return localIdentities_.size(); - } else { - return localIdentitiesBuilder_.getCount(); - } - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentities(int index) { - if (localIdentitiesBuilder_ == null) { - return localIdentities_.get(index); - } else { - return localIdentitiesBuilder_.getMessage(index); - } - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder setLocalIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureLocalIdentitiesIsMutable(); - localIdentities_.set(index, value); - onChanged(); - } else { - localIdentitiesBuilder_.setMessage(index, value); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder setLocalIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (localIdentitiesBuilder_ == null) { - ensureLocalIdentitiesIsMutable(); - localIdentities_.set(index, builderForValue.build()); - onChanged(); - } else { - localIdentitiesBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder addLocalIdentities(io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureLocalIdentitiesIsMutable(); - localIdentities_.add(value); - onChanged(); - } else { - localIdentitiesBuilder_.addMessage(value); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder addLocalIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentitiesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureLocalIdentitiesIsMutable(); - localIdentities_.add(index, value); - onChanged(); - } else { - localIdentitiesBuilder_.addMessage(index, value); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder addLocalIdentities( - io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (localIdentitiesBuilder_ == null) { - ensureLocalIdentitiesIsMutable(); - localIdentities_.add(builderForValue.build()); - onChanged(); - } else { - localIdentitiesBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder addLocalIdentities( - int index, io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (localIdentitiesBuilder_ == null) { - ensureLocalIdentitiesIsMutable(); - localIdentities_.add(index, builderForValue.build()); - onChanged(); - } else { - localIdentitiesBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder addAllLocalIdentities( - java.lang.Iterable values) { - if (localIdentitiesBuilder_ == null) { - ensureLocalIdentitiesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, localIdentities_); - onChanged(); - } else { - localIdentitiesBuilder_.addAllMessages(values); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder clearLocalIdentities() { - if (localIdentitiesBuilder_ == null) { - localIdentities_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - } else { - localIdentitiesBuilder_.clear(); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public Builder removeLocalIdentities(int index) { - if (localIdentitiesBuilder_ == null) { - ensureLocalIdentitiesIsMutable(); - localIdentities_.remove(index); - onChanged(); - } else { - localIdentitiesBuilder_.remove(index); - } - return this; - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder getLocalIdentitiesBuilder( - int index) { - return getLocalIdentitiesFieldBuilder().getBuilder(index); - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentitiesOrBuilder( - int index) { - if (localIdentitiesBuilder_ == null) { - return localIdentities_.get(index); } else { - return localIdentitiesBuilder_.getMessageOrBuilder(index); - } - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public java.util.List - getLocalIdentitiesOrBuilderList() { - if (localIdentitiesBuilder_ != null) { - return localIdentitiesBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(localIdentities_); - } - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder addLocalIdentitiesBuilder() { - return getLocalIdentitiesFieldBuilder().addBuilder( - io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance()); - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder addLocalIdentitiesBuilder( - int index) { - return getLocalIdentitiesFieldBuilder().addBuilder( - index, io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance()); - } - /** - *
-       * (Optional) A list of local identities supported by the server, if
-       * specified. Otherwise, the handshaker chooses a default local identity.
-       * 
- * - * repeated .grpc.gcp.Identity local_identities = 2; - */ - public java.util.List - getLocalIdentitiesBuilderList() { - return getLocalIdentitiesFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> - getLocalIdentitiesFieldBuilder() { - if (localIdentitiesBuilder_ == null) { - localIdentitiesBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder>( - localIdentities_, - ((bitField0_ & 0x00000002) == 0x00000002), - getParentForChildren(), - isClean()); - localIdentities_ = null; - } - return localIdentitiesBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.ServerHandshakeParameters) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.ServerHandshakeParameters) - private static final io.grpc.alts.internal.Handshaker.ServerHandshakeParameters DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.ServerHandshakeParameters(); - } - - public static io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public ServerHandshakeParameters parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new ServerHandshakeParameters(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StartServerHandshakeReqOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.StartServerHandshakeReq) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - java.util.List - getApplicationProtocolsList(); - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - int getApplicationProtocolsCount(); - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - java.lang.String getApplicationProtocols(int index); - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index); - - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - int getHandshakeParametersCount(); - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - boolean containsHandshakeParameters( - int key); - /** - * Use {@link #getHandshakeParametersMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getHandshakeParameters(); - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - java.util.Map - getHandshakeParametersMap(); - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrDefault( - int key, - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters defaultValue); - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrThrow( - int key); - - /** - *
-     * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-     * that the peer's out_frames are split into multiple HandshakReq messages.
-     * 
- * - * bytes in_bytes = 3; - */ - com.google.protobuf.ByteString getInBytes(); - - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - boolean hasLocalEndpoint(); - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint(); - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder(); - - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - boolean hasRemoteEndpoint(); - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint(); - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder(); - - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - boolean hasRpcVersions(); - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions(); - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder(); - } - /** - * Protobuf type {@code grpc.gcp.StartServerHandshakeReq} - */ - public static final class StartServerHandshakeReq extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.StartServerHandshakeReq) - StartServerHandshakeReqOrBuilder { - private static final long serialVersionUID = 0L; - // Use StartServerHandshakeReq.newBuilder() to construct. - private StartServerHandshakeReq(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StartServerHandshakeReq() { - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - inBytes_ = com.google.protobuf.ByteString.EMPTY; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StartServerHandshakeReq( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - applicationProtocols_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; - } - applicationProtocols_.add(s); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - handshakeParameters_ = com.google.protobuf.MapField.newMapField( - HandshakeParametersDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000002; - } - com.google.protobuf.MapEntry - handshakeParameters__ = input.readMessage( - HandshakeParametersDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - handshakeParameters_.getMutableMap().put( - handshakeParameters__.getKey(), handshakeParameters__.getValue()); - break; - } - case 26: { - - inBytes_ = input.readBytes(); - break; - } - case 34: { - io.grpc.alts.internal.Handshaker.Endpoint.Builder subBuilder = null; - if (localEndpoint_ != null) { - subBuilder = localEndpoint_.toBuilder(); - } - localEndpoint_ = input.readMessage(io.grpc.alts.internal.Handshaker.Endpoint.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(localEndpoint_); - localEndpoint_ = subBuilder.buildPartial(); - } - - break; - } - case 42: { - io.grpc.alts.internal.Handshaker.Endpoint.Builder subBuilder = null; - if (remoteEndpoint_ != null) { - subBuilder = remoteEndpoint_.toBuilder(); - } - remoteEndpoint_ = input.readMessage(io.grpc.alts.internal.Handshaker.Endpoint.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(remoteEndpoint_); - remoteEndpoint_ = subBuilder.buildPartial(); - } - - break; - } - case 50: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder subBuilder = null; - if (rpcVersions_ != null) { - subBuilder = rpcVersions_.toBuilder(); - } - rpcVersions_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(rpcVersions_); - rpcVersions_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - applicationProtocols_ = applicationProtocols_.getUnmodifiableView(); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 2: - return internalGetHandshakeParameters(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.class, io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder.class); - } - - private int bitField0_; - public static final int APPLICATION_PROTOCOLS_FIELD_NUMBER = 1; - private com.google.protobuf.LazyStringList applicationProtocols_; - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - public com.google.protobuf.ProtocolStringList - getApplicationProtocolsList() { - return applicationProtocols_; - } - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - public int getApplicationProtocolsCount() { - return applicationProtocols_.size(); - } - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - public java.lang.String getApplicationProtocols(int index) { - return applicationProtocols_.get(index); - } - /** - *
-     * The application protocols supported by the server, e.g., "h2" (for http2),
-     * "grpc".
-     * 
- * - * repeated string application_protocols = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index) { - return applicationProtocols_.getByteString(index); - } - - public static final int HANDSHAKE_PARAMETERS_FIELD_NUMBER = 2; - private static final class HandshakeParametersDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.Integer, io.grpc.alts.internal.Handshaker.ServerHandshakeParameters> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.INT32, - 0, - com.google.protobuf.WireFormat.FieldType.MESSAGE, - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters.getDefaultInstance()); - } - private com.google.protobuf.MapField< - java.lang.Integer, io.grpc.alts.internal.Handshaker.ServerHandshakeParameters> handshakeParameters_; - private com.google.protobuf.MapField - internalGetHandshakeParameters() { - if (handshakeParameters_ == null) { - return com.google.protobuf.MapField.emptyMapField( - HandshakeParametersDefaultEntryHolder.defaultEntry); - } - return handshakeParameters_; - } - - public int getHandshakeParametersCount() { - return internalGetHandshakeParameters().getMap().size(); - } - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public boolean containsHandshakeParameters( - int key) { - - return internalGetHandshakeParameters().getMap().containsKey(key); - } - /** - * Use {@link #getHandshakeParametersMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getHandshakeParameters() { - return getHandshakeParametersMap(); - } - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public java.util.Map getHandshakeParametersMap() { - return internalGetHandshakeParameters().getMap(); - } - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrDefault( - int key, - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters defaultValue) { - - java.util.Map map = - internalGetHandshakeParameters().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - *
-     * Handshake parameters (record protocols and local identities supported by
-     * the server) mapped by the handshake protocol. Each handshake security
-     * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-     * identities. Since protobuf does not support enum as key to the map, the key
-     * to handshake_parameters is the integer value of HandshakeProtocol enum.
-     * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrThrow( - int key) { - - java.util.Map map = - internalGetHandshakeParameters().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public static final int IN_BYTES_FIELD_NUMBER = 3; - private com.google.protobuf.ByteString inBytes_; - /** - *
-     * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-     * that the peer's out_frames are split into multiple HandshakReq messages.
-     * 
- * - * bytes in_bytes = 3; - */ - public com.google.protobuf.ByteString getInBytes() { - return inBytes_; - } - - public static final int LOCAL_ENDPOINT_FIELD_NUMBER = 4; - private io.grpc.alts.internal.Handshaker.Endpoint localEndpoint_; - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public boolean hasLocalEndpoint() { - return localEndpoint_ != null; - } - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint() { - return localEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } - /** - *
-     * (Optional) Local endpoint information of the connection to the client,
-     * such as local IP address, port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder() { - return getLocalEndpoint(); - } - - public static final int REMOTE_ENDPOINT_FIELD_NUMBER = 5; - private io.grpc.alts.internal.Handshaker.Endpoint remoteEndpoint_; - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public boolean hasRemoteEndpoint() { - return remoteEndpoint_ != null; - } - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint() { - return remoteEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } - /** - *
-     * (Optional) Endpoint information of the remote client, such as IP address,
-     * port number, and network protocol.
-     * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder() { - return getRemoteEndpoint(); - } - - public static final int RPC_VERSIONS_FIELD_NUMBER = 6; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions rpcVersions_; - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public boolean hasRpcVersions() { - return rpcVersions_ != null; - } - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions() { - return rpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } - /** - *
-     * (Optional) RPC protocol versions supported by the server.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder() { - return getRpcVersions(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < applicationProtocols_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, applicationProtocols_.getRaw(i)); - } - com.google.protobuf.GeneratedMessageV3 - .serializeIntegerMapTo( - output, - internalGetHandshakeParameters(), - HandshakeParametersDefaultEntryHolder.defaultEntry, - 2); - if (!inBytes_.isEmpty()) { - output.writeBytes(3, inBytes_); - } - if (localEndpoint_ != null) { - output.writeMessage(4, getLocalEndpoint()); - } - if (remoteEndpoint_ != null) { - output.writeMessage(5, getRemoteEndpoint()); - } - if (rpcVersions_ != null) { - output.writeMessage(6, getRpcVersions()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - { - int dataSize = 0; - for (int i = 0; i < applicationProtocols_.size(); i++) { - dataSize += computeStringSizeNoTag(applicationProtocols_.getRaw(i)); - } - size += dataSize; - size += 1 * getApplicationProtocolsList().size(); - } - for (java.util.Map.Entry entry - : internalGetHandshakeParameters().getMap().entrySet()) { - com.google.protobuf.MapEntry - handshakeParameters__ = HandshakeParametersDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, handshakeParameters__); - } - if (!inBytes_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, inBytes_); - } - if (localEndpoint_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, getLocalEndpoint()); - } - if (remoteEndpoint_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getRemoteEndpoint()); - } - if (rpcVersions_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(6, getRpcVersions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.StartServerHandshakeReq)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq other = (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) obj; - - boolean result = true; - result = result && getApplicationProtocolsList() - .equals(other.getApplicationProtocolsList()); - result = result && internalGetHandshakeParameters().equals( - other.internalGetHandshakeParameters()); - result = result && getInBytes() - .equals(other.getInBytes()); - result = result && (hasLocalEndpoint() == other.hasLocalEndpoint()); - if (hasLocalEndpoint()) { - result = result && getLocalEndpoint() - .equals(other.getLocalEndpoint()); - } - result = result && (hasRemoteEndpoint() == other.hasRemoteEndpoint()); - if (hasRemoteEndpoint()) { - result = result && getRemoteEndpoint() - .equals(other.getRemoteEndpoint()); - } - result = result && (hasRpcVersions() == other.hasRpcVersions()); - if (hasRpcVersions()) { - result = result && getRpcVersions() - .equals(other.getRpcVersions()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (getApplicationProtocolsCount() > 0) { - hash = (37 * hash) + APPLICATION_PROTOCOLS_FIELD_NUMBER; - hash = (53 * hash) + getApplicationProtocolsList().hashCode(); - } - if (!internalGetHandshakeParameters().getMap().isEmpty()) { - hash = (37 * hash) + HANDSHAKE_PARAMETERS_FIELD_NUMBER; - hash = (53 * hash) + internalGetHandshakeParameters().hashCode(); - } - hash = (37 * hash) + IN_BYTES_FIELD_NUMBER; - hash = (53 * hash) + getInBytes().hashCode(); - if (hasLocalEndpoint()) { - hash = (37 * hash) + LOCAL_ENDPOINT_FIELD_NUMBER; - hash = (53 * hash) + getLocalEndpoint().hashCode(); - } - if (hasRemoteEndpoint()) { - hash = (37 * hash) + REMOTE_ENDPOINT_FIELD_NUMBER; - hash = (53 * hash) + getRemoteEndpoint().hashCode(); - } - if (hasRpcVersions()) { - hash = (37 * hash) + RPC_VERSIONS_FIELD_NUMBER; - hash = (53 * hash) + getRpcVersions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.StartServerHandshakeReq prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.StartServerHandshakeReq} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.StartServerHandshakeReq) - io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 2: - return internalGetHandshakeParameters(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 2: - return internalGetMutableHandshakeParameters(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.class, io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - internalGetMutableHandshakeParameters().clear(); - inBytes_ = com.google.protobuf.ByteString.EMPTY; - - if (localEndpointBuilder_ == null) { - localEndpoint_ = null; - } else { - localEndpoint_ = null; - localEndpointBuilder_ = null; - } - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = null; - } else { - remoteEndpoint_ = null; - remoteEndpointBuilder_ = null; - } - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = null; - } else { - rpcVersions_ = null; - rpcVersionsBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_StartServerHandshakeReq_descriptor; - } - - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq build() { - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq buildPartial() { - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq result = new io.grpc.alts.internal.Handshaker.StartServerHandshakeReq(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - applicationProtocols_ = applicationProtocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.applicationProtocols_ = applicationProtocols_; - result.handshakeParameters_ = internalGetHandshakeParameters(); - result.handshakeParameters_.makeImmutable(); - result.inBytes_ = inBytes_; - if (localEndpointBuilder_ == null) { - result.localEndpoint_ = localEndpoint_; - } else { - result.localEndpoint_ = localEndpointBuilder_.build(); - } - if (remoteEndpointBuilder_ == null) { - result.remoteEndpoint_ = remoteEndpoint_; - } else { - result.remoteEndpoint_ = remoteEndpointBuilder_.build(); - } - if (rpcVersionsBuilder_ == null) { - result.rpcVersions_ = rpcVersions_; - } else { - result.rpcVersions_ = rpcVersionsBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) { - return mergeFrom((io.grpc.alts.internal.Handshaker.StartServerHandshakeReq)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.StartServerHandshakeReq other) { - if (other == io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance()) return this; - if (!other.applicationProtocols_.isEmpty()) { - if (applicationProtocols_.isEmpty()) { - applicationProtocols_ = other.applicationProtocols_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.addAll(other.applicationProtocols_); - } - onChanged(); - } - internalGetMutableHandshakeParameters().mergeFrom( - other.internalGetHandshakeParameters()); - if (other.getInBytes() != com.google.protobuf.ByteString.EMPTY) { - setInBytes(other.getInBytes()); - } - if (other.hasLocalEndpoint()) { - mergeLocalEndpoint(other.getLocalEndpoint()); - } - if (other.hasRemoteEndpoint()) { - mergeRemoteEndpoint(other.getRemoteEndpoint()); - } - if (other.hasRpcVersions()) { - mergeRpcVersions(other.getRpcVersions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.LazyStringList applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureApplicationProtocolsIsMutable() { - if (!((bitField0_ & 0x00000001) == 0x00000001)) { - applicationProtocols_ = new com.google.protobuf.LazyStringArrayList(applicationProtocols_); - bitField0_ |= 0x00000001; - } - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public com.google.protobuf.ProtocolStringList - getApplicationProtocolsList() { - return applicationProtocols_.getUnmodifiableView(); - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public int getApplicationProtocolsCount() { - return applicationProtocols_.size(); - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public java.lang.String getApplicationProtocols(int index) { - return applicationProtocols_.get(index); - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolsBytes(int index) { - return applicationProtocols_.getByteString(index); - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public Builder setApplicationProtocols( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.set(index, value); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public Builder addApplicationProtocols( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.add(value); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public Builder addAllApplicationProtocols( - java.lang.Iterable values) { - ensureApplicationProtocolsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, applicationProtocols_); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public Builder clearApplicationProtocols() { - applicationProtocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - *
-       * The application protocols supported by the server, e.g., "h2" (for http2),
-       * "grpc".
-       * 
- * - * repeated string application_protocols = 1; - */ - public Builder addApplicationProtocolsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureApplicationProtocolsIsMutable(); - applicationProtocols_.add(value); - onChanged(); - return this; - } - - private com.google.protobuf.MapField< - java.lang.Integer, io.grpc.alts.internal.Handshaker.ServerHandshakeParameters> handshakeParameters_; - private com.google.protobuf.MapField - internalGetHandshakeParameters() { - if (handshakeParameters_ == null) { - return com.google.protobuf.MapField.emptyMapField( - HandshakeParametersDefaultEntryHolder.defaultEntry); - } - return handshakeParameters_; - } - private com.google.protobuf.MapField - internalGetMutableHandshakeParameters() { - onChanged();; - if (handshakeParameters_ == null) { - handshakeParameters_ = com.google.protobuf.MapField.newMapField( - HandshakeParametersDefaultEntryHolder.defaultEntry); - } - if (!handshakeParameters_.isMutable()) { - handshakeParameters_ = handshakeParameters_.copy(); - } - return handshakeParameters_; - } - - public int getHandshakeParametersCount() { - return internalGetHandshakeParameters().getMap().size(); - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public boolean containsHandshakeParameters( - int key) { - - return internalGetHandshakeParameters().getMap().containsKey(key); - } - /** - * Use {@link #getHandshakeParametersMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getHandshakeParameters() { - return getHandshakeParametersMap(); - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public java.util.Map getHandshakeParametersMap() { - return internalGetHandshakeParameters().getMap(); - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrDefault( - int key, - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters defaultValue) { - - java.util.Map map = - internalGetHandshakeParameters().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public io.grpc.alts.internal.Handshaker.ServerHandshakeParameters getHandshakeParametersOrThrow( - int key) { - - java.util.Map map = - internalGetHandshakeParameters().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearHandshakeParameters() { - internalGetMutableHandshakeParameters().getMutableMap() - .clear(); - return this; - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public Builder removeHandshakeParameters( - int key) { - - internalGetMutableHandshakeParameters().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableHandshakeParameters() { - return internalGetMutableHandshakeParameters().getMutableMap(); - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - public Builder putHandshakeParameters( - int key, - io.grpc.alts.internal.Handshaker.ServerHandshakeParameters value) { - - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableHandshakeParameters().getMutableMap() - .put(key, value); - return this; - } - /** - *
-       * Handshake parameters (record protocols and local identities supported by
-       * the server) mapped by the handshake protocol. Each handshake security
-       * protocol (e.g., TLS or ALTS) has its own set of record protocols and local
-       * identities. Since protobuf does not support enum as key to the map, the key
-       * to handshake_parameters is the integer value of HandshakeProtocol enum.
-       * 
- * - * map<int32, .grpc.gcp.ServerHandshakeParameters> handshake_parameters = 2; - */ - - public Builder putAllHandshakeParameters( - java.util.Map values) { - internalGetMutableHandshakeParameters().getMutableMap() - .putAll(values); - return this; - } - - private com.google.protobuf.ByteString inBytes_ = com.google.protobuf.ByteString.EMPTY; - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple HandshakReq messages.
-       * 
- * - * bytes in_bytes = 3; - */ - public com.google.protobuf.ByteString getInBytes() { - return inBytes_; - } - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple HandshakReq messages.
-       * 
- * - * bytes in_bytes = 3; - */ - public Builder setInBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - - inBytes_ = value; - onChanged(); - return this; - } - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple HandshakReq messages.
-       * 
- * - * bytes in_bytes = 3; - */ - public Builder clearInBytes() { - - inBytes_ = getDefaultInstance().getInBytes(); - onChanged(); - return this; - } - - private io.grpc.alts.internal.Handshaker.Endpoint localEndpoint_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> localEndpointBuilder_; - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public boolean hasLocalEndpoint() { - return localEndpointBuilder_ != null || localEndpoint_ != null; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getLocalEndpoint() { - if (localEndpointBuilder_ == null) { - return localEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } else { - return localEndpointBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public Builder setLocalEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (localEndpointBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - localEndpoint_ = value; - onChanged(); - } else { - localEndpointBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public Builder setLocalEndpoint( - io.grpc.alts.internal.Handshaker.Endpoint.Builder builderForValue) { - if (localEndpointBuilder_ == null) { - localEndpoint_ = builderForValue.build(); - onChanged(); - } else { - localEndpointBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public Builder mergeLocalEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (localEndpointBuilder_ == null) { - if (localEndpoint_ != null) { - localEndpoint_ = - io.grpc.alts.internal.Handshaker.Endpoint.newBuilder(localEndpoint_).mergeFrom(value).buildPartial(); - } else { - localEndpoint_ = value; - } - onChanged(); - } else { - localEndpointBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public Builder clearLocalEndpoint() { - if (localEndpointBuilder_ == null) { - localEndpoint_ = null; - onChanged(); - } else { - localEndpoint_ = null; - localEndpointBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public io.grpc.alts.internal.Handshaker.Endpoint.Builder getLocalEndpointBuilder() { - - onChanged(); - return getLocalEndpointFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getLocalEndpointOrBuilder() { - if (localEndpointBuilder_ != null) { - return localEndpointBuilder_.getMessageOrBuilder(); - } else { - return localEndpoint_ == null ? - io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : localEndpoint_; - } - } - /** - *
-       * (Optional) Local endpoint information of the connection to the client,
-       * such as local IP address, port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint local_endpoint = 4; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> - getLocalEndpointFieldBuilder() { - if (localEndpointBuilder_ == null) { - localEndpointBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder>( - getLocalEndpoint(), - getParentForChildren(), - isClean()); - localEndpoint_ = null; - } - return localEndpointBuilder_; - } - - private io.grpc.alts.internal.Handshaker.Endpoint remoteEndpoint_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> remoteEndpointBuilder_; - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public boolean hasRemoteEndpoint() { - return remoteEndpointBuilder_ != null || remoteEndpoint_ != null; - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public io.grpc.alts.internal.Handshaker.Endpoint getRemoteEndpoint() { - if (remoteEndpointBuilder_ == null) { - return remoteEndpoint_ == null ? io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } else { - return remoteEndpointBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public Builder setRemoteEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (remoteEndpointBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - remoteEndpoint_ = value; - onChanged(); - } else { - remoteEndpointBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public Builder setRemoteEndpoint( - io.grpc.alts.internal.Handshaker.Endpoint.Builder builderForValue) { - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = builderForValue.build(); - onChanged(); - } else { - remoteEndpointBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public Builder mergeRemoteEndpoint(io.grpc.alts.internal.Handshaker.Endpoint value) { - if (remoteEndpointBuilder_ == null) { - if (remoteEndpoint_ != null) { - remoteEndpoint_ = - io.grpc.alts.internal.Handshaker.Endpoint.newBuilder(remoteEndpoint_).mergeFrom(value).buildPartial(); - } else { - remoteEndpoint_ = value; - } - onChanged(); - } else { - remoteEndpointBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public Builder clearRemoteEndpoint() { - if (remoteEndpointBuilder_ == null) { - remoteEndpoint_ = null; - onChanged(); - } else { - remoteEndpoint_ = null; - remoteEndpointBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public io.grpc.alts.internal.Handshaker.Endpoint.Builder getRemoteEndpointBuilder() { - - onChanged(); - return getRemoteEndpointFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - public io.grpc.alts.internal.Handshaker.EndpointOrBuilder getRemoteEndpointOrBuilder() { - if (remoteEndpointBuilder_ != null) { - return remoteEndpointBuilder_.getMessageOrBuilder(); - } else { - return remoteEndpoint_ == null ? - io.grpc.alts.internal.Handshaker.Endpoint.getDefaultInstance() : remoteEndpoint_; - } - } - /** - *
-       * (Optional) Endpoint information of the remote client, such as IP address,
-       * port number, and network protocol.
-       * 
- * - * .grpc.gcp.Endpoint remote_endpoint = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder> - getRemoteEndpointFieldBuilder() { - if (remoteEndpointBuilder_ == null) { - remoteEndpointBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Endpoint, io.grpc.alts.internal.Handshaker.Endpoint.Builder, io.grpc.alts.internal.Handshaker.EndpointOrBuilder>( - getRemoteEndpoint(), - getParentForChildren(), - isClean()); - remoteEndpoint_ = null; - } - return remoteEndpointBuilder_; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions rpcVersions_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> rpcVersionsBuilder_; - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public boolean hasRpcVersions() { - return rpcVersionsBuilder_ != null || rpcVersions_ != null; - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getRpcVersions() { - if (rpcVersionsBuilder_ == null) { - return rpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } else { - return rpcVersionsBuilder_.getMessage(); - } - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public Builder setRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (rpcVersionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - rpcVersions_ = value; - onChanged(); - } else { - rpcVersionsBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public Builder setRpcVersions( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder builderForValue) { - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = builderForValue.build(); - onChanged(); - } else { - rpcVersionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public Builder mergeRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (rpcVersionsBuilder_ == null) { - if (rpcVersions_ != null) { - rpcVersions_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.newBuilder(rpcVersions_).mergeFrom(value).buildPartial(); - } else { - rpcVersions_ = value; - } - onChanged(); - } else { - rpcVersionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public Builder clearRpcVersions() { - if (rpcVersionsBuilder_ == null) { - rpcVersions_ = null; - onChanged(); - } else { - rpcVersions_ = null; - rpcVersionsBuilder_ = null; - } - - return this; - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder getRpcVersionsBuilder() { - - onChanged(); - return getRpcVersionsFieldBuilder().getBuilder(); - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getRpcVersionsOrBuilder() { - if (rpcVersionsBuilder_ != null) { - return rpcVersionsBuilder_.getMessageOrBuilder(); - } else { - return rpcVersions_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : rpcVersions_; - } - } - /** - *
-       * (Optional) RPC protocol versions supported by the server.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions rpc_versions = 6; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> - getRpcVersionsFieldBuilder() { - if (rpcVersionsBuilder_ == null) { - rpcVersionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder>( - getRpcVersions(), - getParentForChildren(), - isClean()); - rpcVersions_ = null; - } - return rpcVersionsBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.StartServerHandshakeReq) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.StartServerHandshakeReq) - private static final io.grpc.alts.internal.Handshaker.StartServerHandshakeReq DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.StartServerHandshakeReq(); - } - - public static io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public StartServerHandshakeReq parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StartServerHandshakeReq(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface NextHandshakeMessageReqOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.NextHandshakeMessageReq) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-     * that the peer's out_frames are split into multiple NextHandshakerMessageReq
-     * messages.
-     * 
- * - * bytes in_bytes = 1; - */ - com.google.protobuf.ByteString getInBytes(); - } - /** - * Protobuf type {@code grpc.gcp.NextHandshakeMessageReq} - */ - public static final class NextHandshakeMessageReq extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.NextHandshakeMessageReq) - NextHandshakeMessageReqOrBuilder { - private static final long serialVersionUID = 0L; - // Use NextHandshakeMessageReq.newBuilder() to construct. - private NextHandshakeMessageReq(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private NextHandshakeMessageReq() { - inBytes_ = com.google.protobuf.ByteString.EMPTY; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private NextHandshakeMessageReq( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - - inBytes_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_NextHandshakeMessageReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.class, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder.class); - } - - public static final int IN_BYTES_FIELD_NUMBER = 1; - private com.google.protobuf.ByteString inBytes_; - /** - *
-     * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-     * that the peer's out_frames are split into multiple NextHandshakerMessageReq
-     * messages.
-     * 
- * - * bytes in_bytes = 1; - */ - public com.google.protobuf.ByteString getInBytes() { - return inBytes_; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!inBytes_.isEmpty()) { - output.writeBytes(1, inBytes_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!inBytes_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, inBytes_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq other = (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) obj; - - boolean result = true; - result = result && getInBytes() - .equals(other.getInBytes()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + IN_BYTES_FIELD_NUMBER; - hash = (53 * hash) + getInBytes().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.NextHandshakeMessageReq} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.NextHandshakeMessageReq) - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_NextHandshakeMessageReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.class, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - inBytes_ = com.google.protobuf.ByteString.EMPTY; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor; - } - - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq build() { - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq buildPartial() { - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq result = new io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq(this); - result.inBytes_ = inBytes_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) { - return mergeFrom((io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq other) { - if (other == io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance()) return this; - if (other.getInBytes() != com.google.protobuf.ByteString.EMPTY) { - setInBytes(other.getInBytes()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private com.google.protobuf.ByteString inBytes_ = com.google.protobuf.ByteString.EMPTY; - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple NextHandshakerMessageReq
-       * messages.
-       * 
- * - * bytes in_bytes = 1; - */ - public com.google.protobuf.ByteString getInBytes() { - return inBytes_; - } - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple NextHandshakerMessageReq
-       * messages.
-       * 
- * - * bytes in_bytes = 1; - */ - public Builder setInBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - - inBytes_ = value; - onChanged(); - return this; - } - /** - *
-       * Bytes in out_frames returned from the peer's HandshakerResp. It is possible
-       * that the peer's out_frames are split into multiple NextHandshakerMessageReq
-       * messages.
-       * 
- * - * bytes in_bytes = 1; - */ - public Builder clearInBytes() { - - inBytes_ = getDefaultInstance().getInBytes(); - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.NextHandshakeMessageReq) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.NextHandshakeMessageReq) - private static final io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq(); - } - - public static io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public NextHandshakeMessageReq parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new NextHandshakeMessageReq(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface HandshakerReqOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.HandshakerReq) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - boolean hasClientStart(); - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getClientStart(); - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder getClientStartOrBuilder(); - - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - boolean hasServerStart(); - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getServerStart(); - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder getServerStartOrBuilder(); - - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - boolean hasNext(); - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getNext(); - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder getNextOrBuilder(); - - public io.grpc.alts.internal.Handshaker.HandshakerReq.ReqOneofCase getReqOneofCase(); - } - /** - * Protobuf type {@code grpc.gcp.HandshakerReq} - */ - public static final class HandshakerReq extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.HandshakerReq) - HandshakerReqOrBuilder { - private static final long serialVersionUID = 0L; - // Use HandshakerReq.newBuilder() to construct. - private HandshakerReq(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private HandshakerReq() { - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private HandshakerReq( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder subBuilder = null; - if (reqOneofCase_ == 1) { - subBuilder = ((io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_).toBuilder(); - } - reqOneof_ = - input.readMessage(io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom((io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_); - reqOneof_ = subBuilder.buildPartial(); - } - reqOneofCase_ = 1; - break; - } - case 18: { - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder subBuilder = null; - if (reqOneofCase_ == 2) { - subBuilder = ((io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_).toBuilder(); - } - reqOneof_ = - input.readMessage(io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom((io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_); - reqOneof_ = subBuilder.buildPartial(); - } - reqOneofCase_ = 2; - break; - } - case 26: { - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder subBuilder = null; - if (reqOneofCase_ == 3) { - subBuilder = ((io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_).toBuilder(); - } - reqOneof_ = - input.readMessage(io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom((io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_); - reqOneof_ = subBuilder.buildPartial(); - } - reqOneofCase_ = 3; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerReq.class, io.grpc.alts.internal.Handshaker.HandshakerReq.Builder.class); - } - - private int reqOneofCase_ = 0; - private java.lang.Object reqOneof_; - public enum ReqOneofCase - implements com.google.protobuf.Internal.EnumLite { - CLIENT_START(1), - SERVER_START(2), - NEXT(3), - REQONEOF_NOT_SET(0); - private final int value; - private ReqOneofCase(int value) { - this.value = value; - } - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static ReqOneofCase valueOf(int value) { - return forNumber(value); - } - - public static ReqOneofCase forNumber(int value) { - switch (value) { - case 1: return CLIENT_START; - case 2: return SERVER_START; - case 3: return NEXT; - case 0: return REQONEOF_NOT_SET; - default: return null; - } - } - public int getNumber() { - return this.value; - } - }; - - public ReqOneofCase - getReqOneofCase() { - return ReqOneofCase.forNumber( - reqOneofCase_); - } - - public static final int CLIENT_START_FIELD_NUMBER = 1; - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public boolean hasClientStart() { - return reqOneofCase_ == 1; - } - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getClientStart() { - if (reqOneofCase_ == 1) { - return (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - /** - *
-     * The start client handshake request message.
-     * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder getClientStartOrBuilder() { - if (reqOneofCase_ == 1) { - return (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - - public static final int SERVER_START_FIELD_NUMBER = 2; - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public boolean hasServerStart() { - return reqOneofCase_ == 2; - } - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getServerStart() { - if (reqOneofCase_ == 2) { - return (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - /** - *
-     * The start server handshake request message.
-     * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder getServerStartOrBuilder() { - if (reqOneofCase_ == 2) { - return (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - - public static final int NEXT_FIELD_NUMBER = 3; - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public boolean hasNext() { - return reqOneofCase_ == 3; - } - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getNext() { - if (reqOneofCase_ == 3) { - return (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - /** - *
-     * The next handshake request message.
-     * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder getNextOrBuilder() { - if (reqOneofCase_ == 3) { - return (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (reqOneofCase_ == 1) { - output.writeMessage(1, (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_); - } - if (reqOneofCase_ == 2) { - output.writeMessage(2, (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_); - } - if (reqOneofCase_ == 3) { - output.writeMessage(3, (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (reqOneofCase_ == 1) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_); - } - if (reqOneofCase_ == 2) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_); - } - if (reqOneofCase_ == 3) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.HandshakerReq)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.HandshakerReq other = (io.grpc.alts.internal.Handshaker.HandshakerReq) obj; - - boolean result = true; - result = result && getReqOneofCase().equals( - other.getReqOneofCase()); - if (!result) return false; - switch (reqOneofCase_) { - case 1: - result = result && getClientStart() - .equals(other.getClientStart()); - break; - case 2: - result = result && getServerStart() - .equals(other.getServerStart()); - break; - case 3: - result = result && getNext() - .equals(other.getNext()); - break; - case 0: - default: - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - switch (reqOneofCase_) { - case 1: - hash = (37 * hash) + CLIENT_START_FIELD_NUMBER; - hash = (53 * hash) + getClientStart().hashCode(); - break; - case 2: - hash = (37 * hash) + SERVER_START_FIELD_NUMBER; - hash = (53 * hash) + getServerStart().hashCode(); - break; - case 3: - hash = (37 * hash) + NEXT_FIELD_NUMBER; - hash = (53 * hash) + getNext().hashCode(); - break; - case 0: - default: - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerReq parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.HandshakerReq prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.HandshakerReq} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.HandshakerReq) - io.grpc.alts.internal.Handshaker.HandshakerReqOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerReq_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerReq_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerReq.class, io.grpc.alts.internal.Handshaker.HandshakerReq.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.HandshakerReq.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - reqOneofCase_ = 0; - reqOneof_ = null; - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerReq_descriptor; - } - - public io.grpc.alts.internal.Handshaker.HandshakerReq getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.HandshakerReq.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.HandshakerReq build() { - io.grpc.alts.internal.Handshaker.HandshakerReq result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.HandshakerReq buildPartial() { - io.grpc.alts.internal.Handshaker.HandshakerReq result = new io.grpc.alts.internal.Handshaker.HandshakerReq(this); - if (reqOneofCase_ == 1) { - if (clientStartBuilder_ == null) { - result.reqOneof_ = reqOneof_; - } else { - result.reqOneof_ = clientStartBuilder_.build(); - } - } - if (reqOneofCase_ == 2) { - if (serverStartBuilder_ == null) { - result.reqOneof_ = reqOneof_; - } else { - result.reqOneof_ = serverStartBuilder_.build(); - } - } - if (reqOneofCase_ == 3) { - if (nextBuilder_ == null) { - result.reqOneof_ = reqOneof_; - } else { - result.reqOneof_ = nextBuilder_.build(); - } - } - result.reqOneofCase_ = reqOneofCase_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.HandshakerReq) { - return mergeFrom((io.grpc.alts.internal.Handshaker.HandshakerReq)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.HandshakerReq other) { - if (other == io.grpc.alts.internal.Handshaker.HandshakerReq.getDefaultInstance()) return this; - switch (other.getReqOneofCase()) { - case CLIENT_START: { - mergeClientStart(other.getClientStart()); - break; - } - case SERVER_START: { - mergeServerStart(other.getServerStart()); - break; - } - case NEXT: { - mergeNext(other.getNext()); - break; - } - case REQONEOF_NOT_SET: { - break; - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.HandshakerReq parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.HandshakerReq) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int reqOneofCase_ = 0; - private java.lang.Object reqOneof_; - public ReqOneofCase - getReqOneofCase() { - return ReqOneofCase.forNumber( - reqOneofCase_); - } - - public Builder clearReqOneof() { - reqOneofCase_ = 0; - reqOneof_ = null; - onChanged(); - return this; - } - - - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq, io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder> clientStartBuilder_; - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public boolean hasClientStart() { - return reqOneofCase_ == 1; - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq getClientStart() { - if (clientStartBuilder_ == null) { - if (reqOneofCase_ == 1) { - return (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } else { - if (reqOneofCase_ == 1) { - return clientStartBuilder_.getMessage(); - } - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public Builder setClientStart(io.grpc.alts.internal.Handshaker.StartClientHandshakeReq value) { - if (clientStartBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - reqOneof_ = value; - onChanged(); - } else { - clientStartBuilder_.setMessage(value); - } - reqOneofCase_ = 1; - return this; - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public Builder setClientStart( - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder builderForValue) { - if (clientStartBuilder_ == null) { - reqOneof_ = builderForValue.build(); - onChanged(); - } else { - clientStartBuilder_.setMessage(builderForValue.build()); - } - reqOneofCase_ = 1; - return this; - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public Builder mergeClientStart(io.grpc.alts.internal.Handshaker.StartClientHandshakeReq value) { - if (clientStartBuilder_ == null) { - if (reqOneofCase_ == 1 && - reqOneof_ != io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance()) { - reqOneof_ = io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.newBuilder((io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_) - .mergeFrom(value).buildPartial(); - } else { - reqOneof_ = value; - } - onChanged(); - } else { - if (reqOneofCase_ == 1) { - clientStartBuilder_.mergeFrom(value); - } - clientStartBuilder_.setMessage(value); - } - reqOneofCase_ = 1; - return this; - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public Builder clearClientStart() { - if (clientStartBuilder_ == null) { - if (reqOneofCase_ == 1) { - reqOneofCase_ = 0; - reqOneof_ = null; - onChanged(); - } - } else { - if (reqOneofCase_ == 1) { - reqOneofCase_ = 0; - reqOneof_ = null; - } - clientStartBuilder_.clear(); - } - return this; - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder getClientStartBuilder() { - return getClientStartFieldBuilder().getBuilder(); - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - public io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder getClientStartOrBuilder() { - if ((reqOneofCase_ == 1) && (clientStartBuilder_ != null)) { - return clientStartBuilder_.getMessageOrBuilder(); - } else { - if (reqOneofCase_ == 1) { - return (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - } - /** - *
-       * The start client handshake request message.
-       * 
- * - * .grpc.gcp.StartClientHandshakeReq client_start = 1; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq, io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder> - getClientStartFieldBuilder() { - if (clientStartBuilder_ == null) { - if (!(reqOneofCase_ == 1)) { - reqOneof_ = io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.getDefaultInstance(); - } - clientStartBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartClientHandshakeReq, io.grpc.alts.internal.Handshaker.StartClientHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartClientHandshakeReqOrBuilder>( - (io.grpc.alts.internal.Handshaker.StartClientHandshakeReq) reqOneof_, - getParentForChildren(), - isClean()); - reqOneof_ = null; - } - reqOneofCase_ = 1; - onChanged();; - return clientStartBuilder_; - } - - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq, io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder> serverStartBuilder_; - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public boolean hasServerStart() { - return reqOneofCase_ == 2; - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq getServerStart() { - if (serverStartBuilder_ == null) { - if (reqOneofCase_ == 2) { - return (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } else { - if (reqOneofCase_ == 2) { - return serverStartBuilder_.getMessage(); - } - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public Builder setServerStart(io.grpc.alts.internal.Handshaker.StartServerHandshakeReq value) { - if (serverStartBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - reqOneof_ = value; - onChanged(); - } else { - serverStartBuilder_.setMessage(value); - } - reqOneofCase_ = 2; - return this; - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public Builder setServerStart( - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder builderForValue) { - if (serverStartBuilder_ == null) { - reqOneof_ = builderForValue.build(); - onChanged(); - } else { - serverStartBuilder_.setMessage(builderForValue.build()); - } - reqOneofCase_ = 2; - return this; - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public Builder mergeServerStart(io.grpc.alts.internal.Handshaker.StartServerHandshakeReq value) { - if (serverStartBuilder_ == null) { - if (reqOneofCase_ == 2 && - reqOneof_ != io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance()) { - reqOneof_ = io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.newBuilder((io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_) - .mergeFrom(value).buildPartial(); - } else { - reqOneof_ = value; - } - onChanged(); - } else { - if (reqOneofCase_ == 2) { - serverStartBuilder_.mergeFrom(value); - } - serverStartBuilder_.setMessage(value); - } - reqOneofCase_ = 2; - return this; - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public Builder clearServerStart() { - if (serverStartBuilder_ == null) { - if (reqOneofCase_ == 2) { - reqOneofCase_ = 0; - reqOneof_ = null; - onChanged(); - } - } else { - if (reqOneofCase_ == 2) { - reqOneofCase_ = 0; - reqOneof_ = null; - } - serverStartBuilder_.clear(); - } - return this; - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder getServerStartBuilder() { - return getServerStartFieldBuilder().getBuilder(); - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - public io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder getServerStartOrBuilder() { - if ((reqOneofCase_ == 2) && (serverStartBuilder_ != null)) { - return serverStartBuilder_.getMessageOrBuilder(); - } else { - if (reqOneofCase_ == 2) { - return (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - } - /** - *
-       * The start server handshake request message.
-       * 
- * - * .grpc.gcp.StartServerHandshakeReq server_start = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq, io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder> - getServerStartFieldBuilder() { - if (serverStartBuilder_ == null) { - if (!(reqOneofCase_ == 2)) { - reqOneof_ = io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.getDefaultInstance(); - } - serverStartBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.StartServerHandshakeReq, io.grpc.alts.internal.Handshaker.StartServerHandshakeReq.Builder, io.grpc.alts.internal.Handshaker.StartServerHandshakeReqOrBuilder>( - (io.grpc.alts.internal.Handshaker.StartServerHandshakeReq) reqOneof_, - getParentForChildren(), - isClean()); - reqOneof_ = null; - } - reqOneofCase_ = 2; - onChanged();; - return serverStartBuilder_; - } - - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder> nextBuilder_; - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public boolean hasNext() { - return reqOneofCase_ == 3; - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq getNext() { - if (nextBuilder_ == null) { - if (reqOneofCase_ == 3) { - return (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } else { - if (reqOneofCase_ == 3) { - return nextBuilder_.getMessage(); - } - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public Builder setNext(io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq value) { - if (nextBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - reqOneof_ = value; - onChanged(); - } else { - nextBuilder_.setMessage(value); - } - reqOneofCase_ = 3; - return this; - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public Builder setNext( - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder builderForValue) { - if (nextBuilder_ == null) { - reqOneof_ = builderForValue.build(); - onChanged(); - } else { - nextBuilder_.setMessage(builderForValue.build()); - } - reqOneofCase_ = 3; - return this; - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public Builder mergeNext(io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq value) { - if (nextBuilder_ == null) { - if (reqOneofCase_ == 3 && - reqOneof_ != io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance()) { - reqOneof_ = io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.newBuilder((io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_) - .mergeFrom(value).buildPartial(); - } else { - reqOneof_ = value; - } - onChanged(); - } else { - if (reqOneofCase_ == 3) { - nextBuilder_.mergeFrom(value); - } - nextBuilder_.setMessage(value); - } - reqOneofCase_ = 3; - return this; - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public Builder clearNext() { - if (nextBuilder_ == null) { - if (reqOneofCase_ == 3) { - reqOneofCase_ = 0; - reqOneof_ = null; - onChanged(); - } - } else { - if (reqOneofCase_ == 3) { - reqOneofCase_ = 0; - reqOneof_ = null; - } - nextBuilder_.clear(); - } - return this; - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder getNextBuilder() { - return getNextFieldBuilder().getBuilder(); - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - public io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder getNextOrBuilder() { - if ((reqOneofCase_ == 3) && (nextBuilder_ != null)) { - return nextBuilder_.getMessageOrBuilder(); - } else { - if (reqOneofCase_ == 3) { - return (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_; - } - return io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - } - /** - *
-       * The next handshake request message.
-       * 
- * - * .grpc.gcp.NextHandshakeMessageReq next = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder> - getNextFieldBuilder() { - if (nextBuilder_ == null) { - if (!(reqOneofCase_ == 3)) { - reqOneof_ = io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.getDefaultInstance(); - } - nextBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq.Builder, io.grpc.alts.internal.Handshaker.NextHandshakeMessageReqOrBuilder>( - (io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq) reqOneof_, - getParentForChildren(), - isClean()); - reqOneof_ = null; - } - reqOneofCase_ = 3; - onChanged();; - return nextBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.HandshakerReq) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.HandshakerReq) - private static final io.grpc.alts.internal.Handshaker.HandshakerReq DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.HandshakerReq(); - } - - public static io.grpc.alts.internal.Handshaker.HandshakerReq getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HandshakerReq parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new HandshakerReq(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.HandshakerReq getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface HandshakerResultOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.HandshakerResult) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - java.lang.String getApplicationProtocol(); - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - com.google.protobuf.ByteString - getApplicationProtocolBytes(); - - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - java.lang.String getRecordProtocol(); - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - com.google.protobuf.ByteString - getRecordProtocolBytes(); - - /** - *
-     * Cryptographic key data. The key data may be more than the key length
-     * required for the record protocol, thus the client of the handshaker
-     * service needs to truncate the key data into the right key length.
-     * 
- * - * bytes key_data = 3; - */ - com.google.protobuf.ByteString getKeyData(); - - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - boolean hasPeerIdentity(); - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - io.grpc.alts.internal.Handshaker.Identity getPeerIdentity(); - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - io.grpc.alts.internal.Handshaker.IdentityOrBuilder getPeerIdentityOrBuilder(); - - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - boolean hasLocalIdentity(); - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - io.grpc.alts.internal.Handshaker.Identity getLocalIdentity(); - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder(); - - /** - *
-     * Indicate whether the handshaker service client should keep the channel
-     * between the handshaker service open, e.g., in order to handle
-     * post-handshake messages in the future.
-     * 
- * - * bool keep_channel_open = 6; - */ - boolean getKeepChannelOpen(); - - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - boolean hasPeerRpcVersions(); - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions(); - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder(); - } - /** - * Protobuf type {@code grpc.gcp.HandshakerResult} - */ - public static final class HandshakerResult extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.HandshakerResult) - HandshakerResultOrBuilder { - private static final long serialVersionUID = 0L; - // Use HandshakerResult.newBuilder() to construct. - private HandshakerResult(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private HandshakerResult() { - applicationProtocol_ = ""; - recordProtocol_ = ""; - keyData_ = com.google.protobuf.ByteString.EMPTY; - keepChannelOpen_ = false; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private HandshakerResult( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - applicationProtocol_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - recordProtocol_ = s; - break; - } - case 26: { - - keyData_ = input.readBytes(); - break; - } - case 34: { - io.grpc.alts.internal.Handshaker.Identity.Builder subBuilder = null; - if (peerIdentity_ != null) { - subBuilder = peerIdentity_.toBuilder(); - } - peerIdentity_ = input.readMessage(io.grpc.alts.internal.Handshaker.Identity.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(peerIdentity_); - peerIdentity_ = subBuilder.buildPartial(); - } - - break; - } - case 42: { - io.grpc.alts.internal.Handshaker.Identity.Builder subBuilder = null; - if (localIdentity_ != null) { - subBuilder = localIdentity_.toBuilder(); - } - localIdentity_ = input.readMessage(io.grpc.alts.internal.Handshaker.Identity.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(localIdentity_); - localIdentity_ = subBuilder.buildPartial(); - } - - break; - } - case 48: { - - keepChannelOpen_ = input.readBool(); - break; - } - case 58: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder subBuilder = null; - if (peerRpcVersions_ != null) { - subBuilder = peerRpcVersions_.toBuilder(); - } - peerRpcVersions_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(peerRpcVersions_); - peerRpcVersions_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResult_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResult_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerResult.class, io.grpc.alts.internal.Handshaker.HandshakerResult.Builder.class); - } - - public static final int APPLICATION_PROTOCOL_FIELD_NUMBER = 1; - private volatile java.lang.Object applicationProtocol_; - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - public java.lang.String getApplicationProtocol() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - applicationProtocol_ = s; - return s; - } - } - /** - *
-     * The application protocol negotiated for this connection.
-     * 
- * - * string application_protocol = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolBytes() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - applicationProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RECORD_PROTOCOL_FIELD_NUMBER = 2; - private volatile java.lang.Object recordProtocol_; - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - public java.lang.String getRecordProtocol() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - recordProtocol_ = s; - return s; - } - } - /** - *
-     * The record protocol negotiated for this connection.
-     * 
- * - * string record_protocol = 2; - */ - public com.google.protobuf.ByteString - getRecordProtocolBytes() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - recordProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int KEY_DATA_FIELD_NUMBER = 3; - private com.google.protobuf.ByteString keyData_; - /** - *
-     * Cryptographic key data. The key data may be more than the key length
-     * required for the record protocol, thus the client of the handshaker
-     * service needs to truncate the key data into the right key length.
-     * 
- * - * bytes key_data = 3; - */ - public com.google.protobuf.ByteString getKeyData() { - return keyData_; - } - - public static final int PEER_IDENTITY_FIELD_NUMBER = 4; - private io.grpc.alts.internal.Handshaker.Identity peerIdentity_; - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public boolean hasPeerIdentity() { - return peerIdentity_ != null; - } - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity getPeerIdentity() { - return peerIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : peerIdentity_; - } - /** - *
-     * The authenticated identity of the peer.
-     * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getPeerIdentityOrBuilder() { - return getPeerIdentity(); - } - - public static final int LOCAL_IDENTITY_FIELD_NUMBER = 5; - private io.grpc.alts.internal.Handshaker.Identity localIdentity_; - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public boolean hasLocalIdentity() { - return localIdentity_ != null; - } - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentity() { - return localIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } - /** - *
-     * The local identity used in the handshake.
-     * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder() { - return getLocalIdentity(); - } - - public static final int KEEP_CHANNEL_OPEN_FIELD_NUMBER = 6; - private boolean keepChannelOpen_; - /** - *
-     * Indicate whether the handshaker service client should keep the channel
-     * between the handshaker service open, e.g., in order to handle
-     * post-handshake messages in the future.
-     * 
- * - * bool keep_channel_open = 6; - */ - public boolean getKeepChannelOpen() { - return keepChannelOpen_; - } - - public static final int PEER_RPC_VERSIONS_FIELD_NUMBER = 7; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions peerRpcVersions_; - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public boolean hasPeerRpcVersions() { - return peerRpcVersions_ != null; - } - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions() { - return peerRpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } - /** - *
-     * The RPC protocol versions supported by the peer.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder() { - return getPeerRpcVersions(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getApplicationProtocolBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, applicationProtocol_); - } - if (!getRecordProtocolBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, recordProtocol_); - } - if (!keyData_.isEmpty()) { - output.writeBytes(3, keyData_); - } - if (peerIdentity_ != null) { - output.writeMessage(4, getPeerIdentity()); - } - if (localIdentity_ != null) { - output.writeMessage(5, getLocalIdentity()); - } - if (keepChannelOpen_ != false) { - output.writeBool(6, keepChannelOpen_); - } - if (peerRpcVersions_ != null) { - output.writeMessage(7, getPeerRpcVersions()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getApplicationProtocolBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, applicationProtocol_); - } - if (!getRecordProtocolBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, recordProtocol_); - } - if (!keyData_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, keyData_); - } - if (peerIdentity_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, getPeerIdentity()); - } - if (localIdentity_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getLocalIdentity()); - } - if (keepChannelOpen_ != false) { - size += com.google.protobuf.CodedOutputStream - .computeBoolSize(6, keepChannelOpen_); - } - if (peerRpcVersions_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(7, getPeerRpcVersions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.HandshakerResult)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.HandshakerResult other = (io.grpc.alts.internal.Handshaker.HandshakerResult) obj; - - boolean result = true; - result = result && getApplicationProtocol() - .equals(other.getApplicationProtocol()); - result = result && getRecordProtocol() - .equals(other.getRecordProtocol()); - result = result && getKeyData() - .equals(other.getKeyData()); - result = result && (hasPeerIdentity() == other.hasPeerIdentity()); - if (hasPeerIdentity()) { - result = result && getPeerIdentity() - .equals(other.getPeerIdentity()); - } - result = result && (hasLocalIdentity() == other.hasLocalIdentity()); - if (hasLocalIdentity()) { - result = result && getLocalIdentity() - .equals(other.getLocalIdentity()); - } - result = result && (getKeepChannelOpen() - == other.getKeepChannelOpen()); - result = result && (hasPeerRpcVersions() == other.hasPeerRpcVersions()); - if (hasPeerRpcVersions()) { - result = result && getPeerRpcVersions() - .equals(other.getPeerRpcVersions()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + APPLICATION_PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + getApplicationProtocol().hashCode(); - hash = (37 * hash) + RECORD_PROTOCOL_FIELD_NUMBER; - hash = (53 * hash) + getRecordProtocol().hashCode(); - hash = (37 * hash) + KEY_DATA_FIELD_NUMBER; - hash = (53 * hash) + getKeyData().hashCode(); - if (hasPeerIdentity()) { - hash = (37 * hash) + PEER_IDENTITY_FIELD_NUMBER; - hash = (53 * hash) + getPeerIdentity().hashCode(); - } - if (hasLocalIdentity()) { - hash = (37 * hash) + LOCAL_IDENTITY_FIELD_NUMBER; - hash = (53 * hash) + getLocalIdentity().hashCode(); - } - hash = (37 * hash) + KEEP_CHANNEL_OPEN_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( - getKeepChannelOpen()); - if (hasPeerRpcVersions()) { - hash = (37 * hash) + PEER_RPC_VERSIONS_FIELD_NUMBER; - hash = (53 * hash) + getPeerRpcVersions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResult parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.HandshakerResult prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.HandshakerResult} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.HandshakerResult) - io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResult_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResult_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerResult.class, io.grpc.alts.internal.Handshaker.HandshakerResult.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.HandshakerResult.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - applicationProtocol_ = ""; - - recordProtocol_ = ""; - - keyData_ = com.google.protobuf.ByteString.EMPTY; - - if (peerIdentityBuilder_ == null) { - peerIdentity_ = null; - } else { - peerIdentity_ = null; - peerIdentityBuilder_ = null; - } - if (localIdentityBuilder_ == null) { - localIdentity_ = null; - } else { - localIdentity_ = null; - localIdentityBuilder_ = null; - } - keepChannelOpen_ = false; - - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = null; - } else { - peerRpcVersions_ = null; - peerRpcVersionsBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResult_descriptor; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResult getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.HandshakerResult.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.HandshakerResult build() { - io.grpc.alts.internal.Handshaker.HandshakerResult result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResult buildPartial() { - io.grpc.alts.internal.Handshaker.HandshakerResult result = new io.grpc.alts.internal.Handshaker.HandshakerResult(this); - result.applicationProtocol_ = applicationProtocol_; - result.recordProtocol_ = recordProtocol_; - result.keyData_ = keyData_; - if (peerIdentityBuilder_ == null) { - result.peerIdentity_ = peerIdentity_; - } else { - result.peerIdentity_ = peerIdentityBuilder_.build(); - } - if (localIdentityBuilder_ == null) { - result.localIdentity_ = localIdentity_; - } else { - result.localIdentity_ = localIdentityBuilder_.build(); - } - result.keepChannelOpen_ = keepChannelOpen_; - if (peerRpcVersionsBuilder_ == null) { - result.peerRpcVersions_ = peerRpcVersions_; - } else { - result.peerRpcVersions_ = peerRpcVersionsBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.HandshakerResult) { - return mergeFrom((io.grpc.alts.internal.Handshaker.HandshakerResult)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.HandshakerResult other) { - if (other == io.grpc.alts.internal.Handshaker.HandshakerResult.getDefaultInstance()) return this; - if (!other.getApplicationProtocol().isEmpty()) { - applicationProtocol_ = other.applicationProtocol_; - onChanged(); - } - if (!other.getRecordProtocol().isEmpty()) { - recordProtocol_ = other.recordProtocol_; - onChanged(); - } - if (other.getKeyData() != com.google.protobuf.ByteString.EMPTY) { - setKeyData(other.getKeyData()); - } - if (other.hasPeerIdentity()) { - mergePeerIdentity(other.getPeerIdentity()); - } - if (other.hasLocalIdentity()) { - mergeLocalIdentity(other.getLocalIdentity()); - } - if (other.getKeepChannelOpen() != false) { - setKeepChannelOpen(other.getKeepChannelOpen()); - } - if (other.hasPeerRpcVersions()) { - mergePeerRpcVersions(other.getPeerRpcVersions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.HandshakerResult parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.HandshakerResult) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object applicationProtocol_ = ""; - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public java.lang.String getApplicationProtocol() { - java.lang.Object ref = applicationProtocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - applicationProtocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public com.google.protobuf.ByteString - getApplicationProtocolBytes() { - java.lang.Object ref = applicationProtocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - applicationProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder setApplicationProtocol( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - applicationProtocol_ = value; - onChanged(); - return this; - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder clearApplicationProtocol() { - - applicationProtocol_ = getDefaultInstance().getApplicationProtocol(); - onChanged(); - return this; - } - /** - *
-       * The application protocol negotiated for this connection.
-       * 
- * - * string application_protocol = 1; - */ - public Builder setApplicationProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - applicationProtocol_ = value; - onChanged(); - return this; - } - - private java.lang.Object recordProtocol_ = ""; - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public java.lang.String getRecordProtocol() { - java.lang.Object ref = recordProtocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - recordProtocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public com.google.protobuf.ByteString - getRecordProtocolBytes() { - java.lang.Object ref = recordProtocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - recordProtocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder setRecordProtocol( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - recordProtocol_ = value; - onChanged(); - return this; - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder clearRecordProtocol() { - - recordProtocol_ = getDefaultInstance().getRecordProtocol(); - onChanged(); - return this; - } - /** - *
-       * The record protocol negotiated for this connection.
-       * 
- * - * string record_protocol = 2; - */ - public Builder setRecordProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - recordProtocol_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.ByteString keyData_ = com.google.protobuf.ByteString.EMPTY; - /** - *
-       * Cryptographic key data. The key data may be more than the key length
-       * required for the record protocol, thus the client of the handshaker
-       * service needs to truncate the key data into the right key length.
-       * 
- * - * bytes key_data = 3; - */ - public com.google.protobuf.ByteString getKeyData() { - return keyData_; - } - /** - *
-       * Cryptographic key data. The key data may be more than the key length
-       * required for the record protocol, thus the client of the handshaker
-       * service needs to truncate the key data into the right key length.
-       * 
- * - * bytes key_data = 3; - */ - public Builder setKeyData(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - - keyData_ = value; - onChanged(); - return this; - } - /** - *
-       * Cryptographic key data. The key data may be more than the key length
-       * required for the record protocol, thus the client of the handshaker
-       * service needs to truncate the key data into the right key length.
-       * 
- * - * bytes key_data = 3; - */ - public Builder clearKeyData() { - - keyData_ = getDefaultInstance().getKeyData(); - onChanged(); - return this; - } - - private io.grpc.alts.internal.Handshaker.Identity peerIdentity_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> peerIdentityBuilder_; - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public boolean hasPeerIdentity() { - return peerIdentityBuilder_ != null || peerIdentity_ != null; - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity getPeerIdentity() { - if (peerIdentityBuilder_ == null) { - return peerIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : peerIdentity_; - } else { - return peerIdentityBuilder_.getMessage(); - } - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public Builder setPeerIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (peerIdentityBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - peerIdentity_ = value; - onChanged(); - } else { - peerIdentityBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public Builder setPeerIdentity( - io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (peerIdentityBuilder_ == null) { - peerIdentity_ = builderForValue.build(); - onChanged(); - } else { - peerIdentityBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public Builder mergePeerIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (peerIdentityBuilder_ == null) { - if (peerIdentity_ != null) { - peerIdentity_ = - io.grpc.alts.internal.Handshaker.Identity.newBuilder(peerIdentity_).mergeFrom(value).buildPartial(); - } else { - peerIdentity_ = value; - } - onChanged(); - } else { - peerIdentityBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public Builder clearPeerIdentity() { - if (peerIdentityBuilder_ == null) { - peerIdentity_ = null; - onChanged(); - } else { - peerIdentity_ = null; - peerIdentityBuilder_ = null; - } - - return this; - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder getPeerIdentityBuilder() { - - onChanged(); - return getPeerIdentityFieldBuilder().getBuilder(); - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getPeerIdentityOrBuilder() { - if (peerIdentityBuilder_ != null) { - return peerIdentityBuilder_.getMessageOrBuilder(); - } else { - return peerIdentity_ == null ? - io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : peerIdentity_; - } - } - /** - *
-       * The authenticated identity of the peer.
-       * 
- * - * .grpc.gcp.Identity peer_identity = 4; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> - getPeerIdentityFieldBuilder() { - if (peerIdentityBuilder_ == null) { - peerIdentityBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder>( - getPeerIdentity(), - getParentForChildren(), - isClean()); - peerIdentity_ = null; - } - return peerIdentityBuilder_; - } - - private io.grpc.alts.internal.Handshaker.Identity localIdentity_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> localIdentityBuilder_; - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public boolean hasLocalIdentity() { - return localIdentityBuilder_ != null || localIdentity_ != null; - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity getLocalIdentity() { - if (localIdentityBuilder_ == null) { - return localIdentity_ == null ? io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } else { - return localIdentityBuilder_.getMessage(); - } - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder setLocalIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentityBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - localIdentity_ = value; - onChanged(); - } else { - localIdentityBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder setLocalIdentity( - io.grpc.alts.internal.Handshaker.Identity.Builder builderForValue) { - if (localIdentityBuilder_ == null) { - localIdentity_ = builderForValue.build(); - onChanged(); - } else { - localIdentityBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder mergeLocalIdentity(io.grpc.alts.internal.Handshaker.Identity value) { - if (localIdentityBuilder_ == null) { - if (localIdentity_ != null) { - localIdentity_ = - io.grpc.alts.internal.Handshaker.Identity.newBuilder(localIdentity_).mergeFrom(value).buildPartial(); - } else { - localIdentity_ = value; - } - onChanged(); - } else { - localIdentityBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public Builder clearLocalIdentity() { - if (localIdentityBuilder_ == null) { - localIdentity_ = null; - onChanged(); - } else { - localIdentity_ = null; - localIdentityBuilder_ = null; - } - - return this; - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.Identity.Builder getLocalIdentityBuilder() { - - onChanged(); - return getLocalIdentityFieldBuilder().getBuilder(); - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - public io.grpc.alts.internal.Handshaker.IdentityOrBuilder getLocalIdentityOrBuilder() { - if (localIdentityBuilder_ != null) { - return localIdentityBuilder_.getMessageOrBuilder(); - } else { - return localIdentity_ == null ? - io.grpc.alts.internal.Handshaker.Identity.getDefaultInstance() : localIdentity_; - } - } - /** - *
-       * The local identity used in the handshake.
-       * 
- * - * .grpc.gcp.Identity local_identity = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder> - getLocalIdentityFieldBuilder() { - if (localIdentityBuilder_ == null) { - localIdentityBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.Identity, io.grpc.alts.internal.Handshaker.Identity.Builder, io.grpc.alts.internal.Handshaker.IdentityOrBuilder>( - getLocalIdentity(), - getParentForChildren(), - isClean()); - localIdentity_ = null; - } - return localIdentityBuilder_; - } - - private boolean keepChannelOpen_ ; - /** - *
-       * Indicate whether the handshaker service client should keep the channel
-       * between the handshaker service open, e.g., in order to handle
-       * post-handshake messages in the future.
-       * 
- * - * bool keep_channel_open = 6; - */ - public boolean getKeepChannelOpen() { - return keepChannelOpen_; - } - /** - *
-       * Indicate whether the handshaker service client should keep the channel
-       * between the handshaker service open, e.g., in order to handle
-       * post-handshake messages in the future.
-       * 
- * - * bool keep_channel_open = 6; - */ - public Builder setKeepChannelOpen(boolean value) { - - keepChannelOpen_ = value; - onChanged(); - return this; - } - /** - *
-       * Indicate whether the handshaker service client should keep the channel
-       * between the handshaker service open, e.g., in order to handle
-       * post-handshake messages in the future.
-       * 
- * - * bool keep_channel_open = 6; - */ - public Builder clearKeepChannelOpen() { - - keepChannelOpen_ = false; - onChanged(); - return this; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions peerRpcVersions_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> peerRpcVersionsBuilder_; - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public boolean hasPeerRpcVersions() { - return peerRpcVersionsBuilder_ != null || peerRpcVersions_ != null; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getPeerRpcVersions() { - if (peerRpcVersionsBuilder_ == null) { - return peerRpcVersions_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } else { - return peerRpcVersionsBuilder_.getMessage(); - } - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public Builder setPeerRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (peerRpcVersionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - peerRpcVersions_ = value; - onChanged(); - } else { - peerRpcVersionsBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public Builder setPeerRpcVersions( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder builderForValue) { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = builderForValue.build(); - onChanged(); - } else { - peerRpcVersionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public Builder mergePeerRpcVersions(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions value) { - if (peerRpcVersionsBuilder_ == null) { - if (peerRpcVersions_ != null) { - peerRpcVersions_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.newBuilder(peerRpcVersions_).mergeFrom(value).buildPartial(); - } else { - peerRpcVersions_ = value; - } - onChanged(); - } else { - peerRpcVersionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public Builder clearPeerRpcVersions() { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersions_ = null; - onChanged(); - } else { - peerRpcVersions_ = null; - peerRpcVersionsBuilder_ = null; - } - - return this; - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder getPeerRpcVersionsBuilder() { - - onChanged(); - return getPeerRpcVersionsFieldBuilder().getBuilder(); - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder getPeerRpcVersionsOrBuilder() { - if (peerRpcVersionsBuilder_ != null) { - return peerRpcVersionsBuilder_.getMessageOrBuilder(); - } else { - return peerRpcVersions_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance() : peerRpcVersions_; - } - } - /** - *
-       * The RPC protocol versions supported by the peer.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions peer_rpc_versions = 7; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder> - getPeerRpcVersionsFieldBuilder() { - if (peerRpcVersionsBuilder_ == null) { - peerRpcVersionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder>( - getPeerRpcVersions(), - getParentForChildren(), - isClean()); - peerRpcVersions_ = null; - } - return peerRpcVersionsBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.HandshakerResult) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.HandshakerResult) - private static final io.grpc.alts.internal.Handshaker.HandshakerResult DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.HandshakerResult(); - } - - public static io.grpc.alts.internal.Handshaker.HandshakerResult getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HandshakerResult parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new HandshakerResult(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResult getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface HandshakerStatusOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.HandshakerStatus) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * The status code. This could be the gRPC status code.
-     * 
- * - * uint32 code = 1; - */ - int getCode(); - - /** - *
-     * The status details.
-     * 
- * - * string details = 2; - */ - java.lang.String getDetails(); - /** - *
-     * The status details.
-     * 
- * - * string details = 2; - */ - com.google.protobuf.ByteString - getDetailsBytes(); - } - /** - * Protobuf type {@code grpc.gcp.HandshakerStatus} - */ - public static final class HandshakerStatus extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.HandshakerStatus) - HandshakerStatusOrBuilder { - private static final long serialVersionUID = 0L; - // Use HandshakerStatus.newBuilder() to construct. - private HandshakerStatus(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private HandshakerStatus() { - code_ = 0; - details_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private HandshakerStatus( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - - code_ = input.readUInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - details_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerStatus_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerStatus_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerStatus.class, io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder.class); - } - - public static final int CODE_FIELD_NUMBER = 1; - private int code_; - /** - *
-     * The status code. This could be the gRPC status code.
-     * 
- * - * uint32 code = 1; - */ - public int getCode() { - return code_; - } - - public static final int DETAILS_FIELD_NUMBER = 2; - private volatile java.lang.Object details_; - /** - *
-     * The status details.
-     * 
- * - * string details = 2; - */ - public java.lang.String getDetails() { - java.lang.Object ref = details_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - details_ = s; - return s; - } - } - /** - *
-     * The status details.
-     * 
- * - * string details = 2; - */ - public com.google.protobuf.ByteString - getDetailsBytes() { - java.lang.Object ref = details_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - details_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (code_ != 0) { - output.writeUInt32(1, code_); - } - if (!getDetailsBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, details_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (code_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeUInt32Size(1, code_); - } - if (!getDetailsBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, details_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.HandshakerStatus)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.HandshakerStatus other = (io.grpc.alts.internal.Handshaker.HandshakerStatus) obj; - - boolean result = true; - result = result && (getCode() - == other.getCode()); - result = result && getDetails() - .equals(other.getDetails()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + CODE_FIELD_NUMBER; - hash = (53 * hash) + getCode(); - hash = (37 * hash) + DETAILS_FIELD_NUMBER; - hash = (53 * hash) + getDetails().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerStatus parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.HandshakerStatus prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.HandshakerStatus} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.HandshakerStatus) - io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerStatus_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerStatus_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerStatus.class, io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.HandshakerStatus.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - code_ = 0; - - details_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerStatus_descriptor; - } - - public io.grpc.alts.internal.Handshaker.HandshakerStatus getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.HandshakerStatus.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.HandshakerStatus build() { - io.grpc.alts.internal.Handshaker.HandshakerStatus result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.HandshakerStatus buildPartial() { - io.grpc.alts.internal.Handshaker.HandshakerStatus result = new io.grpc.alts.internal.Handshaker.HandshakerStatus(this); - result.code_ = code_; - result.details_ = details_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.HandshakerStatus) { - return mergeFrom((io.grpc.alts.internal.Handshaker.HandshakerStatus)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.HandshakerStatus other) { - if (other == io.grpc.alts.internal.Handshaker.HandshakerStatus.getDefaultInstance()) return this; - if (other.getCode() != 0) { - setCode(other.getCode()); - } - if (!other.getDetails().isEmpty()) { - details_ = other.details_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.HandshakerStatus parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.HandshakerStatus) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int code_ ; - /** - *
-       * The status code. This could be the gRPC status code.
-       * 
- * - * uint32 code = 1; - */ - public int getCode() { - return code_; - } - /** - *
-       * The status code. This could be the gRPC status code.
-       * 
- * - * uint32 code = 1; - */ - public Builder setCode(int value) { - - code_ = value; - onChanged(); - return this; - } - /** - *
-       * The status code. This could be the gRPC status code.
-       * 
- * - * uint32 code = 1; - */ - public Builder clearCode() { - - code_ = 0; - onChanged(); - return this; - } - - private java.lang.Object details_ = ""; - /** - *
-       * The status details.
-       * 
- * - * string details = 2; - */ - public java.lang.String getDetails() { - java.lang.Object ref = details_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - details_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - *
-       * The status details.
-       * 
- * - * string details = 2; - */ - public com.google.protobuf.ByteString - getDetailsBytes() { - java.lang.Object ref = details_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - details_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       * The status details.
-       * 
- * - * string details = 2; - */ - public Builder setDetails( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - details_ = value; - onChanged(); - return this; - } - /** - *
-       * The status details.
-       * 
- * - * string details = 2; - */ - public Builder clearDetails() { - - details_ = getDefaultInstance().getDetails(); - onChanged(); - return this; - } - /** - *
-       * The status details.
-       * 
- * - * string details = 2; - */ - public Builder setDetailsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - details_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.HandshakerStatus) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.HandshakerStatus) - private static final io.grpc.alts.internal.Handshaker.HandshakerStatus DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.HandshakerStatus(); - } - - public static io.grpc.alts.internal.Handshaker.HandshakerStatus getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HandshakerStatus parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new HandshakerStatus(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.HandshakerStatus getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface HandshakerRespOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.HandshakerResp) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * Frames to be given to the peer for the NextHandshakeMessageReq. May be
-     * empty if no out_frames have to be sent to the peer or if in_bytes in the
-     * HandshakerReq are incomplete. All the non-empty out frames must be sent to
-     * the peer even if the handshaker status is not OK as these frames may
-     * contain the alert frames.
-     * 
- * - * bytes out_frames = 1; - */ - com.google.protobuf.ByteString getOutFrames(); - - /** - *
-     * Number of bytes in the in_bytes consumed by the handshaker. It is possible
-     * that part of in_bytes in HandshakerReq was unrelated to the handshake
-     * process.
-     * 
- * - * uint32 bytes_consumed = 2; - */ - int getBytesConsumed(); - - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - boolean hasResult(); - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - io.grpc.alts.internal.Handshaker.HandshakerResult getResult(); - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder getResultOrBuilder(); - - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - boolean hasStatus(); - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - io.grpc.alts.internal.Handshaker.HandshakerStatus getStatus(); - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder getStatusOrBuilder(); - } - /** - * Protobuf type {@code grpc.gcp.HandshakerResp} - */ - public static final class HandshakerResp extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.HandshakerResp) - HandshakerRespOrBuilder { - private static final long serialVersionUID = 0L; - // Use HandshakerResp.newBuilder() to construct. - private HandshakerResp(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private HandshakerResp() { - outFrames_ = com.google.protobuf.ByteString.EMPTY; - bytesConsumed_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private HandshakerResp( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - - outFrames_ = input.readBytes(); - break; - } - case 16: { - - bytesConsumed_ = input.readUInt32(); - break; - } - case 26: { - io.grpc.alts.internal.Handshaker.HandshakerResult.Builder subBuilder = null; - if (result_ != null) { - subBuilder = result_.toBuilder(); - } - result_ = input.readMessage(io.grpc.alts.internal.Handshaker.HandshakerResult.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(result_); - result_ = subBuilder.buildPartial(); - } - - break; - } - case 34: { - io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder subBuilder = null; - if (status_ != null) { - subBuilder = status_.toBuilder(); - } - status_ = input.readMessage(io.grpc.alts.internal.Handshaker.HandshakerStatus.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(status_); - status_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResp_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResp_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerResp.class, io.grpc.alts.internal.Handshaker.HandshakerResp.Builder.class); - } - - public static final int OUT_FRAMES_FIELD_NUMBER = 1; - private com.google.protobuf.ByteString outFrames_; - /** - *
-     * Frames to be given to the peer for the NextHandshakeMessageReq. May be
-     * empty if no out_frames have to be sent to the peer or if in_bytes in the
-     * HandshakerReq are incomplete. All the non-empty out frames must be sent to
-     * the peer even if the handshaker status is not OK as these frames may
-     * contain the alert frames.
-     * 
- * - * bytes out_frames = 1; - */ - public com.google.protobuf.ByteString getOutFrames() { - return outFrames_; - } - - public static final int BYTES_CONSUMED_FIELD_NUMBER = 2; - private int bytesConsumed_; - /** - *
-     * Number of bytes in the in_bytes consumed by the handshaker. It is possible
-     * that part of in_bytes in HandshakerReq was unrelated to the handshake
-     * process.
-     * 
- * - * uint32 bytes_consumed = 2; - */ - public int getBytesConsumed() { - return bytesConsumed_; - } - - public static final int RESULT_FIELD_NUMBER = 3; - private io.grpc.alts.internal.Handshaker.HandshakerResult result_; - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public boolean hasResult() { - return result_ != null; - } - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public io.grpc.alts.internal.Handshaker.HandshakerResult getResult() { - return result_ == null ? io.grpc.alts.internal.Handshaker.HandshakerResult.getDefaultInstance() : result_; - } - /** - *
-     * This is set iff the handshake was successful. out_frames may still be set
-     * to frames that needs to be forwarded to the peer.
-     * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder getResultOrBuilder() { - return getResult(); - } - - public static final int STATUS_FIELD_NUMBER = 4; - private io.grpc.alts.internal.Handshaker.HandshakerStatus status_; - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public boolean hasStatus() { - return status_ != null; - } - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public io.grpc.alts.internal.Handshaker.HandshakerStatus getStatus() { - return status_ == null ? io.grpc.alts.internal.Handshaker.HandshakerStatus.getDefaultInstance() : status_; - } - /** - *
-     * Status of the handshaker.
-     * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder getStatusOrBuilder() { - return getStatus(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!outFrames_.isEmpty()) { - output.writeBytes(1, outFrames_); - } - if (bytesConsumed_ != 0) { - output.writeUInt32(2, bytesConsumed_); - } - if (result_ != null) { - output.writeMessage(3, getResult()); - } - if (status_ != null) { - output.writeMessage(4, getStatus()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!outFrames_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, outFrames_); - } - if (bytesConsumed_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeUInt32Size(2, bytesConsumed_); - } - if (result_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getResult()); - } - if (status_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, getStatus()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.Handshaker.HandshakerResp)) { - return super.equals(obj); - } - io.grpc.alts.internal.Handshaker.HandshakerResp other = (io.grpc.alts.internal.Handshaker.HandshakerResp) obj; - - boolean result = true; - result = result && getOutFrames() - .equals(other.getOutFrames()); - result = result && (getBytesConsumed() - == other.getBytesConsumed()); - result = result && (hasResult() == other.hasResult()); - if (hasResult()) { - result = result && getResult() - .equals(other.getResult()); - } - result = result && (hasStatus() == other.hasStatus()); - if (hasStatus()) { - result = result && getStatus() - .equals(other.getStatus()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + OUT_FRAMES_FIELD_NUMBER; - hash = (53 * hash) + getOutFrames().hashCode(); - hash = (37 * hash) + BYTES_CONSUMED_FIELD_NUMBER; - hash = (53 * hash) + getBytesConsumed(); - if (hasResult()) { - hash = (37 * hash) + RESULT_FIELD_NUMBER; - hash = (53 * hash) + getResult().hashCode(); - } - if (hasStatus()) { - hash = (37 * hash) + STATUS_FIELD_NUMBER; - hash = (53 * hash) + getStatus().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.Handshaker.HandshakerResp parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.Handshaker.HandshakerResp prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code grpc.gcp.HandshakerResp} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.HandshakerResp) - io.grpc.alts.internal.Handshaker.HandshakerRespOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResp_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResp_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.Handshaker.HandshakerResp.class, io.grpc.alts.internal.Handshaker.HandshakerResp.Builder.class); - } - - // Construct using io.grpc.alts.internal.Handshaker.HandshakerResp.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - outFrames_ = com.google.protobuf.ByteString.EMPTY; - - bytesConsumed_ = 0; - - if (resultBuilder_ == null) { - result_ = null; - } else { - result_ = null; - resultBuilder_ = null; - } - if (statusBuilder_ == null) { - status_ = null; - } else { - status_ = null; - statusBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.Handshaker.internal_static_grpc_gcp_HandshakerResp_descriptor; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResp getDefaultInstanceForType() { - return io.grpc.alts.internal.Handshaker.HandshakerResp.getDefaultInstance(); - } - - public io.grpc.alts.internal.Handshaker.HandshakerResp build() { - io.grpc.alts.internal.Handshaker.HandshakerResp result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResp buildPartial() { - io.grpc.alts.internal.Handshaker.HandshakerResp result = new io.grpc.alts.internal.Handshaker.HandshakerResp(this); - result.outFrames_ = outFrames_; - result.bytesConsumed_ = bytesConsumed_; - if (resultBuilder_ == null) { - result.result_ = result_; - } else { - result.result_ = resultBuilder_.build(); - } - if (statusBuilder_ == null) { - result.status_ = status_; - } else { - result.status_ = statusBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.Handshaker.HandshakerResp) { - return mergeFrom((io.grpc.alts.internal.Handshaker.HandshakerResp)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.Handshaker.HandshakerResp other) { - if (other == io.grpc.alts.internal.Handshaker.HandshakerResp.getDefaultInstance()) return this; - if (other.getOutFrames() != com.google.protobuf.ByteString.EMPTY) { - setOutFrames(other.getOutFrames()); - } - if (other.getBytesConsumed() != 0) { - setBytesConsumed(other.getBytesConsumed()); - } - if (other.hasResult()) { - mergeResult(other.getResult()); - } - if (other.hasStatus()) { - mergeStatus(other.getStatus()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.Handshaker.HandshakerResp parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.Handshaker.HandshakerResp) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private com.google.protobuf.ByteString outFrames_ = com.google.protobuf.ByteString.EMPTY; - /** - *
-       * Frames to be given to the peer for the NextHandshakeMessageReq. May be
-       * empty if no out_frames have to be sent to the peer or if in_bytes in the
-       * HandshakerReq are incomplete. All the non-empty out frames must be sent to
-       * the peer even if the handshaker status is not OK as these frames may
-       * contain the alert frames.
-       * 
- * - * bytes out_frames = 1; - */ - public com.google.protobuf.ByteString getOutFrames() { - return outFrames_; - } - /** - *
-       * Frames to be given to the peer for the NextHandshakeMessageReq. May be
-       * empty if no out_frames have to be sent to the peer or if in_bytes in the
-       * HandshakerReq are incomplete. All the non-empty out frames must be sent to
-       * the peer even if the handshaker status is not OK as these frames may
-       * contain the alert frames.
-       * 
- * - * bytes out_frames = 1; - */ - public Builder setOutFrames(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - - outFrames_ = value; - onChanged(); - return this; - } - /** - *
-       * Frames to be given to the peer for the NextHandshakeMessageReq. May be
-       * empty if no out_frames have to be sent to the peer or if in_bytes in the
-       * HandshakerReq are incomplete. All the non-empty out frames must be sent to
-       * the peer even if the handshaker status is not OK as these frames may
-       * contain the alert frames.
-       * 
- * - * bytes out_frames = 1; - */ - public Builder clearOutFrames() { - - outFrames_ = getDefaultInstance().getOutFrames(); - onChanged(); - return this; - } - - private int bytesConsumed_ ; - /** - *
-       * Number of bytes in the in_bytes consumed by the handshaker. It is possible
-       * that part of in_bytes in HandshakerReq was unrelated to the handshake
-       * process.
-       * 
- * - * uint32 bytes_consumed = 2; - */ - public int getBytesConsumed() { - return bytesConsumed_; - } - /** - *
-       * Number of bytes in the in_bytes consumed by the handshaker. It is possible
-       * that part of in_bytes in HandshakerReq was unrelated to the handshake
-       * process.
-       * 
- * - * uint32 bytes_consumed = 2; - */ - public Builder setBytesConsumed(int value) { - - bytesConsumed_ = value; - onChanged(); - return this; - } - /** - *
-       * Number of bytes in the in_bytes consumed by the handshaker. It is possible
-       * that part of in_bytes in HandshakerReq was unrelated to the handshake
-       * process.
-       * 
- * - * uint32 bytes_consumed = 2; - */ - public Builder clearBytesConsumed() { - - bytesConsumed_ = 0; - onChanged(); - return this; - } - - private io.grpc.alts.internal.Handshaker.HandshakerResult result_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerResult, io.grpc.alts.internal.Handshaker.HandshakerResult.Builder, io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder> resultBuilder_; - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public boolean hasResult() { - return resultBuilder_ != null || result_ != null; - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public io.grpc.alts.internal.Handshaker.HandshakerResult getResult() { - if (resultBuilder_ == null) { - return result_ == null ? io.grpc.alts.internal.Handshaker.HandshakerResult.getDefaultInstance() : result_; - } else { - return resultBuilder_.getMessage(); - } - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public Builder setResult(io.grpc.alts.internal.Handshaker.HandshakerResult value) { - if (resultBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - result_ = value; - onChanged(); - } else { - resultBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public Builder setResult( - io.grpc.alts.internal.Handshaker.HandshakerResult.Builder builderForValue) { - if (resultBuilder_ == null) { - result_ = builderForValue.build(); - onChanged(); - } else { - resultBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public Builder mergeResult(io.grpc.alts.internal.Handshaker.HandshakerResult value) { - if (resultBuilder_ == null) { - if (result_ != null) { - result_ = - io.grpc.alts.internal.Handshaker.HandshakerResult.newBuilder(result_).mergeFrom(value).buildPartial(); - } else { - result_ = value; - } - onChanged(); - } else { - resultBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public Builder clearResult() { - if (resultBuilder_ == null) { - result_ = null; - onChanged(); - } else { - result_ = null; - resultBuilder_ = null; - } - - return this; - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public io.grpc.alts.internal.Handshaker.HandshakerResult.Builder getResultBuilder() { - - onChanged(); - return getResultFieldBuilder().getBuilder(); - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - public io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder getResultOrBuilder() { - if (resultBuilder_ != null) { - return resultBuilder_.getMessageOrBuilder(); - } else { - return result_ == null ? - io.grpc.alts.internal.Handshaker.HandshakerResult.getDefaultInstance() : result_; - } - } - /** - *
-       * This is set iff the handshake was successful. out_frames may still be set
-       * to frames that needs to be forwarded to the peer.
-       * 
- * - * .grpc.gcp.HandshakerResult result = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerResult, io.grpc.alts.internal.Handshaker.HandshakerResult.Builder, io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder> - getResultFieldBuilder() { - if (resultBuilder_ == null) { - resultBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerResult, io.grpc.alts.internal.Handshaker.HandshakerResult.Builder, io.grpc.alts.internal.Handshaker.HandshakerResultOrBuilder>( - getResult(), - getParentForChildren(), - isClean()); - result_ = null; - } - return resultBuilder_; - } - - private io.grpc.alts.internal.Handshaker.HandshakerStatus status_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerStatus, io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder, io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder> statusBuilder_; - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public boolean hasStatus() { - return statusBuilder_ != null || status_ != null; - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public io.grpc.alts.internal.Handshaker.HandshakerStatus getStatus() { - if (statusBuilder_ == null) { - return status_ == null ? io.grpc.alts.internal.Handshaker.HandshakerStatus.getDefaultInstance() : status_; - } else { - return statusBuilder_.getMessage(); - } - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public Builder setStatus(io.grpc.alts.internal.Handshaker.HandshakerStatus value) { - if (statusBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - status_ = value; - onChanged(); - } else { - statusBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public Builder setStatus( - io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder builderForValue) { - if (statusBuilder_ == null) { - status_ = builderForValue.build(); - onChanged(); - } else { - statusBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public Builder mergeStatus(io.grpc.alts.internal.Handshaker.HandshakerStatus value) { - if (statusBuilder_ == null) { - if (status_ != null) { - status_ = - io.grpc.alts.internal.Handshaker.HandshakerStatus.newBuilder(status_).mergeFrom(value).buildPartial(); - } else { - status_ = value; - } - onChanged(); - } else { - statusBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public Builder clearStatus() { - if (statusBuilder_ == null) { - status_ = null; - onChanged(); - } else { - status_ = null; - statusBuilder_ = null; - } - - return this; - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder getStatusBuilder() { - - onChanged(); - return getStatusFieldBuilder().getBuilder(); - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - public io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder getStatusOrBuilder() { - if (statusBuilder_ != null) { - return statusBuilder_.getMessageOrBuilder(); - } else { - return status_ == null ? - io.grpc.alts.internal.Handshaker.HandshakerStatus.getDefaultInstance() : status_; - } - } - /** - *
-       * Status of the handshaker.
-       * 
- * - * .grpc.gcp.HandshakerStatus status = 4; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerStatus, io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder, io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder> - getStatusFieldBuilder() { - if (statusBuilder_ == null) { - statusBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.Handshaker.HandshakerStatus, io.grpc.alts.internal.Handshaker.HandshakerStatus.Builder, io.grpc.alts.internal.Handshaker.HandshakerStatusOrBuilder>( - getStatus(), - getParentForChildren(), - isClean()); - status_ = null; - } - return statusBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.HandshakerResp) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.HandshakerResp) - private static final io.grpc.alts.internal.Handshaker.HandshakerResp DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.Handshaker.HandshakerResp(); - } - - public static io.grpc.alts.internal.Handshaker.HandshakerResp getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public HandshakerResp parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new HandshakerResp(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.Handshaker.HandshakerResp getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_Endpoint_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_Endpoint_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_Identity_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_Identity_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_StartClientHandshakeReq_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_StartClientHandshakeReq_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_ServerHandshakeParameters_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_ServerHandshakeParameters_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_StartServerHandshakeReq_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_StartServerHandshakeReq_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_NextHandshakeMessageReq_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_HandshakerReq_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_HandshakerReq_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_HandshakerResult_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_HandshakerResult_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_HandshakerStatus_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_HandshakerStatus_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_HandshakerResp_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_HandshakerResp_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\020handshaker.proto\022\010grpc.gcp\032\037transport_" + - "security_common.proto\"Y\n\010Endpoint\022\022\n\nip_" + - "address\030\001 \001(\t\022\014\n\004port\030\002 \001(\005\022+\n\010protocol\030" + - "\003 \001(\0162\031.grpc.gcp.NetworkProtocol\"K\n\010Iden" + - "tity\022\031\n\017service_account\030\001 \001(\tH\000\022\022\n\010hostn" + - "ame\030\002 \001(\tH\000B\020\n\016identity_oneof\"\222\003\n\027StartC" + - "lientHandshakeReq\022@\n\033handshake_security_" + - "protocol\030\001 \001(\0162\033.grpc.gcp.HandshakeProto" + - "col\022\035\n\025application_protocols\030\002 \003(\t\022\030\n\020re" + - "cord_protocols\030\003 \003(\t\022-\n\021target_identitie" + - "s\030\004 \003(\0132\022.grpc.gcp.Identity\022*\n\016local_ide" + - "ntity\030\005 \001(\0132\022.grpc.gcp.Identity\022*\n\016local" + - "_endpoint\030\006 \001(\0132\022.grpc.gcp.Endpoint\022+\n\017r" + - "emote_endpoint\030\007 \001(\0132\022.grpc.gcp.Endpoint" + - "\022\023\n\013target_name\030\010 \001(\t\0223\n\014rpc_versions\030\t " + - "\001(\0132\035.grpc.gcp.RpcProtocolVersions\"c\n\031Se" + - "rverHandshakeParameters\022\030\n\020record_protoc" + - "ols\030\001 \003(\t\022,\n\020local_identities\030\002 \003(\0132\022.gr" + - "pc.gcp.Identity\"\223\003\n\027StartServerHandshake" + - "Req\022\035\n\025application_protocols\030\001 \003(\t\022X\n\024ha" + - "ndshake_parameters\030\002 \003(\0132:.grpc.gcp.Star" + - "tServerHandshakeReq.HandshakeParametersE" + - "ntry\022\020\n\010in_bytes\030\003 \001(\014\022*\n\016local_endpoint" + - "\030\004 \001(\0132\022.grpc.gcp.Endpoint\022+\n\017remote_end" + - "point\030\005 \001(\0132\022.grpc.gcp.Endpoint\0223\n\014rpc_v" + - "ersions\030\006 \001(\0132\035.grpc.gcp.RpcProtocolVers" + - "ions\032_\n\030HandshakeParametersEntry\022\013\n\003key\030" + - "\001 \001(\005\0222\n\005value\030\002 \001(\0132#.grpc.gcp.ServerHa" + - "ndshakeParameters:\0028\001\"+\n\027NextHandshakeMe" + - "ssageReq\022\020\n\010in_bytes\030\001 \001(\014\"\305\001\n\rHandshake" + - "rReq\0229\n\014client_start\030\001 \001(\0132!.grpc.gcp.St" + - "artClientHandshakeReqH\000\0229\n\014server_start\030" + - "\002 \001(\0132!.grpc.gcp.StartServerHandshakeReq" + - "H\000\0221\n\004next\030\003 \001(\0132!.grpc.gcp.NextHandshak" + - "eMessageReqH\000B\013\n\treq_oneof\"\207\002\n\020Handshake" + - "rResult\022\034\n\024application_protocol\030\001 \001(\t\022\027\n" + - "\017record_protocol\030\002 \001(\t\022\020\n\010key_data\030\003 \001(\014" + - "\022)\n\rpeer_identity\030\004 \001(\0132\022.grpc.gcp.Ident" + - "ity\022*\n\016local_identity\030\005 \001(\0132\022.grpc.gcp.I" + - "dentity\022\031\n\021keep_channel_open\030\006 \001(\010\0228\n\021pe" + - "er_rpc_versions\030\007 \001(\0132\035.grpc.gcp.RpcProt" + - "ocolVersions\"1\n\020HandshakerStatus\022\014\n\004code" + - "\030\001 \001(\r\022\017\n\007details\030\002 \001(\t\"\224\001\n\016HandshakerRe" + - "sp\022\022\n\nout_frames\030\001 \001(\014\022\026\n\016bytes_consumed" + - "\030\002 \001(\r\022*\n\006result\030\003 \001(\0132\032.grpc.gcp.Handsh" + - "akerResult\022*\n\006status\030\004 \001(\0132\032.grpc.gcp.Ha" + - "ndshakerStatus*J\n\021HandshakeProtocol\022\"\n\036H" + - "ANDSHAKE_PROTOCOL_UNSPECIFIED\020\000\022\007\n\003TLS\020\001" + - "\022\010\n\004ALTS\020\002*E\n\017NetworkProtocol\022 \n\034NETWORK" + - "_PROTOCOL_UNSPECIFIED\020\000\022\007\n\003TCP\020\001\022\007\n\003UDP\020" + - "\0022[\n\021HandshakerService\022F\n\013DoHandshake\022\027." + - "grpc.gcp.HandshakerReq\032\030.grpc.gcp.Handsh" + - "akerResp\"\000(\0010\001B\027\n\025io.grpc.alts.internalb" + - "\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - io.grpc.alts.internal.TransportSecurityCommon.getDescriptor(), - }, assigner); - internal_static_grpc_gcp_Endpoint_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_grpc_gcp_Endpoint_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_Endpoint_descriptor, - new java.lang.String[] { "IpAddress", "Port", "Protocol", }); - internal_static_grpc_gcp_Identity_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_grpc_gcp_Identity_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_Identity_descriptor, - new java.lang.String[] { "ServiceAccount", "Hostname", "IdentityOneof", }); - internal_static_grpc_gcp_StartClientHandshakeReq_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_grpc_gcp_StartClientHandshakeReq_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_StartClientHandshakeReq_descriptor, - new java.lang.String[] { "HandshakeSecurityProtocol", "ApplicationProtocols", "RecordProtocols", "TargetIdentities", "LocalIdentity", "LocalEndpoint", "RemoteEndpoint", "TargetName", "RpcVersions", }); - internal_static_grpc_gcp_ServerHandshakeParameters_descriptor = - getDescriptor().getMessageTypes().get(3); - internal_static_grpc_gcp_ServerHandshakeParameters_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_ServerHandshakeParameters_descriptor, - new java.lang.String[] { "RecordProtocols", "LocalIdentities", }); - internal_static_grpc_gcp_StartServerHandshakeReq_descriptor = - getDescriptor().getMessageTypes().get(4); - internal_static_grpc_gcp_StartServerHandshakeReq_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_StartServerHandshakeReq_descriptor, - new java.lang.String[] { "ApplicationProtocols", "HandshakeParameters", "InBytes", "LocalEndpoint", "RemoteEndpoint", "RpcVersions", }); - internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_descriptor = - internal_static_grpc_gcp_StartServerHandshakeReq_descriptor.getNestedTypes().get(0); - internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor = - getDescriptor().getMessageTypes().get(5); - internal_static_grpc_gcp_NextHandshakeMessageReq_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_NextHandshakeMessageReq_descriptor, - new java.lang.String[] { "InBytes", }); - internal_static_grpc_gcp_HandshakerReq_descriptor = - getDescriptor().getMessageTypes().get(6); - internal_static_grpc_gcp_HandshakerReq_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_HandshakerReq_descriptor, - new java.lang.String[] { "ClientStart", "ServerStart", "Next", "ReqOneof", }); - internal_static_grpc_gcp_HandshakerResult_descriptor = - getDescriptor().getMessageTypes().get(7); - internal_static_grpc_gcp_HandshakerResult_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_HandshakerResult_descriptor, - new java.lang.String[] { "ApplicationProtocol", "RecordProtocol", "KeyData", "PeerIdentity", "LocalIdentity", "KeepChannelOpen", "PeerRpcVersions", }); - internal_static_grpc_gcp_HandshakerStatus_descriptor = - getDescriptor().getMessageTypes().get(8); - internal_static_grpc_gcp_HandshakerStatus_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_HandshakerStatus_descriptor, - new java.lang.String[] { "Code", "Details", }); - internal_static_grpc_gcp_HandshakerResp_descriptor = - getDescriptor().getMessageTypes().get(9); - internal_static_grpc_gcp_HandshakerResp_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_HandshakerResp_descriptor, - new java.lang.String[] { "OutFrames", "BytesConsumed", "Result", "Status", }); - io.grpc.alts.internal.TransportSecurityCommon.getDescriptor(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/alts/src/generated/main/java/io/grpc/alts/internal/TransportSecurityCommon.java b/alts/src/generated/main/java/io/grpc/alts/internal/TransportSecurityCommon.java deleted file mode 100644 index 65b56e34c35..00000000000 --- a/alts/src/generated/main/java/io/grpc/alts/internal/TransportSecurityCommon.java +++ /dev/null @@ -1,1611 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: transport_security_common.proto - -package io.grpc.alts.internal; - -public final class TransportSecurityCommon { - private TransportSecurityCommon() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - /** - *
-   * The security level of the created channel. The list is sorted in increasing
-   * level of security. This order must always be maintained.
-   * 
- * - * Protobuf enum {@code grpc.gcp.SecurityLevel} - */ - public enum SecurityLevel - implements com.google.protobuf.ProtocolMessageEnum { - /** - * SECURITY_NONE = 0; - */ - SECURITY_NONE(0), - /** - * INTEGRITY_ONLY = 1; - */ - INTEGRITY_ONLY(1), - /** - * INTEGRITY_AND_PRIVACY = 2; - */ - INTEGRITY_AND_PRIVACY(2), - UNRECOGNIZED(-1), - ; - - /** - * SECURITY_NONE = 0; - */ - public static final int SECURITY_NONE_VALUE = 0; - /** - * INTEGRITY_ONLY = 1; - */ - public static final int INTEGRITY_ONLY_VALUE = 1; - /** - * INTEGRITY_AND_PRIVACY = 2; - */ - public static final int INTEGRITY_AND_PRIVACY_VALUE = 2; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static SecurityLevel valueOf(int value) { - return forNumber(value); - } - - public static SecurityLevel forNumber(int value) { - switch (value) { - case 0: return SECURITY_NONE; - case 1: return INTEGRITY_ONLY; - case 2: return INTEGRITY_AND_PRIVACY; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - SecurityLevel> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public SecurityLevel findValueByNumber(int number) { - return SecurityLevel.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return io.grpc.alts.internal.TransportSecurityCommon.getDescriptor().getEnumTypes().get(0); - } - - private static final SecurityLevel[] VALUES = values(); - - public static SecurityLevel valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private SecurityLevel(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:grpc.gcp.SecurityLevel) - } - - public interface RpcProtocolVersionsOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.RpcProtocolVersions) - com.google.protobuf.MessageOrBuilder { - - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - boolean hasMaxRpcVersion(); - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMaxRpcVersion(); - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMaxRpcVersionOrBuilder(); - - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - boolean hasMinRpcVersion(); - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMinRpcVersion(); - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMinRpcVersionOrBuilder(); - } - /** - *
-   * Max and min supported RPC protocol versions.
-   * 
- * - * Protobuf type {@code grpc.gcp.RpcProtocolVersions} - */ - public static final class RpcProtocolVersions extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.RpcProtocolVersions) - RpcProtocolVersionsOrBuilder { - private static final long serialVersionUID = 0L; - // Use RpcProtocolVersions.newBuilder() to construct. - private RpcProtocolVersions(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private RpcProtocolVersions() { - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private RpcProtocolVersions( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder subBuilder = null; - if (maxRpcVersion_ != null) { - subBuilder = maxRpcVersion_.toBuilder(); - } - maxRpcVersion_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(maxRpcVersion_); - maxRpcVersion_ = subBuilder.buildPartial(); - } - - break; - } - case 18: { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder subBuilder = null; - if (minRpcVersion_ != null) { - subBuilder = minRpcVersion_.toBuilder(); - } - minRpcVersion_ = input.readMessage(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(minRpcVersion_); - minRpcVersion_ = subBuilder.buildPartial(); - } - - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.class, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder.class); - } - - public interface VersionOrBuilder extends - // @@protoc_insertion_point(interface_extends:grpc.gcp.RpcProtocolVersions.Version) - com.google.protobuf.MessageOrBuilder { - - /** - * uint32 major = 1; - */ - int getMajor(); - - /** - * uint32 minor = 2; - */ - int getMinor(); - } - /** - *
-     * RPC version contains a major version and a minor version.
-     * 
- * - * Protobuf type {@code grpc.gcp.RpcProtocolVersions.Version} - */ - public static final class Version extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:grpc.gcp.RpcProtocolVersions.Version) - VersionOrBuilder { - private static final long serialVersionUID = 0L; - // Use Version.newBuilder() to construct. - private Version(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private Version() { - major_ = 0; - minor_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private Version( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - - major_ = input.readUInt32(); - break; - } - case 16: { - - minor_ = input.readUInt32(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_Version_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.class, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder.class); - } - - public static final int MAJOR_FIELD_NUMBER = 1; - private int major_; - /** - * uint32 major = 1; - */ - public int getMajor() { - return major_; - } - - public static final int MINOR_FIELD_NUMBER = 2; - private int minor_; - /** - * uint32 minor = 2; - */ - public int getMinor() { - return minor_; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (major_ != 0) { - output.writeUInt32(1, major_); - } - if (minor_ != 0) { - output.writeUInt32(2, minor_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (major_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeUInt32Size(1, major_); - } - if (minor_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeUInt32Size(2, minor_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version)) { - return super.equals(obj); - } - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version other = (io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version) obj; - - boolean result = true; - result = result && (getMajor() - == other.getMajor()); - result = result && (getMinor() - == other.getMinor()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + MAJOR_FIELD_NUMBER; - hash = (53 * hash) + getMajor(); - hash = (37 * hash) + MINOR_FIELD_NUMBER; - hash = (53 * hash) + getMinor(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - *
-       * RPC version contains a major version and a minor version.
-       * 
- * - * Protobuf type {@code grpc.gcp.RpcProtocolVersions.Version} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.RpcProtocolVersions.Version) - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_Version_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.class, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder.class); - } - - // Construct using io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - major_ = 0; - - minor_ = 0; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getDefaultInstanceForType() { - return io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance(); - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version build() { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version buildPartial() { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version result = new io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version(this); - result.major_ = major_; - result.minor_ = minor_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version) { - return mergeFrom((io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version other) { - if (other == io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance()) return this; - if (other.getMajor() != 0) { - setMajor(other.getMajor()); - } - if (other.getMinor() != 0) { - setMinor(other.getMinor()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int major_ ; - /** - * uint32 major = 1; - */ - public int getMajor() { - return major_; - } - /** - * uint32 major = 1; - */ - public Builder setMajor(int value) { - - major_ = value; - onChanged(); - return this; - } - /** - * uint32 major = 1; - */ - public Builder clearMajor() { - - major_ = 0; - onChanged(); - return this; - } - - private int minor_ ; - /** - * uint32 minor = 2; - */ - public int getMinor() { - return minor_; - } - /** - * uint32 minor = 2; - */ - public Builder setMinor(int value) { - - minor_ = value; - onChanged(); - return this; - } - /** - * uint32 minor = 2; - */ - public Builder clearMinor() { - - minor_ = 0; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.RpcProtocolVersions.Version) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.RpcProtocolVersions.Version) - private static final io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version(); - } - - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Version parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Version(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public static final int MAX_RPC_VERSION_FIELD_NUMBER = 1; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version maxRpcVersion_; - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public boolean hasMaxRpcVersion() { - return maxRpcVersion_ != null; - } - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMaxRpcVersion() { - return maxRpcVersion_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : maxRpcVersion_; - } - /** - *
-     * Maximum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMaxRpcVersionOrBuilder() { - return getMaxRpcVersion(); - } - - public static final int MIN_RPC_VERSION_FIELD_NUMBER = 2; - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version minRpcVersion_; - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public boolean hasMinRpcVersion() { - return minRpcVersion_ != null; - } - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMinRpcVersion() { - return minRpcVersion_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : minRpcVersion_; - } - /** - *
-     * Minimum supported RPC version.
-     * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMinRpcVersionOrBuilder() { - return getMinRpcVersion(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (maxRpcVersion_ != null) { - output.writeMessage(1, getMaxRpcVersion()); - } - if (minRpcVersion_ != null) { - output.writeMessage(2, getMinRpcVersion()); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (maxRpcVersion_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, getMaxRpcVersion()); - } - if (minRpcVersion_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getMinRpcVersion()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions)) { - return super.equals(obj); - } - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions other = (io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions) obj; - - boolean result = true; - result = result && (hasMaxRpcVersion() == other.hasMaxRpcVersion()); - if (hasMaxRpcVersion()) { - result = result && getMaxRpcVersion() - .equals(other.getMaxRpcVersion()); - } - result = result && (hasMinRpcVersion() == other.hasMinRpcVersion()); - if (hasMinRpcVersion()) { - result = result && getMinRpcVersion() - .equals(other.getMinRpcVersion()); - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (hasMaxRpcVersion()) { - hash = (37 * hash) + MAX_RPC_VERSION_FIELD_NUMBER; - hash = (53 * hash) + getMaxRpcVersion().hashCode(); - } - if (hasMinRpcVersion()) { - hash = (37 * hash) + MIN_RPC_VERSION_FIELD_NUMBER; - hash = (53 * hash) + getMinRpcVersion().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - *
-     * Max and min supported RPC protocol versions.
-     * 
- * - * Protobuf type {@code grpc.gcp.RpcProtocolVersions} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:grpc.gcp.RpcProtocolVersions) - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersionsOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.class, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Builder.class); - } - - // Construct using io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - if (maxRpcVersionBuilder_ == null) { - maxRpcVersion_ = null; - } else { - maxRpcVersion_ = null; - maxRpcVersionBuilder_ = null; - } - if (minRpcVersionBuilder_ == null) { - minRpcVersion_ = null; - } else { - minRpcVersion_ = null; - minRpcVersionBuilder_ = null; - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.grpc.alts.internal.TransportSecurityCommon.internal_static_grpc_gcp_RpcProtocolVersions_descriptor; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getDefaultInstanceForType() { - return io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance(); - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions build() { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions buildPartial() { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions result = new io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions(this); - if (maxRpcVersionBuilder_ == null) { - result.maxRpcVersion_ = maxRpcVersion_; - } else { - result.maxRpcVersion_ = maxRpcVersionBuilder_.build(); - } - if (minRpcVersionBuilder_ == null) { - result.minRpcVersion_ = minRpcVersion_; - } else { - result.minRpcVersion_ = minRpcVersionBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions) { - return mergeFrom((io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions other) { - if (other == io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.getDefaultInstance()) return this; - if (other.hasMaxRpcVersion()) { - mergeMaxRpcVersion(other.getMaxRpcVersion()); - } - if (other.hasMinRpcVersion()) { - mergeMinRpcVersion(other.getMinRpcVersion()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version maxRpcVersion_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder> maxRpcVersionBuilder_; - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public boolean hasMaxRpcVersion() { - return maxRpcVersionBuilder_ != null || maxRpcVersion_ != null; - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMaxRpcVersion() { - if (maxRpcVersionBuilder_ == null) { - return maxRpcVersion_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : maxRpcVersion_; - } else { - return maxRpcVersionBuilder_.getMessage(); - } - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public Builder setMaxRpcVersion(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version value) { - if (maxRpcVersionBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - maxRpcVersion_ = value; - onChanged(); - } else { - maxRpcVersionBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public Builder setMaxRpcVersion( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder builderForValue) { - if (maxRpcVersionBuilder_ == null) { - maxRpcVersion_ = builderForValue.build(); - onChanged(); - } else { - maxRpcVersionBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public Builder mergeMaxRpcVersion(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version value) { - if (maxRpcVersionBuilder_ == null) { - if (maxRpcVersion_ != null) { - maxRpcVersion_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.newBuilder(maxRpcVersion_).mergeFrom(value).buildPartial(); - } else { - maxRpcVersion_ = value; - } - onChanged(); - } else { - maxRpcVersionBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public Builder clearMaxRpcVersion() { - if (maxRpcVersionBuilder_ == null) { - maxRpcVersion_ = null; - onChanged(); - } else { - maxRpcVersion_ = null; - maxRpcVersionBuilder_ = null; - } - - return this; - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder getMaxRpcVersionBuilder() { - - onChanged(); - return getMaxRpcVersionFieldBuilder().getBuilder(); - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMaxRpcVersionOrBuilder() { - if (maxRpcVersionBuilder_ != null) { - return maxRpcVersionBuilder_.getMessageOrBuilder(); - } else { - return maxRpcVersion_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : maxRpcVersion_; - } - } - /** - *
-       * Maximum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version max_rpc_version = 1; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder> - getMaxRpcVersionFieldBuilder() { - if (maxRpcVersionBuilder_ == null) { - maxRpcVersionBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder>( - getMaxRpcVersion(), - getParentForChildren(), - isClean()); - maxRpcVersion_ = null; - } - return maxRpcVersionBuilder_; - } - - private io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version minRpcVersion_ = null; - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder> minRpcVersionBuilder_; - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public boolean hasMinRpcVersion() { - return minRpcVersionBuilder_ != null || minRpcVersion_ != null; - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version getMinRpcVersion() { - if (minRpcVersionBuilder_ == null) { - return minRpcVersion_ == null ? io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : minRpcVersion_; - } else { - return minRpcVersionBuilder_.getMessage(); - } - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public Builder setMinRpcVersion(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version value) { - if (minRpcVersionBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - minRpcVersion_ = value; - onChanged(); - } else { - minRpcVersionBuilder_.setMessage(value); - } - - return this; - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public Builder setMinRpcVersion( - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder builderForValue) { - if (minRpcVersionBuilder_ == null) { - minRpcVersion_ = builderForValue.build(); - onChanged(); - } else { - minRpcVersionBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public Builder mergeMinRpcVersion(io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version value) { - if (minRpcVersionBuilder_ == null) { - if (minRpcVersion_ != null) { - minRpcVersion_ = - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.newBuilder(minRpcVersion_).mergeFrom(value).buildPartial(); - } else { - minRpcVersion_ = value; - } - onChanged(); - } else { - minRpcVersionBuilder_.mergeFrom(value); - } - - return this; - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public Builder clearMinRpcVersion() { - if (minRpcVersionBuilder_ == null) { - minRpcVersion_ = null; - onChanged(); - } else { - minRpcVersion_ = null; - minRpcVersionBuilder_ = null; - } - - return this; - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder getMinRpcVersionBuilder() { - - onChanged(); - return getMinRpcVersionFieldBuilder().getBuilder(); - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder getMinRpcVersionOrBuilder() { - if (minRpcVersionBuilder_ != null) { - return minRpcVersionBuilder_.getMessageOrBuilder(); - } else { - return minRpcVersion_ == null ? - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.getDefaultInstance() : minRpcVersion_; - } - } - /** - *
-       * Minimum supported RPC version.
-       * 
- * - * .grpc.gcp.RpcProtocolVersions.Version min_rpc_version = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder> - getMinRpcVersionFieldBuilder() { - if (minRpcVersionBuilder_ == null) { - minRpcVersionBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version.Builder, io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.VersionOrBuilder>( - getMinRpcVersion(), - getParentForChildren(), - isClean()); - minRpcVersion_ = null; - } - return minRpcVersionBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:grpc.gcp.RpcProtocolVersions) - } - - // @@protoc_insertion_point(class_scope:grpc.gcp.RpcProtocolVersions) - private static final io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions(); - } - - public static io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public RpcProtocolVersions parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new RpcProtocolVersions(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_RpcProtocolVersions_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_RpcProtocolVersions_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_grpc_gcp_RpcProtocolVersions_Version_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\037transport_security_common.proto\022\010grpc." + - "gcp\"\276\001\n\023RpcProtocolVersions\022>\n\017max_rpc_v" + - "ersion\030\001 \001(\0132%.grpc.gcp.RpcProtocolVersi" + - "ons.Version\022>\n\017min_rpc_version\030\002 \001(\0132%.g" + - "rpc.gcp.RpcProtocolVersions.Version\032\'\n\007V" + - "ersion\022\r\n\005major\030\001 \001(\r\022\r\n\005minor\030\002 \001(\r*Q\n\r" + - "SecurityLevel\022\021\n\rSECURITY_NONE\020\000\022\022\n\016INTE" + - "GRITY_ONLY\020\001\022\031\n\025INTEGRITY_AND_PRIVACY\020\002B" + - "\027\n\025io.grpc.alts.internalb\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_grpc_gcp_RpcProtocolVersions_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_grpc_gcp_RpcProtocolVersions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_RpcProtocolVersions_descriptor, - new java.lang.String[] { "MaxRpcVersion", "MinRpcVersion", }); - internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor = - internal_static_grpc_gcp_RpcProtocolVersions_descriptor.getNestedTypes().get(0); - internal_static_grpc_gcp_RpcProtocolVersions_Version_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_grpc_gcp_RpcProtocolVersions_Version_descriptor, - new java.lang.String[] { "Major", "Minor", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java b/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java index 43301efdc40..ca33f8b00b9 100644 --- a/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java +++ b/alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,50 +16,29 @@ package io.grpc.alts; -import static com.google.common.base.Preconditions.checkArgument; - import com.google.common.annotations.VisibleForTesting; -import io.grpc.CallOptions; -import io.grpc.ClientCall; -import io.grpc.ConnectivityState; import io.grpc.ExperimentalApi; -import io.grpc.ForwardingChannelBuilder; +import io.grpc.ForwardingChannelBuilder2; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.grpc.MethodDescriptor; -import io.grpc.alts.internal.AltsClientOptions; -import io.grpc.alts.internal.AltsProtocolNegotiator; -import io.grpc.alts.internal.AltsTsiHandshaker; -import io.grpc.alts.internal.HandshakerServiceGrpc; -import io.grpc.alts.internal.RpcProtocolVersionsUtil; -import io.grpc.alts.internal.TsiHandshaker; -import io.grpc.alts.internal.TsiHandshakerFactory; import io.grpc.internal.GrpcUtil; -import io.grpc.internal.ProxyParameters; import io.grpc.netty.InternalNettyChannelBuilder; -import io.grpc.netty.InternalNettyChannelBuilder.TransportCreationParamsFilter; -import io.grpc.netty.InternalNettyChannelBuilder.TransportCreationParamsFilterFactory; +import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; import io.grpc.netty.NettyChannelBuilder; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; /** * ALTS version of {@code ManagedChannelBuilder}. This class sets up a secure and authenticated - * commmunication between two cloud VMs using ALTS. + * communication between two cloud VMs using ALTS. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") -public final class AltsChannelBuilder extends ForwardingChannelBuilder { - +public final class AltsChannelBuilder extends ForwardingChannelBuilder2 { private final NettyChannelBuilder delegate; - private final AltsClientOptions.Builder handshakerOptionsBuilder = - new AltsClientOptions.Builder(); - private TcpfFactory tcpfFactoryForTest; - private boolean enableUntrustedAlts; + private final AltsChannelCredentials.Builder credentialsBuilder = + new AltsChannelCredentials.Builder(); /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ - public static final AltsChannelBuilder forTarget(String target) { + public static AltsChannelBuilder forTarget(String target) { return new AltsChannelBuilder(target); } @@ -69,19 +48,7 @@ public static AltsChannelBuilder forAddress(String name, int port) { } private AltsChannelBuilder(String target) { - delegate = - NettyChannelBuilder.forTarget(target) - .keepAliveTime(20, TimeUnit.SECONDS) - .keepAliveTimeout(10, TimeUnit.SECONDS) - .keepAliveWithoutCalls(true); - handshakerOptionsBuilder.setRpcProtocolVersions( - RpcProtocolVersionsUtil.getRpcProtocolVersions()); - } - - /** The server service account name for secure name checking. */ - public AltsChannelBuilder withSecureNamingTarget(String targetName) { - handshakerOptionsBuilder.setTargetName(targetName); - return this; + delegate = NettyChannelBuilder.forTarget(target); } /** @@ -89,7 +56,7 @@ public AltsChannelBuilder withSecureNamingTarget(String targetName) { * service account in the handshaker result. Otherwise, the handshake fails. */ public AltsChannelBuilder addTargetServiceAccount(String targetServiceAccount) { - handshakerOptionsBuilder.addTargetServiceAccount(targetServiceAccount); + credentialsBuilder.addTargetServiceAccount(targetServiceAccount); return this; } @@ -98,13 +65,13 @@ public AltsChannelBuilder addTargetServiceAccount(String targetServiceAccount) { * is running on Google Cloud Platform. */ public AltsChannelBuilder enableUntrustedAltsForTesting() { - enableUntrustedAlts = true; + credentialsBuilder.enableUntrustedAltsForTesting(); return this; } /** Sets a new handshaker service address for testing. */ public AltsChannelBuilder setHandshakerAddressForTesting(String handshakerAddress) { - HandshakerServiceChannel.setHandshakerAddressForTesting(handshakerAddress); + credentialsBuilder.setHandshakerAddressForTesting(handshakerAddress); return this; } @@ -115,143 +82,16 @@ protected NettyChannelBuilder delegate() { @Override public ManagedChannel build() { - CheckGcpEnvironment.check(enableUntrustedAlts); - TcpfFactory tcpfFactory = new TcpfFactory(); - InternalNettyChannelBuilder.setDynamicTransportParamsFactory(delegate(), tcpfFactory); - - tcpfFactoryForTest = tcpfFactory; - - return new AltsChannel(delegate().build()); - } + InternalNettyChannelBuilder.setProtocolNegotiatorFactory( + delegate(), + credentialsBuilder.buildProtocolNegotiatorFactory()); - @VisibleForTesting - @Nullable - TransportCreationParamsFilterFactory getTcpfFactoryForTest() { - return tcpfFactoryForTest; + return delegate().build(); } @VisibleForTesting @Nullable - AltsClientOptions getAltsClientOptionsForTest() { - if (tcpfFactoryForTest == null) { - return null; - } - return tcpfFactoryForTest.handshakerOptions; - } - - private final class TcpfFactory implements TransportCreationParamsFilterFactory { - final AltsClientOptions handshakerOptions = handshakerOptionsBuilder.build(); - - private final TsiHandshakerFactory altsHandshakerFactory = - new TsiHandshakerFactory() { - @Override - public TsiHandshaker newHandshaker() { - // Used the shared grpc channel to connecting to the ALTS handshaker service. - ManagedChannel channel = HandshakerServiceChannel.get(); - return AltsTsiHandshaker.newClient( - HandshakerServiceGrpc.newStub(channel), handshakerOptions); - } - }; - - @Override - public TransportCreationParamsFilter create( - final SocketAddress serverAddress, - final String authority, - final String userAgent, - final ProxyParameters proxy) { - checkArgument( - serverAddress instanceof InetSocketAddress, - "%s must be a InetSocketAddress", - serverAddress); - final AltsProtocolNegotiator negotiator = - AltsProtocolNegotiator.create(altsHandshakerFactory); - return new TransportCreationParamsFilter() { - @Override - public SocketAddress getTargetServerAddress() { - return serverAddress; - } - - @Override - public String getAuthority() { - return authority; - } - - @Override - public String getUserAgent() { - return userAgent; - } - - @Override - public AltsProtocolNegotiator getProtocolNegotiator() { - return negotiator; - } - }; - } - } - - static final class AltsChannel extends ManagedChannel { - private final ManagedChannel delegate; - - AltsChannel(ManagedChannel delegate) { - this.delegate = delegate; - } - - @Override - public ConnectivityState getState(boolean requestConnection) { - return delegate.getState(requestConnection); - } - - @Override - public void notifyWhenStateChanged(ConnectivityState source, Runnable callback) { - delegate.notifyWhenStateChanged(source, callback); - } - - @Override - public AltsChannel shutdown() { - delegate.shutdown(); - return this; - } - - @Override - public boolean isShutdown() { - return delegate.isShutdown(); - } - - @Override - public boolean isTerminated() { - return delegate.isTerminated(); - } - - @Override - public AltsChannel shutdownNow() { - delegate.shutdownNow(); - return this; - } - - @Override - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { - return delegate.awaitTermination(timeout, unit); - } - - @Override - public ClientCall newCall( - MethodDescriptor methodDescriptor, CallOptions callOptions) { - return delegate.newCall(methodDescriptor, callOptions); - } - - @Override - public String authority() { - return delegate.authority(); - } - - @Override - public void resetConnectBackoff() { - delegate.resetConnectBackoff(); - } - - @Override - public void enterIdle() { - delegate.enterIdle(); - } + ProtocolNegotiator getProtocolNegotiatorForTest() { + return credentialsBuilder.buildProtocolNegotiatorFactory().newNegotiator(); } } diff --git a/alts/src/main/java/io/grpc/alts/AltsChannelCredentials.java b/alts/src/main/java/io/grpc/alts/AltsChannelCredentials.java new file mode 100644 index 00000000000..e12344f73d7 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/AltsChannelCredentials.java @@ -0,0 +1,159 @@ +/* + * Copyright 2020 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import com.google.common.collect.ImmutableList; +import io.grpc.Channel; +import io.grpc.ChannelCredentials; +import io.grpc.ExperimentalApi; +import io.grpc.Status; +import io.grpc.alts.internal.AltsProtocolNegotiator.ClientAltsProtocolNegotiatorFactory; +import io.grpc.internal.ObjectPool; +import io.grpc.internal.SharedResourcePool; +import io.grpc.netty.GrpcHttp2ConnectionHandler; +import io.grpc.netty.InternalNettyChannelCredentials; +import io.grpc.netty.InternalProtocolNegotiator; +import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerAdapter; +import io.netty.channel.ChannelHandlerContext; +import io.netty.util.AsciiString; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Provides secure and authenticated communication between two cloud VMs using ALTS. + */ +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") +public final class AltsChannelCredentials { + private static final Logger logger = Logger.getLogger(AltsChannelCredentials.class.getName()); + + private AltsChannelCredentials() {} + + public static ChannelCredentials create() { + return newBuilder().build(); + } + + public static Builder newBuilder() { + return new Builder(); + } + + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") + public static final class Builder { + private final ImmutableList.Builder targetServiceAccountsBuilder = + ImmutableList.builder(); + private ObjectPool handshakerChannelPool = + SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL); + private boolean enableUntrustedAlts; + + /** + * Adds an expected target service accounts. One of the added service accounts should match peer + * service account in the handshaker result. Otherwise, the handshake fails. + */ + public Builder addTargetServiceAccount(String targetServiceAccount) { + targetServiceAccountsBuilder.add(targetServiceAccount); + return this; + } + + /** + * Enables untrusted ALTS for testing. If this function is called, we will not check whether + * ALTS is running on Google Cloud Platform. + */ + public Builder enableUntrustedAltsForTesting() { + enableUntrustedAlts = true; + return this; + } + + /** Sets a new handshaker service address for testing. */ + public Builder setHandshakerAddressForTesting(String handshakerAddress) { + // Instead of using the default shared channel to the handshaker service, create a separate + // resource to the test address. + handshakerChannelPool = + SharedResourcePool.forResource( + HandshakerServiceChannel.getHandshakerChannelForTesting(handshakerAddress)); + return this; + } + + public ChannelCredentials build() { + return InternalNettyChannelCredentials.create(buildProtocolNegotiatorFactory()); + } + + InternalProtocolNegotiator.ClientFactory buildProtocolNegotiatorFactory() { + if (!InternalCheckGcpEnvironment.isOnGcp()) { + if (enableUntrustedAlts) { + logger.log( + Level.WARNING, + "Untrusted ALTS mode is enabled and we cannot guarantee the trustworthiness of the " + + "ALTS handshaker service"); + } else { + Status status = Status.INTERNAL.withDescription( + "ALTS is only allowed to run on Google Cloud Platform"); + return new FailingProtocolNegotiatorFactory(status); + } + } + + return new ClientAltsProtocolNegotiatorFactory( + targetServiceAccountsBuilder.build(), handshakerChannelPool); + } + } + + private static final class FailingProtocolNegotiatorFactory + implements InternalProtocolNegotiator.ClientFactory { + private final Status status; + + public FailingProtocolNegotiatorFactory(Status status) { + this.status = status; + } + + @Override + public ProtocolNegotiator newNegotiator() { + return new FailingProtocolNegotiator(status); + } + + @Override + public int getDefaultPort() { + return 443; + } + } + + private static final AsciiString SCHEME = AsciiString.of("https"); + + static final class FailingProtocolNegotiator implements ProtocolNegotiator { + private final Status status; + + public FailingProtocolNegotiator(Status status) { + this.status = status; + } + + @Override + public AsciiString scheme() { + return SCHEME; + } + + @Override + public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { + return new ChannelHandlerAdapter() { + @Override public void handlerAdded(ChannelHandlerContext ctx) { + ctx.fireExceptionCaught(status.asRuntimeException()); + } + }; + } + + @Override + public void close() {} + } +} diff --git a/alts/src/main/java/io/grpc/alts/AltsContext.java b/alts/src/main/java/io/grpc/alts/AltsContext.java new file mode 100644 index 00000000000..7680de4160e --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/AltsContext.java @@ -0,0 +1,91 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.ExperimentalApi; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.HandshakerResult; +import io.grpc.alts.internal.Identity; + +/** {@code AltsContext} contains security-related information on the ALTS channel. */ +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/7864") +public final class AltsContext { + + private final AltsInternalContext wrapped; + + AltsContext(AltsInternalContext wrapped) { + this.wrapped = wrapped; + } + + /** + * Creates an {@code AltsContext} for testing purposes. + * @param peerServiceAccount the peer service account of the to be created {@code AltsContext} + * @param localServiceAccount the local service account of the to be created {@code AltsContext} + * @return the created {@code AltsContext} + */ + public static AltsContext createTestInstance(String peerServiceAccount, + String localServiceAccount) { + return new AltsContext(new AltsInternalContext(HandshakerResult.newBuilder() + .setPeerIdentity(Identity.newBuilder().setServiceAccount(peerServiceAccount).build()) + .setLocalIdentity(Identity.newBuilder().setServiceAccount(localServiceAccount).build()) + .build())); + } + + /** + * Get security level. + * + * @return the context's security level. + */ + public SecurityLevel getSecurityLevel() { + switch (wrapped.getSecurityLevel()) { + case SECURITY_NONE: + return SecurityLevel.SECURITY_NONE; + case INTEGRITY_ONLY: + return SecurityLevel.INTEGRITY_ONLY; + case INTEGRITY_AND_PRIVACY: + return SecurityLevel.INTEGRITY_AND_PRIVACY; + default: + return SecurityLevel.UNKNOWN; + } + } + + /** + * Get peer service account. + * + * @return the context's peer service account. + */ + public String getPeerServiceAccount() { + return wrapped.getPeerServiceAccount(); + } + + /** + * Get local service account. + * + * @return the context's local service account. + */ + public String getLocalServiceAccount() { + return wrapped.getLocalServiceAccount(); + } + + /** SecurityLevel of the ALTS channel. */ + public enum SecurityLevel { + UNKNOWN, + SECURITY_NONE, + INTEGRITY_ONLY, + INTEGRITY_AND_PRIVACY, + } +} diff --git a/alts/src/main/java/io/grpc/alts/AltsContextUtil.java b/alts/src/main/java/io/grpc/alts/AltsContextUtil.java new file mode 100644 index 00000000000..f45179bbd91 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/AltsContextUtil.java @@ -0,0 +1,99 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.Attributes; +import io.grpc.ClientCall; +import io.grpc.ExperimentalApi; +import io.grpc.ServerCall; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.AltsProtocolNegotiator; + +/** Utility class for {@link AltsContext}. */ +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/7864") +public final class AltsContextUtil { + + private AltsContextUtil() {} + + /** + * Creates an {@link AltsContext} from ALTS context information in the {@link ServerCall}. + * + * @param call the {@link ServerCall} containing the ALTS information + * @return the created {@link AltsContext} + * @throws IllegalArgumentException if the {@link ServerCall} has no ALTS information. + */ + public static AltsContext createFrom(ServerCall call) { + return createFrom(call.getAttributes()); + } + + /** + * Creates an {@link AltsContext} from ALTS context information in the {@link ClientCall}. + * + * @param call the {@link ClientCall} containing the ALTS information + * @return the created {@link AltsContext} + * @throws IllegalArgumentException if the {@link ClientCall} has no ALTS information. + */ + public static AltsContext createFrom(ClientCall call) { + return createFrom(call.getAttributes()); + } + + /** + * Creates an {@link AltsContext} from ALTS context information in the {@link Attributes}. + * + * @param attributes the {@link Attributes} containing the ALTS information + * @return the created {@link AltsContext} + * @throws IllegalArgumentException if the {@link Attributes} has no ALTS information. + */ + public static AltsContext createFrom(Attributes attributes) { + Object authContext = attributes.get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY); + if (!(authContext instanceof AltsInternalContext)) { + throw new IllegalArgumentException("No ALTS context information found"); + } + return new AltsContext((AltsInternalContext) authContext); + } + + /** + * Checks if the {@link ServerCall} contains ALTS information. + * + * @param call the {@link ServerCall} to check + * @return true, if the {@link ServerCall} contains ALTS information and false otherwise. + */ + public static boolean check(ServerCall call) { + return check(call.getAttributes()); + } + + /** + * Checks if the {@link ClientCall} contains ALTS information. + * + * @param call the {@link ClientCall} to check + * @return true, if the {@link ClientCall} contains ALTS information and false otherwise. + */ + public static boolean check(ClientCall call) { + return check(call.getAttributes()); + } + + /** + * Checks if the {@link Attributes} contains ALTS information. + * + * @param attributes the {@link Attributes} to check + * @return true, if the {@link Attributes} contains ALTS information and false otherwise. + */ + public static boolean check(Attributes attributes) { + Object authContext = attributes.get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY); + return authContext instanceof AltsInternalContext; + } +} diff --git a/alts/src/main/java/io/grpc/alts/AltsServerBuilder.java b/alts/src/main/java/io/grpc/alts/AltsServerBuilder.java index 058958510cc..e307fd1c63a 100644 --- a/alts/src/main/java/io/grpc/alts/AltsServerBuilder.java +++ b/alts/src/main/java/io/grpc/alts/AltsServerBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,25 +20,17 @@ import io.grpc.CompressorRegistry; import io.grpc.DecompressorRegistry; import io.grpc.ExperimentalApi; +import io.grpc.ForwardingServerBuilder; import io.grpc.HandlerRegistry; import io.grpc.Server; import io.grpc.ServerBuilder; import io.grpc.ServerInterceptor; import io.grpc.ServerServiceDefinition; -import io.grpc.ServerStreamTracer.Factory; +import io.grpc.ServerStreamTracer; import io.grpc.ServerTransportFilter; -import io.grpc.alts.internal.AltsHandshakerOptions; -import io.grpc.alts.internal.AltsProtocolNegotiator; -import io.grpc.alts.internal.AltsTsiHandshaker; -import io.grpc.alts.internal.HandshakerServiceGrpc; -import io.grpc.alts.internal.RpcProtocolVersionsUtil; -import io.grpc.alts.internal.TsiHandshaker; -import io.grpc.alts.internal.TsiHandshakerFactory; import io.grpc.netty.NettyServerBuilder; import java.io.File; -import java.io.IOException; import java.net.InetSocketAddress; -import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; @@ -47,10 +39,10 @@ * a production server on Google Cloud Platform. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") -public final class AltsServerBuilder extends ServerBuilder { - +public final class AltsServerBuilder extends ForwardingServerBuilder { private final NettyServerBuilder delegate; - private boolean enableUntrustedAlts; + private final AltsServerCredentials.Builder credentialsBuilder = + new AltsServerCredentials.Builder(); private AltsServerBuilder(NettyServerBuilder nettyDelegate) { this.delegate = nettyDelegate; @@ -58,13 +50,7 @@ private AltsServerBuilder(NettyServerBuilder nettyDelegate) { /** Creates a gRPC server builder for the given port. */ public static AltsServerBuilder forPort(int port) { - NettyServerBuilder nettyDelegate = - NettyServerBuilder.forAddress(new InetSocketAddress(port)) - .maxConnectionIdle(1, TimeUnit.HOURS) - .keepAliveTime(270, TimeUnit.SECONDS) - .keepAliveTimeout(20, TimeUnit.SECONDS) - .permitKeepAliveTime(10, TimeUnit.SECONDS) - .permitKeepAliveWithoutCalls(true); + NettyServerBuilder nettyDelegate = NettyServerBuilder.forAddress(new InetSocketAddress(port)); return new AltsServerBuilder(nettyDelegate); } @@ -73,16 +59,21 @@ public static AltsServerBuilder forPort(int port) { * is running on Google Cloud Platform. */ public AltsServerBuilder enableUntrustedAltsForTesting() { - enableUntrustedAlts = true; + credentialsBuilder.enableUntrustedAltsForTesting(); return this; } /** Sets a new handshaker service address for testing. */ public AltsServerBuilder setHandshakerAddressForTesting(String handshakerAddress) { - HandshakerServiceChannel.setHandshakerAddressForTesting(handshakerAddress); + credentialsBuilder.setHandshakerAddressForTesting(handshakerAddress); return this; } + @Override + protected ServerBuilder delegate() { + return delegate; + } + /** {@inheritDoc} */ @Override public AltsServerBuilder handshakeTimeout(long timeout, TimeUnit unit) { @@ -99,7 +90,7 @@ public AltsServerBuilder directExecutor() { /** {@inheritDoc} */ @Override - public AltsServerBuilder addStreamTracerFactory(Factory factory) { + public AltsServerBuilder addStreamTracerFactory(ServerStreamTracer.Factory factory) { delegate.addStreamTracerFactory(factory); return this; } @@ -169,84 +160,7 @@ public AltsServerBuilder intercept(ServerInterceptor interceptor) { /** {@inheritDoc} */ @Override public Server build() { - CheckGcpEnvironment.check(enableUntrustedAlts); - delegate.protocolNegotiator( - AltsProtocolNegotiator.create( - new TsiHandshakerFactory() { - @Override - public TsiHandshaker newHandshaker() { - // Used the shared grpc channel to connecting to the ALTS handshaker service. - return AltsTsiHandshaker.newServer( - HandshakerServiceGrpc.newStub(HandshakerServiceChannel.get()), - new AltsHandshakerOptions(RpcProtocolVersionsUtil.getRpcProtocolVersions())); - } - })); - return new AltsServer(delegate.build()); - } - - static final class AltsServer extends io.grpc.Server { - private final Server delegate; - - AltsServer(Server delegate) { - this.delegate = delegate; - } - - @Override - public List getImmutableServices() { - return delegate.getImmutableServices(); - } - - @Override - public List getMutableServices() { - return delegate.getMutableServices(); - } - - @Override - public int getPort() { - return delegate.getPort(); - } - - @Override - public List getServices() { - return delegate.getServices(); - } - - @Override - public Server start() throws IOException { - delegate.start(); - return this; - } - - @Override - public Server shutdown() { - delegate.shutdown(); - return this; - } - - @Override - public Server shutdownNow() { - delegate.shutdownNow(); - return this; - } - - @Override - public boolean isShutdown() { - return delegate.isShutdown(); - } - - @Override - public boolean isTerminated() { - return delegate.isTerminated(); - } - - @Override - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { - return delegate.awaitTermination(timeout, unit); - } - - @Override - public void awaitTermination() throws InterruptedException { - delegate.awaitTermination(); - } + delegate.protocolNegotiator(credentialsBuilder.buildProtocolNegotiator()); + return delegate.build(); } } diff --git a/alts/src/main/java/io/grpc/alts/AltsServerCredentials.java b/alts/src/main/java/io/grpc/alts/AltsServerCredentials.java new file mode 100644 index 00000000000..36dc9f6a4ae --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/AltsServerCredentials.java @@ -0,0 +1,95 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.Channel; +import io.grpc.ExperimentalApi; +import io.grpc.ServerCredentials; +import io.grpc.Status; +import io.grpc.alts.internal.AltsProtocolNegotiator; +import io.grpc.internal.ObjectPool; +import io.grpc.internal.SharedResourcePool; +import io.grpc.netty.InternalNettyServerCredentials; +import io.grpc.netty.InternalProtocolNegotiator; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * gRPC secure server builder used for ALTS. This class adds on the necessary ALTS support to create + * a production server on Google Cloud Platform. + */ +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") +public final class AltsServerCredentials { + private static final Logger logger = Logger.getLogger(AltsServerCredentials.class.getName()); + + private AltsServerCredentials() {} + + public static ServerCredentials create() { + return newBuilder().build(); + } + + public static Builder newBuilder() { + return new Builder(); + } + + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") + public static final class Builder { + private ObjectPool handshakerChannelPool = + SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL); + private boolean enableUntrustedAlts; + + /** + * Enables untrusted ALTS for testing. If this function is called, we will not check whether + * ALTS is running on Google Cloud Platform. + */ + public Builder enableUntrustedAltsForTesting() { + enableUntrustedAlts = true; + return this; + } + + /** Sets a new handshaker service address for testing. */ + public Builder setHandshakerAddressForTesting(String handshakerAddress) { + // Instead of using the default shared channel to the handshaker service, create a separate + // resource to the test address. + handshakerChannelPool = + SharedResourcePool.forResource( + HandshakerServiceChannel.getHandshakerChannelForTesting(handshakerAddress)); + return this; + } + + public ServerCredentials build() { + return InternalNettyServerCredentials.create(buildProtocolNegotiator()); + } + + InternalProtocolNegotiator.ProtocolNegotiator buildProtocolNegotiator() { + if (!InternalCheckGcpEnvironment.isOnGcp()) { + if (enableUntrustedAlts) { + logger.log( + Level.WARNING, + "Untrusted ALTS mode is enabled and we cannot guarantee the trustworthiness of the " + + "ALTS handshaker service"); + } else { + Status status = Status.INTERNAL.withDescription( + "ALTS is only allowed to run on Google Cloud Platform"); + return new AltsChannelCredentials.FailingProtocolNegotiator(status); + } + } + + return AltsProtocolNegotiator.serverAltsProtocolNegotiator(handshakerChannelPool); + } + } +} diff --git a/alts/src/main/java/io/grpc/alts/AuthorizationUtil.java b/alts/src/main/java/io/grpc/alts/AuthorizationUtil.java new file mode 100644 index 00000000000..53e45105d9b --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/AuthorizationUtil.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.ServerCall; +import io.grpc.Status; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.AltsProtocolNegotiator; +import java.util.Collection; + +/** Utility class for ALTS client authorization. */ +public final class AuthorizationUtil { + + private AuthorizationUtil() {} + + /** + * Given a server call, performs client authorization check, i.e., checks if the client service + * account matches one of the expected service accounts. It returns OK if client is authorized and + * an error otherwise. + */ + public static Status clientAuthorizationCheck( + ServerCall call, Collection expectedServiceAccounts) { + AltsInternalContext altsContext = + (AltsInternalContext) call.getAttributes().get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY); + if (altsContext == null) { + return Status.PERMISSION_DENIED.withDescription("Peer ALTS AuthContext not found"); + } + if (expectedServiceAccounts.contains(altsContext.getPeerServiceAccount())) { + return Status.OK; + } + return Status.PERMISSION_DENIED.withDescription( + "Client " + altsContext.getPeerServiceAccount() + " is not authorized"); + } +} diff --git a/alts/src/main/java/io/grpc/alts/CheckGcpEnvironment.java b/alts/src/main/java/io/grpc/alts/CheckGcpEnvironment.java deleted file mode 100644 index 58b0503d254..00000000000 --- a/alts/src/main/java/io/grpc/alts/CheckGcpEnvironment.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2018, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.alts; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import com.google.common.annotations.VisibleForTesting; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.lang3.SystemUtils; - -/** Class for checking if the system is running on Google Cloud Platform (GCP). */ -final class CheckGcpEnvironment { - private static final Logger logger = Logger.getLogger(CheckGcpEnvironment.class.getName()); - private static final String DMI_PRODUCT_NAME = "/sys/class/dmi/id/product_name"; - private static final String WINDOWS_COMMAND = "powershell.exe"; - private static Boolean cachedResult = null; - - // Construct me not! - private CheckGcpEnvironment() {} - - public static void check(boolean enableUntrustedAlts) { - if (enableUntrustedAlts) { - logger.log( - Level.WARNING, - "Untrusted ALTS mode is enabled and we cannot guarantee the trustworthiness of the ALTS " - + "handshaker service."); - } else if (!isOnGcp()) { - throw new RuntimeException("ALTS is only allowed to run on Google Cloud Platform."); - } - } - - private static synchronized boolean isOnGcp() { - if (cachedResult == null) { - cachedResult = isRunningOnGcp(); - } - return cachedResult; - } - - @VisibleForTesting - static boolean checkProductNameOnLinux(BufferedReader reader) throws IOException { - String name = reader.readLine().trim(); - return name.equals("Google") || name.equals("Google Compute Engine"); - } - - @VisibleForTesting - static boolean checkBiosDataOnWindows(BufferedReader reader) throws IOException { - String line; - while ((line = reader.readLine()) != null) { - if (line.startsWith("Manufacturer")) { - String name = line.substring(line.indexOf(':') + 1).trim(); - return name.equals("Google"); - } - } - return false; - } - - private static boolean isRunningOnGcp() { - try { - if (SystemUtils.IS_OS_LINUX) { - // Checks GCE residency on Linux platform. - return checkProductNameOnLinux(Files.newBufferedReader(Paths.get(DMI_PRODUCT_NAME), UTF_8)); - } else if (SystemUtils.IS_OS_WINDOWS) { - // Checks GCE residency on Windows platform. - Process p = - new ProcessBuilder() - .command(WINDOWS_COMMAND, "Get-WmiObject", "-Class", "Win32_BIOS") - .start(); - return checkBiosDataOnWindows( - new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8))); - } - } catch (IOException e) { - logger.log(Level.WARNING, "Fail to read platform information: ", e); - return false; - } - // Platforms other than Linux and Windows are not supported. - return false; - } -} diff --git a/alts/src/main/java/io/grpc/alts/ComputeEngineChannelBuilder.java b/alts/src/main/java/io/grpc/alts/ComputeEngineChannelBuilder.java new file mode 100644 index 00000000000..b5ee6a8d362 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/ComputeEngineChannelBuilder.java @@ -0,0 +1,52 @@ +/* + * Copyright 2019 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.ForwardingChannelBuilder; +import io.grpc.ManagedChannelBuilder; +import io.grpc.internal.GrpcUtil; +import io.grpc.netty.NettyChannelBuilder; + +/** + * {@code ManagedChannelBuilder} for Google Compute Engine. This class sets up a secure channel + * using ALTS if applicable and using TLS as fallback. + */ +public final class ComputeEngineChannelBuilder + extends ForwardingChannelBuilder { + + private final NettyChannelBuilder delegate; + + private ComputeEngineChannelBuilder(String target) { + delegate = NettyChannelBuilder.forTarget(target, ComputeEngineChannelCredentials.create()); + } + + /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ + public static ComputeEngineChannelBuilder forTarget(String target) { + return new ComputeEngineChannelBuilder(target); + } + + /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ + public static ComputeEngineChannelBuilder forAddress(String name, int port) { + return forTarget(GrpcUtil.authorityFromHostAndPort(name, port)); + } + + @Override + @SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI. + protected NettyChannelBuilder delegate() { + return delegate; + } +} diff --git a/alts/src/main/java/io/grpc/alts/ComputeEngineChannelCredentials.java b/alts/src/main/java/io/grpc/alts/ComputeEngineChannelCredentials.java new file mode 100644 index 00000000000..518642a675d --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/ComputeEngineChannelCredentials.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import com.google.auth.oauth2.ComputeEngineCredentials; +import com.google.common.collect.ImmutableList; +import io.grpc.CallCredentials; +import io.grpc.ChannelCredentials; +import io.grpc.CompositeChannelCredentials; +import io.grpc.Status; +import io.grpc.alts.internal.AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory; +import io.grpc.auth.MoreCallCredentials; +import io.grpc.internal.SharedResourcePool; +import io.grpc.netty.GrpcSslContexts; +import io.grpc.netty.InternalNettyChannelCredentials; +import io.grpc.netty.InternalProtocolNegotiator; +import io.netty.handler.ssl.SslContext; +import javax.net.ssl.SSLException; + +/** + * Credentials appropriate to contact Google services when running on Google Compute Engine. This + * class sets up a secure channel using ALTS if applicable and using TLS as fallback. It is a subset + * of the functionality provided by {@link GoogleDefaultChannelCredentials}. + */ +public final class ComputeEngineChannelCredentials { + private ComputeEngineChannelCredentials() {} + + /** + * Creates credentials for Google Compute Engine. This class sets up a secure channel using ALTS + * if applicable and using TLS as fallback. + */ + public static ChannelCredentials create() { + ChannelCredentials nettyCredentials = + InternalNettyChannelCredentials.create(createClientFactory()); + CallCredentials callCredentials; + if (InternalCheckGcpEnvironment.isOnGcp()) { + callCredentials = MoreCallCredentials.from(ComputeEngineCredentials.create()); + } else { + callCredentials = new FailingCallCredentials( + Status.INTERNAL.withDescription( + "Compute Engine Credentials can only be used on Google Cloud Platform")); + } + return CompositeChannelCredentials.create(nettyCredentials, callCredentials); + } + + private static InternalProtocolNegotiator.ClientFactory createClientFactory() { + SslContext sslContext; + try { + sslContext = GrpcSslContexts.forClient().build(); + } catch (SSLException e) { + throw new RuntimeException(e); + } + return new GoogleDefaultProtocolNegotiatorFactory( + /* targetServiceAccounts= */ ImmutableList.of(), + SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL), + sslContext); + } +} diff --git a/alts/src/main/java/io/grpc/alts/DualCallCredentials.java b/alts/src/main/java/io/grpc/alts/DualCallCredentials.java new file mode 100644 index 00000000000..08104712e65 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/DualCallCredentials.java @@ -0,0 +1,46 @@ +/* + * Copyright 2024 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.CallCredentials; +import java.util.concurrent.Executor; + +/** + * {@code CallCredentials} that will pick the right credentials based on whether the established + * connection is ALTS or TLS. + */ +final class DualCallCredentials extends CallCredentials { + private final CallCredentials tlsCallCredentials; + private final CallCredentials altsCallCredentials; + + public DualCallCredentials(CallCredentials tlsCallCreds, CallCredentials altsCallCreds) { + tlsCallCredentials = tlsCallCreds; + altsCallCredentials = altsCallCreds; + } + + @Override + public void applyRequestMetadata( + CallCredentials.RequestInfo requestInfo, + Executor appExecutor, + CallCredentials.MetadataApplier applier) { + if (AltsContextUtil.check(requestInfo.getTransportAttrs())) { + altsCallCredentials.applyRequestMetadata(requestInfo, appExecutor, applier); + } else { + tlsCallCredentials.applyRequestMetadata(requestInfo, appExecutor, applier); + } + } +} diff --git a/alts/src/main/java/io/grpc/alts/FailingCallCredentials.java b/alts/src/main/java/io/grpc/alts/FailingCallCredentials.java new file mode 100644 index 00000000000..3c59c5b6d09 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/FailingCallCredentials.java @@ -0,0 +1,41 @@ +/* + * Copyright 2020 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import com.google.common.base.Preconditions; +import io.grpc.CallCredentials; +import io.grpc.Status; +import java.util.concurrent.Executor; + +/** + * {@code CallCredentials} that always fail the RPC. + */ +final class FailingCallCredentials extends CallCredentials { + private final Status status; + + public FailingCallCredentials(Status status) { + this.status = Preconditions.checkNotNull(status, "status"); + } + + @Override + public void applyRequestMetadata( + CallCredentials.RequestInfo requestInfo, + Executor appExecutor, + CallCredentials.MetadataApplier applier) { + applier.fail(status); + } +} diff --git a/alts/src/main/java/io/grpc/alts/FailingClientCall.java b/alts/src/main/java/io/grpc/alts/FailingClientCall.java new file mode 100644 index 00000000000..ab674364ee6 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/FailingClientCall.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.ClientCall; +import io.grpc.Metadata; +import io.grpc.Status; + +/** An implementation of {@link ClientCall} that fails when started. */ +final class FailingClientCall extends ClientCall { + + private final Status error; + + public FailingClientCall(Status error) { + this.error = error; + } + + @Override + public void start(ClientCall.Listener listener, Metadata headers) { + listener.onClose(error, new Metadata()); + } + + @Override + public void request(int numMessages) {} + + @Override + public void cancel(String message, Throwable cause) {} + + @Override + public void halfClose() {} + + @Override + public void sendMessage(ReqT message) {} +} diff --git a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java new file mode 100644 index 00000000000..c78b94417c4 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelBuilder.java @@ -0,0 +1,52 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import io.grpc.ForwardingChannelBuilder; +import io.grpc.ManagedChannelBuilder; +import io.grpc.internal.GrpcUtil; +import io.grpc.netty.NettyChannelBuilder; + +/** + * Google default version of {@code ManagedChannelBuilder}. This class sets up a secure channel + * using ALTS if applicable and using TLS as fallback. + */ +public final class GoogleDefaultChannelBuilder + extends ForwardingChannelBuilder { + + private final NettyChannelBuilder delegate; + + private GoogleDefaultChannelBuilder(String target) { + delegate = NettyChannelBuilder.forTarget(target, GoogleDefaultChannelCredentials.create()); + } + + /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ + public static GoogleDefaultChannelBuilder forTarget(String target) { + return new GoogleDefaultChannelBuilder(target); + } + + /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ + public static GoogleDefaultChannelBuilder forAddress(String name, int port) { + return forTarget(GrpcUtil.authorityFromHostAndPort(name, port)); + } + + @Override + @SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI. + protected NettyChannelBuilder delegate() { + return delegate; + } +} diff --git a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java new file mode 100644 index 00000000000..1b5880120a4 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java @@ -0,0 +1,118 @@ +/* + * Copyright 2020 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import com.google.auth.oauth2.GoogleCredentials; +import com.google.common.collect.ImmutableList; +import io.grpc.CallCredentials; +import io.grpc.ChannelCredentials; +import io.grpc.CompositeChannelCredentials; +import io.grpc.Status; +import io.grpc.alts.internal.AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory; +import io.grpc.auth.MoreCallCredentials; +import io.grpc.internal.SharedResourcePool; +import io.grpc.netty.GrpcSslContexts; +import io.grpc.netty.InternalNettyChannelCredentials; +import io.grpc.netty.InternalProtocolNegotiator; +import io.netty.handler.ssl.SslContext; +import java.io.IOException; +import javax.net.ssl.SSLException; + +/** + * Credentials appropriate to contact Google services. This class sets up a secure channel using + * ALTS if applicable and uses TLS as fallback. + */ +public final class GoogleDefaultChannelCredentials { + private GoogleDefaultChannelCredentials() {} + + /** + * Creates Google default credentials uses a secure channel with ALTS if applicable and uses TLS + * as fallback. + */ + public static ChannelCredentials create() { + return newBuilder().build(); + } + + /** + * Returns a new instance of {@link Builder}. + * + * @since 1.43.0 + */ + public static Builder newBuilder() { + return new Builder(); + } + + /** + * Builder for {@link GoogleDefaultChannelCredentials} instances. + * + * @since 1.43.0 + */ + public static final class Builder { + private CallCredentials callCredentials; + private CallCredentials altsCallCredentials; + + private Builder() {} + + /** Constructs GoogleDefaultChannelCredentials with a given call credential. */ + public Builder callCredentials(CallCredentials callCreds) { + callCredentials = callCreds; + return this; + } + + /** Constructs GoogleDefaultChannelCredentials with an ALTS-specific call credential. */ + public Builder altsCallCredentials(CallCredentials callCreds) { + altsCallCredentials = callCreds; + return this; + } + + /** Builds a GoogleDefaultChannelCredentials instance. */ + public ChannelCredentials build() { + ChannelCredentials nettyCredentials = + InternalNettyChannelCredentials.create(createClientFactory()); + CallCredentials tlsCallCreds = callCredentials; + if (tlsCallCreds == null) { + try { + tlsCallCreds = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()); + } catch (IOException e) { + tlsCallCreds = + new FailingCallCredentials( + Status.UNAUTHENTICATED + .withDescription("Failed to get Google default credentials") + .withCause(e)); + } + } + CallCredentials callCreds = + altsCallCredentials == null + ? tlsCallCreds + : new DualCallCredentials(tlsCallCreds, altsCallCredentials); + return CompositeChannelCredentials.create(nettyCredentials, callCreds); + } + + private static InternalProtocolNegotiator.ClientFactory createClientFactory() { + SslContext sslContext; + try { + sslContext = GrpcSslContexts.forClient().build(); + } catch (SSLException e) { + throw new RuntimeException(e); + } + return new GoogleDefaultProtocolNegotiatorFactory( + /* targetServiceAccounts= */ ImmutableList.of(), + SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL), + sslContext); + } + } +} diff --git a/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java b/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java index fdfa972e9cc..5e32d22d901 100644 --- a/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java +++ b/alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,57 +16,136 @@ package io.grpc.alts; -import com.google.common.base.Preconditions; +import io.grpc.CallOptions; +import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.ManagedChannel; +import io.grpc.MethodDescriptor; +import io.grpc.internal.GrpcUtil; +import io.grpc.internal.SharedResourceHolder.Resource; import io.grpc.netty.NettyChannelBuilder; +import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.concurrent.DefaultThreadFactory; -import java.util.concurrent.ThreadFactory; +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; /** - * Class for creating a single shared grpc channel to the ALTS Handshaker Service. The channel to - * the handshaker service is local and is over plaintext. Each application will have at most one - * connection to the handshaker service. - * - *

TODO: Release the channel if it is not used. + * Class for creating a single shared gRPC channel to the ALTS Handshaker Service using + * SharedResourceHolder. The channel to the handshaker service is local and is over plaintext. Each + * application will have at most one connection to the handshaker service. */ final class HandshakerServiceChannel { - // Default handshaker service address. - private static String handshakerAddress = "metadata.google.internal:8080"; - // Shared channel to ALTS handshaker service. - private static ManagedChannel channel = null; - - // Construct me not! - private HandshakerServiceChannel() {} - - // Sets handshaker service address for testing and creates the channel to the handshaker service. - public static synchronized void setHandshakerAddressForTesting(String handshakerAddress) { - Preconditions.checkState( - channel == null || HandshakerServiceChannel.handshakerAddress.equals(handshakerAddress), - "HandshakerServiceChannel already created with a different handshakerAddress"); - HandshakerServiceChannel.handshakerAddress = handshakerAddress; - if (channel == null) { - channel = createChannel(); + // Port 8080 is necessary for ALTS handshake. + private static final int ALTS_PORT = 8080; + private static final String DEFAULT_TARGET = "metadata.google.internal.:8080"; + + static final Resource SHARED_HANDSHAKER_CHANNEL = + new ChannelResource(getHandshakerTarget(System.getenv("GCE_METADATA_HOST"))); + + /** + * Returns handshaker target. When GCE_METADATA_HOST is provided, it might contain port which we + * will discard and use ALTS_PORT instead. + */ + static String getHandshakerTarget(String envValue) { + if (envValue == null || envValue.isEmpty()) { + return DEFAULT_TARGET; + } + String host = envValue; + int portIndex = host.lastIndexOf(':'); + if (portIndex != -1) { + host = host.substring(0, portIndex); // Discard port if specified + } + return host + ":" + ALTS_PORT; // Utilize ALTS port in all cases + } + + /** Returns a resource of handshaker service channel for testing only. */ + static Resource getHandshakerChannelForTesting(String handshakerAddress) { + return new ChannelResource(handshakerAddress); + } + + private static final boolean EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS = + GrpcUtil.getFlag("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS", false); + + private static class ChannelResource implements Resource { + private final String target; + + public ChannelResource(String target) { + this.target = target; + } + + @Override + public Channel create() { + /* Use its own event loop thread pool to avoid blocking. */ + EventLoopGroup eventGroup = + new NioEventLoopGroup(1, new DefaultThreadFactory("handshaker pool", true)); + NettyChannelBuilder channelBuilder = + NettyChannelBuilder.forTarget(target) + .channelType(NioSocketChannel.class, InetSocketAddress.class) + .directExecutor() + .eventLoopGroup(eventGroup) + .usePlaintext(); + if (EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS) { + channelBuilder.keepAliveTime(10, TimeUnit.MINUTES).keepAliveTimeout(10, TimeUnit.SECONDS); + } + ManagedChannel channel = channelBuilder.build(); + return new EventLoopHoldingChannel(channel, eventGroup); + } + + @Override + public void close(Channel instanceChannel) { + ((EventLoopHoldingChannel) instanceChannel).close(); + } + + @Override + public String toString() { + return "grpc-alts-handshaker-service-channel"; } } - /** Create a new channel to ALTS handshaker service, if it has not been created yet. */ - private static ManagedChannel createChannel() { - /* Use its own event loop thread pool to avoid blocking. */ - ThreadFactory clientThreadFactory = new DefaultThreadFactory("handshaker pool", true); - ManagedChannel channel = - NettyChannelBuilder.forTarget(handshakerAddress) - .directExecutor() - .eventLoopGroup(new NioEventLoopGroup(1, clientThreadFactory)) - .usePlaintext() - .build(); - return channel; + private abstract static class ForwardingChannel extends Channel { + protected abstract Channel delegate(); + + @Override + public String authority() { + return delegate().authority(); + } + + @Override + public ClientCall newCall( + MethodDescriptor methodDescriptor, CallOptions options) { + return delegate().newCall(methodDescriptor, options); + } } - public static synchronized ManagedChannel get() { - if (channel == null) { - channel = createChannel(); + private static class EventLoopHoldingChannel extends ForwardingChannel { + private final ManagedChannel delegate; + private final EventLoopGroup eventLoopGroup; + + public EventLoopHoldingChannel(ManagedChannel delegate, EventLoopGroup eventLoopGroup) { + this.delegate = delegate; + this.eventLoopGroup = eventLoopGroup; + } + + @Override + protected Channel delegate() { + return delegate; + } + + @SuppressWarnings("FutureReturnValueIgnored") // netty ChannelFuture + public void close() { + // This method will generally be run on the ResourceHolder's ScheduledExecutorService thread + delegate.shutdownNow(); + boolean terminated = false; + try { + terminated = delegate.awaitTermination(2, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + // terminated will be false + } + // Try hard to shutdown abruptly so any bug is more likely to be noticed during testing. + long quietPeriodSeconds = terminated ? 0 : 1; + eventLoopGroup.shutdownGracefully(quietPeriodSeconds, 10, TimeUnit.SECONDS); } - return channel; } } diff --git a/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java b/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java new file mode 100644 index 00000000000..aae4a45d530 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java @@ -0,0 +1,97 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.annotations.VisibleForTesting; +import io.grpc.Internal; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Class for checking if the system is running on Google Cloud Platform (GCP). This is intended for + * usage internal to the gRPC team. If you *really* think you need to use this, contact the gRPC + * team first. + */ +@Internal +public final class InternalCheckGcpEnvironment { + + private static final Logger logger = + Logger.getLogger(InternalCheckGcpEnvironment.class.getName()); + private static final String WINDOWS_COMMAND = "powershell.exe"; + private static Boolean cachedResult = null; + + // Construct me not! + private InternalCheckGcpEnvironment() {} + + /** Returns {@code true} if currently running on Google Cloud Platform (GCP). */ + public static synchronized boolean isOnGcp() { + if (cachedResult == null) { + cachedResult = isRunningOnGcp(); + } + return cachedResult; + } + + @VisibleForTesting + static boolean checkProductNameOnLinux(BufferedReader reader) throws IOException { + String name = reader.readLine().trim(); + return name.equals("Google") || name.equals("Google Compute Engine"); + } + + @VisibleForTesting + static boolean checkBiosDataOnWindows(BufferedReader reader) throws IOException { + String line; + while ((line = reader.readLine()) != null) { + if (line.startsWith("Manufacturer")) { + String name = line.substring(line.indexOf(':') + 1).trim(); + return name.equals("Google"); + } + } + return false; + } + + private static boolean isRunningOnGcp() { + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + try { + if (osName.startsWith("linux")) { + // Checks GCE residency on Linux platform. + return checkProductNameOnLinux( + Files.newBufferedReader(Paths.get("/sys/class/dmi/id/product_name"), UTF_8)); + } else if (osName.startsWith("windows")) { + // Checks GCE residency on Windows platform. + Process p = + new ProcessBuilder() + .command(WINDOWS_COMMAND, "Get-WmiObject", "-Class", "Win32_BIOS") + .start(); + return checkBiosDataOnWindows( + new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8))); + } + } catch (IOException e) { + logger.log(Level.WARNING, "Fail to read platform information: ", e); + return false; + } + // Platforms other than Linux and Windows are not supported. + return false; + } +} diff --git a/alts/src/main/java/io/grpc/alts/internal/AeadCrypter.java b/alts/src/main/java/io/grpc/alts/internal/AeadCrypter.java index aadb0150c55..4d99187c33d 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AeadCrypter.java +++ b/alts/src/main/java/io/grpc/alts/internal/AeadCrypter.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/main/java/io/grpc/alts/internal/AesGcmAeadCrypter.java b/alts/src/main/java/io/grpc/alts/internal/AesGcmAeadCrypter.java index 2f23ab1588a..e3e6302b591 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AesGcmAeadCrypter.java +++ b/alts/src/main/java/io/grpc/alts/internal/AesGcmAeadCrypter.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,13 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.VisibleForTesting; +import io.grpc.internal.ConscryptLoader; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; +import java.security.Provider; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.annotation.Nullable; import javax.crypto.Cipher; import javax.crypto.spec.GCMParameterSpec; @@ -27,12 +32,15 @@ /** AES128-GCM implementation of {@link AeadCrypter} that uses default JCE provider. */ final class AesGcmAeadCrypter implements AeadCrypter { + private static final Logger logger = Logger.getLogger(AesGcmAeadCrypter.class.getName()); private static final int KEY_LENGTH = 16; private static final int TAG_LENGTH = 16; static final int NONCE_LENGTH = 12; private static final String AES = "AES"; private static final String AES_GCM = AES + "/GCM/NoPadding"; + // Conscrypt if available, otherwise null. Conscrypt is much faster than Java 8's JSSE + private static final Provider CONSCRYPT = getConscrypt(); private final byte[] key; private final Cipher cipher; @@ -40,7 +48,11 @@ final class AesGcmAeadCrypter implements AeadCrypter { AesGcmAeadCrypter(byte[] key) throws GeneralSecurityException { checkArgument(key.length == KEY_LENGTH); this.key = key; - cipher = Cipher.getInstance(AES_GCM); + if (CONSCRYPT != null) { + cipher = Cipher.getInstance(AES_GCM, CONSCRYPT); + } else { + cipher = Cipher.getInstance(AES_GCM); + } } private int encryptAad( @@ -98,4 +110,49 @@ public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, ByteBuffer aad, static int getKeyLength() { return KEY_LENGTH; } + + @VisibleForTesting + static Provider getConscrypt() { + if (!ConscryptLoader.isPresent()) { + return null; + } + // Conscrypt 2.1.0 or later is required. If an older version is used, it will fail with these + // sorts of errors: + // "The underlying Cipher implementation does not support this method" + // "error:1e000067:Cipher functions:OPENSSL_internal:BUFFER_TOO_SMALL" + // + // While we could use Conscrypt.version() to check compatibility, that is _very_ verbose via + // reflection. In practice, old conscrypts are probably not much of a problem. + Provider provider; + try { + provider = ConscryptLoader.newProvider(); + } catch (Throwable t) { + logger.log(Level.INFO, "Could not load Conscrypt. Will use slower JDK implementation", t); + return null; + } + try { + Cipher.getInstance(AES_GCM, provider); + } catch (SecurityException t) { + // Pre-Java 7u121/Java 8u111 fails with SecurityException: + // JCE cannot authenticate the provider Conscrypt + // + // This is because Conscrypt uses a newer (more secure) signing CA than the earlier Java + // supported. https://www.oracle.com/technetwork/java/javase/8u111-relnotes-3124969.html + // https://www.oracle.com/technetwork/java/javase/documentation/javase7supportreleasenotes-1601161.html#R170_121 + // + // Use WARNING instead of INFO in this case because it is unlikely to be a supported + // environment. In the other cases we might be on Java 9+; it seems unlikely in this case. + // Note that on Java 7, we're likely to crash later because GCM is unsupported. + logger.log( + Level.WARNING, + "Could not load Conscrypt. Will try slower JDK implementation. This may be because the " + + "JDK is older than Java 7 update 121 or Java 8 update 111. If so, please update", + t); + return null; + } catch (Throwable t) { + logger.log(Level.INFO, "Could not load Conscrypt. Will use slower JDK implementation", t); + return null; + } + return provider; + } } diff --git a/alts/src/main/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypter.java b/alts/src/main/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypter.java index 4e5bbd17201..b0f7535d35a 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypter.java +++ b/alts/src/main/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypter.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsAuthContext.java b/alts/src/main/java/io/grpc/alts/internal/AltsAuthContext.java deleted file mode 100644 index 06b4ee8143f..00000000000 --- a/alts/src/main/java/io/grpc/alts/internal/AltsAuthContext.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2018, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.alts.internal; - -import com.google.common.annotations.VisibleForTesting; -import io.grpc.alts.internal.Altscontext.AltsContext; -import io.grpc.alts.internal.Handshaker.HandshakerResult; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel; - -/** AltsAuthContext contains security-related context information about an ALTs connection. */ -public final class AltsAuthContext { - final AltsContext context; - - /** Create a new AltsAuthContext. */ - public AltsAuthContext(HandshakerResult result) { - context = - AltsContext.newBuilder() - .setApplicationProtocol(result.getApplicationProtocol()) - .setRecordProtocol(result.getRecordProtocol()) - // TODO: Set security level based on the handshaker result. - .setSecurityLevel(SecurityLevel.INTEGRITY_AND_PRIVACY) - .setPeerServiceAccount(result.getPeerIdentity().getServiceAccount()) - .setLocalServiceAccount(result.getLocalIdentity().getServiceAccount()) - .setPeerRpcVersions(result.getPeerRpcVersions()) - .build(); - } - - @VisibleForTesting - public static AltsAuthContext getDefaultInstance() { - return new AltsAuthContext(HandshakerResult.newBuilder().build()); - } - - /** - * Get application protocol. - * - * @return the context's application protocol. - */ - public String getApplicationProtocol() { - return context.getApplicationProtocol(); - } - - /** - * Get negotiated record protocol. - * - * @return the context's negotiated record protocol. - */ - public String getRecordProtocol() { - return context.getRecordProtocol(); - } - - /** - * Get security level. - * - * @return the context's security level. - */ - public SecurityLevel getSecurityLevel() { - return context.getSecurityLevel(); - } - - /** - * Get peer service account. - * - * @return the context's peer service account. - */ - public String getPeerServiceAccount() { - return context.getPeerServiceAccount(); - } - - /** - * Get local service account. - * - * @return the context's local service account. - */ - public String getLocalServiceAccount() { - return context.getLocalServiceAccount(); - } - - /** - * Get peer RPC versions. - * - * @return the context's peer RPC versions. - */ - public RpcProtocolVersions getPeerRpcVersions() { - return context.getPeerRpcVersions(); - } -} diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsChannelCrypter.java b/alts/src/main/java/io/grpc/alts/internal/AltsChannelCrypter.java index 71b8a8351f2..5e4c6fec301 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsChannelCrypter.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsChannelCrypter.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,6 @@ static int getCounterLength() { return COUNTER_LENGTH; } - @SuppressWarnings("BetaApi") // verify is stable in Guava @Override public void encrypt(ByteBuf outBuf, List plainBufs) throws GeneralSecurityException { checkArgument(outBuf.nioBufferCount() == 1); @@ -93,7 +92,6 @@ public void decrypt(ByteBuf out, ByteBuf tag, List ciphertextBufs) decrypt(out, cipherTextAndTag); } - @SuppressWarnings("BetaApi") // verify is stable in Guava @Override public void decrypt(ByteBuf out, ByteBuf ciphertextAndTag) throws GeneralSecurityException { int bytesRead = ciphertextAndTag.readableBytes(); diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsClientOptions.java b/alts/src/main/java/io/grpc/alts/internal/AltsClientOptions.java index 0b749ca22a5..9ad614c9623 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsClientOptions.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsClientOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,42 +16,39 @@ package io.grpc.alts.internal; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import com.google.common.collect.ImmutableList; import javax.annotation.Nullable; /** Handshaker options for creating ALTS client channel. */ public final class AltsClientOptions extends AltsHandshakerOptions { - // targetName is the server service account name for secure name checking. This field is not yet - // supported. + + // targetName is the server service account name for secure name checking. @Nullable private final String targetName; // targetServiceAccounts contains a list of expected target service accounts. One of these service // accounts should match peer service account in the handshaker result. Otherwise, the handshake // fails. - private final List targetServiceAccounts; + private final ImmutableList targetServiceAccounts; private AltsClientOptions(Builder builder) { super(builder.rpcProtocolVersions); targetName = builder.targetName; - targetServiceAccounts = - Collections.unmodifiableList(new ArrayList(builder.targetServiceAccounts)); + targetServiceAccounts = builder.targetServiceAccounts; } public String getTargetName() { return targetName; } - public List getTargetServiceAccounts() { + public ImmutableList getTargetServiceAccounts() { return targetServiceAccounts; } /** Builder for AltsClientOptions. */ public static final class Builder { + @Nullable private String targetName; @Nullable private RpcProtocolVersions rpcProtocolVersions; - private ArrayList targetServiceAccounts = new ArrayList(); + private ImmutableList targetServiceAccounts = ImmutableList.of(); public Builder setTargetName(String targetName) { this.targetName = targetName; @@ -63,8 +60,8 @@ public Builder setRpcProtocolVersions(RpcProtocolVersions rpcProtocolVersions) { return this; } - public Builder addTargetServiceAccount(String targetServiceAccount) { - targetServiceAccounts.add(targetServiceAccount); + public Builder setTargetServiceAccounts(ImmutableList targetServiceAccounts) { + this.targetServiceAccounts = targetServiceAccounts; return this; } diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsFraming.java b/alts/src/main/java/io/grpc/alts/internal/AltsFraming.java index 5b1a5ef7f71..2571f937225 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsFraming.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsFraming.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package io.grpc.alts.internal; import com.google.common.base.Preconditions; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.security.GeneralSecurityException; @@ -63,10 +64,10 @@ static ByteBuffer toFrame(ByteBuffer input, int dataSize) throws GeneralSecurity } Producer producer = new Producer(); ByteBuffer inputAlias = input.duplicate(); - inputAlias.limit(input.position() + dataSize); + ((Buffer) inputAlias).limit(input.position() + dataSize); producer.readBytes(inputAlias); producer.flush(); - input.position(inputAlias.position()); + ((Buffer) input).position(inputAlias.position()); ByteBuffer output = producer.getRawFrame(); return output; } @@ -166,10 +167,10 @@ void flush() throws GeneralSecurityException { int frameLength = buffer.position() + getFrameSuffixLength(); // Set the limit and move to the start. - buffer.flip(); + ((Buffer) buffer).flip(); // Advance the limit to allow a crypto suffix. - buffer.limit(buffer.limit() + getFrameSuffixLength()); + ((Buffer) buffer).limit(buffer.limit() + getFrameSuffixLength()); // Write the data length and the message type. int dataLength = frameLength - FRAME_LENGTH_HEADER_SIZE; @@ -178,17 +179,17 @@ void flush() throws GeneralSecurityException { buffer.putInt(MESSAGE_TYPE); // Move the position back to 0, the frame is ready. - buffer.position(0); + ((Buffer) buffer).position(0); isComplete = true; } /** Resets the state, preparing to construct a new frame. Must be called between frames. */ private void reset() { - buffer.clear(); + ((Buffer) buffer).clear(); // Save some space for framing, we'll fill that in later. - buffer.position(getFramePrefixLength()); - buffer.limit(buffer.limit() - getFrameSuffixLength()); + ((Buffer) buffer).position(getFramePrefixLength()); + ((Buffer) buffer).limit(buffer.limit() - getFrameSuffixLength()); isComplete = false; } @@ -279,7 +280,7 @@ public boolean readBytes(ByteBuffer input) throws GeneralSecurityException { // internal buffer is large enough. if (buffer.position() == FRAME_LENGTH_HEADER_SIZE && input.hasRemaining()) { ByteBuffer bufferAlias = buffer.duplicate(); - bufferAlias.flip(); + ((Buffer) bufferAlias).flip(); bufferAlias.order(ByteOrder.LITTLE_ENDIAN); int dataLength = bufferAlias.getInt(); if (dataLength < FRAME_MESSAGE_TYPE_HEADER_SIZE || dataLength > MAX_DATA_LENGTH) { @@ -292,7 +293,7 @@ public boolean readBytes(ByteBuffer input) throws GeneralSecurityException { buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(dataLength); } - buffer.limit(frameLength); + ((Buffer) buffer).limit(frameLength); } // TODO: Similarly extract and check message type. @@ -300,7 +301,7 @@ public boolean readBytes(ByteBuffer input) throws GeneralSecurityException { // Read the remaining data into the internal buffer. copy(buffer, input); if (!buffer.hasRemaining()) { - buffer.flip(); + ((Buffer) buffer).flip(); isComplete = true; } return isComplete; @@ -323,7 +324,7 @@ public boolean isComplete() { /** Resets the state, preparing to parse a new frame. Must be called between frames. */ private void reset() { - buffer.clear(); + ((Buffer) buffer).clear(); isComplete = false; } @@ -356,9 +357,9 @@ private static void copy(ByteBuffer dst, ByteBuffer src) { } else { int count = Math.min(dst.remaining(), src.remaining()); ByteBuffer slice = src.slice(); - slice.limit(count); + ((Buffer) slice).limit(count); dst.put(slice); - src.position(src.position() + count); + ((Buffer) src).position(src.position() + count); } } } diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerClient.java b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerClient.java index 6e13c110e79..9eb07f3e86d 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerClient.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,27 +20,17 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.protobuf.ByteString; +import io.grpc.ChannelLogger; +import io.grpc.ChannelLogger.ChannelLogLevel; import io.grpc.Status; -import io.grpc.alts.internal.Handshaker.HandshakeProtocol; -import io.grpc.alts.internal.Handshaker.HandshakerReq; -import io.grpc.alts.internal.Handshaker.HandshakerResp; -import io.grpc.alts.internal.Handshaker.HandshakerResult; -import io.grpc.alts.internal.Handshaker.HandshakerStatus; -import io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq; -import io.grpc.alts.internal.Handshaker.ServerHandshakeParameters; -import io.grpc.alts.internal.Handshaker.StartClientHandshakeReq; -import io.grpc.alts.internal.Handshaker.StartServerHandshakeReq; import io.grpc.alts.internal.HandshakerServiceGrpc.HandshakerServiceStub; import java.io.IOException; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; -import java.util.logging.Level; -import java.util.logging.Logger; /** An API for conducting handshakes via ALTS handshaker service. */ class AltsHandshakerClient { - private static final Logger logger = Logger.getLogger(AltsHandshakerClient.class.getName()); - private static final String APPLICATION_PROTOCOL = "grpc"; private static final String RECORD_PROTOCOL = "ALTSRP_GCM_AES128_REKEY"; private static final int KEY_LENGTH = AltsChannelCrypter.getKeyLength(); @@ -49,17 +39,22 @@ class AltsHandshakerClient { private final AltsHandshakerOptions handshakerOptions; private HandshakerResult result; private HandshakerStatus status; + private final ChannelLogger logger; /** Starts a new handshake interacting with the handshaker service. */ - AltsHandshakerClient(HandshakerServiceStub stub, AltsHandshakerOptions options) { + AltsHandshakerClient( + HandshakerServiceStub stub, AltsHandshakerOptions options, ChannelLogger logger) { handshakerStub = new AltsHandshakerStub(stub); handshakerOptions = options; + this.logger = logger; } @VisibleForTesting - AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options) { + AltsHandshakerClient( + AltsHandshakerStub handshakerStub, AltsHandshakerOptions options, ChannelLogger logger) { this.handshakerStub = handshakerStub; handshakerOptions = options; + this.logger = logger; } static String getApplicationProtocol() { @@ -91,6 +86,7 @@ private void setStartClientFields(HandshakerReq.Builder req) { startClientReq.addTargetIdentitiesBuilder().setServiceAccount(serviceAccount); } } + startClientReq.setMaxFrameSize(AltsTsiFrameProtector.getMaxFrameSize()); req.setClientStart(startClientReq); } @@ -106,6 +102,7 @@ private void setStartServerFields(HandshakerReq.Builder req, ByteBuffer inBytes) if (handshakerOptions.getRpcProtocolVersions() != null) { startServerReq.setRpcVersions(handshakerOptions.getRpcProtocolVersions()); } + startServerReq.setMaxFrameSize(AltsTsiFrameProtector.getMaxFrameSize()); req.setServerStart(startServerReq); } @@ -145,7 +142,7 @@ public byte[] getKey() { throw new IllegalStateException("Could not get enough key data from the handshake."); } byte[] key = new byte[KEY_LENGTH]; - result.getKeyData().copyTo(key, 0, 0, KEY_LENGTH); + result.getKeyData().substring(0, KEY_LENGTH).copyTo(key, 0); return key; } @@ -160,7 +157,7 @@ private void handleResponse(HandshakerResp resp) throws GeneralSecurityException } if (status.getCode() != Status.Code.OK.value()) { String error = "Handshaker service error: " + status.getDetails(); - logger.log(Level.INFO, error); + logger.log(ChannelLogLevel.DEBUG, error); close(); throw new GeneralSecurityException(error); } @@ -179,7 +176,9 @@ public ByteBuffer startClientHandshake() throws GeneralSecurityException { setStartClientFields(req); HandshakerResp resp; try { + logger.log(ChannelLogLevel.DEBUG, "Send ALTS handshake request to upstream"); resp = handshakerStub.send(req.build()); + logger.log(ChannelLogLevel.DEBUG, "Receive ALTS handshake response from upstream"); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } @@ -206,7 +205,7 @@ public ByteBuffer startServerHandshake(ByteBuffer inBytes) throws GeneralSecurit throw new GeneralSecurityException(e); } handleResponse(resp); - inBytes.position(inBytes.position() + resp.getBytesConsumed()); + ((Buffer) inBytes).position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } @@ -229,17 +228,25 @@ public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { .build()); HandshakerResp resp; try { + logger.log(ChannelLogLevel.DEBUG, "Send ALTS handshake request to upstream"); resp = handshakerStub.send(req.build()); + logger.log(ChannelLogLevel.DEBUG, "Receive ALTS handshake response from upstream"); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); - inBytes.position(inBytes.position() + resp.getBytesConsumed()); + ((Buffer) inBytes).position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } + private boolean closed = false; + /** Closes the connection. */ public void close() { + if (closed) { + return; + } + closed = true; handshakerStub.close(); } } diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerOptions.java b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerOptions.java index 2b98cc48a33..d50f92f185f 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerOptions.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package io.grpc.alts.internal; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; import javax.annotation.Nullable; /** Handshaker options for creating ALTS channel. */ diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerStub.java b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerStub.java index 76657131380..6c2748dcc9c 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerStub.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsHandshakerStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package io.grpc.alts.internal; +import static java.util.concurrent.TimeUnit.SECONDS; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; -import io.grpc.alts.internal.Handshaker.HandshakerReq; -import io.grpc.alts.internal.Handshaker.HandshakerResp; import io.grpc.alts.internal.HandshakerServiceGrpc.HandshakerServiceStub; import io.grpc.stub.StreamObserver; import java.io.IOException; @@ -29,23 +29,27 @@ /** An interface to the ALTS handshaker service. */ class AltsHandshakerStub { private final StreamObserver reader = new Reader(); - private final StreamObserver writer; + private StreamObserver writer; + private final HandshakerServiceStub serviceStub; private final ArrayBlockingQueue> responseQueue = - new ArrayBlockingQueue>(1); - private final AtomicReference exceptionMessage = new AtomicReference<>(); + new ArrayBlockingQueue<>(1); + private final AtomicReference exceptionMessage = new AtomicReference<>(); + + private static final long HANDSHAKE_RPC_DEADLINE_SECS = 20; AltsHandshakerStub(HandshakerServiceStub serviceStub) { - this.writer = serviceStub.doHandshake(this.reader); + this.serviceStub = serviceStub; } @VisibleForTesting AltsHandshakerStub() { - writer = null; + serviceStub = null; } @VisibleForTesting AltsHandshakerStub(StreamObserver writer) { this.writer = writer; + serviceStub = null; } @VisibleForTesting @@ -55,28 +59,45 @@ StreamObserver getReaderForTest() { /** Send a handshaker request and return the handshaker response. */ public HandshakerResp send(HandshakerReq req) throws InterruptedException, IOException { + createWriterIfNull(); maybeThrowIoException(); if (!responseQueue.isEmpty()) { throw new IOException("Received an unexpected response."); } + writer.onNext(req); Optional result = responseQueue.take(); - if (!result.isPresent()) { - maybeThrowIoException(); + if (result.isPresent()) { + return result.get(); + } + + if (exceptionMessage.get() != null) { + throw new IOException(exceptionMessage.get().info, exceptionMessage.get().throwable); + } else { + throw new IOException("No handshaker response received"); + } + } + + /** Create a new writer if the writer is null. */ + private void createWriterIfNull() { + if (writer == null) { + writer = + serviceStub.withDeadlineAfter(HANDSHAKE_RPC_DEADLINE_SECS, SECONDS).doHandshake(reader); } - return result.get(); } /** Throw exception if there is an outstanding exception. */ private void maybeThrowIoException() throws IOException { if (exceptionMessage.get() != null) { - throw new IOException(exceptionMessage.get()); + throw new IOException(exceptionMessage.get().info, exceptionMessage.get().throwable); } } /** Close the connection. */ public void close() { - writer.onCompleted(); + if (writer != null) { + writer.onCompleted(); + } } private class Reader implements StreamObserver { @@ -87,7 +108,7 @@ public void onNext(HandshakerResp resp) { AltsHandshakerStub.this.responseQueue.add(Optional.of(resp)); } catch (IllegalStateException e) { AltsHandshakerStub.this.exceptionMessage.compareAndSet( - null, "Received an unexpected response."); + null, new ThrowableInfo(e, "Received an unexpected response.")); AltsHandshakerStub.this.close(); } } @@ -96,7 +117,7 @@ public void onNext(HandshakerResp resp) { @Override public void onError(Throwable t) { AltsHandshakerStub.this.exceptionMessage.compareAndSet( - null, "Received a terminating error: " + t.toString()); + null, new ThrowableInfo(t, "Received a terminating error.")); // Trigger the release of any blocked send. Optional result = Optional.absent(); AltsHandshakerStub.this.responseQueue.offer(result); @@ -105,10 +126,22 @@ public void onError(Throwable t) { /** Receive the closing message from the server. */ @Override public void onCompleted() { - AltsHandshakerStub.this.exceptionMessage.compareAndSet(null, "Response stream closed."); + AltsHandshakerStub.this.exceptionMessage.compareAndSet( + null, new ThrowableInfo(null, "Response stream closed.")); // Trigger the release of any blocked send. Optional result = Optional.absent(); AltsHandshakerStub.this.responseQueue.offer(result); } } + + private static class ThrowableInfo { + + private final Throwable throwable; + private final String info; + + private ThrowableInfo(Throwable throwable, String info) { + this.throwable = throwable; + this.info = info; + } + } } diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsInternalContext.java b/alts/src/main/java/io/grpc/alts/internal/AltsInternalContext.java new file mode 100644 index 00000000000..a70c67b2933 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/internal/AltsInternalContext.java @@ -0,0 +1,108 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import com.google.common.annotations.VisibleForTesting; +import java.util.Map; + +/** AltsInternalContext contains security-related context information about an ALTs connection. */ +public final class AltsInternalContext { + final AltsContext context; + + /** Create a new AltsInternalContext. */ + public AltsInternalContext(HandshakerResult result) { + context = + AltsContext.newBuilder() + .setApplicationProtocol(result.getApplicationProtocol()) + .setRecordProtocol(result.getRecordProtocol()) + // TODO: Set security level based on the handshaker result. + .setSecurityLevel(SecurityLevel.INTEGRITY_AND_PRIVACY) + .setPeerServiceAccount(result.getPeerIdentity().getServiceAccount()) + .setLocalServiceAccount(result.getLocalIdentity().getServiceAccount()) + .setPeerRpcVersions(result.getPeerRpcVersions()) + .putAllPeerAttributes(result.getPeerIdentity().getAttributesMap()) + .build(); + } + + @VisibleForTesting + public static AltsInternalContext getDefaultInstance() { + return new AltsInternalContext(HandshakerResult.newBuilder().build()); + } + + /** + * Get application protocol. + * + * @return the context's application protocol. + */ + public String getApplicationProtocol() { + return context.getApplicationProtocol(); + } + + /** + * Get negotiated record protocol. + * + * @return the context's negotiated record protocol. + */ + public String getRecordProtocol() { + return context.getRecordProtocol(); + } + + /** + * Get security level. + * + * @return the context's security level. + */ + public SecurityLevel getSecurityLevel() { + return context.getSecurityLevel(); + } + + /** + * Get peer service account. + * + * @return the context's peer service account. + */ + public String getPeerServiceAccount() { + return context.getPeerServiceAccount(); + } + + /** + * Get local service account. + * + * @return the context's local service account. + */ + public String getLocalServiceAccount() { + return context.getLocalServiceAccount(); + } + + /** + * Get peer RPC versions. + * + * @return the context's peer RPC versions. + */ + public RpcProtocolVersions getPeerRpcVersions() { + return context.getPeerRpcVersions(); + } + + /** + * Get peer attributes. + * + * @return the context's peer attributes. + */ + public Map getPeerAttributes() { + return context.getPeerAttributesMap(); + } +} diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java b/alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java index ef49835a53b..9c51cf6a053 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,123 +16,437 @@ package io.grpc.alts.internal; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.protobuf.Any; import io.grpc.Attributes; +import io.grpc.Channel; +import io.grpc.ChannelLogger; import io.grpc.Grpc; +import io.grpc.InternalChannelz.OtherSecurity; +import io.grpc.InternalChannelz.Security; +import io.grpc.SecurityLevel; import io.grpc.Status; import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult; -import io.grpc.alts.internal.TsiHandshakeHandler.TsiHandshakeCompletionEvent; +import io.grpc.internal.ObjectPool; import io.grpc.netty.GrpcHttp2ConnectionHandler; -import io.grpc.netty.ProtocolNegotiator; -import io.grpc.netty.ProtocolNegotiators.AbstractBufferingHandler; +import io.grpc.netty.InternalProtocolNegotiator; +import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; +import io.grpc.netty.InternalProtocolNegotiators; import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.ssl.SslContext; import io.netty.util.AsciiString; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.Nullable; /** - * A client-side GRPC {@link ProtocolNegotiator} for ALTS. This class creates a Netty handler that - * provides ALTS security on the wire, similar to Netty's {@code SslHandler}. + * A gRPC {@link ProtocolNegotiator} for ALTS. This class creates a Netty handler that provides ALTS + * security on the wire, similar to Netty's {@code SslHandler}. */ -public abstract class AltsProtocolNegotiator implements ProtocolNegotiator { +// TODO(carl-mastrangelo): rename this AltsProtocolNegotiators. +public final class AltsProtocolNegotiator { + private static final Logger logger = Logger.getLogger(AltsProtocolNegotiator.class.getName()); + + static final String ALTS_MAX_CONCURRENT_HANDSHAKES_ENV_VARIABLE = + "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES"; + @VisibleForTesting static final int DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES = 32; + private static final AsyncSemaphore handshakeSemaphore = + new AsyncSemaphore(getAltsMaxConcurrentHandshakes()); + + @Grpc.TransportAttr + public static final Attributes.Key TSI_PEER_KEY = + Attributes.Key.create("internal:TSI_PEER"); + @Grpc.TransportAttr + public static final Attributes.Key AUTH_CONTEXT_KEY = + Attributes.Key.create("internal:AUTH_CONTEXT_KEY"); + + private static final AsciiString SCHEME = AsciiString.of("https"); + + private static final String DIRECT_PATH_SERVICE_CFE_CLUSTER_PREFIX = "google_cfe_"; + private static final String CFE_CLUSTER_RESOURCE_NAME_PREFIX = + "/envoy.config.cluster.v3.Cluster/google_cfe_"; + private static final String CFE_CLUSTER_AUTHORITY_NAME = + "traffic-director-c2p.xds.googleapis.com"; + + /** + * ClientAltsProtocolNegotiatorFactory is a factory for doing client side negotiation of an ALTS + * channel. + */ + public static final class ClientAltsProtocolNegotiatorFactory + implements InternalProtocolNegotiator.ClientFactory { - private static final Attributes.Key TSI_PEER_KEY = Attributes.Key.of("TSI_PEER"); - private static final Attributes.Key ALTS_CONTEXT_KEY = - Attributes.Key.of("ALTS_CONTEXT_KEY"); - private static final AsciiString scheme = AsciiString.of("https"); + private final ImmutableList targetServiceAccounts; + private final ObjectPool handshakerChannelPool; - public static Attributes.Key getTsiPeerAttributeKey() { - return TSI_PEER_KEY; + public ClientAltsProtocolNegotiatorFactory( + List targetServiceAccounts, + ObjectPool handshakerChannelPool) { + this.targetServiceAccounts = ImmutableList.copyOf(targetServiceAccounts); + this.handshakerChannelPool = checkNotNull(handshakerChannelPool, "handshakerChannelPool"); + } + + @Override + public ProtocolNegotiator newNegotiator() { + return new ClientAltsProtocolNegotiator( + targetServiceAccounts, + handshakerChannelPool); + } + + @Override + public int getDefaultPort() { + return 443; + } } - public static Attributes.Key getAltsAuthContextAttributeKey() { - return ALTS_CONTEXT_KEY; + private static final class ClientAltsProtocolNegotiator implements ProtocolNegotiator { + private final TsiHandshakerFactory handshakerFactory; + private final LazyChannel lazyHandshakerChannel; + + ClientAltsProtocolNegotiator( + ImmutableList targetServiceAccounts, ObjectPool handshakerChannelPool) { + this.lazyHandshakerChannel = new LazyChannel(handshakerChannelPool); + this.handshakerFactory = + new ClientTsiHandshakerFactory(targetServiceAccounts, lazyHandshakerChannel); + } + + @Override + public AsciiString scheme() { + return SCHEME; + } + + @Override + public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { + ChannelLogger negotiationLogger = grpcHandler.getNegotiationLogger(); + TsiHandshaker handshaker = + handshakerFactory.newHandshaker(grpcHandler.getAuthority(), negotiationLogger); + NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker); + ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler); + ChannelHandler thh = new TsiHandshakeHandler( + gnh, nettyHandshaker, new AltsHandshakeValidator(), handshakeSemaphore, + negotiationLogger); + ChannelHandler wuah = InternalProtocolNegotiators.waitUntilActiveHandler(thh, + negotiationLogger); + return wuah; + } + + @Override + public void close() { + lazyHandshakerChannel.close(); + } } - /** Creates a negotiator used for ALTS. */ - public static AltsProtocolNegotiator create(final TsiHandshakerFactory handshakerFactory) { - return new AltsProtocolNegotiator() { + /** + * Creates a protocol negotiator for ALTS on the server side. + */ + public static ProtocolNegotiator serverAltsProtocolNegotiator( + ObjectPool handshakerChannelPool) { + final LazyChannel lazyHandshakerChannel = new LazyChannel(handshakerChannelPool); + final class ServerTsiHandshakerFactory implements TsiHandshakerFactory { + @Override - public Handler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { - return new BufferUntilAltsNegotiatedHandler( - grpcHandler, - new TsiHandshakeHandler(new NettyTsiHandshaker(handshakerFactory.newHandshaker())), - new TsiFrameHandler()); + public TsiHandshaker newHandshaker( + @Nullable String authority, ChannelLogger negotiationLogger) { + assert authority == null; + return AltsTsiHandshaker.newServer( + HandshakerServiceGrpc.newStub(lazyHandshakerChannel.get()), + new AltsHandshakerOptions(RpcProtocolVersionsUtil.getRpcProtocolVersions()), + negotiationLogger); } - }; + } + + return new ServerAltsProtocolNegotiator( + new ServerTsiHandshakerFactory(), lazyHandshakerChannel); } - /** Buffers all writes until the ALTS handshake is complete. */ @VisibleForTesting - static class BufferUntilAltsNegotiatedHandler extends AbstractBufferingHandler - implements ProtocolNegotiator.Handler { + static final class ServerAltsProtocolNegotiator implements ProtocolNegotiator { + private final TsiHandshakerFactory handshakerFactory; + private final LazyChannel lazyHandshakerChannel; - private final GrpcHttp2ConnectionHandler grpcHandler; + @VisibleForTesting + ServerAltsProtocolNegotiator( + TsiHandshakerFactory handshakerFactory, LazyChannel lazyHandshakerChannel) { + this.handshakerFactory = checkNotNull(handshakerFactory, "handshakerFactory"); + this.lazyHandshakerChannel = checkNotNull(lazyHandshakerChannel, "lazyHandshakerChannel"); + } - BufferUntilAltsNegotiatedHandler( - GrpcHttp2ConnectionHandler grpcHandler, ChannelHandler... negotiationhandlers) { - super(negotiationhandlers); - // Save the gRPC handler. The ALTS handler doesn't support buffering before the handshake - // completes, so we wait until the handshake was successful before adding the grpc handler. - this.grpcHandler = grpcHandler; + @Override + public AsciiString scheme() { + return SCHEME; } - // TODO: Remove this once https://github.com/grpc/grpc-java/pull/3715 is in. @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - fail(ctx, cause); - ctx.fireExceptionCaught(cause); + public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { + ChannelLogger negotiationLogger = grpcHandler.getNegotiationLogger(); + TsiHandshaker handshaker = + handshakerFactory.newHandshaker(/* authority= */ null, negotiationLogger); + NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker); + ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler); + ChannelHandler thh = new TsiHandshakeHandler( + gnh, nettyHandshaker, new AltsHandshakeValidator(), handshakeSemaphore, + negotiationLogger); + ChannelHandler wuah = InternalProtocolNegotiators.waitUntilActiveHandler(thh, + negotiationLogger); + return wuah; + } + + @Override + public void close() { + logger.finest("ALTS Server ProtocolNegotiator Closed"); + lazyHandshakerChannel.close(); + } + } + + /** + * A Protocol Negotiator factory which can switch between ALTS and TLS based on EAG Attrs. + */ + public static final class GoogleDefaultProtocolNegotiatorFactory + implements InternalProtocolNegotiator.ClientFactory { + @VisibleForTesting + @Nullable + static Attributes.Key clusterNameAttrKey = loadClusterNameAttrKey(); + private final ImmutableList targetServiceAccounts; + private final ObjectPool handshakerChannelPool; + private final SslContext sslContext; + + /** + * Creates Negotiator Factory, which will either use the targetServiceAccounts and + * handshakerChannelPool, or the sslContext. + */ + public GoogleDefaultProtocolNegotiatorFactory( + List targetServiceAccounts, + ObjectPool handshakerChannelPool, + SslContext sslContext) { + this.targetServiceAccounts = ImmutableList.copyOf(targetServiceAccounts); + this.handshakerChannelPool = checkNotNull(handshakerChannelPool, "handshakerChannelPool"); + this.sslContext = checkNotNull(sslContext, "sslContext"); + } + + @Override + public ProtocolNegotiator newNegotiator() { + return new GoogleDefaultProtocolNegotiator( + targetServiceAccounts, + handshakerChannelPool, + sslContext, + clusterNameAttrKey); + } + + @Override + public int getDefaultPort() { + return 443; + } + + @SuppressWarnings("unchecked") + @Nullable + private static Attributes.Key loadClusterNameAttrKey() { + Attributes.Key key = null; + try { + Class klass = Class.forName("io.grpc.xds.InternalXdsAttributes"); + key = (Attributes.Key) klass.getField("ATTR_CLUSTER_NAME").get(null); + } catch (ClassNotFoundException e) { + logger.log(Level.FINE, + "Unable to load xDS endpoint cluster name key, this may be expected", e); + } catch (NoSuchFieldException e) { + logger.log(Level.FINE, + "Unable to load xDS endpoint cluster name key, this may be expected", e); + } catch (IllegalAccessException e) { + logger.log(Level.FINE, + "Unable to load xDS endpoint cluster name key, this may be expected", e); + } + return key; + } + } + + private static final class GoogleDefaultProtocolNegotiator implements ProtocolNegotiator { + private final TsiHandshakerFactory handshakerFactory; + private final LazyChannel lazyHandshakerChannel; + private final SslContext sslContext; + @Nullable + private final Attributes.Key clusterNameAttrKey; + + GoogleDefaultProtocolNegotiator( + ImmutableList targetServiceAccounts, + ObjectPool handshakerChannelPool, + SslContext sslContext, + @Nullable Attributes.Key clusterNameAttrKey) { + this.lazyHandshakerChannel = new LazyChannel(handshakerChannelPool); + this.handshakerFactory = + new ClientTsiHandshakerFactory(targetServiceAccounts, lazyHandshakerChannel); + this.sslContext = checkNotNull(sslContext, "checkNotNull"); + this.clusterNameAttrKey = clusterNameAttrKey; } @Override public AsciiString scheme() { - return scheme; + return SCHEME; + } + + @Override + public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { + ChannelHandler gnh = InternalProtocolNegotiators.grpcNegotiationHandler(grpcHandler); + ChannelLogger negotiationLogger = grpcHandler.getNegotiationLogger(); + ChannelHandler securityHandler; + boolean isXdsDirectPath = false; + if (clusterNameAttrKey != null) { + isXdsDirectPath = isDirectPathCluster( + grpcHandler.getEagAttributes().get(clusterNameAttrKey)); + } + if (isXdsDirectPath) { + TsiHandshaker handshaker = + handshakerFactory.newHandshaker(grpcHandler.getAuthority(), negotiationLogger); + NettyTsiHandshaker nettyHandshaker = new NettyTsiHandshaker(handshaker); + securityHandler = new TsiHandshakeHandler( + gnh, nettyHandshaker, new AltsHandshakeValidator(), handshakeSemaphore, + negotiationLogger); + } else { + securityHandler = InternalProtocolNegotiators.clientTlsHandler( + gnh, sslContext, grpcHandler.getAuthority(), negotiationLogger); + } + ChannelHandler wuah = InternalProtocolNegotiators.waitUntilActiveHandler(securityHandler, + negotiationLogger); + return wuah; + } + + private boolean isDirectPathCluster(String clusterName) { + if (clusterName == null) { + return false; + } + if (clusterName.startsWith(DIRECT_PATH_SERVICE_CFE_CLUSTER_PREFIX)) { + return false; + } + if (!clusterName.startsWith("xdstp:")) { + return true; + } + try { + URI uri = new URI(clusterName); + // If authority AND path match our CFE checks, use TLS; otherwise use ALTS. + return !CFE_CLUSTER_AUTHORITY_NAME.equals(uri.getHost()) + || !uri.getPath().startsWith(CFE_CLUSTER_RESOURCE_NAME_PREFIX); + } catch (URISyntaxException e) { + return true; // Shouldn't happen, but assume ALTS. + } + } + + @Override + public void close() { + logger.finest("ALTS Server ProtocolNegotiator Closed"); + lazyHandshakerChannel.close(); + } + } + + private static final class ClientTsiHandshakerFactory implements TsiHandshakerFactory { + + private final ImmutableList targetServiceAccounts; + private final LazyChannel lazyHandshakerChannel; + + ClientTsiHandshakerFactory( + ImmutableList targetServiceAccounts, LazyChannel lazyHandshakerChannel) { + this.targetServiceAccounts = checkNotNull(targetServiceAccounts, "targetServiceAccounts"); + this.lazyHandshakerChannel = checkNotNull(lazyHandshakerChannel, "lazyHandshakerChannel"); } @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if (evt instanceof TsiHandshakeCompletionEvent) { - TsiHandshakeCompletionEvent altsEvt = (TsiHandshakeCompletionEvent) evt; - if (altsEvt.isSuccess()) { - // Add the gRPC handler just before this handler. We only allow the grpcHandler to be - // null to support testing. In production, a grpc handler will always be provided. - if (grpcHandler != null) { - ctx.pipeline().addBefore(ctx.name(), null, grpcHandler); - AltsAuthContext altsContext = (AltsAuthContext) altsEvt.context(); - Preconditions.checkNotNull(altsContext); - // Checks peer Rpc Protocol Versions in the ALTS auth context. Fails the connection if - // Rpc Protocol Versions mismatch. - RpcVersionsCheckResult checkResult = - RpcProtocolVersionsUtil.checkRpcProtocolVersions( - RpcProtocolVersionsUtil.getRpcProtocolVersions(), - altsContext.getPeerRpcVersions()); - if (!checkResult.getResult()) { - String errorMessage = - "Local Rpc Protocol Versions " - + RpcProtocolVersionsUtil.getRpcProtocolVersions().toString() - + "are not compatible with peer Rpc Protocol Versions " - + altsContext.getPeerRpcVersions().toString(); - fail(ctx, Status.UNAVAILABLE.withDescription(errorMessage).asRuntimeException()); - } - grpcHandler.handleProtocolNegotiationCompleted( - Attributes.newBuilder() - .set(TSI_PEER_KEY, altsEvt.peer()) - .set(ALTS_CONTEXT_KEY, altsContext) - .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress()) - .build()); - } - - // Now write any buffered data and remove this handler. - writeBufferedAndRemove(ctx); - } else { - fail(ctx, unavailableException("ALTS handshake failed", altsEvt.cause())); - } + public TsiHandshaker newHandshaker( + @Nullable String authority, ChannelLogger negotiationLogger) { + AltsClientOptions handshakerOptions = + new AltsClientOptions.Builder() + .setRpcProtocolVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions()) + .setTargetServiceAccounts(targetServiceAccounts) + .setTargetName(authority) + .build(); + return AltsTsiHandshaker.newClient( + HandshakerServiceGrpc.newStub(lazyHandshakerChannel.get()), + handshakerOptions, + negotiationLogger); + } + } + + /** Channel created from a channel pool lazily. */ + @VisibleForTesting + static final class LazyChannel { + private final ObjectPool channelPool; + private Channel channel; + + @VisibleForTesting + LazyChannel(ObjectPool channelPool) { + this.channelPool = checkNotNull(channelPool, "channelPool"); + } + + /** + * If channel is null, gets a channel from the channel pool, otherwise, returns the cached + * channel. + */ + synchronized Channel get() { + if (channel == null) { + channel = channelPool.getObject(); } - super.userEventTriggered(ctx, evt); + return channel; } - private static RuntimeException unavailableException(String msg, Throwable cause) { - return Status.UNAVAILABLE.withCause(cause).withDescription(msg).asRuntimeException(); + /** Returns the cached channel to the channel pool. */ + synchronized void close() { + if (channel != null) { + channel = channelPool.returnObject(channel); + } } } + + private static final class AltsHandshakeValidator extends TsiHandshakeHandler.HandshakeValidator { + + @Override + public SecurityDetails validatePeerObject(Object peerObject) throws GeneralSecurityException { + AltsInternalContext altsContext = (AltsInternalContext) peerObject; + // Checks peer Rpc Protocol Versions in the ALTS auth context. Fails the connection if + // Rpc Protocol Versions mismatch. + RpcVersionsCheckResult checkResult = + RpcProtocolVersionsUtil.checkRpcProtocolVersions( + RpcProtocolVersionsUtil.getRpcProtocolVersions(), + altsContext.getPeerRpcVersions()); + if (!checkResult.getResult()) { + String errorMessage = + "Local Rpc Protocol Versions " + + RpcProtocolVersionsUtil.getRpcProtocolVersions() + + " are not compatible with peer Rpc Protocol Versions " + + altsContext.getPeerRpcVersions(); + throw Status.UNAVAILABLE.withDescription(errorMessage).asRuntimeException(); + } + return new SecurityDetails( + SecurityLevel.PRIVACY_AND_INTEGRITY, + new Security(new OtherSecurity("alts", Any.pack(altsContext.context)))); + } + } + + @VisibleForTesting + static int getAltsMaxConcurrentHandshakes(String altsMaxConcurrentHandshakes) { + if (altsMaxConcurrentHandshakes == null) { + return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES; + } + try { + int effectiveMaxConcurrentHandshakes = Integer.parseInt(altsMaxConcurrentHandshakes); + if (effectiveMaxConcurrentHandshakes < 0) { + logger.warning( + "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES environment variable set to invalid value."); + return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES; + } + return effectiveMaxConcurrentHandshakes; + } catch (NumberFormatException e) { + logger.warning( + "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES environment variable set to invalid value."); + return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES; + } + } + + private static int getAltsMaxConcurrentHandshakes() { + return getAltsMaxConcurrentHandshakes( + System.getenv(ALTS_MAX_CONCURRENT_HANDSHAKES_ENV_VARIABLE)); + } + + private AltsProtocolNegotiator() {} } diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsTsiFrameProtector.java b/alts/src/main/java/io/grpc/alts/internal/AltsTsiFrameProtector.java index 178e881a2af..67d6637a130 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsTsiFrameProtector.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsTsiFrameProtector.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,10 @@ public final class AltsTsiFrameProtector implements TsiFrameProtector { private static final int HEADER_TYPE_FIELD_BYTES = 4; private static final int HEADER_BYTES = HEADER_LEN_FIELD_BYTES + HEADER_TYPE_FIELD_BYTES; private static final int HEADER_TYPE_DEFAULT = 6; - // Total frame size including full header and tag. - private static final int MAX_ALLOWED_FRAME_BYTES = 16 * 1024; - private static final int LIMIT_MAX_ALLOWED_FRAME_BYTES = 1024 * 1024; + private static final int LIMIT_MAX_ALLOWED_FRAME_SIZE = 1024 * 1024; + // Frame size negotiation extends frame size range to [MIN_FRAME_SIZE, MAX_FRAME_SIZE]. + private static final int MIN_FRAME_SIZE = 16 * 1024; + private static final int MAX_FRAME_SIZE = 128 * 1024; private final Protector protector; private final Unprotector unprotector; @@ -44,7 +45,7 @@ public final class AltsTsiFrameProtector implements TsiFrameProtector { public AltsTsiFrameProtector( int maxProtectedFrameBytes, ChannelCrypterNetty crypter, ByteBufAllocator alloc) { checkArgument(maxProtectedFrameBytes > HEADER_BYTES + crypter.getSuffixLength()); - maxProtectedFrameBytes = Math.min(LIMIT_MAX_ALLOWED_FRAME_BYTES, maxProtectedFrameBytes); + maxProtectedFrameBytes = Math.min(LIMIT_MAX_ALLOWED_FRAME_SIZE, maxProtectedFrameBytes); protector = new Protector(maxProtectedFrameBytes, crypter); unprotector = new Unprotector(crypter, alloc); } @@ -65,12 +66,16 @@ static int getHeaderTypeDefault() { return HEADER_TYPE_DEFAULT; } - public static int getMaxAllowedFrameBytes() { - return MAX_ALLOWED_FRAME_BYTES; + static int getLimitMaxAllowedFrameSize() { + return LIMIT_MAX_ALLOWED_FRAME_SIZE; } - static int getLimitMaxAllowedFrameBytes() { - return LIMIT_MAX_ALLOWED_FRAME_BYTES; + public static int getMinFrameSize() { + return MIN_FRAME_SIZE; + } + + public static int getMaxFrameSize() { + return MAX_FRAME_SIZE; } @Override @@ -128,7 +133,6 @@ void protectFlush( } } - @SuppressWarnings("BetaApi") // verify is stable in Guava private ByteBuf handleUnprotected(List unprotectedBufs, ByteBufAllocator alloc) throws GeneralSecurityException { long unprotectedBytes = 0; @@ -263,14 +267,13 @@ private void handleHeader() { checkArgument( requiredProtectedBytes >= suffixBytes, "Invalid header field: frame size too small"); checkArgument( - requiredProtectedBytes <= LIMIT_MAX_ALLOWED_FRAME_BYTES - HEADER_BYTES, + requiredProtectedBytes <= LIMIT_MAX_ALLOWED_FRAME_SIZE - HEADER_BYTES, "Invalid header field: frame size too large"); int frameType = header.readIntLE(); checkArgument(frameType == HEADER_TYPE_DEFAULT, "Invalid header field: frame type"); state = DeframerState.READ_PROTECTED_PAYLOAD; } - @SuppressWarnings("BetaApi") // verify is stable in Guava private ByteBuf handlePayload(ByteBufAllocator alloc) throws GeneralSecurityException { int requiredCiphertextBytes = requiredProtectedBytes - suffixBytes; int firstFrameUnprotectedLen = requiredCiphertextBytes; diff --git a/alts/src/main/java/io/grpc/alts/internal/AltsTsiHandshaker.java b/alts/src/main/java/io/grpc/alts/internal/AltsTsiHandshaker.java index 6ce8ff99a70..2d6c322c1b1 100644 --- a/alts/src/main/java/io/grpc/alts/internal/AltsTsiHandshaker.java +++ b/alts/src/main/java/io/grpc/alts/internal/AltsTsiHandshaker.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,11 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import io.grpc.ChannelLogger; +import io.grpc.ChannelLogger.ChannelLogLevel; import io.grpc.alts.internal.HandshakerServiceGrpc.HandshakerServiceStub; import io.netty.buffer.ByteBufAllocator; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; import java.util.ArrayList; @@ -31,6 +34,8 @@ * Negotiates a grpc channel key to be used by the TsiFrameProtector, using ALTs handshaker service. */ public final class AltsTsiHandshaker implements TsiHandshaker { + private final ChannelLogger logger; + public static final String TSI_SERVICE_ACCOUNT_PEER_PROPERTY = "service_account"; private final boolean isClient; @@ -40,15 +45,20 @@ public final class AltsTsiHandshaker implements TsiHandshaker { /** Starts a new TSI handshaker with client options. */ private AltsTsiHandshaker( - boolean isClient, HandshakerServiceStub stub, AltsHandshakerOptions options) { + boolean isClient, + HandshakerServiceStub stub, + AltsHandshakerOptions options, + ChannelLogger logger) { this.isClient = isClient; - handshaker = new AltsHandshakerClient(stub, options); + this.logger = logger; + handshaker = new AltsHandshakerClient(stub, options, logger); } @VisibleForTesting - AltsTsiHandshaker(boolean isClient, AltsHandshakerClient handshaker) { + AltsTsiHandshaker(boolean isClient, AltsHandshakerClient handshaker, ChannelLogger logger) { this.isClient = isClient; this.handshaker = handshaker; + this.logger = logger; } /** @@ -70,11 +80,12 @@ public boolean processBytesFromPeer(ByteBuffer bytes) throws GeneralSecurityExce return true; } int remaining = bytes.remaining(); - // Call handshaker service to proceess the bytes. + // Call handshaker service to process the bytes. if (outputFrame == null) { checkState(!isClient, "Client handshaker should not process any frame at the beginning."); outputFrame = handshaker.startServerHandshake(bytes); } else { + logger.log(ChannelLogLevel.DEBUG, "Receive ALTS handshake from downstream"); outputFrame = handshaker.next(bytes); } // If handshake has finished or we already have bytes to write, just return true. @@ -99,7 +110,7 @@ public boolean processBytesFromPeer(ByteBuffer bytes) throws GeneralSecurityExce @Override public TsiPeer extractPeer() throws GeneralSecurityException { Preconditions.checkState(!isInProgress(), "Handshake is not complete."); - List> peerProperties = new ArrayList>(); + List> peerProperties = new ArrayList<>(); peerProperties.add( new TsiPeer.StringProperty( TSI_SERVICE_ACCOUNT_PEER_PROPERTY, @@ -115,17 +126,19 @@ public TsiPeer extractPeer() throws GeneralSecurityException { @Override public Object extractPeerObject() throws GeneralSecurityException { Preconditions.checkState(!isInProgress(), "Handshake is not complete."); - return new AltsAuthContext(handshaker.getResult()); + return new AltsInternalContext(handshaker.getResult()); } /** Creates a new TsiHandshaker for use by the client. */ - public static TsiHandshaker newClient(HandshakerServiceStub stub, AltsHandshakerOptions options) { - return new AltsTsiHandshaker(true, stub, options); + public static TsiHandshaker newClient( + HandshakerServiceStub stub, AltsHandshakerOptions options, ChannelLogger logger) { + return new AltsTsiHandshaker(true, stub, options, logger); } /** Creates a new TsiHandshaker for use by the server. */ - public static TsiHandshaker newServer(HandshakerServiceStub stub, AltsHandshakerOptions options) { - return new AltsTsiHandshaker(false, stub, options); + public static TsiHandshaker newServer( + HandshakerServiceStub stub, AltsHandshakerOptions options, ChannelLogger logger) { + return new AltsTsiHandshaker(false, stub, options, logger); } /** @@ -137,24 +150,26 @@ public static TsiHandshaker newServer(HandshakerServiceStub stub, AltsHandshaker public void getBytesToSendToPeer(ByteBuffer bytes) throws GeneralSecurityException { if (outputFrame == null) { // A null outputFrame indicates we haven't started the handshake. if (isClient) { + logger.log(ChannelLogLevel.DEBUG, "Initial ALTS handshake to downstream"); outputFrame = handshaker.startClientHandshake(); } else { // The server needs bytes to process before it can start the handshake. return; } } + logger.log(ChannelLogLevel.DEBUG, "Send ALTS request to downstream"); // Write as many bytes as we are able. ByteBuffer outputFrameAlias = outputFrame; if (outputFrame.remaining() > bytes.remaining()) { outputFrameAlias = outputFrame.duplicate(); - outputFrameAlias.limit(outputFrameAlias.position() + bytes.remaining()); + ((Buffer) outputFrameAlias).limit(outputFrameAlias.position() + bytes.remaining()); } bytes.put(outputFrameAlias); - outputFrame.position(outputFrameAlias.position()); + ((Buffer) outputFrame).position(outputFrameAlias.position()); } /** - * Returns true if and only if the handshake is still in progress + * Returns true if and only if the handshake is still in progress. * * @return true, if the handshake is still in progress, false otherwise. */ @@ -178,6 +193,14 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator byte[] key = handshaker.getKey(); Preconditions.checkState(key.length == AltsChannelCrypter.getKeyLength(), "Bad key length."); + // Frame size negotiation is not performed if the peer does not send max frame size (e.g. peer + // is gRPC Go or peer uses an old binary). + int peerMaxFrameSize = handshaker.getResult().getMaxFrameSize(); + if (peerMaxFrameSize != 0) { + maxFrameSize = Math.min(peerMaxFrameSize, AltsTsiFrameProtector.getMaxFrameSize()); + maxFrameSize = Math.max(AltsTsiFrameProtector.getMinFrameSize(), maxFrameSize); + } + logger.log(ChannelLogLevel.INFO, "Maximum frame size value is {0}.", maxFrameSize); return new AltsTsiFrameProtector(maxFrameSize, new AltsChannelCrypter(key, isClient), alloc); } @@ -190,6 +213,11 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator */ @Override public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) { - return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc); + return createFrameProtector(AltsTsiFrameProtector.getMinFrameSize(), alloc); + } + + @Override + public void close() { + handshaker.close(); } } diff --git a/alts/src/main/java/io/grpc/alts/internal/AsyncSemaphore.java b/alts/src/main/java/io/grpc/alts/internal/AsyncSemaphore.java new file mode 100644 index 00000000000..a8251c7fbd3 --- /dev/null +++ b/alts/src/main/java/io/grpc/alts/internal/AsyncSemaphore.java @@ -0,0 +1,61 @@ +/* + * Copyright 2021 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import com.google.errorprone.annotations.concurrent.GuardedBy; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import java.util.LinkedList; +import java.util.Queue; + +/** Provides a semaphore primitive, without blocking waiting on permits. */ +final class AsyncSemaphore { + private final Object lock = new Object(); + @SuppressWarnings("JdkObsolete") // LinkedList avoids high watermark memory issues + private final Queue queue = new LinkedList<>(); + @GuardedBy("lock") + private int permits; + + public AsyncSemaphore(int permits) { + this.permits = permits; + } + + public ChannelFuture acquire(ChannelHandlerContext ctx) { + synchronized (lock) { + if (permits > 0) { + permits--; + return ctx.newSucceededFuture(); + } + ChannelPromise promise = ctx.newPromise(); + queue.add(promise); + return promise; + } + } + + public void release() { + ChannelPromise next; + synchronized (lock) { + next = queue.poll(); + if (next == null) { + permits++; + return; + } + } + next.setSuccess(); + } +} diff --git a/alts/src/main/java/io/grpc/alts/internal/BufUnwrapper.java b/alts/src/main/java/io/grpc/alts/internal/BufUnwrapper.java index 668753278a8..9934dd2ff55 100644 --- a/alts/src/main/java/io/grpc/alts/internal/BufUnwrapper.java +++ b/alts/src/main/java/io/grpc/alts/internal/BufUnwrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/main/java/io/grpc/alts/internal/ChannelCrypterNetty.java b/alts/src/main/java/io/grpc/alts/internal/ChannelCrypterNetty.java index 991caa78d49..e2e7d4046fb 100644 --- a/alts/src/main/java/io/grpc/alts/internal/ChannelCrypterNetty.java +++ b/alts/src/main/java/io/grpc/alts/internal/ChannelCrypterNetty.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import java.util.List; /** - * A @{code ChannelCrypterNetty} performs stateful encryption and decryption of independent input - * and output streams. Both decrypt and encrypt gather their input from a list of Netty @{link + * A {@code ChannelCrypterNetty} performs stateful encryption and decryption of independent input + * and output streams. Both decrypt and encrypt gather their input from a list of Netty {@link * ByteBuf} instances. * *

Note that we provide implementations of this interface that provide integrity only and diff --git a/alts/src/main/java/io/grpc/alts/internal/NettyTsiHandshaker.java b/alts/src/main/java/io/grpc/alts/internal/NettyTsiHandshaker.java index 01c317d7212..b91cfdad08c 100644 --- a/alts/src/main/java/io/grpc/alts/internal/NettyTsiHandshaker.java +++ b/alts/src/main/java/io/grpc/alts/internal/NettyTsiHandshaker.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,7 +99,7 @@ boolean processBytesFromPeer(ByteBuf data) throws GeneralSecurityException { } /** - * Returns true if and only if the handshake is still in progress + * Returns true if and only if the handshake is still in progress. * * @return true, if the handshake is still in progress, false otherwise. */ @@ -149,4 +149,8 @@ TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) { unwrapper = null; return internalHandshaker.createFrameProtector(alloc); } + + void close() { + internalHandshaker.close(); + } } diff --git a/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java b/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java index 2cbb1e7d4e7..871a51f1bea 100644 --- a/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java +++ b/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkState; +import io.grpc.Internal; import io.netty.channel.Channel; import io.netty.channel.ChannelPromise; import io.netty.channel.DefaultChannelPromise; @@ -34,14 +35,15 @@ * *

NOTE: this code is based on code in Netty's {@code Http2CodecUtil}. */ -final class ProtectedPromise extends DefaultChannelPromise { +@Internal +public final class ProtectedPromise extends DefaultChannelPromise { private final List unprotectedPromises; private int expectedCount; private int successfulCount; private int failureCount; private boolean doneAllocating; - ProtectedPromise(Channel channel, EventExecutor executor, int numUnprotectedPromises) { + public ProtectedPromise(Channel channel, EventExecutor executor, int numUnprotectedPromises) { super(channel, executor); unprotectedPromises = new ArrayList<>(numUnprotectedPromises); } @@ -50,7 +52,7 @@ final class ProtectedPromise extends DefaultChannelPromise { * Adds a promise for a pending unprotected write. This will be notified after all of the writes * complete. */ - void addUnprotectedPromise(ChannelPromise promise) { + public void addUnprotectedPromise(ChannelPromise promise) { unprotectedPromises.add(promise); } @@ -60,7 +62,7 @@ void addUnprotectedPromise(ChannelPromise promise) { * * @return {@code this} promise. */ - ChannelPromise newPromise() { + public ChannelPromise newPromise() { checkState(!doneAllocating, "Done allocating. No more promises can be allocated."); expectedCount++; return this; @@ -72,11 +74,11 @@ ChannelPromise newPromise() { * * @return {@code this} promise. */ - ChannelPromise doneAllocatingPromises() { + public ChannelPromise doneAllocatingPromises() { if (!doneAllocating) { doneAllocating = true; if (successfulCount == expectedCount) { - trySuccessInternal(null); + trySuccessInternal(); return super.setSuccess(null); } } @@ -115,18 +117,18 @@ private boolean awaitingPromises() { } @Override - public ChannelPromise setSuccess(Void result) { - trySuccess(result); + public ChannelPromise setSuccess(Void unused) { + trySuccess(null); return this; } @Override - public boolean trySuccess(Void result) { + public boolean trySuccess(Void unused) { if (awaitingPromises()) { ++successfulCount; if (successfulCount == expectedCount && doneAllocating) { - trySuccessInternal(result); - return super.trySuccess(result); + trySuccessInternal(); + return super.trySuccess(null); } // TODO: We break the interface a bit here. // Multiple success events can be processed without issue because this is an aggregation. @@ -135,9 +137,9 @@ public boolean trySuccess(Void result) { return false; } - private void trySuccessInternal(Void result) { + private void trySuccessInternal() { for (int i = 0; i < unprotectedPromises.size(); ++i) { - unprotectedPromises.get(i).trySuccess(result); + unprotectedPromises.get(i).trySuccess(null); } } diff --git a/alts/src/main/java/io/grpc/alts/internal/RpcProtocolVersionsUtil.java b/alts/src/main/java/io/grpc/alts/internal/RpcProtocolVersionsUtil.java index 294e75ca8df..005065b4e2e 100644 --- a/alts/src/main/java/io/grpc/alts/internal/RpcProtocolVersionsUtil.java +++ b/alts/src/main/java/io/grpc/alts/internal/RpcProtocolVersionsUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,7 @@ package io.grpc.alts.internal; import com.google.common.annotations.VisibleForTesting; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version; +import io.grpc.alts.internal.RpcProtocolVersions.Version; import javax.annotation.Nullable; /** Utility class for Rpc Protocol Versions. */ diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiFrameHandler.java b/alts/src/main/java/io/grpc/alts/internal/TsiFrameHandler.java index 7fd24b8b341..2294d7a07e6 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiFrameHandler.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiFrameHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import com.google.common.annotations.VisibleForTesting; import io.grpc.alts.internal.TsiFrameProtector.Consumer; -import io.grpc.alts.internal.TsiHandshakeHandler.TsiHandshakeCompletionEvent; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelException; import io.netty.channel.ChannelHandlerContext; @@ -33,7 +31,8 @@ import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Future; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Encrypts and decrypts TSI Frames. Writes are buffered here until {@link #flush} is called. Writes @@ -41,10 +40,15 @@ */ public final class TsiFrameHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { + private static final Logger logger = Logger.getLogger(TsiFrameHandler.class.getName()); + private TsiFrameProtector protector; private PendingWriteQueue pendingUnprotectedWrites; + private boolean closeInitiated; - public TsiFrameHandler() {} + public TsiFrameHandler(TsiFrameProtector protector) { + this.protector = checkNotNull(protector, "protector"); + } @Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { @@ -53,40 +57,23 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception { pendingUnprotectedWrites = new PendingWriteQueue(checkNotNull(ctx)); } - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object event) throws Exception { - if (event instanceof TsiHandshakeCompletionEvent) { - TsiHandshakeCompletionEvent tsiEvent = (TsiHandshakeCompletionEvent) event; - if (tsiEvent.isSuccess()) { - setProtector(tsiEvent.protector()); - } - // Ignore errors. Another handler in the pipeline must handle TSI Errors. - } - // Keep propagating the message, as others may want to read it. - super.userEventTriggered(ctx, event); - } - - @VisibleForTesting - void setProtector(TsiFrameProtector protector) { - checkState(this.protector == null); - this.protector = checkNotNull(protector); - } - @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - checkState(protector != null, "Cannot read frames while the TSI handshake is in progress"); + checkState(protector != null, "decode() called after close()"); protector.unprotect(in, out, ctx.alloc()); } @Override - public void write(ChannelHandlerContext ctx, Object message, ChannelPromise promise) - throws Exception { - checkState(protector != null, "Cannot write frames while the TSI handshake is in progress"); + @SuppressWarnings("FutureReturnValueIgnored") // for setSuccess + public void write(ChannelHandlerContext ctx, Object message, ChannelPromise promise) { + if (protector == null) { + promise.setFailure(new IllegalStateException("write() called after close()")); + return; + } ByteBuf msg = (ByteBuf) message; if (!msg.isReadable()) { // Nothing to encode. - @SuppressWarnings("unused") // go/futurereturn-lsc - Future possiblyIgnoredError = promise.setSuccess(); + promise.setSuccess(); return; } @@ -96,23 +83,81 @@ public void write(ChannelHandlerContext ctx, Object message, ChannelPromise prom @Override public void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { - if (!pendingUnprotectedWrites.isEmpty()) { - pendingUnprotectedWrites.removeAndFailAll( - new ChannelException("Pending write on removal of TSI handler")); + destroyProtectorAndWrites(); + } + + @Override + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { + doClose(ctx); + ctx.disconnect(promise); + } + + @Override + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { + doClose(ctx); + ctx.close(promise); + } + + private void doClose(ChannelHandlerContext ctx) { + if (closeInitiated) { + return; + } + closeInitiated = true; + try { + // flush any remaining writes before close + if (!pendingUnprotectedWrites.isEmpty()) { + flush(ctx); + } + } catch (GeneralSecurityException e) { + logger.log(Level.FINE, "Ignored error on flush before close", e); + } finally { + destroyProtectorAndWrites(); } } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - pendingUnprotectedWrites.removeAndFailAll(cause); - super.exceptionCaught(ctx, cause); + @SuppressWarnings("FutureReturnValueIgnored") // for aggregatePromise.doneAllocatingPromises + public void flush(final ChannelHandlerContext ctx) throws GeneralSecurityException { + if (pendingUnprotectedWrites == null || pendingUnprotectedWrites.isEmpty()) { + // Return early if there's nothing to write. Otherwise protector.protectFlush() below may + // not check for "no-data" and go on writing the 0-byte "data" to the socket with the + // protection framing. + return; + } + // Flushes can happen after close, but only when there are no pending writes. + checkState(protector != null, "flush() called after close()"); + final ProtectedPromise aggregatePromise = + new ProtectedPromise(ctx.channel(), ctx.executor(), pendingUnprotectedWrites.size()); + List bufs = new ArrayList<>(pendingUnprotectedWrites.size()); + + // Drain the unprotected writes. + while (!pendingUnprotectedWrites.isEmpty()) { + ByteBuf in = (ByteBuf) pendingUnprotectedWrites.current(); + bufs.add(in.retain()); + // Remove and release the buffer and add its promise to the aggregate. + aggregatePromise.addUnprotectedPromise(pendingUnprotectedWrites.remove()); + } + + final class ProtectedFrameWriteFlusher implements Consumer { + + @Override + public void accept(ByteBuf byteBuf) { + ctx.writeAndFlush(byteBuf, aggregatePromise.newPromise()); + } + } + + protector.protectFlush(bufs, new ProtectedFrameWriteFlusher(), ctx.alloc()); + // We're done writing, start the flow of promise events. + aggregatePromise.doneAllocatingPromises(); } + // Only here to fulfill ChannelOutboundHandler @Override public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { ctx.bind(localAddress, promise); } + // Only here to fulfill ChannelOutboundHandler @Override public void connect( ChannelHandlerContext ctx, @@ -122,60 +167,33 @@ public void connect( ctx.connect(remoteAddress, localAddress, promise); } - @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { - ctx.disconnect(promise); - } - - @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) { - ctx.close(promise); - } - + // Only here to fulfill ChannelOutboundHandler @Override public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.deregister(promise); } + // Only here to fulfill ChannelOutboundHandler @Override public void read(ChannelHandlerContext ctx) { ctx.read(); } - @Override - public void flush(final ChannelHandlerContext ctx) throws GeneralSecurityException { - checkState(protector != null, "Cannot write frames while the TSI handshake is in progress"); - final ProtectedPromise aggregatePromise = - new ProtectedPromise(ctx.channel(), ctx.executor(), pendingUnprotectedWrites.size()); - - List bufs = new ArrayList<>(pendingUnprotectedWrites.size()); - - if (pendingUnprotectedWrites.isEmpty()) { - // Return early if there's nothing to write. Otherwise protector.protectFlush() below may - // not check for "no-data" and go on writing the 0-byte "data" to the socket with the - // protection framing. - return; + private void destroyProtectorAndWrites() { + try { + if (pendingUnprotectedWrites != null && !pendingUnprotectedWrites.isEmpty()) { + pendingUnprotectedWrites.removeAndFailAll( + new ChannelException("Pending write on teardown of TSI handler")); + } + } finally { + pendingUnprotectedWrites = null; } - // Drain the unprotected writes. - while (!pendingUnprotectedWrites.isEmpty()) { - ByteBuf in = (ByteBuf) pendingUnprotectedWrites.current(); - bufs.add(in.retain()); - // Remove and release the buffer and add its promise to the aggregate. - aggregatePromise.addUnprotectedPromise(pendingUnprotectedWrites.remove()); + if (protector != null) { + try { + protector.destroy(); + } finally { + protector = null; + } } - - protector.protectFlush( - bufs, - new Consumer() { - @Override - public void accept(ByteBuf b) { - ctx.writeAndFlush(b, aggregatePromise.newPromise()); - } - }, - ctx.alloc()); - - // We're done writing, start the flow of promise events. - @SuppressWarnings("unused") // go/futurereturn-lsc - Future possiblyIgnoredError = aggregatePromise.doneAllocatingPromises(); } } diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiFrameProtector.java b/alts/src/main/java/io/grpc/alts/internal/TsiFrameProtector.java index b5caeab4527..b4227989ef2 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiFrameProtector.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiFrameProtector.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiHandshakeHandler.java b/alts/src/main/java/io/grpc/alts/internal/TsiHandshakeHandler.java index 362179aebd4..7964b122f8c 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiHandshakeHandler.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiHandshakeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,119 +17,99 @@ package io.grpc.alts.internal; import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.annotations.VisibleForTesting; +import static com.google.common.base.Preconditions.checkState; +import static io.grpc.alts.internal.AltsProtocolNegotiator.AUTH_CONTEXT_KEY; +import static io.grpc.alts.internal.AltsProtocolNegotiator.TSI_PEER_KEY; + +import io.grpc.Attributes; +import io.grpc.ChannelLogger; +import io.grpc.ChannelLogger.ChannelLogLevel; +import io.grpc.InternalChannelz.Security; +import io.grpc.SecurityLevel; +import io.grpc.alts.internal.TsiHandshakeHandler.HandshakeValidator.SecurityDetails; +import io.grpc.internal.GrpcAttributes; +import io.grpc.netty.InternalProtocolNegotiationEvent; +import io.grpc.netty.ProtocolNegotiationEvent; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.util.ReferenceCountUtil; import java.security.GeneralSecurityException; import java.util.List; -import java.util.concurrent.Future; import javax.annotation.Nullable; /** - * Performs The TSI Handshake. When the handshake is complete, it fires a user event with a {@link - * TsiHandshakeCompletionEvent} indicating the result of the handshake. + * Performs The TSI Handshake. */ public final class TsiHandshakeHandler extends ByteToMessageDecoder { - private static final int HANDSHAKE_FRAME_SIZE = 1024; - - private final NettyTsiHandshaker handshaker; - private boolean started; - /** - * This buffer doesn't store any state. We just hold onto it in case we end up allocating a buffer - * that ends up being unused. + * Validates a Tsi Peer object. */ - private ByteBuf buffer; + public abstract static class HandshakeValidator { - public TsiHandshakeHandler(NettyTsiHandshaker handshaker) { - this.handshaker = checkNotNull(handshaker); - } + public static final class SecurityDetails { - /** - * Event that is fired once the TSI handshake is complete, which may be because it was successful - * or there was an error. - */ - public static final class TsiHandshakeCompletionEvent { - - private final Throwable cause; - private final TsiPeer peer; - private final Object context; - private final TsiFrameProtector protector; - - /** Creates a new event that indicates a successful handshake. */ - @VisibleForTesting - TsiHandshakeCompletionEvent( - TsiFrameProtector protector, TsiPeer peer, @Nullable Object peerObject) { - this.cause = null; - this.peer = checkNotNull(peer); - this.protector = checkNotNull(protector); - this.context = peerObject; - } + private final SecurityLevel securityLevel; + private final Security security; - /** Creates a new event that indicates an unsuccessful handshake/. */ - TsiHandshakeCompletionEvent(Throwable cause) { - this.cause = checkNotNull(cause); - this.peer = null; - this.protector = null; - this.context = null; - } + /** + * Constructs SecurityDetails. + */ + public SecurityDetails(io.grpc.SecurityLevel securityLevel, @Nullable Security security) { + this.securityLevel = checkNotNull(securityLevel, "securityLevel"); + this.security = security; + } - /** Return {@code true} if the handshake was successful. */ - public boolean isSuccess() { - return cause == null; + public Security getSecurity() { + return security; + } + + public SecurityLevel getSecurityLevel() { + return securityLevel; + } } /** - * Return the {@link Throwable} if {@link #isSuccess()} returns {@code false} and so the - * handshake failed. + * Validates a Tsi Peer object. */ - @Nullable - public Throwable cause() { - return cause; - } - - @Nullable - public TsiPeer peer() { - return peer; - } - - @Nullable - public Object context() { - return context; - } - - @Nullable - TsiFrameProtector protector() { - return protector; - } + public abstract SecurityDetails validatePeerObject(Object peerObject) + throws GeneralSecurityException; } - @Override - public void handlerAdded(ChannelHandlerContext ctx) throws Exception { - maybeStart(ctx); - super.handlerAdded(ctx); - } + private static final int HANDSHAKE_FRAME_SIZE = 1024; - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - maybeStart(ctx); - super.channelActive(ctx); - } + private final NettyTsiHandshaker handshaker; + private final HandshakeValidator handshakeValidator; + private final ChannelHandler next; + private final AsyncSemaphore semaphore; - @Override - public void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { - close(); - super.handlerRemoved0(ctx); + private ProtocolNegotiationEvent pne; + private boolean semaphoreAcquired; + private final ChannelLogger negotiationLogger; + + /** + * Constructs a TsiHandshakeHandler. + */ + public TsiHandshakeHandler( + ChannelHandler next, NettyTsiHandshaker handshaker, HandshakeValidator handshakeValidator, + ChannelLogger negotiationLogger) { + this(next, handshaker, handshakeValidator, null, negotiationLogger); } - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - ctx.fireUserEventTriggered(new TsiHandshakeCompletionEvent(cause)); - super.exceptionCaught(ctx, cause); + /** + * Constructs a TsHandshakeHandler. If a semaphore is provided, a permit from the semaphore is + * required to start the handshake and is returned when the handshake ends. + */ + public TsiHandshakeHandler( + ChannelHandler next, NettyTsiHandshaker handshaker, HandshakeValidator handshakeValidator, + AsyncSemaphore semaphore, ChannelLogger negotiationLogger) { + this.handshaker = checkNotNull(handshaker, "handshaker"); + this.handshakeValidator = checkNotNull(handshakeValidator, "handshakeValidator"); + this.next = checkNotNull(next, "next"); + this.semaphore = semaphore; + this.negotiationLogger = negotiationLogger; } @Override @@ -148,65 +128,123 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) t // If the handshake is complete, transition to the framing state. if (!handshaker.isInProgress()) { + TsiPeer peer = handshaker.extractPeer(); + Object authContext = handshaker.extractPeerObject(); + SecurityDetails details = handshakeValidator.validatePeerObject(authContext); + // createFrameProtector must be called last. + TsiFrameProtector protector = handshaker.createFrameProtector(ctx.alloc()); + TsiFrameHandler framer; + boolean success = false; try { - ctx.pipeline().remove(this); - ctx.fireUserEventTriggered( - new TsiHandshakeCompletionEvent( - handshaker.createFrameProtector(ctx.alloc()), - handshaker.extractPeer(), - handshaker.extractPeerObject())); - // No need to do anything with the in buffer, it will be re added to the pipeline when this - // handler is removed. + framer = new TsiFrameHandler(protector); + // adding framer and next handler after this handler before removing Decoder (current + // handler). This will prevents any missing read from decoder and/or unframed write from + // next handler. + ctx.pipeline().addAfter(ctx.name(), null, framer); + ctx.pipeline().addAfter(ctx.pipeline().context(framer).name(), null, next); + ctx.pipeline().remove(ctx.name()); + fireProtocolNegotiationEvent(ctx, peer, authContext, details); + success = true; } finally { - close(); + if (!success && protector != null) { + protector.destroy(); + } } } } - private void maybeStart(ChannelHandlerContext ctx) { - if (!started && ctx.channel().isActive()) { - started = true; - sendHandshake(ctx); + @Override + public void userEventTriggered(final ChannelHandlerContext ctx, Object evt) throws Exception { + if (evt instanceof ProtocolNegotiationEvent) { + checkState(pne == null, "negotiation already started"); + pne = (ProtocolNegotiationEvent) evt; + negotiationLogger.log(ChannelLogLevel.INFO, "TsiHandshake started"); + ChannelFuture acquire = semaphoreAcquire(ctx); + if (acquire.isSuccess()) { + semaphoreAcquired = true; + sendHandshake(ctx); + } else { + acquire.addListener(new ChannelFutureListener() { + @Override public void operationComplete(ChannelFuture future) { + if (!future.isSuccess()) { + ctx.fireExceptionCaught(future.cause()); + return; + } + if (ctx.isRemoved()) { + semaphoreRelease(); + return; + } + semaphoreAcquired = true; + try { + sendHandshake(ctx); + } catch (Exception ex) { + ctx.fireExceptionCaught(ex); + } + ctx.flush(); + } + }); + } + } else { + super.userEventTriggered(ctx, evt); } } - /** Sends as many bytes as are available from the handshaker to the remote peer. */ - private void sendHandshake(ChannelHandlerContext ctx) { - boolean needToFlush = false; + private void fireProtocolNegotiationEvent( + ChannelHandlerContext ctx, TsiPeer peer, Object authContext, SecurityDetails details) { + checkState(pne != null, "negotiation not yet complete"); + negotiationLogger.log(ChannelLogLevel.INFO, "TsiHandshake finished"); + ProtocolNegotiationEvent localPne = pne; + Attributes.Builder attrs = InternalProtocolNegotiationEvent.getAttributes(localPne).toBuilder() + .set(TSI_PEER_KEY, peer) + .set(AUTH_CONTEXT_KEY, authContext) + .set(GrpcAttributes.ATTR_SECURITY_LEVEL, details.getSecurityLevel()); + localPne = InternalProtocolNegotiationEvent.withAttributes(localPne, attrs.build()); + localPne = InternalProtocolNegotiationEvent.withSecurity(localPne, details.getSecurity()); + ctx.fireUserEventTriggered(localPne); + } - // Iterate until there is nothing left to write. + /** Sends as many bytes as are available from the handshaker to the remote peer. */ + @SuppressWarnings("FutureReturnValueIgnored") // for addListener + private void sendHandshake(ChannelHandlerContext ctx) throws GeneralSecurityException { while (true) { - buffer = getOrCreateBuffer(ctx.alloc()); + boolean written = false; + ByteBuf buf = ctx.alloc().buffer(HANDSHAKE_FRAME_SIZE).retain(); // refcnt = 2 try { - handshaker.getBytesToSendToPeer(buffer); + handshaker.getBytesToSendToPeer(buf); + if (buf.isReadable()) { + ctx.writeAndFlush(buf).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + written = true; + } else { + break; + } } catch (GeneralSecurityException e) { - throw new RuntimeException(e); - } - if (!buffer.isReadable()) { - break; + throw new GeneralSecurityException("TsiHandshakeHandler encountered exception", e); + } finally { + buf.release(written ? 1 : 2); } - - needToFlush = true; - @SuppressWarnings("unused") // go/futurereturn-lsc - Future possiblyIgnoredError = ctx.write(buffer); - buffer = null; } + } - // If something was written, flush. - if (needToFlush) { - ctx.flush(); + @Override + protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { + if (semaphoreAcquired) { + semaphoreRelease(); + semaphoreAcquired = false; } + handshaker.close(); } - private ByteBuf getOrCreateBuffer(ByteBufAllocator alloc) { - if (buffer == null) { - buffer = alloc.buffer(HANDSHAKE_FRAME_SIZE); + private ChannelFuture semaphoreAcquire(ChannelHandlerContext ctx) { + if (semaphore == null) { + return ctx.newSucceededFuture(); + } else { + return semaphore.acquire(ctx); } - return buffer; } - private void close() { - ReferenceCountUtil.safeRelease(buffer); - buffer = null; + private void semaphoreRelease() { + if (semaphore != null) { + semaphore.release(); + } } } diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiHandshaker.java b/alts/src/main/java/io/grpc/alts/internal/TsiHandshaker.java index 546f5972128..6580a4433c7 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiHandshaker.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiHandshaker.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ public interface TsiHandshaker { boolean processBytesFromPeer(ByteBuffer bytes) throws GeneralSecurityException; /** - * Returns true if and only if the handshake is still in progress + * Returns true if and only if the handshake is still in progress. * * @return true, if the handshake is still in progress, false otherwise. */ @@ -86,7 +86,7 @@ public interface TsiHandshaker { * * @return the extracted peer. */ - public Object extractPeerObject() throws GeneralSecurityException; + Object extractPeerObject() throws GeneralSecurityException; /** * Creates a frame protector from a completed handshake. No other methods may be called after the @@ -106,4 +106,9 @@ public interface TsiHandshaker { * @return a new TsiFrameProtector. */ TsiFrameProtector createFrameProtector(ByteBufAllocator alloc); + + /** + * Closes resources. + */ + void close(); } diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiHandshakerFactory.java b/alts/src/main/java/io/grpc/alts/internal/TsiHandshakerFactory.java index 9ad5d1ad401..7d17a3954c8 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiHandshakerFactory.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiHandshakerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,12 @@ package io.grpc.alts.internal; +import io.grpc.ChannelLogger; +import javax.annotation.Nullable; + /** Factory that manufactures instances of {@link TsiHandshaker}. */ public interface TsiHandshakerFactory { /** Creates a new handshaker. */ - TsiHandshaker newHandshaker(); + TsiHandshaker newHandshaker(@Nullable String authority, ChannelLogger logger); } diff --git a/alts/src/main/java/io/grpc/alts/internal/TsiPeer.java b/alts/src/main/java/io/grpc/alts/internal/TsiPeer.java index 9198744b0be..c02188c50ac 100644 --- a/alts/src/main/java/io/grpc/alts/internal/TsiPeer.java +++ b/alts/src/main/java/io/grpc/alts/internal/TsiPeer.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ public abstract static class Property { private final String name; private final T value; - public Property(@Nonnull String name, @Nonnull T value) { + protected Property(@Nonnull String name, @Nonnull T value) { this.name = name; this.value = value; } @@ -73,6 +73,13 @@ public String toString() { } } + /** A peer property corresponding to a boolean. */ + public static final class BooleanProperty extends Property { + public BooleanProperty(@Nonnull String name, boolean value) { + super(name, value); + } + } + /** A peer property corresponding to a signed 64-bit integer. */ public static final class SignedInt64Property extends Property { public SignedInt64Property(@Nonnull String name, @Nonnull Long value) { diff --git a/alts/src/main/proto/altscontext.proto b/alts/src/main/proto/altscontext.proto deleted file mode 100644 index 823d4a0f488..00000000000 --- a/alts/src/main/proto/altscontext.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto3"; - -import "transport_security_common.proto"; - -package grpc.gcp; - -option java_package = "io.grpc.alts.internal"; - -message AltsContext { - // The application protocol negotiated for this connection. - string application_protocol = 1; - - // The record protocol negotiated for this connection. - string record_protocol = 2; - - // The security level of the created secure channel. - SecurityLevel security_level = 3; - - // The peer service account. - string peer_service_account = 4; - - // The local service account. - string local_service_account = 5; - - // The RPC protocol versions supported by the peer. - RpcProtocolVersions peer_rpc_versions = 6; -} diff --git a/alts/src/main/proto/grpc/gcp/altscontext.proto b/alts/src/main/proto/grpc/gcp/altscontext.proto new file mode 100644 index 00000000000..a6cceb1c303 --- /dev/null +++ b/alts/src/main/proto/grpc/gcp/altscontext.proto @@ -0,0 +1,50 @@ +// Copyright 2018 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/gcp/altscontext.proto + +syntax = "proto3"; + +package grpc.gcp; + +import "grpc/gcp/transport_security_common.proto"; + +option go_package = "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"; +option java_multiple_files = true; +option java_outer_classname = "AltsContextProto"; +option java_package = "io.grpc.alts.internal"; + +message AltsContext { + // The application protocol negotiated for this connection. + string application_protocol = 1; + + // The record protocol negotiated for this connection. + string record_protocol = 2; + + // The security level of the created secure channel. + SecurityLevel security_level = 3; + + // The peer service account. + string peer_service_account = 4; + + // The local service account. + string local_service_account = 5; + + // The RPC protocol versions supported by the peer. + RpcProtocolVersions peer_rpc_versions = 6; + + // Additional attributes of the peer. + map peer_attributes = 7; +} diff --git a/alts/src/main/proto/handshaker.proto b/alts/src/main/proto/grpc/gcp/handshaker.proto similarity index 84% rename from alts/src/main/proto/handshaker.proto rename to alts/src/main/proto/grpc/gcp/handshaker.proto index 9350f63d41a..02764ba4c08 100644 --- a/alts/src/main/proto/handshaker.proto +++ b/alts/src/main/proto/grpc/gcp/handshaker.proto @@ -1,11 +1,32 @@ -syntax = "proto3"; +// Copyright 2018 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/gcp/handshaker.proto -import "transport_security_common.proto"; +syntax = "proto3"; package grpc.gcp; +import "grpc/gcp/transport_security_common.proto"; + +option go_package = "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"; +option java_multiple_files = true; +option java_outer_classname = "HandshakerProto"; option java_package = "io.grpc.alts.internal"; + enum HandshakeProtocol { // Default value. HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; @@ -43,6 +64,9 @@ message Identity { // Hostname of a connection endpoint. string hostname = 2; } + + // Additional attributes of the identity. + map attributes = 3; } message StartClientHandshakeReq { @@ -81,6 +105,9 @@ message StartClientHandshakeReq { // (Optional) RPC protocol versions supported by the client. RpcProtocolVersions rpc_versions = 9; + + // (Optional) Maximum frame size supported by the client. + uint32 max_frame_size = 10; } message ServerHandshakeParameters { @@ -119,6 +146,9 @@ message StartServerHandshakeReq { // (Optional) RPC protocol versions supported by the server. RpcProtocolVersions rpc_versions = 6; + + // (Optional) Maximum frame size supported by the server. + uint32 max_frame_size = 7; } message NextHandshakeMessageReq { @@ -166,6 +196,9 @@ message HandshakerResult { // The RPC protocol versions supported by the peer. RpcProtocolVersions peer_rpc_versions = 7; + + // The maximum frame size of the peer. + uint32 max_frame_size = 8; } message HandshakerStatus { diff --git a/alts/src/main/proto/grpc/gcp/transport_security_common.proto b/alts/src/main/proto/grpc/gcp/transport_security_common.proto new file mode 100644 index 00000000000..8f01be79e36 --- /dev/null +++ b/alts/src/main/proto/grpc/gcp/transport_security_common.proto @@ -0,0 +1,46 @@ +// Copyright 2018 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/gcp/transport_security_common.proto + +syntax = "proto3"; + +package grpc.gcp; + +option go_package = "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"; +option java_multiple_files = true; +option java_outer_classname = "TransportSecurityCommonProto"; +option java_package = "io.grpc.alts.internal"; + +// The security level of the created channel. The list is sorted in increasing +// level of security. This order must always be maintained. +enum SecurityLevel { + SECURITY_NONE = 0; + INTEGRITY_ONLY = 1; + INTEGRITY_AND_PRIVACY = 2; +} + +// Max and min supported RPC protocol versions. +message RpcProtocolVersions { + // RPC version contains a major version and a minor version. + message Version { + uint32 major = 1; + uint32 minor = 2; + } + // Maximum supported RPC version. + Version max_rpc_version = 1; + // Minimum supported RPC version. + Version min_rpc_version = 2; +} diff --git a/alts/src/main/proto/transport_security_common.proto b/alts/src/main/proto/transport_security_common.proto deleted file mode 100644 index 70c0909589f..00000000000 --- a/alts/src/main/proto/transport_security_common.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; - -package grpc.gcp; - -option java_package = "io.grpc.alts.internal"; - -// The security level of the created channel. The list is sorted in increasing -// level of security. This order must always be maintained. -enum SecurityLevel { - SECURITY_NONE = 0; - INTEGRITY_ONLY = 1; - INTEGRITY_AND_PRIVACY = 2; -} - -// Max and min supported RPC protocol versions. -message RpcProtocolVersions { - // RPC version contains a major version and a minor version. - message Version { - uint32 major = 1; - uint32 minor = 2; - } - // Maximum supported RPC version. - Version max_rpc_version = 1; - // Minimum supported RPC version. - Version min_rpc_version = 2; -} diff --git a/alts/src/test/java/io/grpc/alts/AltsChannelBuilderTest.java b/alts/src/test/java/io/grpc/alts/AltsChannelBuilderTest.java index 44ab158db7f..a44de19b911 100644 --- a/alts/src/test/java/io/grpc/alts/AltsChannelBuilderTest.java +++ b/alts/src/test/java/io/grpc/alts/AltsChannelBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,8 @@ package io.grpc.alts; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import com.google.common.base.Defaults; -import io.grpc.ManagedChannel; -import io.grpc.alts.AltsChannelBuilder.AltsChannel; -import io.grpc.alts.internal.AltsClientOptions; -import io.grpc.alts.internal.AltsProtocolNegotiator; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import io.grpc.netty.InternalNettyChannelBuilder.TransportCreationParamsFilterFactory; -import io.grpc.netty.ProtocolNegotiator; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.InetSocketAddress; +import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -39,57 +27,14 @@ public final class AltsChannelBuilderTest { @Test - public void buildsNettyChannel() throws Exception { + public void buildsNettyChannel() { AltsChannelBuilder builder = AltsChannelBuilder.forTarget("localhost:8080").enableUntrustedAltsForTesting(); - TransportCreationParamsFilterFactory tcpfFactory = builder.getTcpfFactoryForTest(); - AltsClientOptions altsClientOptions = builder.getAltsClientOptionsForTest(); - - assertThat(tcpfFactory).isNull(); - assertThat(altsClientOptions).isNull(); - - ManagedChannel channel = builder.build(); - assertThat(channel).isInstanceOf(AltsChannel.class); - - tcpfFactory = builder.getTcpfFactoryForTest(); - altsClientOptions = builder.getAltsClientOptionsForTest(); - - assertThat(tcpfFactory).isNotNull(); - ProtocolNegotiator protocolNegotiator = - tcpfFactory - .create(new InetSocketAddress(8080), "fakeAuthority", "fakeUserAgent", null) - .getProtocolNegotiator(); - assertThat(protocolNegotiator).isInstanceOf(AltsProtocolNegotiator.class); - - assertThat(altsClientOptions).isNotNull(); - RpcProtocolVersions expectedVersions = - RpcProtocolVersions.newBuilder() - .setMaxRpcVersion( - RpcProtocolVersions.Version.newBuilder().setMajor(2).setMinor(1).build()) - .setMinRpcVersion( - RpcProtocolVersions.Version.newBuilder().setMajor(2).setMinor(1).build()) - .build(); - assertThat(altsClientOptions.getRpcProtocolVersions()).isEqualTo(expectedVersions); - } - - @Test - public void allAltsChannelMethodsForward() throws Exception { - ManagedChannel mockDelegate = mock(ManagedChannel.class); - AltsChannel altsChannel = new AltsChannel(mockDelegate); - - for (Method method : ManagedChannel.class.getDeclaredMethods()) { - if (Modifier.isStatic(method.getModifiers()) || Modifier.isPrivate(method.getModifiers())) { - continue; - } - Class[] argTypes = method.getParameterTypes(); - Object[] args = new Object[argTypes.length]; - for (int i = 0; i < argTypes.length; i++) { - args[i] = Defaults.defaultValue(argTypes[i]); - } - - method.invoke(altsChannel, args); - method.invoke(verify(mockDelegate), args); - } + ProtocolNegotiator protocolNegotiator = builder.getProtocolNegotiatorForTest(); + assertThat(protocolNegotiator).isNotNull(); + // Avoids exposing this class + assertThat(protocolNegotiator.getClass().getSimpleName()) + .isEqualTo("ClientAltsProtocolNegotiator"); } } diff --git a/alts/src/test/java/io/grpc/alts/AltsContextUtilTest.java b/alts/src/test/java/io/grpc/alts/AltsContextUtilTest.java new file mode 100644 index 00000000000..675fa29fc99 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/AltsContextUtilTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.grpc.alts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import io.grpc.Attributes; +import io.grpc.ClientCall; +import io.grpc.ServerCall; +import io.grpc.alts.AltsContext.SecurityLevel; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.AltsProtocolNegotiator; +import io.grpc.alts.internal.HandshakerResult; +import io.grpc.alts.internal.Identity; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link AltsContextUtil}. */ +@RunWith(JUnit4.class) +public class AltsContextUtilTest { + @Test + public void check_noAttributeValue() { + assertFalse(AltsContextUtil.check(Attributes.newBuilder().build())); + } + + @Test + public void check_unexpectedAttributeValueType() { + assertFalse(AltsContextUtil.check(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new Object()) + .build())); + } + + @Test + public void check_altsInternalContext() { + assertTrue(AltsContextUtil.check(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) + .build())); + } + + @Test + public void checkServer_altsInternalContext() { + ServerCall call = mock(ServerCall.class); + when(call.getAttributes()).thenReturn(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) + .build()); + + assertTrue(AltsContextUtil.check(call)); + } + + @Test + public void checkClient_altsInternalContext() { + ClientCall call = mock(ClientCall.class); + when(call.getAttributes()).thenReturn(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) + .build()); + + assertTrue(AltsContextUtil.check(call)); + } + + @Test + public void createFrom_altsInternalContext() { + HandshakerResult handshakerResult = + HandshakerResult.newBuilder() + .setPeerIdentity(Identity.newBuilder().setServiceAccount("remote@peer")) + .setLocalIdentity(Identity.newBuilder().setServiceAccount("local@peer")) + .build(); + + AltsContext context = AltsContextUtil.createFrom(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new AltsInternalContext(handshakerResult)) + .build()); + assertEquals("remote@peer", context.getPeerServiceAccount()); + assertEquals("local@peer", context.getLocalServiceAccount()); + assertEquals(SecurityLevel.INTEGRITY_AND_PRIVACY, context.getSecurityLevel()); + } + + @Test(expected = IllegalArgumentException.class) + public void createFrom_noAttributeValue() { + AltsContextUtil.createFrom(Attributes.newBuilder().build()); + } + + @Test + public void createFromServer_altsInternalContext() { + HandshakerResult handshakerResult = + HandshakerResult.newBuilder() + .setPeerIdentity(Identity.newBuilder().setServiceAccount("remote@peer")) + .setLocalIdentity(Identity.newBuilder().setServiceAccount("local@peer")) + .build(); + + ServerCall call = mock(ServerCall.class); + when(call.getAttributes()).thenReturn(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new AltsInternalContext(handshakerResult)) + .build()); + + AltsContext context = AltsContextUtil.createFrom(call); + assertEquals("remote@peer", context.getPeerServiceAccount()); + } + + @Test + public void createFromClient_altsInternalContext() { + HandshakerResult handshakerResult = + HandshakerResult.newBuilder() + .setPeerIdentity(Identity.newBuilder().setServiceAccount("remote@peer")) + .setLocalIdentity(Identity.newBuilder().setServiceAccount("local@peer")) + .build(); + + ClientCall call = mock(ClientCall.class); + when(call.getAttributes()).thenReturn(Attributes.newBuilder() + .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new AltsInternalContext(handshakerResult)) + .build()); + + AltsContext context = AltsContextUtil.createFrom(call); + assertEquals("remote@peer", context.getPeerServiceAccount()); + } +} diff --git a/alts/src/test/java/io/grpc/alts/AltsServerBuilderTest.java b/alts/src/test/java/io/grpc/alts/AltsServerBuilderTest.java index afdd89025a4..f729a8be2b3 100644 --- a/alts/src/test/java/io/grpc/alts/AltsServerBuilderTest.java +++ b/alts/src/test/java/io/grpc/alts/AltsServerBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/test/java/io/grpc/alts/AuthorizationUtilTest.java b/alts/src/test/java/io/grpc/alts/AuthorizationUtilTest.java new file mode 100644 index 00000000000..8b4691df331 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/AuthorizationUtilTest.java @@ -0,0 +1,114 @@ +/* + * Copyright 2019 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.Lists; +import io.grpc.Attributes; +import io.grpc.Metadata; +import io.grpc.MethodDescriptor; +import io.grpc.ServerCall; +import io.grpc.Status; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.AltsProtocolNegotiator; +import io.grpc.alts.internal.HandshakerResult; +import io.grpc.alts.internal.Identity; +import javax.annotation.Nullable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link AuthorizationUtil}. */ +@RunWith(JUnit4.class) +public final class AuthorizationUtilTest { + + @Test + public void altsAuthorizationCheck() throws Exception { + Status status = + AuthorizationUtil.clientAuthorizationCheck( + new FakeServerCall(null), Lists.newArrayList("Alice")); + assertThat(status.getCode()).isEqualTo(Status.Code.PERMISSION_DENIED); + assertThat(status.getDescription()).startsWith("Peer ALTS AuthContext not found"); + status = + AuthorizationUtil.clientAuthorizationCheck( + new FakeServerCall("Alice"), Lists.newArrayList("Alice", "Bob")); + assertThat(status.getCode()).isEqualTo(Status.Code.OK); + status = + AuthorizationUtil.clientAuthorizationCheck( + new FakeServerCall("Alice"), Lists.newArrayList("Bob", "Joe")); + assertThat(status.getCode()).isEqualTo(Status.Code.PERMISSION_DENIED); + assertThat(status.getDescription()).endsWith("not authorized"); + } + + private static class FakeServerCall extends ServerCall { + final Attributes attrs; + + FakeServerCall(@Nullable String peerServiceAccount) { + Attributes.Builder attrsBuilder = Attributes.newBuilder(); + if (peerServiceAccount != null) { + HandshakerResult handshakerResult = + HandshakerResult.newBuilder() + .setPeerIdentity(Identity.newBuilder().setServiceAccount(peerServiceAccount)) + .build(); + AltsInternalContext altsContext = new AltsInternalContext(handshakerResult); + attrsBuilder.set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, altsContext); + } + attrs = attrsBuilder.build(); + } + + @Override + public void request(int numMessages) { + throw new AssertionError("Should not be called"); + } + + @Override + public void sendHeaders(Metadata headers) { + throw new AssertionError("Should not be called"); + } + + @Override + public void sendMessage(String message) { + throw new AssertionError("Should not be called"); + } + + @Override + public void close(Status status, Metadata trailers) { + throw new AssertionError("Should not be called"); + } + + @Override + public boolean isCancelled() { + throw new AssertionError("Should not be called"); + } + + @Override + public Attributes getAttributes() { + return attrs; + } + + @Override + public String getAuthority() { + throw new AssertionError("Should not be called"); + } + + @Override + public MethodDescriptor getMethodDescriptor() { + throw new AssertionError("Should not be called"); + } + } +} diff --git a/alts/src/test/java/io/grpc/alts/CheckGcpEnvironmentTest.java b/alts/src/test/java/io/grpc/alts/CheckGcpEnvironmentTest.java deleted file mode 100644 index 5e05f18815f..00000000000 --- a/alts/src/test/java/io/grpc/alts/CheckGcpEnvironmentTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2018, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.alts; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.StringReader; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class CheckGcpEnvironmentTest { - - @Test - public void checkGcpLinuxPlatformData() throws Exception { - BufferedReader reader; - reader = new BufferedReader(new StringReader("HP Z440 Workstation")); - assertFalse(CheckGcpEnvironment.checkProductNameOnLinux(reader)); - reader = new BufferedReader(new StringReader("Google")); - assertTrue(CheckGcpEnvironment.checkProductNameOnLinux(reader)); - reader = new BufferedReader(new StringReader("Google Compute Engine")); - assertTrue(CheckGcpEnvironment.checkProductNameOnLinux(reader)); - reader = new BufferedReader(new StringReader("Google Compute Engine ")); - assertTrue(CheckGcpEnvironment.checkProductNameOnLinux(reader)); - } - - @Test - public void checkGcpWindowsPlatformData() throws Exception { - BufferedReader reader; - reader = new BufferedReader(new StringReader("Product : Google")); - assertFalse(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("Manufacturer : LENOVO")); - assertFalse(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("Manufacturer : Google Compute Engine")); - assertFalse(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("Manufacturer : Google")); - assertTrue(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("Manufacturer:Google")); - assertTrue(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("Manufacturer : Google ")); - assertTrue(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - reader = new BufferedReader(new StringReader("BIOSVersion : 1.0\nManufacturer : Google\n")); - assertTrue(CheckGcpEnvironment.checkBiosDataOnWindows(reader)); - } -} diff --git a/alts/src/test/java/io/grpc/alts/ComputeEngineChannelBuilderTest.java b/alts/src/test/java/io/grpc/alts/ComputeEngineChannelBuilderTest.java new file mode 100644 index 00000000000..03fd113a65e --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/ComputeEngineChannelBuilderTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2019 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class ComputeEngineChannelBuilderTest { + + @Test + public void buildsNettyChannel() throws Exception { + ComputeEngineChannelBuilder builder = ComputeEngineChannelBuilder.forTarget("localhost:8080"); + builder.build(); + } +} diff --git a/alts/src/test/java/io/grpc/alts/DualCallCredentialsTest.java b/alts/src/test/java/io/grpc/alts/DualCallCredentialsTest.java new file mode 100644 index 00000000000..29646191be1 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/DualCallCredentialsTest.java @@ -0,0 +1,109 @@ +/* + * Copyright 2024 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.grpc.Attributes; +import io.grpc.CallCredentials; +import io.grpc.CallCredentials.RequestInfo; +import io.grpc.MethodDescriptor; +import io.grpc.SecurityLevel; +import io.grpc.alts.internal.AltsInternalContext; +import io.grpc.alts.internal.AltsProtocolNegotiator; +import io.grpc.testing.TestMethodDescriptors; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** Unit tests for {@link DualCallCredentials}. */ +@RunWith(JUnit4.class) +public class DualCallCredentialsTest { + + @Rule public final MockitoRule mocks = MockitoJUnit.rule(); + + @Mock CallCredentials tlsCallCredentials; + + @Mock CallCredentials altsCallCredentials; + + private static final String AUTHORITY = "testauthority"; + private static final SecurityLevel SECURITY_LEVEL = SecurityLevel.PRIVACY_AND_INTEGRITY; + + @Test + public void invokeTlsCallCredentials() { + DualCallCredentials callCredentials = + new DualCallCredentials(tlsCallCredentials, altsCallCredentials); + RequestInfo requestInfo = new RequestInfoImpl(false); + callCredentials.applyRequestMetadata(requestInfo, null, null); + + verify(altsCallCredentials, never()).applyRequestMetadata(any(), any(), any()); + verify(tlsCallCredentials, times(1)).applyRequestMetadata(requestInfo, null, null); + } + + @Test + public void invokeAltsCallCredentials() { + DualCallCredentials callCredentials = + new DualCallCredentials(tlsCallCredentials, altsCallCredentials); + RequestInfo requestInfo = new RequestInfoImpl(true); + callCredentials.applyRequestMetadata(requestInfo, null, null); + + verify(altsCallCredentials, times(1)).applyRequestMetadata(requestInfo, null, null); + verify(tlsCallCredentials, never()).applyRequestMetadata(any(), any(), any()); + } + + private static final class RequestInfoImpl extends CallCredentials.RequestInfo { + private Attributes attrs; + + RequestInfoImpl(boolean hasAltsContext) { + attrs = + hasAltsContext + ? Attributes.newBuilder() + .set( + AltsProtocolNegotiator.AUTH_CONTEXT_KEY, + AltsInternalContext.getDefaultInstance()) + .build() + : Attributes.EMPTY; + } + + @Override + public MethodDescriptor getMethodDescriptor() { + return TestMethodDescriptors.voidMethod(); + } + + @Override + public SecurityLevel getSecurityLevel() { + return SECURITY_LEVEL; + } + + @Override + public String getAuthority() { + return AUTHORITY; + } + + @Override + public Attributes getTransportAttrs() { + return attrs; + } + } +} diff --git a/alts/src/test/java/io/grpc/alts/GoogleDefaultChannelBuilderTest.java b/alts/src/test/java/io/grpc/alts/GoogleDefaultChannelBuilderTest.java new file mode 100644 index 00000000000..c73ef4444e9 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/GoogleDefaultChannelBuilderTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class GoogleDefaultChannelBuilderTest { + + @Test + public void buildsNettyChannel() throws Exception { + GoogleDefaultChannelBuilder builder = GoogleDefaultChannelBuilder.forTarget("localhost:8080"); + builder.build(); + } +} diff --git a/alts/src/test/java/io/grpc/alts/HandshakerServiceChannelTest.java b/alts/src/test/java/io/grpc/alts/HandshakerServiceChannelTest.java new file mode 100644 index 00000000000..221001157f1 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/HandshakerServiceChannelTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import static com.google.common.truth.Truth.assertThat; + +import io.grpc.Channel; +import io.grpc.Server; +import io.grpc.ServerBuilder; +import io.grpc.internal.SharedResourceHolder.Resource; +import io.grpc.stub.StreamObserver; +import io.grpc.testing.GrpcCleanupRule; +import io.grpc.testing.protobuf.SimpleRequest; +import io.grpc.testing.protobuf.SimpleResponse; +import io.grpc.testing.protobuf.SimpleServiceGrpc; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class HandshakerServiceChannelTest { + @Rule + public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule(); + private final Server server = grpcCleanup.register( + ServerBuilder.forPort(0) + .addService(new SimpleServiceGrpc.SimpleServiceImplBase() { + @Override + public void unaryRpc(SimpleRequest request, StreamObserver so) { + so.onNext(SimpleResponse.getDefaultInstance()); + so.onCompleted(); + } + }) + .build()); + private Resource resource; + + @Before + public void setUp() throws Exception { + server.start(); + resource = + HandshakerServiceChannel.getHandshakerChannelForTesting("localhost:" + server.getPort()); + } + + @Test + public void sharedChannel_authority() { + resource = HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL; + Channel channel = resource.create(); + try { + assertThat(channel.authority()).isEqualTo("metadata.google.internal.:8080"); + } finally { + resource.close(channel); + } + } + + @Test + public void getHandshakerTarget_nullEnvVar() { + assertThat(HandshakerServiceChannel.getHandshakerTarget(null)) + .isEqualTo("metadata.google.internal.:8080"); + } + + @Test + public void getHandshakerTarget_envVarWithPort() { + assertThat(HandshakerServiceChannel.getHandshakerTarget("169.254.169.254:80")) + .isEqualTo("169.254.169.254:8080"); + } + + @Test + public void getHandshakerTarget_envVarWithHostOnly() { + assertThat(HandshakerServiceChannel.getHandshakerTarget("169.254.169.254")) + .isEqualTo("169.254.169.254:8080"); + } + + @Test + public void resource_works() { + Channel channel = resource.create(); + try { + // Do an RPC to verify that the channel actually works + doRpc(channel); + } finally { + resource.close(channel); + } + } + + @Test + public void resource_lifecycleTwice() { + Channel channel = resource.create(); + try { + doRpc(channel); + } finally { + resource.close(channel); + } + channel = resource.create(); + try { + doRpc(channel); + } finally { + resource.close(channel); + } + } + + private void doRpc(Channel channel) { + SimpleServiceGrpc.newBlockingStub(channel).unaryRpc(SimpleRequest.getDefaultInstance()); + } +} diff --git a/alts/src/test/java/io/grpc/alts/InternalCheckGcpEnvironmentTest.java b/alts/src/test/java/io/grpc/alts/InternalCheckGcpEnvironmentTest.java new file mode 100644 index 00000000000..1234cfc49c3 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/InternalCheckGcpEnvironmentTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.StringReader; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class InternalCheckGcpEnvironmentTest { + + @Test + public void checkGcpLinuxPlatformData() throws Exception { + BufferedReader reader; + reader = new BufferedReader(new StringReader("HP Z440 Workstation")); + assertFalse(InternalCheckGcpEnvironment.checkProductNameOnLinux(reader)); + reader = new BufferedReader(new StringReader("Google")); + assertTrue(InternalCheckGcpEnvironment.checkProductNameOnLinux(reader)); + reader = new BufferedReader(new StringReader("Google Compute Engine")); + assertTrue(InternalCheckGcpEnvironment.checkProductNameOnLinux(reader)); + reader = new BufferedReader(new StringReader("Google Compute Engine ")); + assertTrue(InternalCheckGcpEnvironment.checkProductNameOnLinux(reader)); + } + + @Test + public void checkGcpWindowsPlatformData() throws Exception { + BufferedReader reader; + reader = new BufferedReader(new StringReader("Product : Google")); + assertFalse(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("Manufacturer : LENOVO")); + assertFalse(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("Manufacturer : Google Compute Engine")); + assertFalse(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("Manufacturer : Google")); + assertTrue(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("Manufacturer:Google")); + assertTrue(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("Manufacturer : Google ")); + assertTrue(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + reader = new BufferedReader(new StringReader("BIOSVersion : 1.0\nManufacturer : Google\n")); + assertTrue(InternalCheckGcpEnvironment.checkBiosDataOnWindows(reader)); + } +} diff --git a/alts/src/test/java/io/grpc/alts/internal/AesGcmAeadCrypterTest.java b/alts/src/test/java/io/grpc/alts/internal/AesGcmAeadCrypterTest.java new file mode 100644 index 00000000000..bcf8c2810ee --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/internal/AesGcmAeadCrypterTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.TruthJUnit.assume; + +import org.conscrypt.Conscrypt; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class AesGcmAeadCrypterTest { + @Test + public void getConscrypt_worksWhenConscryptIsAvailable() { + assume().that(Conscrypt.isAvailable()).isTrue(); + assertThat(AesGcmAeadCrypter.getConscrypt()).isNotNull(); + } +} diff --git a/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java b/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java index ef64633ea5d..06f2ff5365f 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,7 +117,7 @@ public void testVectorEncrypt() throws GeneralSecurityException { ByteBuffer.wrap(testVector.plaintext), ByteBuffer.wrap(testVector.aad), testVector.nonce); - String msg = "Failure for test vector " + i; + String msg = "Failure for test vector " + i + " " + testVector.comment; assertWithMessage(msg) .that(ciphertextBuffer.remaining()) .isEqualTo(bufferSize - testVector.ciphertext.length); @@ -142,7 +142,7 @@ public void testVectorDecrypt() throws GeneralSecurityException { ByteBuffer.wrap(testVector.ciphertext), ByteBuffer.wrap(testVector.aad), testVector.nonce); - String msg = "Failure for test vector " + i; + String msg = "Failure for test vector " + i + " " + testVector.comment; assertWithMessage(msg) .that(plaintextBuffer.remaining()) .isEqualTo(bufferSize - testVector.plaintext.length); diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsAuthContextTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsAuthContextTest.java deleted file mode 100644 index 7778ffd3d57..00000000000 --- a/alts/src/test/java/io/grpc/alts/internal/AltsAuthContextTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2018, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.alts.internal; - -import static org.junit.Assert.assertEquals; - -import io.grpc.alts.internal.Handshaker.HandshakerResult; -import io.grpc.alts.internal.Handshaker.Identity; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import io.grpc.alts.internal.TransportSecurityCommon.SecurityLevel; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link AltsAuthContext}. */ -@RunWith(JUnit4.class) -public final class AltsAuthContextTest { - private static final int TEST_MAX_RPC_VERSION_MAJOR = 3; - private static final int TEST_MAX_RPC_VERSION_MINOR = 5; - private static final int TEST_MIN_RPC_VERSION_MAJOR = 2; - private static final int TEST_MIN_RPC_VERSION_MINOR = 1; - private static final SecurityLevel TEST_SECURITY_LEVEL = SecurityLevel.INTEGRITY_AND_PRIVACY; - private static final String TEST_APPLICATION_PROTOCOL = "grpc"; - private static final String TEST_LOCAL_SERVICE_ACCOUNT = "local@gserviceaccount.com"; - private static final String TEST_PEER_SERVICE_ACCOUNT = "peer@gserviceaccount.com"; - private static final String TEST_RECORD_PROTOCOL = "ALTSRP_GCM_AES128"; - - private HandshakerResult handshakerResult; - private RpcProtocolVersions rpcVersions; - - @Before - public void setUp() { - rpcVersions = - RpcProtocolVersions.newBuilder() - .setMaxRpcVersion( - RpcProtocolVersions.Version.newBuilder() - .setMajor(TEST_MAX_RPC_VERSION_MAJOR) - .setMinor(TEST_MAX_RPC_VERSION_MINOR) - .build()) - .setMinRpcVersion( - RpcProtocolVersions.Version.newBuilder() - .setMajor(TEST_MIN_RPC_VERSION_MAJOR) - .setMinor(TEST_MIN_RPC_VERSION_MINOR) - .build()) - .build(); - handshakerResult = - HandshakerResult.newBuilder() - .setApplicationProtocol(TEST_APPLICATION_PROTOCOL) - .setRecordProtocol(TEST_RECORD_PROTOCOL) - .setPeerIdentity(Identity.newBuilder().setServiceAccount(TEST_PEER_SERVICE_ACCOUNT)) - .setLocalIdentity(Identity.newBuilder().setServiceAccount(TEST_LOCAL_SERVICE_ACCOUNT)) - .setPeerRpcVersions(rpcVersions) - .build(); - } - - @Test - public void testAltsAuthContext() { - AltsAuthContext authContext = new AltsAuthContext(handshakerResult); - assertEquals(TEST_APPLICATION_PROTOCOL, authContext.getApplicationProtocol()); - assertEquals(TEST_RECORD_PROTOCOL, authContext.getRecordProtocol()); - assertEquals(TEST_SECURITY_LEVEL, authContext.getSecurityLevel()); - assertEquals(TEST_PEER_SERVICE_ACCOUNT, authContext.getPeerServiceAccount()); - assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, authContext.getLocalServiceAccount()); - assertEquals(rpcVersions, authContext.getPeerRpcVersions()); - } -} diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsChannelCrypterTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsChannelCrypterTest.java index 39b84f77123..0b40a8b31df 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsChannelCrypterTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsChannelCrypterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsClientOptionsTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsClientOptionsTest.java index 56767735e48..45fac0aa301 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsClientOptionsTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsClientOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; +import com.google.common.collect.ImmutableList; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -39,17 +39,18 @@ public void setAndGet() throws Exception { .setMinRpcVersion( RpcProtocolVersions.Version.newBuilder().setMajor(2).setMinor(1).build()) .build(); + ImmutableList serviceAccounts = ImmutableList.of(serviceAccount1, serviceAccount2); AltsClientOptions options = new AltsClientOptions.Builder() .setTargetName(targetName) - .addTargetServiceAccount(serviceAccount1) - .addTargetServiceAccount(serviceAccount2) + .setTargetServiceAccounts(serviceAccounts) .setRpcProtocolVersions(rpcVersions) .build(); assertThat(options.getTargetName()).isEqualTo(targetName); - assertThat(options.getTargetServiceAccounts()).containsAllOf(serviceAccount1, serviceAccount2); + assertThat(options.getTargetServiceAccounts()) + .containsAtLeast(serviceAccount1, serviceAccount2); assertThat(options.getRpcProtocolVersions()).isEqualTo(rpcVersions); } } diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsFramingTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsFramingTest.java index c2656403bd2..a4703e052ee 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsFramingTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsFramingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.security.GeneralSecurityException; @@ -38,7 +39,7 @@ public void parserFrameLengthNegativeFails() throws GeneralSecurityException { buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(-1); // write invalid length buffer.put((byte) 0); // write some byte - buffer.flip(); + ((Buffer) buffer).flip(); try { parser.readBytes(buffer); @@ -56,7 +57,7 @@ public void parserFrameLengthSmallerMessageTypeFails() throws GeneralSecurityExc buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(AltsFraming.getFrameMessageTypeHeaderSize() - 1); // write invalid length buffer.put((byte) 0); // write some byte - buffer.flip(); + ((Buffer) buffer).flip(); try { parser.readBytes(buffer); @@ -74,7 +75,7 @@ public void parserFrameLengthTooLargeFails() throws GeneralSecurityException { buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(AltsFraming.getMaxDataLength() + 1); // write invalid length buffer.put((byte) 0); // write some byte - buffer.flip(); + ((Buffer) buffer).flip(); try { parser.readBytes(buffer); @@ -97,7 +98,7 @@ public void parserFrameLengthMaxOk() throws GeneralSecurityException { buffer.putInt(6); // default message type buffer.put(new byte[dataLength - AltsFraming.getFrameMessageTypeHeaderSize()]); // write data buffer.put((byte) 0); - buffer.flip(); + ((Buffer) buffer).flip(); parser.readBytes(buffer); @@ -116,7 +117,7 @@ public void parserFrameLengthZeroOk() throws GeneralSecurityException { buffer.putInt(dataLength); // write invalid length buffer.putInt(6); // default message type buffer.put((byte) 0); - buffer.flip(); + ((Buffer) buffer).flip(); parser.readBytes(buffer); diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerClientTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerClientTest.java index c33f607506d..5a41fc0fc4f 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerClientTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,12 +27,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableList; import com.google.protobuf.ByteString; -import io.grpc.alts.internal.Handshaker.HandshakeProtocol; -import io.grpc.alts.internal.Handshaker.HandshakerReq; -import io.grpc.alts.internal.Handshaker.Identity; -import io.grpc.alts.internal.Handshaker.StartClientHandshakeReq; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; +import io.grpc.internal.TestUtils.NoopChannelLogger; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; import org.junit.Before; @@ -40,7 +38,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; /** Unit tests for {@link AltsHandshakerClient}. */ @RunWith(JUnit4.class) @@ -61,14 +59,15 @@ public void setUp() { clientOptions = new AltsClientOptions.Builder() .setTargetName(TEST_TARGET_NAME) - .addTargetServiceAccount(TEST_TARGET_SERVICE_ACCOUNT) + .setTargetServiceAccounts(ImmutableList.of(TEST_TARGET_SERVICE_ACCOUNT)) .build(); - handshaker = new AltsHandshakerClient(mockStub, clientOptions); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + handshaker = new AltsHandshakerClient(mockStub, clientOptions, channelLogger); } @Test public void startClientHandshakeFailure() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getErrorResponse()); try { @@ -81,7 +80,7 @@ public void startClientHandshakeFailure() throws Exception { @Test public void startClientHandshakeSuccess() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(0)); ByteBuffer outFrame = handshaker.startClientHandshake(); @@ -94,7 +93,7 @@ public void startClientHandshakeSuccess() throws Exception { @Test public void startClientHandshakeWithOptions() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(0)); ByteBuffer outFrame = handshaker.startClientHandshake(); @@ -110,6 +109,7 @@ public void startClientHandshakeWithOptions() throws Exception { .setTargetName(TEST_TARGET_NAME) .addTargetIdentities( Identity.newBuilder().setServiceAccount(TEST_TARGET_SERVICE_ACCOUNT)) + .setMaxFrameSize(AltsTsiFrameProtector.getMaxFrameSize()) .build()) .build(); verify(mockStub).send(req); @@ -117,7 +117,7 @@ public void startClientHandshakeWithOptions() throws Exception { @Test public void startServerHandshakeFailure() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getErrorResponse()); try { @@ -131,12 +131,28 @@ public void startServerHandshakeFailure() throws Exception { @Test public void startServerHandshakeSuccess() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); ByteBuffer outFrame = handshaker.startServerHandshake(inBytes); + HandshakerReq req = + HandshakerReq.newBuilder() + .setServerStart( + StartServerHandshakeReq.newBuilder() + .addApplicationProtocols(AltsHandshakerClient.getApplicationProtocol()) + .putHandshakeParameters( + HandshakeProtocol.ALTS.getNumber(), + ServerHandshakeParameters.newBuilder() + .addRecordProtocols(AltsHandshakerClient.getRecordProtocol()) + .build()) + .setInBytes(ByteString.copyFrom(ByteBuffer.allocate(IN_BYTES_SIZE))) + .setMaxFrameSize(AltsTsiFrameProtector.getMaxFrameSize()) + .build()) + .build(); + verify(mockStub).send(req); + assertEquals(ByteString.copyFrom(outFrame), MockAltsHandshakerResp.getOutFrame()); assertFalse(handshaker.isFinished()); assertNull(handshaker.getResult()); @@ -146,7 +162,7 @@ public void startServerHandshakeSuccess() throws Exception { @Test public void startServerHandshakeEmptyOutFrame() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getEmptyOutFrameResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); @@ -161,11 +177,11 @@ public void startServerHandshakeEmptyOutFrame() throws Exception { @Test public void startServerHandshakeWithPrefixBuffer() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); - inBytes.position(PREFIX_POSITION); + ((Buffer) inBytes).position(PREFIX_POSITION); ByteBuffer outFrame = handshaker.startServerHandshake(inBytes); assertEquals(ByteString.copyFrom(outFrame), MockAltsHandshakerResp.getOutFrame()); @@ -178,7 +194,7 @@ public void startServerHandshakeWithPrefixBuffer() throws Exception { @Test public void nextFailure() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getErrorResponse()); try { @@ -192,7 +208,7 @@ public void nextFailure() throws Exception { @Test public void nextSuccess() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); @@ -207,7 +223,7 @@ public void nextSuccess() throws Exception { @Test public void nextEmptyOutFrame() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getEmptyOutFrameResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); @@ -222,7 +238,7 @@ public void nextEmptyOutFrame() throws Exception { @Test public void nextFinished() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getFinishedResponse(BYTES_CONSUMED)); ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); @@ -236,7 +252,7 @@ public void nextFinished() throws Exception { @Test public void setRpcVersions() throws Exception { - when(mockStub.send(Matchers.any())) + when(mockStub.send(ArgumentMatchers.any())) .thenReturn(MockAltsHandshakerResp.getOkResponse(0)); RpcProtocolVersions rpcVersions = @@ -249,10 +265,11 @@ public void setRpcVersions() throws Exception { clientOptions = new AltsClientOptions.Builder() .setTargetName(TEST_TARGET_NAME) - .addTargetServiceAccount(TEST_TARGET_SERVICE_ACCOUNT) + .setTargetServiceAccounts(ImmutableList.of(TEST_TARGET_SERVICE_ACCOUNT)) .setRpcProtocolVersions(rpcVersions) .build(); - handshaker = new AltsHandshakerClient(mockStub, clientOptions); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + handshaker = new AltsHandshakerClient(mockStub, clientOptions, channelLogger); handshaker.startClientHandshake(); diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerOptionsTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerOptionsTest.java index ae58a16f154..ab065f2f2ef 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerOptionsTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerStubTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerStubTest.java index 52aef0343db..7a6018b5064 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerStubTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsHandshakerStubTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,8 @@ import static org.junit.Assert.fail; import com.google.protobuf.ByteString; -import io.grpc.alts.internal.Handshaker.HandshakerReq; -import io.grpc.alts.internal.Handshaker.HandshakerResp; -import io.grpc.alts.internal.Handshaker.NextHandshakeMessageReq; import io.grpc.stub.StreamObserver; import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,7 +32,7 @@ @RunWith(JUnit4.class) public class AltsHandshakerStubTest { /** Mock status of handshaker service. */ - private static enum Status { + private enum Status { OK, ERROR, COMPLETE @@ -46,21 +40,14 @@ private static enum Status { private AltsHandshakerStub stub; private MockWriter writer; - private ExecutorService executor; @Before public void setUp() { - executor = Executors.newSingleThreadExecutor(); writer = new MockWriter(); stub = new AltsHandshakerStub(writer); writer.setReader(stub.getReaderForTest()); } - @After - public void tearDown() { - executor.shutdown(); - } - /** Send a message as in_bytes and expect same message as out_frames echo back. */ private void sendSuccessfulMessage() throws Exception { String message = "hello world"; @@ -81,6 +68,7 @@ private void sendAndExpectError() throws InterruptedException { fail("Exception expected"); } catch (IOException ex) { assertThat(ex).hasMessageThat().contains("Received a terminating error"); + assertThat(ex.getCause()).hasMessageThat().contains("Root cause message"); } } @@ -139,7 +127,7 @@ public void closeEarlyTest() throws InterruptedException { sendAndExpectComplete(); } - private class MockWriter implements StreamObserver { + private static class MockWriter implements StreamObserver { private StreamObserver reader; private Status status = Status.OK; @@ -159,26 +147,20 @@ private void sendUnexpectedResponse() { /** Mock writer onNext. Will respond based on the server status. */ @Override public void onNext(final HandshakerReq req) { - executor.execute( - new Runnable() { - @Override - public void run() { - switch (status) { - case OK: - HandshakerResp.Builder resp = HandshakerResp.newBuilder(); - reader.onNext(resp.setOutFrames(req.getNext().getInBytes()).build()); - break; - case ERROR: - reader.onError(new RuntimeException()); - break; - case COMPLETE: - reader.onCompleted(); - break; - default: - return; - } - } - }); + switch (status) { + case OK: + HandshakerResp.Builder resp = HandshakerResp.newBuilder(); + reader.onNext(resp.setOutFrames(req.getNext().getInBytes()).build()); + break; + case ERROR: + reader.onError(new RuntimeException("Root cause message")); + break; + case COMPLETE: + reader.onCompleted(); + break; + default: + return; + } } @Override @@ -187,13 +169,7 @@ public void onError(Throwable t) {} /** Mock writer onComplete. */ @Override public void onCompleted() { - executor.execute( - new Runnable() { - @Override - public void run() { - reader.onCompleted(); - } - }); + reader.onCompleted(); } } } diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsInternalContextTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsInternalContextTest.java new file mode 100644 index 00000000000..87898a3300b --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/internal/AltsInternalContextTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link AltsInternalContext}. */ +@RunWith(JUnit4.class) +public final class AltsInternalContextTest { + private static final int TEST_MAX_RPC_VERSION_MAJOR = 3; + private static final int TEST_MAX_RPC_VERSION_MINOR = 5; + private static final int TEST_MIN_RPC_VERSION_MAJOR = 2; + private static final int TEST_MIN_RPC_VERSION_MINOR = 1; + private static final SecurityLevel TEST_SECURITY_LEVEL = SecurityLevel.INTEGRITY_AND_PRIVACY; + private static final String TEST_APPLICATION_PROTOCOL = "grpc"; + private static final String TEST_LOCAL_SERVICE_ACCOUNT = "local@gserviceaccount.com"; + private static final String TEST_PEER_SERVICE_ACCOUNT = "peer@gserviceaccount.com"; + private static final String TEST_RECORD_PROTOCOL = "ALTSRP_GCM_AES128"; + private static final String TEST_PEER_ATTRIBUTES_KEY = "peer"; + private static final String TEST_PEER_ATTRIBUTES_VALUE = "attributes"; + + private Map testPeerAttributes; + private HandshakerResult handshakerResult; + private RpcProtocolVersions rpcVersions; + + @Before + public void setUp() { + testPeerAttributes = new HashMap(); + testPeerAttributes.put(TEST_PEER_ATTRIBUTES_KEY, TEST_PEER_ATTRIBUTES_VALUE); + rpcVersions = + RpcProtocolVersions.newBuilder() + .setMaxRpcVersion( + RpcProtocolVersions.Version.newBuilder() + .setMajor(TEST_MAX_RPC_VERSION_MAJOR) + .setMinor(TEST_MAX_RPC_VERSION_MINOR) + .build()) + .setMinRpcVersion( + RpcProtocolVersions.Version.newBuilder() + .setMajor(TEST_MIN_RPC_VERSION_MAJOR) + .setMinor(TEST_MIN_RPC_VERSION_MINOR) + .build()) + .build(); + Identity.Builder peerIdentity = Identity.newBuilder() + .setServiceAccount(TEST_PEER_SERVICE_ACCOUNT); + peerIdentity.putAllAttributes(testPeerAttributes); + handshakerResult = + HandshakerResult.newBuilder() + .setApplicationProtocol(TEST_APPLICATION_PROTOCOL) + .setRecordProtocol(TEST_RECORD_PROTOCOL) + .setPeerIdentity(peerIdentity) + .setLocalIdentity(Identity.newBuilder().setServiceAccount(TEST_LOCAL_SERVICE_ACCOUNT)) + .setPeerRpcVersions(rpcVersions) + .build(); + } + + @Test + public void testAltsInternalContext() { + AltsInternalContext context = new AltsInternalContext(handshakerResult); + assertEquals(TEST_APPLICATION_PROTOCOL, context.getApplicationProtocol()); + assertEquals(TEST_RECORD_PROTOCOL, context.getRecordProtocol()); + assertEquals(TEST_SECURITY_LEVEL, context.getSecurityLevel()); + assertEquals(TEST_PEER_SERVICE_ACCOUNT, context.getPeerServiceAccount()); + assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, context.getLocalServiceAccount()); + assertEquals(rpcVersions, context.getPeerRpcVersions()); + assertEquals(testPeerAttributes, context.getPeerAttributes()); + assertEquals(TEST_PEER_ATTRIBUTES_VALUE, context.getPeerAttributes() + .get(TEST_PEER_ATTRIBUTES_KEY)); + } +} diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsProtocolNegotiatorTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsProtocolNegotiatorTest.java index f271c4c47d9..d47607ed90f 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsProtocolNegotiatorTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsProtocolNegotiatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package io.grpc.alts.internal; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; @@ -24,11 +25,23 @@ import static org.junit.Assert.assertTrue; import io.grpc.Attributes; +import io.grpc.Channel; +import io.grpc.ChannelLogger; import io.grpc.Grpc; -import io.grpc.alts.internal.Handshaker.HandshakerResult; +import io.grpc.InternalChannelz; +import io.grpc.ManagedChannel; +import io.grpc.SecurityLevel; +import io.grpc.alts.internal.AltsProtocolNegotiator.LazyChannel; +import io.grpc.alts.internal.AltsProtocolNegotiator.ServerAltsProtocolNegotiator; import io.grpc.alts.internal.TsiFrameProtector.Consumer; import io.grpc.alts.internal.TsiPeer.Property; +import io.grpc.internal.FixedObjectPool; +import io.grpc.internal.GrpcAttributes; +import io.grpc.internal.ObjectPool; +import io.grpc.internal.TestUtils.NoopChannelLogger; import io.grpc.netty.GrpcHttp2ConnectionHandler; +import io.grpc.netty.InternalProtocolNegotiationEvent; +import io.grpc.netty.NettyChannelBuilder; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; @@ -38,6 +51,7 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.http2.DefaultHttp2Connection; @@ -72,7 +86,9 @@ /** Tests for {@link AltsProtocolNegotiator}. */ @RunWith(JUnit4.class) +@SuppressWarnings("FutureReturnValueIgnored") public class AltsProtocolNegotiatorTest { + private final CapturingGrpcHttp2ConnectionHandler grpcHandler = capturingGrpcHandler(); private final List references = new ArrayList<>(); @@ -81,24 +97,21 @@ public class AltsProtocolNegotiatorTest { private EmbeddedChannel channel; private Throwable caughtException; - private volatile TsiHandshakeHandler.TsiHandshakeCompletionEvent tsiEvent; - private ChannelHandler handler; - private TsiPeer mockedTsiPeer = new TsiPeer(Collections.>emptyList()); - private AltsAuthContext mockedAltsContext = - new AltsAuthContext( + private AltsInternalContext mockedAltsContext = + new AltsInternalContext( HandshakerResult.newBuilder() .setPeerRpcVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions()) .build()); private final TsiHandshaker mockHandshaker = new DelegatingTsiHandshaker(FakeTsiHandshaker.newFakeHandshakerServer()) { @Override - public TsiPeer extractPeer() throws GeneralSecurityException { + public TsiPeer extractPeer() { return mockedTsiPeer; } @Override - public Object extractPeerObject() throws GeneralSecurityException { + public Object extractPeerObject() { return mockedAltsContext; } }; @@ -106,32 +119,21 @@ public Object extractPeerObject() throws GeneralSecurityException { @Before public void setup() throws Exception { - ChannelHandler userEventHandler = - new ChannelDuplexHandler() { - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if (evt instanceof TsiHandshakeHandler.TsiHandshakeCompletionEvent) { - tsiEvent = (TsiHandshakeHandler.TsiHandshakeCompletionEvent) evt; - } else { - super.userEventTriggered(ctx, evt); - } - } - }; - ChannelHandler uncaughtExceptionHandler = new ChannelDuplexHandler() { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { caughtException = cause; super.exceptionCaught(ctx, cause); + ctx.close(); } }; TsiHandshakerFactory handshakerFactory = new DelegatingTsiHandshakerFactory(FakeTsiHandshaker.clientHandshakerFactory()) { @Override - public TsiHandshaker newHandshaker() { - return new DelegatingTsiHandshaker(super.newHandshaker()) { + public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) { + return new DelegatingTsiHandshaker(super.newHandshaker(authority, logger)) { @Override public TsiPeer extractPeer() throws GeneralSecurityException { return mockedTsiPeer; @@ -144,8 +146,15 @@ public Object extractPeerObject() throws GeneralSecurityException { }; } }; - handler = AltsProtocolNegotiator.create(handshakerFactory).newHandler(grpcHandler); - channel = new EmbeddedChannel(uncaughtExceptionHandler, handler, userEventHandler); + ManagedChannel fakeChannel = NettyChannelBuilder.forTarget("localhost:8080").build(); + ObjectPool fakeChannelPool = new FixedObjectPool(fakeChannel); + LazyChannel lazyFakeChannel = new LazyChannel(fakeChannelPool); + ChannelHandler altsServerHandler = new ServerAltsProtocolNegotiator( + handshakerFactory, lazyFakeChannel) + .newHandler(grpcHandler); + // On real server, WBAEH fires default ProtocolNegotiationEvent. KickNH provides this behavior. + ChannelHandler handler = new KickNegotiationHandler(altsServerHandler); + channel = new EmbeddedChannel(uncaughtExceptionHandler, handler); } @After @@ -168,6 +177,8 @@ public void handshakeShouldBeSuccessful() throws Exception { @Test @SuppressWarnings("unchecked") // List cast public void protectShouldRoundtrip() throws Exception { + doHandshake(); + // Write the message 1 character at a time. The message should be buffered // and not interfere with the handshake. final AtomicInteger writeCount = new AtomicInteger(); @@ -190,13 +201,12 @@ public void operationComplete(ChannelFuture future) throws Exception { } channel.flush(); - // Now do the handshake. The buffered message will automatically be protected - // and sent. - doHandshake(); - // Capture the protected data written to the wire. - assertEquals(1, channel.outboundMessages().size()); - ByteBuf protectedData = channel.readOutbound(); + assertThat(channel.outboundMessages()).isNotEmpty(); + ByteBuf protectedData = channel.alloc().buffer(); + while (!channel.outboundMessages().isEmpty()) { + protectedData.writeBytes((ByteBuf) channel.readOutbound()); + } assertEquals(message.length(), writeCount.get()); // Read the protected message at the server and verify it matches the original message. @@ -262,7 +272,7 @@ public void accept(ByteBuf buf) { // Read the protected message at the client and verify that it matches the original message. assertEquals(1, channel.inboundMessages().size()); - ByteBuf receivedData1 = channel.readInbound(); + ByteBuf receivedData1 = channel.readInbound(); int receivedLen1 = receivedData1.readableBytes(); byte[] receivedBytes = new byte[receivedLen1]; receivedData1.readBytes(receivedBytes, 0, receivedLen1); @@ -320,34 +330,62 @@ public void doNotFlushEmptyBuffer() throws Exception { String message = "hello"; ByteBuf in = Unpooled.copiedBuffer(message, UTF_8); - assertEquals(0, protector.flushes.get()); + int flushes = protector.flushes.get(); Future done = channel.write(in); channel.flush(); + flushes++; done.get(5, TimeUnit.SECONDS); - assertEquals(1, protector.flushes.get()); + assertEquals(flushes, protector.flushes.get()); + // Flush does not propagate done = channel.write(Unpooled.EMPTY_BUFFER); channel.flush(); done.get(5, TimeUnit.SECONDS); - assertEquals(1, protector.flushes.get()); + assertEquals(flushes, protector.flushes.get()); } @Test public void peerPropagated() throws Exception { doHandshake(); - assertThat(grpcHandler.attrs.get(AltsProtocolNegotiator.getTsiPeerAttributeKey())) - .isEqualTo(mockedTsiPeer); - assertThat(grpcHandler.attrs.get(AltsProtocolNegotiator.getAltsAuthContextAttributeKey())) + assertThat(grpcHandler.attrs.get(AltsProtocolNegotiator.TSI_PEER_KEY)).isEqualTo(mockedTsiPeer); + assertThat(grpcHandler.attrs.get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY)) .isEqualTo(mockedAltsContext); assertThat(grpcHandler.attrs.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString()) .isEqualTo("embedded"); + assertThat(grpcHandler.attrs.get(Grpc.TRANSPORT_ATTR_LOCAL_ADDR).toString()) + .isEqualTo("embedded"); + assertThat(grpcHandler.attrs.get(GrpcAttributes.ATTR_SECURITY_LEVEL)) + .isEqualTo(SecurityLevel.PRIVACY_AND_INTEGRITY); + } + + @Test + public void getAltsMaxConcurrentHandshakes_success() throws Exception { + assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("10")).isEqualTo(10); + } + + @Test + public void getAltsMaxConcurrentHandshakes_envVariableNotSet() throws Exception { + assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes(null)) + .isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES); + } + + @Test + public void getAltsMaxConcurrentHandshakes_envVariableNotANumber() throws Exception { + assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("not-a-number")) + .isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES); + } + + @Test + public void getAltsMaxConcurrentHandshakes_envVariableNegative() throws Exception { + assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("-10")) + .isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES); } private void doHandshake() throws Exception { // Capture the client frame and add to the server. assertEquals(1, channel.outboundMessages().size()); - ByteBuf clientFrame = channel.readOutbound(); + ByteBuf clientFrame = channel.readOutbound(); assertTrue(serverHandshaker.processBytesFromPeer(clientFrame)); // Get the server response handshake frames. @@ -357,7 +395,7 @@ private void doHandshake() throws Exception { // Capture the next client frame and add to the server. assertEquals(1, channel.outboundMessages().size()); - clientFrame = channel.readOutbound(); + clientFrame = channel.readOutbound(); assertTrue(serverHandshaker.processBytesFromPeer(clientFrame)); // Get the server response handshake frames. @@ -371,12 +409,12 @@ private void doHandshake() throws Exception { if (caughtException != null) { throw new RuntimeException(caughtException); } - assertNotNull(tsiEvent); + assertNotNull(grpcHandler.attrs); } private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() { // Netty Boilerplate. We don't really need any of this, but there is a tight coupling - // between a Http2ConnectionHandler and its dependencies. + // between an Http2ConnectionHandler and its dependencies. Http2Connection connection = new DefaultHttp2Connection(true); Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter(); Http2FrameReader frameReader = new DefaultHttp2FrameReader(false); @@ -389,17 +427,20 @@ private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() { } private final class CapturingGrpcHttp2ConnectionHandler extends GrpcHttp2ConnectionHandler { + private Attributes attrs; private CapturingGrpcHttp2ConnectionHandler( Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) { - super(null, decoder, encoder, initialSettings); + super(null, decoder, encoder, initialSettings, new NoopChannelLogger()); } @Override - public void handleProtocolNegotiationCompleted(Attributes attrs) { + public void handleProtocolNegotiationCompleted( + Attributes attrs, + @SuppressWarnings("UnusedVariable") InternalChannelz.Security securityInfo) { // If we are added to the pipeline, we need to remove ourselves. The HTTP2 handler channel.pipeline().remove(this); this.attrs = attrs; @@ -415,8 +456,8 @@ private static class DelegatingTsiHandshakerFactory implements TsiHandshakerFact } @Override - public TsiHandshaker newHandshaker() { - return delegate.newHandshaker(); + public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) { + return delegate.newHandshaker(authority, logger); } } @@ -468,9 +509,15 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator protectors.add(protector); return protector; } + + @Override + public void close() { + delegate.close(); + } } private static class InterceptingProtector implements TsiFrameProtector { + private final TsiFrameProtector delegate; final AtomicInteger flushes = new AtomicInteger(); @@ -497,4 +544,21 @@ public void destroy() { delegate.destroy(); } } + + /** Kicks off negotiation of the server. */ + private static final class KickNegotiationHandler extends ChannelInboundHandlerAdapter { + + private final ChannelHandler next; + + KickNegotiationHandler(ChannelHandler next) { + this.next = checkNotNull(next, "next"); + } + + @Override + public void handlerAdded(ChannelHandlerContext ctx) throws Exception { + super.handlerAdded(ctx); + ctx.pipeline().replace(ctx.name(), /*newName= */ null, next); + ctx.pipeline().fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault()); + } + } } diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsTsiFrameProtectorTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsTsiFrameProtectorTest.java index c5de123ac00..cbda9dbcdc0 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsTsiFrameProtectorTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsTsiFrameProtectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public class AltsTsiFrameProtectorTest { private static final int FRAME_MIN_SIZE = AltsTsiFrameProtector.getHeaderTypeFieldBytes() + FakeChannelCrypter.getTagBytes(); - private final List references = new ArrayList(); + private final List references = new ArrayList<>(); private final RegisterRef ref = new RegisterRef() { @Override @@ -125,7 +125,7 @@ public void parserHeader_frameTooLarge() throws GeneralSecurityException { getDirectBuffer( AltsTsiFrameProtector.getHeaderBytes() + FakeChannelCrypter.getTagBytes(), ref); in.writeIntLE( - AltsTsiFrameProtector.getLimitMaxAllowedFrameBytes() + AltsTsiFrameProtector.getLimitMaxAllowedFrameSize() - AltsTsiFrameProtector.getHeaderLenFieldBytes() + 1); in.writeIntLE(6); @@ -206,7 +206,7 @@ public void parserHeader_frameMaxOk() throws GeneralSecurityException { getDirectBuffer( AltsTsiFrameProtector.getHeaderBytes() + FakeChannelCrypter.getTagBytes(), ref); in.writeIntLE( - AltsTsiFrameProtector.getLimitMaxAllowedFrameBytes() + AltsTsiFrameProtector.getLimitMaxAllowedFrameSize() - AltsTsiFrameProtector.getHeaderLenFieldBytes()); in.writeIntLE(6); diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsTsiHandshakerTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsTsiHandshakerTest.java index 8f8c7a5cc8a..ae1696401be 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsTsiHandshakerTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsTsiHandshakerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,15 +26,14 @@ import static org.mockito.Mockito.when; import com.google.protobuf.ByteString; -import io.grpc.alts.internal.Handshaker.HandshakerResult; -import io.grpc.alts.internal.Handshaker.Identity; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; +import io.grpc.internal.TestUtils.NoopChannelLogger; +import java.nio.Buffer; import java.nio.ByteBuffer; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; /** Unit tests for {@link AltsTsiHandshaker}. */ @RunWith(JUnit4.class) @@ -73,8 +72,9 @@ public class AltsTsiHandshakerTest { public void setUp() throws Exception { mockClient = mock(AltsHandshakerClient.class); mockServer = mock(AltsHandshakerClient.class); - handshakerClient = new AltsTsiHandshaker(true, mockClient); - handshakerServer = new AltsTsiHandshaker(false, mockServer); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + handshakerClient = new AltsTsiHandshaker(true, mockClient, channelLogger); + handshakerServer = new AltsTsiHandshaker(false, mockServer, channelLogger); } private HandshakerResult getHandshakerResult(boolean isClient) { @@ -101,8 +101,8 @@ private HandshakerResult getHandshakerResult(boolean isClient) { @Test public void processBytesFromPeerFalseStart() throws Exception { verify(mockClient, never()).startClientHandshake(); - verify(mockClient, never()).startServerHandshake(Matchers.any()); - verify(mockClient, never()).next(Matchers.any()); + verify(mockClient, never()).startServerHandshake(ArgumentMatchers.any()); + verify(mockClient, never()).next(ArgumentMatchers.any()); ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); assertTrue(handshakerClient.processBytesFromPeer(transportBuffer)); @@ -113,9 +113,9 @@ public void processBytesFromPeerStartServer() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer outputFrame = ByteBuffer.allocate(OUT_FRAME_SIZE); verify(mockServer, never()).startClientHandshake(); - verify(mockServer, never()).next(Matchers.any()); + verify(mockServer, never()).next(ArgumentMatchers.any()); // Mock transport buffer all consumed by processBytesFromPeer and there is an output frame. - transportBuffer.position(transportBuffer.limit()); + ((Buffer) transportBuffer).position(transportBuffer.limit()); when(mockServer.startServerHandshake(transportBuffer)).thenReturn(outputFrame); when(mockServer.isFinished()).thenReturn(false); @@ -127,10 +127,10 @@ public void processBytesFromPeerStartServerEmptyOutput() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer emptyOutputFrame = ByteBuffer.allocate(0); verify(mockServer, never()).startClientHandshake(); - verify(mockServer, never()).next(Matchers.any()); + verify(mockServer, never()).next(ArgumentMatchers.any()); // Mock transport buffer all consumed by processBytesFromPeer and output frame is empty. // Expect processBytesFromPeer return False, because more data are needed from the peer. - transportBuffer.position(transportBuffer.limit()); + ((Buffer) transportBuffer).position(transportBuffer.limit()); when(mockServer.startServerHandshake(transportBuffer)).thenReturn(emptyOutputFrame); when(mockServer.isFinished()).thenReturn(false); @@ -142,7 +142,7 @@ public void processBytesFromPeerStartServerFinished() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer outputFrame = ByteBuffer.allocate(OUT_FRAME_SIZE); verify(mockServer, never()).startClientHandshake(); - verify(mockServer, never()).next(Matchers.any()); + verify(mockServer, never()).next(ArgumentMatchers.any()); // Mock handshake complete after processBytesFromPeer. when(mockServer.startServerHandshake(transportBuffer)).thenReturn(outputFrame); when(mockServer.isFinished()).thenReturn(true); @@ -155,7 +155,7 @@ public void processBytesFromPeerNoBytesConsumed() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer emptyOutputFrame = ByteBuffer.allocate(0); verify(mockServer, never()).startClientHandshake(); - verify(mockServer, never()).next(Matchers.any()); + verify(mockServer, never()).next(ArgumentMatchers.any()); when(mockServer.startServerHandshake(transportBuffer)).thenReturn(emptyOutputFrame); when(mockServer.isFinished()).thenReturn(false); @@ -171,13 +171,13 @@ public void processBytesFromPeerNoBytesConsumed() throws Exception { public void processBytesFromPeerClientNext() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer outputFrame = ByteBuffer.allocate(OUT_FRAME_SIZE); - verify(mockClient, never()).startServerHandshake(Matchers.any()); + verify(mockClient, never()).startServerHandshake(ArgumentMatchers.any()); when(mockClient.startClientHandshake()).thenReturn(outputFrame); when(mockClient.next(transportBuffer)).thenReturn(outputFrame); when(mockClient.isFinished()).thenReturn(false); handshakerClient.getBytesToSendToPeer(transportBuffer); - transportBuffer.position(transportBuffer.limit()); + ((Buffer) transportBuffer).position(transportBuffer.limit()); assertFalse(handshakerClient.processBytesFromPeer(transportBuffer)); } @@ -185,7 +185,7 @@ public void processBytesFromPeerClientNext() throws Exception { public void processBytesFromPeerClientNextFinished() throws Exception { ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); ByteBuffer outputFrame = ByteBuffer.allocate(OUT_FRAME_SIZE); - verify(mockClient, never()).startServerHandshake(Matchers.any()); + verify(mockClient, never()).startServerHandshake(ArgumentMatchers.any()); when(mockClient.startClientHandshake()).thenReturn(outputFrame); when(mockClient.next(transportBuffer)).thenReturn(outputFrame); when(mockClient.isFinished()).thenReturn(true); @@ -234,7 +234,7 @@ public void extractClientPeerSuccess() throws Exception { TEST_SERVER_SERVICE_ACCOUNT, clientPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue()); - AltsAuthContext clientContext = (AltsAuthContext) handshakerClient.extractPeerObject(); + AltsInternalContext clientContext = (AltsInternalContext) handshakerClient.extractPeerObject(); assertEquals(TEST_APPLICATION_PROTOCOL, clientContext.getApplicationProtocol()); assertEquals(TEST_RECORD_PROTOCOL, clientContext.getRecordProtocol()); assertEquals(TEST_SERVER_SERVICE_ACCOUNT, clientContext.getPeerServiceAccount()); @@ -246,7 +246,8 @@ public void extractClientPeerSuccess() throws Exception { public void extractServerPeerSuccess() throws Exception { ByteBuffer outputFrame = ByteBuffer.allocate(OUT_FRAME_SIZE); ByteBuffer transportBuffer = ByteBuffer.allocate(TRANSPORT_BUFFER_SIZE); - when(mockServer.startServerHandshake(Matchers.any())).thenReturn(outputFrame); + when(mockServer.startServerHandshake(ArgumentMatchers.any())) + .thenReturn(outputFrame); when(mockServer.isFinished()).thenReturn(true); when(mockServer.getResult()).thenReturn(getHandshakerResult(/* isClient = */ false)); @@ -259,7 +260,7 @@ public void extractServerPeerSuccess() throws Exception { TEST_CLIENT_SERVICE_ACCOUNT, serverPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue()); - AltsAuthContext serverContext = (AltsAuthContext) handshakerServer.extractPeerObject(); + AltsInternalContext serverContext = (AltsInternalContext) handshakerServer.extractPeerObject(); assertEquals(TEST_APPLICATION_PROTOCOL, serverContext.getApplicationProtocol()); assertEquals(TEST_RECORD_PROTOCOL, serverContext.getRecordProtocol()); assertEquals(TEST_CLIENT_SERVICE_ACCOUNT, serverContext.getPeerServiceAccount()); diff --git a/alts/src/test/java/io/grpc/alts/internal/AltsTsiTest.java b/alts/src/test/java/io/grpc/alts/internal/AltsTsiTest.java index d9872e6f6b2..cb39abb9ddc 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AltsTsiTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AltsTsiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,8 @@ import com.google.common.testing.GcFinalization; import io.grpc.alts.internal.ByteBufTestUtils.RegisterRef; -import io.grpc.alts.internal.Handshaker.HandshakeProtocol; -import io.grpc.alts.internal.Handshaker.HandshakerReq; -import io.grpc.alts.internal.Handshaker.HandshakerResp; import io.grpc.alts.internal.TsiTest.Handshakers; +import io.grpc.internal.TestUtils.NoopChannelLogger; import io.netty.buffer.ByteBuf; import io.netty.util.ReferenceCounted; import io.netty.util.ResourceLeakDetector; @@ -64,8 +62,9 @@ public void setUp() throws Exception { AltsHandshakerOptions handshakerOptions = new AltsHandshakerOptions(null); MockAltsHandshakerStub clientStub = new MockAltsHandshakerStub(); MockAltsHandshakerStub serverStub = new MockAltsHandshakerStub(); - client = new AltsHandshakerClient(clientStub, handshakerOptions); - server = new AltsHandshakerClient(serverStub, handshakerOptions); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + client = new AltsHandshakerClient(clientStub, handshakerOptions, channelLogger); + server = new AltsHandshakerClient(serverStub, handshakerOptions, channelLogger); } @After @@ -79,8 +78,9 @@ public void tearDown() { } private Handshakers newHandshakers() { - TsiHandshaker clientHandshaker = new AltsTsiHandshaker(true, client); - TsiHandshaker serverHandshaker = new AltsTsiHandshaker(false, server); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + TsiHandshaker clientHandshaker = new AltsTsiHandshaker(true, client, channelLogger); + TsiHandshaker serverHandshaker = new AltsTsiHandshaker(false, server, channelLogger); return new Handshakers(clientHandshaker, serverHandshaker); } diff --git a/alts/src/test/java/io/grpc/alts/internal/BufUnwrapperTest.java b/alts/src/test/java/io/grpc/alts/internal/BufUnwrapperTest.java index 6829ca87400..67f318e8611 100644 --- a/alts/src/test/java/io/grpc/alts/internal/BufUnwrapperTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/BufUnwrapperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/test/java/io/grpc/alts/internal/ByteBufTestUtils.java b/alts/src/test/java/io/grpc/alts/internal/ByteBufTestUtils.java index a05d24a1351..0d0f13c9cc4 100644 --- a/alts/src/test/java/io/grpc/alts/internal/ByteBufTestUtils.java +++ b/alts/src/test/java/io/grpc/alts/internal/ByteBufTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/test/java/io/grpc/alts/internal/ChannelCrypterNettyTestBase.java b/alts/src/test/java/io/grpc/alts/internal/ChannelCrypterNettyTestBase.java index 8094e6832d9..cab0765e7d7 100644 --- a/alts/src/test/java/io/grpc/alts/internal/ChannelCrypterNettyTestBase.java +++ b/alts/src/test/java/io/grpc/alts/internal/ChannelCrypterNettyTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ /** Abstract class for unit tests of {@link ChannelCrypterNetty}. */ public abstract class ChannelCrypterNettyTestBase { - private static final String DECRYPTION_FAILURE_MESSAGE = "Tag mismatch"; + private static final String DECRYPTION_FAILURE_MESSAGE_RE = "Tag mismatch|BAD_DECRYPT"; protected final List references = new ArrayList<>(); public ChannelCrypterNetty client; @@ -169,7 +169,7 @@ public void reflection() throws GeneralSecurityException { client.decrypt(frameDecrypt.out, frameDecrypt.tag, frameDecrypt.ciphertext); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_MESSAGE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_MESSAGE_RE); } } @@ -186,7 +186,7 @@ public void skipMessage() throws GeneralSecurityException { client.decrypt(frameDecrypt.out, frameDecrypt.tag, frameDecrypt.ciphertext); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_MESSAGE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_MESSAGE_RE); } } @@ -202,7 +202,7 @@ public void corruptMessage() throws GeneralSecurityException { client.decrypt(frameDecrypt.out, frameDecrypt.tag, frameDecrypt.ciphertext); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_MESSAGE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_MESSAGE_RE); } } @@ -220,7 +220,7 @@ public void replayMessage() throws GeneralSecurityException { server.decrypt(frameDecrypt2.out, frameDecrypt2.tag, frameDecrypt2.ciphertext); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_MESSAGE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_MESSAGE_RE); } } } diff --git a/alts/src/test/java/io/grpc/alts/internal/FakeChannelCrypter.java b/alts/src/test/java/io/grpc/alts/internal/FakeChannelCrypter.java index 0c4986f45fd..037af017ae9 100644 --- a/alts/src/test/java/io/grpc/alts/internal/FakeChannelCrypter.java +++ b/alts/src/test/java/io/grpc/alts/internal/FakeChannelCrypter.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/alts/src/test/java/io/grpc/alts/internal/FakeTsiHandshaker.java b/alts/src/test/java/io/grpc/alts/internal/FakeTsiHandshaker.java index 74bffffffae..7a6119dc0be 100644 --- a/alts/src/test/java/io/grpc/alts/internal/FakeTsiHandshaker.java +++ b/alts/src/test/java/io/grpc/alts/internal/FakeTsiHandshaker.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Preconditions; +import io.grpc.ChannelLogger; import io.grpc.alts.internal.TsiPeer.Property; +import io.grpc.internal.TestUtils.NoopChannelLogger; import io.netty.buffer.ByteBufAllocator; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; @@ -37,7 +39,7 @@ public class FakeTsiHandshaker implements TsiHandshaker { private static final TsiHandshakerFactory clientHandshakerFactory = new TsiHandshakerFactory() { @Override - public TsiHandshaker newHandshaker() { + public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) { return new FakeTsiHandshaker(true); } }; @@ -45,7 +47,7 @@ public TsiHandshaker newHandshaker() { private static final TsiHandshakerFactory serverHandshakerFactory = new TsiHandshakerFactory() { @Override - public TsiHandshaker newHandshaker() { + public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) { return new FakeTsiHandshaker(false); } }; @@ -66,6 +68,7 @@ enum State { SERVER_FINISHED; // Returns the next State. In order to advance to sendState=N, receiveState must be N-1. + @SuppressWarnings("EnumOrdinal") public State next() { if (ordinal() + 1 < values().length) { return values()[ordinal() + 1]; @@ -83,11 +86,13 @@ public static TsiHandshakerFactory serverHandshakerFactory() { } public static TsiHandshaker newFakeHandshakerClient() { - return clientHandshakerFactory.newHandshaker(); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + return clientHandshakerFactory.newHandshaker(null, channelLogger); } public static TsiHandshaker newFakeHandshakerServer() { - return serverHandshakerFactory.newHandshaker(); + NoopChannelLogger channelLogger = new NoopChannelLogger(); + return serverHandshakerFactory.newHandshaker(null, channelLogger); } protected FakeTsiHandshaker(boolean isClient) { @@ -143,7 +148,7 @@ public void getBytesToSendToPeer(ByteBuffer bytes) throws GeneralSecurityExcepti return; } - // Prepare the next message, if neeeded. + // Prepare the next message, if needed. if (sendBuffer == null) { if (sendState.next() != receiveState) { // We're still waiting for bytes from the peer, so bail. @@ -172,6 +177,7 @@ public boolean processBytesFromPeer(ByteBuffer bytes) throws GeneralSecurityExce ByteBuffer messageBytes = frameParser.getRawFrame(); int offset = AltsFraming.getFramingOverhead(); int length = messageBytes.limit() - offset; + @SuppressWarnings("ByteBufferBackingArray") // ByteBuffer is created using allocate() String message = new String(messageBytes.array(), offset, length, UTF_8); logger.log(Level.FINE, "Read message: {0}", message); @@ -209,7 +215,7 @@ public TsiPeer extractPeer() { @Override public Object extractPeerObject() { - return AltsAuthContext.getDefaultInstance(); + return AltsInternalContext.getDefaultInstance(); } @Override @@ -223,6 +229,11 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator @Override public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) { - return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc); + return createFrameProtector(AltsTsiFrameProtector.getMinFrameSize(), alloc); + } + + @Override + public void close() { + // No-op } } diff --git a/alts/src/test/java/io/grpc/alts/internal/FakeTsiTest.java b/alts/src/test/java/io/grpc/alts/internal/FakeTsiTest.java index 3f6576257b5..f908160f958 100644 --- a/alts/src/test/java/io/grpc/alts/internal/FakeTsiTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/FakeTsiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import io.netty.util.ReferenceCounted; import io.netty.util.ResourceLeakDetector; import io.netty.util.ResourceLeakDetector.Level; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; import java.util.ArrayList; @@ -86,11 +87,11 @@ public void handshakeStateOrderTest() { byte[] transportBufferBytes = new byte[TsiTest.getDefaultTransportBufferSize()]; ByteBuffer transportBuffer = ByteBuffer.wrap(transportBufferBytes); - transportBuffer.limit(0); // Start off with an empty buffer + ((Buffer) transportBuffer).limit(0); // Start off with an empty buffer - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); clientHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertEquals( FakeTsiHandshaker.State.CLIENT_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim()); @@ -99,14 +100,14 @@ public void handshakeStateOrderTest() { assertFalse(transportBuffer.hasRemaining()); // client shouldn't offer any more bytes - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); clientHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertFalse(transportBuffer.hasRemaining()); - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); serverHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertEquals( FakeTsiHandshaker.State.SERVER_INIT.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim()); @@ -115,14 +116,14 @@ public void handshakeStateOrderTest() { assertFalse(transportBuffer.hasRemaining()); // server shouldn't offer any more bytes - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); serverHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertFalse(transportBuffer.hasRemaining()); - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); clientHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertEquals( FakeTsiHandshaker.State.CLIENT_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim()); @@ -131,14 +132,14 @@ public void handshakeStateOrderTest() { assertFalse(transportBuffer.hasRemaining()); // client shouldn't offer any more bytes - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); clientHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertFalse(transportBuffer.hasRemaining()); - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); serverHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertEquals( FakeTsiHandshaker.State.SERVER_FINISHED.toString().trim(), new String(transportBufferBytes, 4, transportBuffer.remaining(), UTF_8).trim()); @@ -147,9 +148,9 @@ public void handshakeStateOrderTest() { assertFalse(transportBuffer.hasRemaining()); // server shouldn't offer any more bytes - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); serverHandshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); assertFalse(transportBuffer.hasRemaining()); } catch (GeneralSecurityException e) { throw new AssertionError(e); diff --git a/alts/src/test/java/io/grpc/alts/internal/GoogleDefaultProtocolNegotiatorTest.java b/alts/src/test/java/io/grpc/alts/internal/GoogleDefaultProtocolNegotiatorTest.java new file mode 100644 index 00000000000..14c19e554ae --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/internal/GoogleDefaultProtocolNegotiatorTest.java @@ -0,0 +1,223 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableList; +import io.grpc.Attributes; +import io.grpc.Channel; +import io.grpc.ChannelLogger; +import io.grpc.ChannelLogger.ChannelLogLevel; +import io.grpc.ManagedChannel; +import io.grpc.inprocess.InProcessChannelBuilder; +import io.grpc.internal.ObjectPool; +import io.grpc.netty.GrpcHttp2ConnectionHandler; +import io.grpc.netty.GrpcSslContexts; +import io.grpc.netty.InternalProtocolNegotiationEvent; +import io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.ssl.SslContext; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Nullable; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(Enclosed.class) +public final class GoogleDefaultProtocolNegotiatorTest { + + @RunWith(JUnit4.class) + public abstract static class HandlerSelectionTest { + private ProtocolNegotiator googleProtocolNegotiator; + private Attributes.Key originalClusterNameAttrKey; + private final ObjectPool handshakerChannelPool = new ObjectPool() { + + @Override + public Channel getObject() { + return InProcessChannelBuilder.forName("test").build(); + } + + @Override + public Channel returnObject(Object object) { + ((ManagedChannel) object).shutdownNow(); + return null; + } + }; + + @Before + public void setUp() throws Exception { + SslContext sslContext = GrpcSslContexts.forClient().build(); + originalClusterNameAttrKey = + AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory.clusterNameAttrKey; + AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory.clusterNameAttrKey = + getClusterNameAttrKey(); + googleProtocolNegotiator = new AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory( + ImmutableList.of(), + handshakerChannelPool, + sslContext) + .newNegotiator(); + } + + @After + public void tearDown() { + googleProtocolNegotiator.close(); + AltsProtocolNegotiator.GoogleDefaultProtocolNegotiatorFactory.clusterNameAttrKey = + originalClusterNameAttrKey; + } + + @Nullable + abstract Attributes.Key getClusterNameAttrKey(); + + @Test + public void tlsHandler_emptyAttributes() { + subtest_tlsHandler(Attributes.EMPTY); + } + + void subtest_altsHandler(Attributes eagAttributes) { + GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class); + when(mockHandler.getEagAttributes()).thenReturn(eagAttributes); + ChannelLogger logger = mock(ChannelLogger.class); + doNothing().when(logger).log(any(ChannelLogLevel.class), anyString()); + when(mockHandler.getNegotiationLogger()).thenReturn(logger); + + final AtomicReference failure = new AtomicReference<>(); + ChannelHandler exceptionCaught = new ChannelInboundHandlerAdapter() { + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + failure.set(cause); + super.exceptionCaught(ctx, cause); + } + }; + ChannelHandler h = googleProtocolNegotiator.newHandler(mockHandler); + EmbeddedChannel chan = new EmbeddedChannel(exceptionCaught); + // Add the negotiator handler last, but to the front. Putting this in ctor above would make + // it throw early. + chan.pipeline().addFirst(h); + chan.pipeline().fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault()); + + // Check that the message complained about the ALTS code, rather than SSL. ALTS throws on + // being added, so it's hard to catch it at the right time to make this assertion. + assertThat(failure.get()).hasMessageThat().contains("TsiHandshakeHandler"); + } + + void subtest_tlsHandler(Attributes eagAttributes) { + GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class); + when(mockHandler.getEagAttributes()).thenReturn(eagAttributes); + when(mockHandler.getAuthority()).thenReturn("authority"); + ChannelLogger logger = mock(ChannelLogger.class); + doNothing().when(logger).log(any(ChannelLogLevel.class), anyString()); + when(mockHandler.getNegotiationLogger()).thenReturn(logger); + + ChannelHandler h = googleProtocolNegotiator.newHandler(mockHandler); + EmbeddedChannel chan = new EmbeddedChannel(h); + chan.pipeline().fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault()); + + assertThat(chan.pipeline().first().getClass().getSimpleName()).isEqualTo("SslHandler"); + } + } + + @RunWith(JUnit4.class) + public static class WithoutXdsInClasspath extends HandlerSelectionTest { + + @Nullable + @Override + Attributes.Key getClusterNameAttrKey() { + return null; + } + } + + @RunWith(JUnit4.class) + public static class WithXdsInClasspath extends HandlerSelectionTest { + // Same as io.grpc.xds.InternalXdsAttributes.ATTR_CLUSTER_NAME + private static final Attributes.Key XDS_CLUSTER_NAME_ATTR_KEY = + Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.clusterName"); + + @Nullable + @Override + Attributes.Key getClusterNameAttrKey() { + return XDS_CLUSTER_NAME_ATTR_KEY; + } + + @Test + public void altsHandler_xdsCluster() { + Attributes attrs = + Attributes.newBuilder().set(XDS_CLUSTER_NAME_ATTR_KEY, "api.googleapis.com").build(); + subtest_altsHandler(attrs); + } + + @Test + public void tlsHandler_googleCfe() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, "google_cfe_api.googleapis.com").build(); + subtest_tlsHandler(attrs); + } + + @Test + public void altsHandler_googleCfe_federation() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, "xdstp1://").build(); + subtest_altsHandler(attrs); + } + + @Test + public void tlsHanlder_googleCfe() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, + "xdstp://traffic-director-c2p.xds.googleapis.com/" + + "envoy.config.cluster.v3.Cluster/google_cfe_example/apis") + .build(); + subtest_tlsHandler(attrs); + } + + @Test + public void altsHanlder_nonGoogleCfe_authorityNotMatch() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, + "//example.com/envoy.config.cluster.v3.Cluster/google_cfe_") + .build(); + subtest_altsHandler(attrs); + } + + @Test + public void altsHanlder_nonGoogleCfe_pathNotMatch() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, + "//traffic-director-c2p.xds.googleapis.com/envoy.config.cluster.v3.Cluster/google_gfe") + .build(); + subtest_altsHandler(attrs); + } + + @Test + public void altsHandler_googleCfe_invalidUri() { + Attributes attrs = Attributes.newBuilder().set( + XDS_CLUSTER_NAME_ATTR_KEY, "//").build(); + subtest_altsHandler(attrs); + } + } +} diff --git a/alts/src/test/java/io/grpc/alts/internal/MockAltsHandshakerResp.java b/alts/src/test/java/io/grpc/alts/internal/MockAltsHandshakerResp.java index 28ece25b3c6..a21082be41f 100644 --- a/alts/src/test/java/io/grpc/alts/internal/MockAltsHandshakerResp.java +++ b/alts/src/test/java/io/grpc/alts/internal/MockAltsHandshakerResp.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,7 @@ import com.google.protobuf.ByteString; import io.grpc.Status; -import io.grpc.alts.internal.Handshaker.HandshakerResp; -import io.grpc.alts.internal.Handshaker.HandshakerResult; -import io.grpc.alts.internal.Handshaker.HandshakerStatus; -import io.grpc.alts.internal.Handshaker.Identity; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.security.SecureRandom; @@ -66,7 +63,7 @@ static ByteString getOutFrame() { buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(frameSize); buffer.put(TEST_OUT_FRAME.getBytes(UTF_8)); - buffer.flip(); + ((Buffer) buffer).flip(); return ByteString.copyFrom(buffer); } diff --git a/alts/src/test/java/io/grpc/alts/internal/NettyTsiHandshakerTest.java b/alts/src/test/java/io/grpc/alts/internal/NettyTsiHandshakerTest.java index ff4c9135a0e..d71ff16f352 100644 --- a/alts/src/test/java/io/grpc/alts/internal/NettyTsiHandshakerTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/NettyTsiHandshakerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -146,7 +146,7 @@ public void handshakerMethodsMatch() { actualMethods.add(m.getName()); } - assertThat(actualMethods).containsAllIn(expectedMethods); + assertThat(actualMethods).containsAtLeastElementsIn(expectedMethods); } static void doHandshake( diff --git a/alts/src/test/java/io/grpc/alts/internal/RpcProtocolVersionsUtilTest.java b/alts/src/test/java/io/grpc/alts/internal/RpcProtocolVersionsUtilTest.java index 8009090be2b..07e0358e707 100644 --- a/alts/src/test/java/io/grpc/alts/internal/RpcProtocolVersionsUtilTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/RpcProtocolVersionsUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import io.grpc.alts.internal.RpcProtocolVersions.Version; import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; -import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions.Version; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; diff --git a/alts/src/test/java/io/grpc/alts/internal/TsiFrameHandlerTest.java b/alts/src/test/java/io/grpc/alts/internal/TsiFrameHandlerTest.java new file mode 100644 index 00000000000..f9ed0fa4f97 --- /dev/null +++ b/alts/src/test/java/io/grpc/alts/internal/TsiFrameHandlerTest.java @@ -0,0 +1,135 @@ +/* + * Copyright 2018 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.alts.internal; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelPromise; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.util.CharsetUtil; +import java.security.GeneralSecurityException; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link TsiFrameHandler}. */ +@RunWith(JUnit4.class) +public class TsiFrameHandlerTest { + + @Rule + public final TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(5)); + + private final TsiFrameHandler tsiFrameHandler = new TsiFrameHandler(new IdentityFrameProtector()); + private final EmbeddedChannel channel = new EmbeddedChannel(tsiFrameHandler); + + @Test + public void writeAndFlush_handshakeSucceed() throws InterruptedException { + ByteBuf msg = Unpooled.copiedBuffer("message after handshake finished", CharsetUtil.UTF_8); + + channel.writeAndFlush(msg); + Object actual = channel.readOutbound(); + + assertThat(actual).isEqualTo(msg); + channel.close().sync(); + channel.checkException(); + } + + @Test + public void writeAndFlush_shouldBeIgnoredAfterClose() throws InterruptedException { + channel.close().sync(); + ByteBuf msg = Unpooled.copiedBuffer("message after closed", CharsetUtil.UTF_8); + + channel.writeAndFlush(msg); + + assertThat(channel.outboundMessages()).isEmpty(); + try { + channel.checkException(); + } catch (Exception e) { + throw new AssertionError( + "Any attempt after close should be ignored without out exception", e); + } + } + + @Test + public void close_shouldFlushRemainingMessage() throws InterruptedException { + ByteBuf msg = Unpooled.copiedBuffer("message after handshake failed", CharsetUtil.UTF_8); + channel.write(msg); + + assertThat(channel.outboundMessages()).isEmpty(); + + channel.close().sync(); + Object actual = channel.readOutbound(); + + assertWithMessage("pending write should be flushed on close").that(actual).isEqualTo(msg); + channel.checkException(); + } + + @Test + public void flushAfterCloseShouldWork() throws InterruptedException { + ByteBuf msg = Unpooled.copiedBuffer("message after handshake failed", CharsetUtil.UTF_8); + channel.write(msg); + + channel.pipeline().addFirst(new ChannelOutboundHandlerAdapter() { + @Override + public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + // We have to call flush while doing a close, since close() tears down the pipeline + // immediately after. + channel.flush(); + super.close(ctx, promise); + } + }); + + assertThat(channel.outboundMessages()).isEmpty(); + + channel.close().sync(); + Object actual = channel.readOutbound(); + + assertWithMessage("pending write should be flushed on close").that(actual).isEqualTo(msg); + channel.checkException(); + } + + private static final class IdentityFrameProtector implements TsiFrameProtector { + + @Override + public void protectFlush(List unprotectedBufs, Consumer ctxWrite, + ByteBufAllocator alloc) throws GeneralSecurityException { + for (ByteBuf unprotectedBuf : unprotectedBufs) { + ctxWrite.accept(unprotectedBuf); + } + } + + @Override + public void unprotect(ByteBuf in, List out, ByteBufAllocator alloc) + throws GeneralSecurityException { + out.add(in.toString(CharsetUtil.UTF_8)); + } + + @Override + public void destroy() {} + } +} diff --git a/alts/src/test/java/io/grpc/alts/internal/TsiTest.java b/alts/src/test/java/io/grpc/alts/internal/TsiTest.java index 8e6767b08a2..0241182f2db 100644 --- a/alts/src/test/java/io/grpc/alts/internal/TsiTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/TsiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018, gRPC Authors All rights reserved. + * Copyright 2018 The gRPC Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.buffer.UnpooledByteBufAllocator; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; import java.util.ArrayList; @@ -33,13 +34,13 @@ import java.util.List; import javax.crypto.AEADBadTagException; -/** Utility class that provides tests for implementations of @{link TsiHandshaker}. */ +/** Utility class that provides tests for implementations of {@link TsiHandshaker}. */ public final class TsiTest { - private static final String DECRYPTION_FAILURE_RE = "Tag mismatch!"; + private static final String DECRYPTION_FAILURE_RE = "Tag mismatch|BAD_DECRYPT"; private TsiTest() {} - /** A @{code TsiHandshaker} pair for running tests. */ + /** A {@code TsiHandshaker} pair for running tests. */ public static class Handshakers { private final TsiHandshaker client; private final TsiHandshaker server; @@ -83,7 +84,7 @@ static void performHandshake(int transportBufferSize, Handshakers handshakers) byte[] transportBufferBytes = new byte[transportBufferSize]; ByteBuffer transportBuffer = ByteBuffer.wrap(transportBufferBytes); - transportBuffer.limit(0); // Start off with an empty buffer + ((Buffer) transportBuffer).limit(0); // Start off with an empty buffer while (clientHandshaker.isInProgress() || serverHandshaker.isInProgress()) { for (TsiHandshaker handshaker : new TsiHandshaker[] {clientHandshaker, serverHandshaker}) { @@ -94,9 +95,9 @@ static void performHandshake(int transportBufferSize, Handshakers handshakers) } // Put new bytes on the wire, if needed. if (handshaker.isInProgress()) { - transportBuffer.clear(); + ((Buffer) transportBuffer).clear(); handshaker.getBytesToSendToPeer(transportBuffer); - transportBuffer.flip(); + ((Buffer) transportBuffer).flip(); } } } @@ -282,7 +283,7 @@ public void accept(ByteBuf buf) { receiver.unprotect(protect, unprotectOut, alloc); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_RE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_RE); } sender.destroy(); @@ -321,7 +322,7 @@ public void accept(ByteBuf buf) { receiver.unprotect(protect, unprotectOut, alloc); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_RE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_RE); } sender.destroy(); @@ -360,7 +361,7 @@ public void accept(ByteBuf buf) { receiver.unprotect(protect, unprotectOut, alloc); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_RE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_RE); } sender.destroy(); @@ -396,7 +397,7 @@ public void accept(ByteBuf buf) { sender.unprotect(protect.slice(), unprotectOut, alloc); fail("Exception expected"); } catch (AEADBadTagException ex) { - assertThat(ex).hasMessageThat().contains(DECRYPTION_FAILURE_RE); + assertThat(ex).hasMessageThat().containsMatch(DECRYPTION_FAILURE_RE); } sender.destroy(); diff --git a/android-interop-testing/README.md b/android-interop-testing/README.md index 950907b0881..bd7841e7e84 100644 --- a/android-interop-testing/README.md +++ b/android-interop-testing/README.md @@ -3,8 +3,6 @@ gRPC Android test App Implements gRPC integration tests in an Android App. -TODO(madongfly) integrate this App into the gRPC-Java build system. - In order to build this app, you need a local.properties file under this directory which specifies the location of your android sdk: ``` @@ -35,21 +33,19 @@ $ ../gradlew installDebug Then manually test it with the UI. -Commandline test +Instrumentation tests ---------------- -Run the test with arguments: -``` -$ adb shell am instrument -w -e server_host -e server_port -e server_host_override foo.test.google.fr -e use_tls true -e use_test_ca true -e test_case all io.grpc.android.integrationtest/.TesterInstrumentation -``` +Instrumentation tests must be run on a connected device or emulator. Run with the +following gradle command: -If the test passed successfully, it will output: ``` -INSTRUMENTATION_RESULT: grpc test result=Success! -INSTRUMENTATION_CODE: -1 -``` -otherwise, output something like: -``` -INSTRUMENTATION_RESULT: grpc test result=Failed... : -INSTRUMENTATION_CODE: 0 +$ ../gradlew connectedAndroidTest \ + -Pandroid.testInstrumentationRunnerArguments.server_host=10.0.2.2 \ + -Pandroid.testInstrumentationRunnerArguments.server_port=8080 \ + -Pandroid.testInstrumentationRunnerArguments.use_tls=true \ + -Pandroid.testInstrumentationRunnerArguments.server_host_override=foo.test.google.fr \ + -Pandroid.testInstrumentationRunnerArguments.use_test_ca=true \ + -Pandroid.testInstrumentationRunnerArguments.test_case=all ``` + diff --git a/android-interop-testing/app/build.gradle b/android-interop-testing/app/build.gradle deleted file mode 100644 index 8bc8ccc451b..00000000000 --- a/android-interop-testing/app/build.gradle +++ /dev/null @@ -1,80 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'com.google.protobuf' - -android { - compileSdkVersion 22 - buildToolsVersion '25.0.2' - - defaultConfig { - applicationId "io.grpc.android.integrationtest" - // API level 14+ is required for TLS since Google Play Services v10.2 - minSdkVersion 14 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - debug { - minifyEnabled false - } - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - lintOptions { - disable 'InvalidPackage', 'HardcodedText' - } -} - -protobuf { - protoc { - artifact = 'com.google.protobuf:protoc:3.5.1-1' - } - plugins { - grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.12.0-SNAPSHOT' // CURRENT_GRPC_VERSION - } - } - generateProtoTasks { - all().each { task -> - task.builtins { - javanano { - // Options added to --javanano_out - option 'ignore_services=true' - option 'enum_style=java' - } - } - - task.plugins { - grpc { - // Options added to --grpc_out - option 'nano' - } - } - } - } -} - -dependencies { - compile 'com.android.support:appcompat-v7:22.2.1' - compile 'com.android.support:support-annotations:23.1.1' - compile 'com.google.android.gms:play-services-base:7.3.0' - // You need to build grpc-java to obtain the grpc libraries below. - compile 'io.grpc:grpc-protobuf-nano:1.12.0-SNAPSHOT' // CURRENT_GRPC_VERSION - compile 'io.grpc:grpc-okhttp:1.12.0-SNAPSHOT' // CURRENT_GRPC_VERSION - compile 'io.grpc:grpc-stub:1.12.0-SNAPSHOT' // CURRENT_GRPC_VERSION - compile 'io.grpc:grpc-testing:1.12.0-SNAPSHOT' // CURRENT_GRPC_VERSION - compile 'javax.annotation:javax.annotation-api:1.2' - compile 'junit:junit:4.12' - - androidTestCompile 'com.android.support.test:rules:0.5' - androidTestCompile 'com.android.support.test:runner:0.5' -} - -gradle.projectsEvaluated { - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:deprecation" - } -} diff --git a/android-interop-testing/app/proguard-rules.pro b/android-interop-testing/app/proguard-rules.pro deleted file mode 100644 index 8af80352076..00000000000 --- a/android-interop-testing/app/proguard-rules.pro +++ /dev/null @@ -1,23 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in $ANDROID_HOME/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - --dontwarn android.test.** --dontwarn com.google.common.** --dontwarn javax.naming.** --dontwarn okio.** --dontwarn org.junit.** --dontwarn org.mockito.** --dontwarn sun.reflect.** -# Ignores: can't find referenced class javax.lang.model.element.Modifier --dontwarn com.google.errorprone.annotations.** - -# Ignores: can't find referenced method from grpc-testing's compileOnly dependency on Truth --dontwarn io.grpc.testing.DeadlineSubject diff --git a/android-interop-testing/app/src/androidTest/java/io/grpc/android/integrationtest/InteropTesterTest.java b/android-interop-testing/app/src/androidTest/java/io/grpc/android/integrationtest/InteropTesterTest.java deleted file mode 100644 index 15e2c26e2cc..00000000000 --- a/android-interop-testing/app/src/androidTest/java/io/grpc/android/integrationtest/InteropTesterTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2017, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.android.integrationtest; - -import static junit.framework.Assert.assertEquals; - -import android.support.test.runner.AndroidJUnit4; -import com.google.common.util.concurrent.SettableFuture; -import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(AndroidJUnit4.class) -public class InteropTesterTest { - private final int TIMEOUT_SECONDS = 120; - - @Test - public void interopTests() throws Exception { - final SettableFuture resultFuture = SettableFuture.create(); - new InteropTester( - "all", - TesterOkHttpChannelBuilder.build( - "grpc-test.sandbox.googleapis.com", 443, null, true, null, null), - new InteropTester.TestListener() { - @Override - public void onPreTest() {} - - @Override - public void onPostTest(String result) { - resultFuture.set(result); - } - }, - false) - .execute(); - String result = resultFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS); - assertEquals(result, InteropTester.SUCCESS_MESSAGE); - } -} diff --git a/android-interop-testing/app/src/main/AndroidManifest.xml b/android-interop-testing/app/src/main/AndroidManifest.xml deleted file mode 100644 index 193d8e01bd0..00000000000 --- a/android-interop-testing/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/InteropTester.java b/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/InteropTester.java deleted file mode 100644 index bf71a29273f..00000000000 --- a/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/InteropTester.java +++ /dev/null @@ -1,771 +0,0 @@ -/* - * Copyright 2015, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.android.integrationtest; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; - -import android.os.AsyncTask; -import android.util.Log; -import com.google.protobuf.nano.EmptyProtos; -import com.google.protobuf.nano.MessageNano; -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.ClientInterceptors; -import io.grpc.ClientInterceptors.CheckedForwardingClientCall; -import io.grpc.ManagedChannel; -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import io.grpc.StatusRuntimeException; -import io.grpc.android.integrationtest.nano.Messages; -import io.grpc.android.integrationtest.nano.Messages.Payload; -import io.grpc.android.integrationtest.nano.Messages.ResponseParameters; -import io.grpc.android.integrationtest.nano.Messages.SimpleRequest; -import io.grpc.android.integrationtest.nano.Messages.SimpleResponse; -import io.grpc.android.integrationtest.nano.Messages.StreamingInputCallRequest; -import io.grpc.android.integrationtest.nano.Messages.StreamingInputCallResponse; -import io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest; -import io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse; -import io.grpc.android.integrationtest.nano.TestServiceGrpc; -import io.grpc.android.integrationtest.nano.UnimplementedServiceGrpc; -import io.grpc.internal.testing.StreamRecorder; -import io.grpc.stub.StreamObserver; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -/** - * Implementation of the integration tests, as an AsyncTask. - */ -final class InteropTester extends AsyncTask { - static final String SUCCESS_MESSAGE = "Success!"; - static final String LOG_TAG = "GrpcTest"; - - private ManagedChannel channel; - private TestServiceGrpc.TestServiceBlockingStub blockingStub; - private TestServiceGrpc.TestServiceStub asyncStub; - private String testCase; - private TestListener listener; - private static final int TIMEOUT_MILLIS = 5000; - - private static final class ResponseObserver - implements StreamObserver { - public LinkedBlockingQueue responses = new LinkedBlockingQueue(); - final Object magicTailResponse = new Object(); - - @Override - public void onNext(Messages.StreamingOutputCallResponse value) { - responses.add(value); - } - - @Override - public void onError(Throwable t) { - Log.e(LOG_TAG, "Encounter an error", t); - responses.add(t); - } - - @Override - public void onCompleted() { - responses.add(magicTailResponse); - } - } - - - public InteropTester(String testCase, - ManagedChannel channel, - TestListener listener, - boolean useGet) { - this.testCase = testCase; - this.listener = listener; - this.channel = channel; - Channel channelToUse = channel; - if (useGet) { - channelToUse = ClientInterceptors.intercept(channel, new SafeMethodChannelInterceptor()); - } - blockingStub = TestServiceGrpc.newBlockingStub(channelToUse); - asyncStub = TestServiceGrpc.newStub(channelToUse); - } - - @Override - protected void onPreExecute() { - listener.onPreTest(); - } - - @Override - protected String doInBackground(Void... nothing) { - try { - runTest(testCase); - return SUCCESS_MESSAGE; - } catch (Throwable t) { - // Print the stack trace to logcat. - t.printStackTrace(); - // Then print to the error message. - StringWriter sw = new StringWriter(); - t.printStackTrace(new PrintWriter(sw)); - return "Failed... : " + t.getMessage() + "\n" + sw.toString(); - } finally { - shutdown(); - } - } - - @Override - protected void onPostExecute(String result) { - listener.onPostTest(result); - } - - - public void shutdown() { - channel.shutdown(); - } - - public void runTest(String testCase) throws Exception { - Log.i(LOG_TAG, "Running test " + testCase); - if ("all".equals(testCase)) { - runTest("empty_unary"); - runTest("large_unary"); - runTest("client_streaming"); - runTest("server_streaming"); - runTest("ping_pong"); - runTest("empty_stream"); - runTest("cancel_after_begin"); - runTest("cancel_after_first_response"); - runTest("full_duplex_call_should_succeed"); - runTest("half_duplex_call_should_succeed"); - runTest("server_streaming_should_be_flow_controlled"); - runTest("very_large_request"); - runTest("very_large_response"); - runTest("deadline_not_exceeded"); - runTest("deadline_exceeded"); - runTest("deadline_exceeded_server_streaming"); - runTest("unimplemented_method"); - runTest("timeout_on_sleeping_server"); - // This has to be the last one, because it will shut down the channel. - runTest("graceful_shutdown"); - } else if ("empty_unary".equals(testCase)) { - emptyUnary(); - } else if ("large_unary".equals(testCase)) { - largeUnary(); - } else if ("client_streaming".equals(testCase)) { - clientStreaming(); - } else if ("server_streaming".equals(testCase)) { - serverStreaming(); - } else if ("ping_pong".equals(testCase)) { - pingPong(); - } else if ("empty_stream".equals(testCase)) { - emptyStream(); - } else if ("cancel_after_begin".equals(testCase)) { - cancelAfterBegin(); - } else if ("cancel_after_first_response".equals(testCase)) { - cancelAfterFirstResponse(); - } else if ("full_duplex_call_should_succeed".equals(testCase)) { - fullDuplexCallShouldSucceed(); - } else if ("half_duplex_call_should_succeed".equals(testCase)) { - halfDuplexCallShouldSucceed(); - } else if ("server_streaming_should_be_flow_controlled".equals(testCase)) { - serverStreamingShouldBeFlowControlled(); - } else if ("very_large_request".equals(testCase)) { - veryLargeRequest(); - } else if ("very_large_response".equals(testCase)) { - veryLargeResponse(); - } else if ("deadline_not_exceeded".equals(testCase)) { - deadlineNotExceeded(); - } else if ("deadline_exceeded".equals(testCase)) { - deadlineExceeded(); - } else if ("deadline_exceeded_server_streaming".equals(testCase)) { - deadlineExceededServerStreaming(); - } else if ("unimplemented_method".equals(testCase)) { - unimplementedMethod(); - } else if ("timeout_on_sleeping_server".equals(testCase)) { - timeoutOnSleepingServer(); - } else if ("graceful_shutdown".equals(testCase)) { - gracefulShutdown(); - } else { - throw new IllegalArgumentException("Unimplemented/Unknown test case: " + testCase); - } - } - - public void emptyUnary() { - assertMessageEquals(new EmptyProtos.Empty(), blockingStub.emptyCall(new EmptyProtos.Empty())); - } - - public void largeUnary() { - if (shouldSkip()) { - return; - } - final Messages.SimpleRequest request = new Messages.SimpleRequest(); - request.responseSize = 314159; - request.responseType = Messages.PayloadType.COMPRESSABLE; - request.payload = new Payload(); - request.payload.body = new byte[271828]; - - final Messages.SimpleResponse goldenResponse = new Messages.SimpleResponse(); - goldenResponse.payload = new Payload(); - goldenResponse.payload.body = new byte[314159]; - Messages.SimpleResponse response = blockingStub.unaryCall(request); - assertMessageEquals(goldenResponse, response); - } - - public void serverStreaming() throws Exception { - final Messages.StreamingOutputCallRequest request = new Messages.StreamingOutputCallRequest(); - request.responseType = Messages.PayloadType.COMPRESSABLE; - request.responseParameters = new Messages.ResponseParameters[4]; - for (int i = 0; i < 4; i++) { - request.responseParameters[i] = new Messages.ResponseParameters(); - } - request.responseParameters[0].size = 31415; - request.responseParameters[1].size = 9; - request.responseParameters[2].size = 2653; - request.responseParameters[3].size = 58979; - - final Messages.StreamingOutputCallResponse[] goldenResponses = - new Messages.StreamingOutputCallResponse[4]; - for (int i = 0; i < 4; i++) { - goldenResponses[i] = new Messages.StreamingOutputCallResponse(); - goldenResponses[i].payload = new Payload(); - goldenResponses[i].payload.type = Messages.PayloadType.COMPRESSABLE; - } - goldenResponses[0].payload.body = new byte[31415]; - goldenResponses[1].payload.body = new byte[9]; - goldenResponses[2].payload.body = new byte[2653]; - goldenResponses[3].payload.body = new byte[58979]; - - StreamRecorder recorder = StreamRecorder.create(); - asyncStub.streamingOutputCall(request, recorder); - assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertSuccess(recorder); - assertMessageEquals(Arrays.asList(goldenResponses), recorder.getValues()); - } - - public void clientStreaming() throws Exception { - final Messages.StreamingInputCallRequest[] requests = new Messages.StreamingInputCallRequest[4]; - for (int i = 0; i < 4; i++) { - requests[i] = new Messages.StreamingInputCallRequest(); - requests[i].payload = new Payload(); - } - requests[0].payload.body = new byte[27182]; - requests[1].payload.body = new byte[8]; - requests[2].payload.body = new byte[1828]; - requests[3].payload.body = new byte[45904]; - - final Messages.StreamingInputCallResponse goldenResponse = - new Messages.StreamingInputCallResponse(); - goldenResponse.aggregatedPayloadSize = 74922; - - StreamRecorder responseObserver = StreamRecorder.create(); - StreamObserver requestObserver = - asyncStub.streamingInputCall(responseObserver); - for (Messages.StreamingInputCallRequest request : requests) { - requestObserver.onNext(request); - } - requestObserver.onCompleted(); - assertMessageEquals(goldenResponse, responseObserver.firstValue().get()); - } - - public void pingPong() throws Exception { - final Messages.StreamingOutputCallRequest[] requests = - new Messages.StreamingOutputCallRequest[4]; - for (int i = 0; i < 4; i++) { - requests[i] = new Messages.StreamingOutputCallRequest(); - requests[i].responseParameters = new Messages.ResponseParameters[1]; - requests[i].responseParameters[0] = new Messages.ResponseParameters(); - requests[i].payload = new Payload(); - } - requests[0].responseParameters[0].size = 31415; - requests[0].payload.body = new byte[27182]; - requests[1].responseParameters[0].size = 9; - requests[1].payload.body = new byte[8]; - requests[2].responseParameters[0].size = 2653; - requests[2].payload.body = new byte[1828]; - requests[3].responseParameters[0].size = 58979; - requests[3].payload.body = new byte[45904]; - - - final Messages.StreamingOutputCallResponse[] goldenResponses = - new Messages.StreamingOutputCallResponse[4]; - for (int i = 0; i < 4; i++) { - goldenResponses[i] = new Messages.StreamingOutputCallResponse(); - goldenResponses[i].payload = new Payload(); - goldenResponses[i].payload.type = Messages.PayloadType.COMPRESSABLE; - } - goldenResponses[0].payload.body = new byte[31415]; - goldenResponses[1].payload.body = new byte[9]; - goldenResponses[2].payload.body = new byte[2653]; - goldenResponses[3].payload.body = new byte[58979]; - - ResponseObserver responseObserver = new ResponseObserver(); - StreamObserver requestObserver - = asyncStub.fullDuplexCall(responseObserver); - for (int i = 0; i < requests.length; i++) { - requestObserver.onNext(requests[i]); - Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - if (!(response instanceof Messages.StreamingOutputCallResponse)) { - fail("Unexpected: " + response); - } - assertMessageEquals(goldenResponses[i], (Messages.StreamingOutputCallResponse) response); - assertTrue("More than 1 responses received for ping pong test.", - responseObserver.responses.isEmpty()); - } - requestObserver.onCompleted(); - assertEquals(responseObserver.magicTailResponse, - responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - } - - public void emptyStream() throws Exception { - ResponseObserver responseObserver = new ResponseObserver(); - StreamObserver requestObserver - = asyncStub.fullDuplexCall(responseObserver); - requestObserver.onCompleted(); - assertEquals(responseObserver.magicTailResponse, - responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - } - - public void cancelAfterBegin() throws Exception { - StreamRecorder responseObserver = StreamRecorder.create(); - StreamObserver requestObserver = - asyncStub.streamingInputCall(responseObserver); - requestObserver.onError(new RuntimeException()); - assertTrue(responseObserver.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertEquals(Arrays.asList(), responseObserver.getValues()); - assertCodeEquals(io.grpc.Status.CANCELLED, - io.grpc.Status.fromThrowable(responseObserver.getError())); - } - - public void cancelAfterFirstResponse() throws Exception { - final StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseParameters = new Messages.ResponseParameters[1]; - request.responseParameters[0] = new ResponseParameters(); - request.responseParameters[0].size = 31415; - request.payload = new Payload(); - request.payload.body = new byte[27182]; - final StreamingOutputCallResponse goldenResponse = new StreamingOutputCallResponse(); - goldenResponse.payload = new Payload(); - goldenResponse.payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponse.payload.body = new byte[31415]; - - ResponseObserver responseObserver = new ResponseObserver(); - StreamObserver requestObserver - = asyncStub.fullDuplexCall(responseObserver); - requestObserver.onNext(request); - Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - if (!(response instanceof Messages.StreamingOutputCallResponse)) { - fail("Unexpected: " + response); - } - assertMessageEquals(goldenResponse, (Messages.StreamingOutputCallResponse) response); - - requestObserver.onError(new RuntimeException()); - response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - if (!(response instanceof Throwable)) { - fail("Unexpected: " + response); - } - assertCodeEquals(io.grpc.Status.CANCELLED, io.grpc.Status.fromThrowable((Throwable) response)); - } - - public void fullDuplexCallShouldSucceed() throws Exception { - // Build the request. - Integer[] responseSizes = {50, 100, 150, 200}; - final StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseParameters = new ResponseParameters[responseSizes.length]; - request.responseType = Messages.PayloadType.COMPRESSABLE; - for (int i = 0; i < responseSizes.length; ++i) { - request.responseParameters[i] = new ResponseParameters(); - request.responseParameters[i].size = responseSizes[i]; - request.responseParameters[i].intervalUs = 0; - } - - StreamRecorder recorder = StreamRecorder.create(); - StreamObserver requestStream = - asyncStub.fullDuplexCall(recorder); - - final int numRequests = 10; - for (int ix = numRequests; ix > 0; --ix) { - requestStream.onNext(request); - } - requestStream.onCompleted(); - assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertSuccess(recorder); - assertEquals(responseSizes.length * numRequests, recorder.getValues().size()); - for (int ix = 0; ix < recorder.getValues().size(); ++ix) { - StreamingOutputCallResponse response = recorder.getValues().get(ix); - assertEquals(Messages.PayloadType.COMPRESSABLE, response.payload.type); - int length = response.payload.body.length; - int expectedSize = responseSizes[ix % responseSizes.length]; - assertEquals("comparison failed at index " + ix, expectedSize, length); - } - } - - public void halfDuplexCallShouldSucceed() throws Exception { - // Build the request. - Integer[] responseSizes = {50, 100, 150, 200}; - final StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseParameters = new ResponseParameters[responseSizes.length]; - request.responseType = Messages.PayloadType.COMPRESSABLE; - for (int i = 0; i < responseSizes.length; ++i) { - request.responseParameters[i] = new ResponseParameters(); - request.responseParameters[i].size = responseSizes[i]; - request.responseParameters[i].intervalUs = 0; - } - - StreamRecorder recorder = StreamRecorder.create(); - StreamObserver requestStream = asyncStub.halfDuplexCall(recorder); - - final int numRequests = 10; - for (int ix = numRequests; ix > 0; --ix) { - requestStream.onNext(request); - } - requestStream.onCompleted(); - assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertSuccess(recorder); - assertEquals(responseSizes.length * numRequests, recorder.getValues().size()); - for (int ix = 0; ix < recorder.getValues().size(); ++ix) { - StreamingOutputCallResponse response = recorder.getValues().get(ix); - assertEquals(Messages.PayloadType.COMPRESSABLE, response.payload.type); - int length = response.payload.body.length; - int expectedSize = responseSizes[ix % responseSizes.length]; - assertEquals("comparison failed at index " + ix, expectedSize, length); - } - } - - public void serverStreamingShouldBeFlowControlled() throws Exception { - final StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseType = Messages.PayloadType.COMPRESSABLE; - request.responseParameters = new ResponseParameters[2]; - request.responseParameters[0] = new ResponseParameters(); - request.responseParameters[0].size = 100000; - request.responseParameters[1] = new ResponseParameters(); - request.responseParameters[1].size = 100001; - final StreamingOutputCallResponse[] goldenResponses = new StreamingOutputCallResponse[2]; - goldenResponses[0] = new StreamingOutputCallResponse(); - goldenResponses[0].payload = new Payload(); - goldenResponses[0].payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponses[0].payload.body = new byte[100000]; - goldenResponses[1] = new StreamingOutputCallResponse(); - goldenResponses[1].payload = new Payload(); - goldenResponses[1].payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponses[1].payload.body = new byte[100001]; - - long start = System.nanoTime(); - - final ArrayBlockingQueue queue = new ArrayBlockingQueue(10); - ClientCall call = - channel.newCall(TestServiceGrpc.getStreamingOutputCallMethod(), CallOptions.DEFAULT); - call.start(new ClientCall.Listener() { - @Override - public void onHeaders(Metadata headers) {} - - @Override - public void onMessage(final StreamingOutputCallResponse message) { - queue.add(message); - } - - @Override - public void onClose(io.grpc.Status status, Metadata trailers) { - queue.add(status); - } - }, new Metadata()); - call.sendMessage(request); - call.halfClose(); - - // Time how long it takes to get the first response. - call.request(1); - assertMessageEquals(goldenResponses[0], - (StreamingOutputCallResponse) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - long firstCallDuration = System.nanoTime() - start; - - // Without giving additional flow control, make sure that we don't get another response. We wait - // until we are comfortable the next message isn't coming. We may have very low nanoTime - // resolution (like on Windows) or be using a testing, in-process transport where message - // handling is instantaneous. In both cases, firstCallDuration may be 0, so round up sleep time - // to at least 1ms. - assertNull(queue.poll(Math.max(firstCallDuration * 4, 1 * 1000 * 1000), TimeUnit.NANOSECONDS)); - - // Make sure that everything still completes. - call.request(1); - assertMessageEquals(goldenResponses[1], - (StreamingOutputCallResponse) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertCodeEquals(io.grpc.Status.OK, - (io.grpc.Status) queue.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - } - - public void veryLargeRequest() throws Exception { - if (shouldSkip()) { - return; - } - final SimpleRequest request = new SimpleRequest(); - request.payload = new Payload(); - request.payload.type = Messages.PayloadType.COMPRESSABLE; - request.payload.body = new byte[unaryPayloadLength()]; - request.responseSize = 10; - request.responseType = Messages.PayloadType.COMPRESSABLE; - final SimpleResponse goldenResponse = new SimpleResponse(); - goldenResponse.payload = new Payload(); - goldenResponse.payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponse.payload.body = new byte[10]; - - assertMessageEquals(goldenResponse, blockingStub.unaryCall(request)); - } - - public void veryLargeResponse() throws Exception { - if (shouldSkip()) { - return; - } - final SimpleRequest request = new SimpleRequest(); - request.responseSize = unaryPayloadLength(); - request.responseType = Messages.PayloadType.COMPRESSABLE; - - SimpleResponse resp = blockingStub.unaryCall(request); - final SimpleResponse goldenResponse = new SimpleResponse(); - goldenResponse.payload = new Payload(); - goldenResponse.payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponse.payload.body = new byte[unaryPayloadLength()]; - - assertMessageSizeEquals(goldenResponse, resp); - } - - public void deadlineNotExceeded() { - // warm up the channel and JVM - blockingStub.emptyCall(new EmptyProtos.Empty()); - StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseParameters = new ResponseParameters[1]; - request.responseParameters[0] = new ResponseParameters(); - request.responseParameters[0].intervalUs = 0; - TestServiceGrpc.newBlockingStub(channel) - .withDeadlineAfter(10, TimeUnit.SECONDS) - .streamingOutputCall(request); - } - - public void deadlineExceeded() { - // warm up the channel and JVM - blockingStub.emptyCall(new EmptyProtos.Empty()); - TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel) - .withDeadlineAfter(10, TimeUnit.MILLISECONDS); - StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseParameters = new ResponseParameters[1]; - request.responseParameters[0] = new ResponseParameters(); - request.responseParameters[0].intervalUs = 20000; - try { - stub.streamingOutputCall(request).next(); - fail("Expected deadline to be exceeded"); - } catch (StatusRuntimeException ex) { - assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, ex.getStatus()); - } - } - - public void deadlineExceededServerStreaming() throws Exception { - // warm up the channel and JVM - blockingStub.emptyCall(new EmptyProtos.Empty()); - ResponseParameters responseParameters = new ResponseParameters(); - responseParameters.size = 1; - responseParameters.intervalUs = 10000; - StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.responseType = Messages.PayloadType.COMPRESSABLE; - request.responseParameters = new ResponseParameters[4]; - request.responseParameters[0] = responseParameters; - request.responseParameters[1] = responseParameters; - request.responseParameters[2] = responseParameters; - request.responseParameters[3] = responseParameters; - StreamRecorder recorder = StreamRecorder.create(); - TestServiceGrpc.newStub(channel) - .withDeadlineAfter(30, TimeUnit.MILLISECONDS) - .streamingOutputCall(request, recorder); - assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, - io.grpc.Status.fromThrowable(recorder.getError())); - } - - protected int unaryPayloadLength() { - // 10MiB. - return 10485760; - } - - public void gracefulShutdown() throws Exception { - StreamingOutputCallRequest[] requests = new StreamingOutputCallRequest[3]; - requests[0] = new StreamingOutputCallRequest(); - requests[0].responseParameters = new ResponseParameters[1]; - requests[0].responseParameters[0] = new ResponseParameters(); - requests[0].responseParameters[0].size = 3; - requests[0].payload = new Payload(); - requests[0].payload.body = new byte[2]; - requests[1] = new StreamingOutputCallRequest(); - requests[1].responseParameters = new ResponseParameters[1]; - requests[1].responseParameters[0] = new ResponseParameters(); - requests[1].responseParameters[0].size = 1; - requests[1].payload = new Payload(); - requests[1].payload.body = new byte[7]; - requests[2] = new StreamingOutputCallRequest(); - requests[2].responseParameters = new ResponseParameters[1]; - requests[2].responseParameters[0] = new ResponseParameters(); - requests[2].responseParameters[0].size = 4; - requests[2].payload = new Payload(); - requests[2].payload.body = new byte[1]; - - StreamingOutputCallResponse[] goldenResponses = new StreamingOutputCallResponse[3]; - goldenResponses[0] = new StreamingOutputCallResponse(); - goldenResponses[0].payload = new Payload(); - goldenResponses[0].payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponses[0].payload.body = new byte[3]; - goldenResponses[1] = new StreamingOutputCallResponse(); - goldenResponses[1].payload = new Payload(); - goldenResponses[1].payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponses[1].payload.body = new byte[1]; - goldenResponses[2] = new StreamingOutputCallResponse(); - goldenResponses[2].payload = new Payload(); - goldenResponses[2].payload.type = Messages.PayloadType.COMPRESSABLE; - goldenResponses[2].payload.body = new byte[4]; - - - ResponseObserver responseObserver = new ResponseObserver(); - StreamObserver requestObserver - = asyncStub.fullDuplexCall(responseObserver); - requestObserver.onNext(requests[0]); - Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - assertTrue(response instanceof Messages.StreamingOutputCallResponse); - assertMessageEquals(goldenResponses[0], (Messages.StreamingOutputCallResponse) response); - // Initiate graceful shutdown. - channel.shutdown(); - // The previous ping-pong could have raced with the shutdown, but this one certainly shouldn't. - requestObserver.onNext(requests[1]); - response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - assertTrue(response instanceof Messages.StreamingOutputCallResponse); - assertMessageEquals(goldenResponses[1], (Messages.StreamingOutputCallResponse) response); - requestObserver.onNext(requests[2]); - response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - assertTrue(response instanceof Messages.StreamingOutputCallResponse); - assertMessageEquals(goldenResponses[2], (Messages.StreamingOutputCallResponse) response); - requestObserver.onCompleted(); - assertEquals(responseObserver.magicTailResponse, - responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - } - - /** Sends an rpc to an unimplemented method on the server. */ - public void unimplementedMethod() { - UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub = - UnimplementedServiceGrpc.newBlockingStub(channel); - try { - stub.unimplementedCall(new EmptyProtos.Empty()); - fail(); - } catch (StatusRuntimeException e) { - assertCodeEquals(io.grpc.Status.UNIMPLEMENTED, e.getStatus()); - } - } - - /** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */ - public void timeoutOnSleepingServer() throws Exception { - TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel) - .withDeadlineAfter(1, TimeUnit.MILLISECONDS); - StreamRecorder recorder = StreamRecorder.create(); - StreamObserver requestObserver - = stub.fullDuplexCall(recorder); - - try { - StreamingOutputCallRequest request = new StreamingOutputCallRequest(); - request.payload = new Messages.Payload(); - request.payload.body = new byte[27182]; - requestObserver.onNext(request); - } catch (IllegalStateException expected) { - // This can happen if the stream has already been terminated due to deadline exceeded. - } - - assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)); - assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, - io.grpc.Status.fromThrowable(recorder.getError())); - } - - public static void assertMessageSizeEquals(MessageNano expected, MessageNano actual) { - assertEquals(expected.getSerializedSize(), actual.getSerializedSize()); - } - - - private static void assertSuccess(StreamRecorder recorder) { - if (recorder.getError() != null) { - throw new AssertionError(recorder.getError()); - } - } - - public static void assertMessageEquals(MessageNano expected, MessageNano actual) { - if (!MessageNano.messageNanoEquals(expected, actual)) { - assertEquals(expected.toString(), actual.toString()); - fail("Messages not equal, but assertEquals didn't throw"); - } - } - - public static void assertMessageEquals(List expected, - List actual) { - if (expected == null || actual == null) { - assertEquals(expected, actual); - } else if (expected.size() != actual.size()) { - assertEquals(expected, actual); - } else { - for (int i = 0; i < expected.size(); i++) { - assertMessageEquals(expected.get(i), actual.get(i)); - } - } - } - - private static void assertCodeEquals(io.grpc.Status expected, io.grpc.Status actual) { - if (expected == null) { - fail("expected should not be null"); - } - if (actual == null || !expected.getCode().equals(actual.getCode())) { - assertEquals(expected, actual); - } - } - - public interface TestListener { - void onPreTest(); - - void onPostTest(String result); - } - - /** - * Some tests run on memory constrained environments. Rather than OOM, just give up. 64 is - * choosen as a maximum amount of memory a large test would need. - */ - private static boolean shouldSkip() { - Runtime r = Runtime.getRuntime(); - long usedMem = r.totalMemory() - r.freeMemory(); - long actuallyFreeMemory = r.maxMemory() - usedMem; - long wantedFreeMemory = 64 * 1024 * 1024; - if (actuallyFreeMemory < wantedFreeMemory) { - Log.i(LOG_TAG, "Skipping due to lack of memory. " - + "Have: " + actuallyFreeMemory + " Want: " + wantedFreeMemory); - return true; - } - return false; - } - - private static final class SafeMethodChannelInterceptor implements ClientInterceptor { - @Override - public ClientCall interceptCall( - MethodDescriptor method, CallOptions callOptions, Channel next) { - return new CheckedForwardingClientCall( - next.newCall(method.toBuilder().setSafe(true).build(), callOptions)) { - @Override - public void checkedStart(Listener responseListener, Metadata headers) { - delegate().start(responseListener, headers); - } - }; - } - } -} diff --git a/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/TesterActivity.java b/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/TesterActivity.java deleted file mode 100644 index be7774929fb..00000000000 --- a/android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/TesterActivity.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2015, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.android.integrationtest; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.TextView; -import com.google.android.gms.security.ProviderInstaller; -import java.util.LinkedList; -import java.util.List; - -public class TesterActivity extends AppCompatActivity - implements ProviderInstaller.ProviderInstallListener { - private List