UNPKG

5.09 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { ConnectionOptions, PeerCertificate, SecureContext } from 'tls';
4import { CallCredentials } from './call-credentials';
5import { CertificateProvider } from './certificate-provider';
6/**
7 * A callback that will receive the expected hostname and presented peer
8 * certificate as parameters. The callback should return an error to
9 * indicate that the presented certificate is considered invalid and
10 * otherwise returned undefined.
11 */
12export type CheckServerIdentityCallback = (hostname: string, cert: PeerCertificate) => Error | undefined;
13/**
14 * Additional peer verification options that can be set when creating
15 * SSL credentials.
16 */
17export interface VerifyOptions {
18 /**
19 * If set, this callback will be invoked after the usual hostname verification
20 * has been performed on the peer certificate.
21 */
22 checkServerIdentity?: CheckServerIdentityCallback;
23 rejectUnauthorized?: boolean;
24}
25/**
26 * A class that contains credentials for communicating over a channel, as well
27 * as a set of per-call credentials, which are applied to every method call made
28 * over a channel initialized with an instance of this class.
29 */
30export declare abstract class ChannelCredentials {
31 protected callCredentials: CallCredentials;
32 protected constructor(callCredentials?: CallCredentials);
33 /**
34 * Returns a copy of this object with the included set of per-call credentials
35 * expanded to include callCredentials.
36 * @param callCredentials A CallCredentials object to associate with this
37 * instance.
38 */
39 abstract compose(callCredentials: CallCredentials): ChannelCredentials;
40 /**
41 * Gets the set of per-call credentials associated with this instance.
42 */
43 _getCallCredentials(): CallCredentials;
44 /**
45 * Gets a SecureContext object generated from input parameters if this
46 * instance was created with createSsl, or null if this instance was created
47 * with createInsecure.
48 */
49 abstract _getConnectionOptions(): ConnectionOptions | null;
50 /**
51 * Indicates whether this credentials object creates a secure channel.
52 */
53 abstract _isSecure(): boolean;
54 /**
55 * Check whether two channel credentials objects are equal. Two secure
56 * credentials are equal if they were constructed with the same parameters.
57 * @param other The other ChannelCredentials Object
58 */
59 abstract _equals(other: ChannelCredentials): boolean;
60 _ref(): void;
61 _unref(): void;
62 /**
63 * Return a new ChannelCredentials instance with a given set of credentials.
64 * The resulting instance can be used to construct a Channel that communicates
65 * over TLS.
66 * @param rootCerts The root certificate data.
67 * @param privateKey The client certificate private key, if available.
68 * @param certChain The client certificate key chain, if available.
69 * @param verifyOptions Additional options to modify certificate verification
70 */
71 static createSsl(rootCerts?: Buffer | null, privateKey?: Buffer | null, certChain?: Buffer | null, verifyOptions?: VerifyOptions): ChannelCredentials;
72 /**
73 * Return a new ChannelCredentials instance with credentials created using
74 * the provided secureContext. The resulting instances can be used to
75 * construct a Channel that communicates over TLS. gRPC will not override
76 * anything in the provided secureContext, so the environment variables
77 * GRPC_SSL_CIPHER_SUITES and GRPC_DEFAULT_SSL_ROOTS_FILE_PATH will
78 * not be applied.
79 * @param secureContext The return value of tls.createSecureContext()
80 * @param verifyOptions Additional options to modify certificate verification
81 */
82 static createFromSecureContext(secureContext: SecureContext, verifyOptions?: VerifyOptions): ChannelCredentials;
83 /**
84 * Return a new ChannelCredentials instance with no credentials.
85 */
86 static createInsecure(): ChannelCredentials;
87}
88declare class CertificateProviderChannelCredentialsImpl extends ChannelCredentials {
89 private caCertificateProvider;
90 private identityCertificateProvider;
91 private verifyOptions;
92 private refcount;
93 private latestCaUpdate;
94 private latestIdentityUpdate;
95 private caCertificateUpdateListener;
96 private identityCertificateUpdateListener;
97 constructor(caCertificateProvider: CertificateProvider, identityCertificateProvider: CertificateProvider | null, verifyOptions: VerifyOptions | null);
98 compose(callCredentials: CallCredentials): ChannelCredentials;
99 _getConnectionOptions(): ConnectionOptions | null;
100 _isSecure(): boolean;
101 _equals(other: ChannelCredentials): boolean;
102 _ref(): void;
103 _unref(): void;
104 private handleCaCertificateUpdate;
105 private handleIdentityCertitificateUpdate;
106}
107export declare function createCertificateProviderChannelCredentials(caCertificateProvider: CertificateProvider, identityCertificateProvider: CertificateProvider | null, verifyOptions?: VerifyOptions): CertificateProviderChannelCredentialsImpl;
108export {};