alts: add call credential security level attribute (#4657)

This commit is contained in:
Jiangtao Li 2018-07-19 10:55:22 -07:00 committed by GitHub
parent 603d858186
commit 499f95d3ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -20,7 +20,9 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.protobuf.Any; import com.google.protobuf.Any;
import io.grpc.Attributes; import io.grpc.Attributes;
import io.grpc.CallCredentials;
import io.grpc.Grpc; import io.grpc.Grpc;
import io.grpc.SecurityLevel;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult; import io.grpc.alts.internal.RpcProtocolVersionsUtil.RpcVersionsCheckResult;
import io.grpc.alts.internal.TsiHandshakeHandler.TsiHandshakeCompletionEvent; import io.grpc.alts.internal.TsiHandshakeHandler.TsiHandshakeCompletionEvent;
@ -122,6 +124,7 @@ public abstract class AltsProtocolNegotiator implements ProtocolNegotiator {
.set(TSI_PEER_KEY, altsEvt.peer()) .set(TSI_PEER_KEY, altsEvt.peer())
.set(ALTS_CONTEXT_KEY, altsContext) .set(ALTS_CONTEXT_KEY, altsContext)
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress()) .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
.set(CallCredentials.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)
.build(), .build(),
new Security(new OtherSecurity("alts", Any.pack(altsContext.context)))); new Security(new OtherSecurity("alts", Any.pack(altsContext.context))));
} }

View File

@ -24,7 +24,9 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import io.grpc.Attributes; import io.grpc.Attributes;
import io.grpc.CallCredentials;
import io.grpc.Grpc; import io.grpc.Grpc;
import io.grpc.SecurityLevel;
import io.grpc.alts.internal.Handshaker.HandshakerResult; import io.grpc.alts.internal.Handshaker.HandshakerResult;
import io.grpc.alts.internal.TsiFrameProtector.Consumer; import io.grpc.alts.internal.TsiFrameProtector.Consumer;
import io.grpc.alts.internal.TsiPeer.Property; import io.grpc.alts.internal.TsiPeer.Property;
@ -343,6 +345,8 @@ public class AltsProtocolNegotiatorTest {
.isEqualTo(mockedAltsContext); .isEqualTo(mockedAltsContext);
assertThat(grpcHandler.attrs.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString()) assertThat(grpcHandler.attrs.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString())
.isEqualTo("embedded"); .isEqualTo("embedded");
assertThat(grpcHandler.attrs.get(CallCredentials.ATTR_SECURITY_LEVEL))
.isEqualTo(SecurityLevel.PRIVACY_AND_INTEGRITY);
} }
private void doHandshake() throws Exception { private void doHandshake() throws Exception {