chromium/third_party/grpc/src/src/core/lib/security/credentials/credentials.h

//
//
// Copyright 2015 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.
//
//

#ifndef GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H
#define GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H

#include <grpc/support/port_platform.h>

#include <string>
#include <utility>
#include <vector>

#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"

#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/support/log.h>

#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/unique_type_name.h"
#include "src/core/lib/promise/arena_promise.h"
#include "src/core/lib/security/security_connector/security_connector.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/transport.h"

// --- Constants. ---

grpc_credentials_status;

#define GRPC_FAKE_TRANSPORT_SECURITY_TYPE

#define GRPC_AUTHORIZATION_METADATA_KEY
#define GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY
#define GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY

#define GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS

#define GRPC_COMPUTE_ENGINE_METADATA_HOST
#define GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH

#define GRPC_GOOGLE_OAUTH2_SERVICE_HOST
#define GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH

#define GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX

#define GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING

// --- Google utils ---

// It is the caller's responsibility to gpr_free the result if not NULL.
std::string grpc_get_well_known_google_credentials_file_path(void);

// Implementation function for the different platforms.
std::string grpc_get_well_known_google_credentials_file_path_impl(void);

// Override for testing only. Not thread-safe
grpc_well_known_credentials_path_getter;
void grpc_override_well_known_credentials_path_getter(
    grpc_well_known_credentials_path_getter getter);

// --- grpc_channel_credentials. ---

#define GRPC_ARG_CHANNEL_CREDENTIALS

// This type is forward declared as a C struct and we cannot define it as a
// class. Otherwise, compiler will complain about type mismatch due to
// -Wmismatched-tags.
struct grpc_channel_credentials
    : grpc_core::RefCounted<grpc_channel_credentials> {};

// TODO(roth): Once we eliminate insecure builds, find a better way to
// plumb credentials so that it doesn't need to flow through channel
// args.  For example, we'll want to expose it to LB policies by adding
// methods on the helper API.

// Util to encapsulate the channel credentials in a channel arg.
grpc_arg grpc_channel_credentials_to_arg(grpc_channel_credentials* credentials);

// Util to get the channel credentials from a channel arg.
grpc_channel_credentials* grpc_channel_credentials_from_arg(
    const grpc_arg* arg);

// Util to find the channel credentials from channel args.
grpc_channel_credentials* grpc_channel_credentials_find_in_args(
    const grpc_channel_args* args);

// --- grpc_core::CredentialsMetadataArray. ---

namespace grpc_core {
CredentialsMetadataArray;
}

// --- grpc_call_credentials. ---

// This type is forward declared as a C struct and we cannot define it as a
// class. Otherwise, compiler will complain about type mismatch due to
// -Wmismatched-tags.
struct grpc_call_credentials
    : public grpc_core::RefCounted<grpc_call_credentials> {};

// Metadata-only credentials with the specified key and value where
// asynchronicity can be simulated for testing.
grpc_call_credentials* grpc_md_only_test_credentials_create(
    const char* md_key, const char* md_value);

// --- grpc_server_credentials. ---

#define GRPC_SERVER_CREDENTIALS_ARG

// This type is forward declared as a C struct and we cannot define it as a
// class. Otherwise, compiler will complain about type mismatch due to
// -Wmismatched-tags.
struct grpc_server_credentials
    : public grpc_core::RefCounted<grpc_server_credentials> {};

grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* c);
grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg);
grpc_server_credentials* grpc_find_server_credentials_in_args(
    const grpc_channel_args* args);

#endif  // GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H