Skip to content

Commit

Permalink
gate auth context under _secure (#622)
Browse files Browse the repository at this point in the history
* gate auth context under _secure

Signed-off-by: tabokie <[email protected]>

* try fix windows action

Signed-off-by: tabokie <[email protected]>

* rearrange

Signed-off-by: tabokie <[email protected]>

* reproduce error

Signed-off-by: tabokie <[email protected]>

* update

Signed-off-by: tabokie <[email protected]>

* avoid --all

Signed-off-by: tabokie <[email protected]>

* update

Signed-off-by: tabokie <[email protected]>

---------

Signed-off-by: tabokie <[email protected]>
  • Loading branch information
tabokie authored Jul 27, 2023
1 parent e61834c commit 5f62bad
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ no-omit-frame-pointer = ["grpcio-sys/no-omit-frame-pointer"]
travis-ci = { repository = "tikv/grpc-rs" }

[patch.crates-io]
grpcio-compiler = { path = "compiler", version = "0.12.1", default-features = false }
grpcio-compiler = { path = "compiler", version = "0.12.1" }
9 changes: 5 additions & 4 deletions src/call/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use futures_util::{Sink, Stream};
use parking_lot::Mutex;

use super::{RpcStatus, ShareCall, ShareCallHolder, WriteFlags};
use crate::auth_context::AuthContext;
use crate::buf::GrpcSlice;
use crate::call::{
BatchContext, Call, MessageReader, MethodType, RpcStatusCode, SinkBase, StreamingBase,
Expand Down Expand Up @@ -193,10 +192,11 @@ impl RequestContext {
}

/// If the server binds in non-secure mode, this will return None
fn auth_context(&self) -> Option<AuthContext> {
#[cfg(feature = "_secure")]
fn auth_context(&self) -> Option<crate::AuthContext> {
unsafe {
let call = grpc_sys::grpcwrap_request_call_context_get_call(self.ctx);
AuthContext::from_call_ptr(call)
crate::AuthContext::from_call_ptr(call)
}
}
}
Expand Down Expand Up @@ -690,7 +690,8 @@ impl<'a> RpcContext<'a> {
/// Wrapper around the gRPC Core AuthContext
///
/// If the server binds in non-secure mode, this will return None
pub fn auth_context(&self) -> Option<AuthContext> {
#[cfg(feature = "_secure")]
pub fn auth_context(&self) -> Option<crate::AuthContext> {
self.ctx.auth_context()
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use grpcio_sys as grpc_sys;
#[macro_use]
extern crate log;

mod auth_context;
mod buf;
mod call;
mod channel;
Expand Down Expand Up @@ -68,7 +67,6 @@ pub use crate::codec::pb_codec::{de as pb_de, ser as pb_ser};
#[cfg(feature = "prost-codec")]
pub use crate::codec::pr_codec::{de as pr_de, ser as pr_ser};

pub use crate::auth_context::{AuthContext, AuthProperty, AuthPropertyIter};
pub use crate::codec::{Marshaller, MAX_MESSAGE_SIZE};
pub use crate::env::{EnvBuilder, Environment};
pub use crate::error::{Error, Result};
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/security/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

#[cfg(feature = "_secure")]
mod auth_context;
#[cfg(feature = "_secure")]
mod credentials;

use grpcio_sys::{grpc_channel_credentials, grpc_server_credentials};

#[cfg(feature = "_secure")]
pub use self::auth_context::*;
#[cfg(feature = "_secure")]
pub use self::credentials::{
CertificateRequestType, ChannelCredentialsBuilder, ServerCredentialsBuilder,
Expand Down Expand Up @@ -59,6 +63,7 @@ impl ServerCredentials {
ServerCredentials::from_raw(creds)
}
}

pub(crate) unsafe fn from_raw(creds: *mut grpc_server_credentials) -> ServerCredentials {
ServerCredentials {
creds,
Expand Down

0 comments on commit 5f62bad

Please sign in to comment.