UNPKG

3.21 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ConnectionOptions } from 'tls';
3import { CallCredentials } from './call-credentials';
4/**
5 * A certificate as received by the checkServerIdentity callback.
6 */
7export interface Certificate {
8 /**
9 * The raw certificate in DER form.
10 */
11 raw: Buffer;
12}
13/**
14 * A callback that will receive the expected hostname and presented peer
15 * certificate as parameters. The callback should return an error to
16 * indicate that the presented certificate is considered invalid and
17 * otherwise returned undefined.
18 */
19export declare type CheckServerIdentityCallback = (hostname: string, cert: Certificate) => Error | undefined;
20/**
21 * Additional peer verification options that can be set when creating
22 * SSL credentials.
23 */
24export interface VerifyOptions {
25 /**
26 * If set, this callback will be invoked after the usual hostname verification
27 * has been performed on the peer certificate.
28 */
29 checkServerIdentity?: CheckServerIdentityCallback;
30}
31/**
32 * A class that contains credentials for communicating over a channel, as well
33 * as a set of per-call credentials, which are applied to every method call made
34 * over a channel initialized with an instance of this class.
35 */
36export declare abstract class ChannelCredentials {
37 protected callCredentials: CallCredentials;
38 protected constructor(callCredentials?: CallCredentials);
39 /**
40 * Returns a copy of this object with the included set of per-call credentials
41 * expanded to include callCredentials.
42 * @param callCredentials A CallCredentials object to associate with this
43 * instance.
44 */
45 abstract compose(callCredentials: CallCredentials): ChannelCredentials;
46 /**
47 * Gets the set of per-call credentials associated with this instance.
48 */
49 _getCallCredentials(): CallCredentials;
50 /**
51 * Gets a SecureContext object generated from input parameters if this
52 * instance was created with createSsl, or null if this instance was created
53 * with createInsecure.
54 */
55 abstract _getConnectionOptions(): ConnectionOptions | null;
56 /**
57 * Indicates whether this credentials object creates a secure channel.
58 */
59 abstract _isSecure(): boolean;
60 /**
61 * Check whether two channel credentials objects are equal. Two secure
62 * credentials are equal if they were constructed with the same parameters.
63 * @param other The other ChannelCredentials Object
64 */
65 abstract _equals(other: ChannelCredentials): boolean;
66 /**
67 * Return a new ChannelCredentials instance with a given set of credentials.
68 * The resulting instance can be used to construct a Channel that communicates
69 * over TLS.
70 * @param rootCerts The root certificate data.
71 * @param privateKey The client certificate private key, if available.
72 * @param certChain The client certificate key chain, if available.
73 */
74 static createSsl(rootCerts?: Buffer | null, privateKey?: Buffer | null, certChain?: Buffer | null, verifyOptions?: VerifyOptions): ChannelCredentials;
75 /**
76 * Return a new ChannelCredentials instance with no credentials.
77 */
78 static createInsecure(): ChannelCredentials;
79}