-
Notifications
You must be signed in to change notification settings - Fork 8.6k
add socket.getPeerCertificate to KibanaRequest #42929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) > [getPeerCertificate](./kibana-plugin-server.ikibanasocket.getpeercertificate_1.md) | ||
|
|
||
| ## IKibanaSocket.getPeerCertificate() method | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| getPeerCertificate(detailed: true): DetailedPeerCertificate | null; | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --- | --- | --- | | ||
| | detailed | <code>true</code> | | | ||
|
|
||
| <b>Returns:</b> | ||
|
|
||
| `DetailedPeerCertificate | null` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) > [getPeerCertificate](./kibana-plugin-server.ikibanasocket.getpeercertificate_2.md) | ||
|
|
||
| ## IKibanaSocket.getPeerCertificate() method | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| getPeerCertificate(detailed: false): PeerCertificate | null; | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --- | --- | --- | | ||
| | detailed | <code>false</code> | | | ||
|
|
||
| <b>Returns:</b> | ||
|
|
||
| `PeerCertificate | null` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) > [getPeerCertificate](./kibana-plugin-server.ikibanasocket.getpeercertificate_3.md) | ||
|
|
||
| ## IKibanaSocket.getPeerCertificate() method | ||
|
|
||
| Returns an object representing the peer's certificate. The returned object has some properties corresponding to the field of the certificate. If detailed argument is true the full chain with issuer property will be returned, if false only the top certificate without issuer property. If the peer does not provide a certificate, it returns null. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --- | --- | --- | | ||
| | detailed | <code>boolean</code> | If true; the full chain with issuer property will be returned. | | ||
|
|
||
| <b>Returns:</b> | ||
|
|
||
| `PeerCertificate | DetailedPeerCertificate | null` | ||
|
|
||
| An object representing the peer's certificate. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) | ||
|
|
||
| ## IKibanaSocket interface | ||
|
|
||
| A tiny abstraction for TCP socket. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| export interface IKibanaSocket | ||
| ``` | ||
|
|
||
| ## Methods | ||
|
|
||
| | Method | Description | | ||
| | --- | --- | | ||
| | [getPeerCertificate(detailed)](./kibana-plugin-server.ikibanasocket.getpeercertificate_1.md) | | | ||
| | [getPeerCertificate(detailed)](./kibana-plugin-server.ikibanasocket.getpeercertificate_2.md) | | | ||
| | [getPeerCertificate(detailed)](./kibana-plugin-server.ikibanasocket.getpeercertificate_3.md) | Returns an object representing the peer's certificate. The returned object has some properties corresponding to the field of the certificate. If detailed argument is true the full chain with issuer property will be returned, if false only the top certificate without issuer property. If the peer does not provide a certificate, it returns null. | | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [KibanaRequest](./kibana-plugin-server.kibanarequest.md) > [socket](./kibana-plugin-server.kibanarequest.socket.md) | ||
|
|
||
| ## KibanaRequest.socket property | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| readonly socket: IKibanaSocket; | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you 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. | ||
| */ | ||
| import { Socket } from 'net'; | ||
| import { DetailedPeerCertificate, TLSSocket } from 'tls'; | ||
| import { KibanaSocket } from './socket'; | ||
|
|
||
| describe('KibanaSocket', () => { | ||
| describe('getPeerCertificate', () => { | ||
| it('returns null for net.Socket instance', () => { | ||
| const socket = new KibanaSocket(new Socket()); | ||
|
|
||
| expect(socket.getPeerCertificate()).toBe(null); | ||
| }); | ||
|
|
||
| it('delegates a call to tls.Socket instance', () => { | ||
| const tlsSocket = new TLSSocket(new Socket()); | ||
| const cert = { issuerCertificate: {} } as DetailedPeerCertificate; | ||
| const spy = jest.spyOn(tlsSocket, 'getPeerCertificate').mockImplementation(() => cert); | ||
| const socket = new KibanaSocket(tlsSocket); | ||
| const result = socket.getPeerCertificate(true); | ||
|
|
||
| expect(spy).toBeCalledTimes(1); | ||
| expect(spy).toBeCalledWith(true); | ||
| expect(result).toBe(cert); | ||
| }); | ||
|
|
||
| it('returns null if tls.Socket getPeerCertificate returns null', () => { | ||
| const tlsSocket = new TLSSocket(new Socket()); | ||
| jest.spyOn(tlsSocket, 'getPeerCertificate').mockImplementation(() => null as any); | ||
| const socket = new KibanaSocket(tlsSocket); | ||
|
|
||
| expect(socket.getPeerCertificate()).toBe(null); | ||
| }); | ||
|
|
||
| it('returns null if tls.Socket getPeerCertificate returns empty object', () => { | ||
| const tlsSocket = new TLSSocket(new Socket()); | ||
| jest.spyOn(tlsSocket, 'getPeerCertificate').mockImplementation(() => ({} as any)); | ||
| const socket = new KibanaSocket(tlsSocket); | ||
|
|
||
| expect(socket.getPeerCertificate()).toBe(null); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you 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. | ||
| */ | ||
|
|
||
| import { Socket } from 'net'; | ||
| import { DetailedPeerCertificate, PeerCertificate, TLSSocket } from 'tls'; | ||
|
|
||
| /** | ||
| * A tiny abstraction for TCP socket. | ||
| * @public | ||
| */ | ||
| export interface IKibanaSocket { | ||
| getPeerCertificate(detailed: true): DetailedPeerCertificate | null; | ||
| getPeerCertificate(detailed: false): PeerCertificate | null; | ||
| /** | ||
| * Returns an object representing the peer's certificate. | ||
| * The returned object has some properties corresponding to the field of the certificate. | ||
| * If detailed argument is true the full chain with issuer property will be returned, | ||
| * if false only the top certificate without issuer property. | ||
| * If the peer does not provide a certificate, it returns null. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it can also be |
||
| * @param detailed - If true; the full chain with issuer property will be returned. | ||
| * @returns An object representing the peer's certificate. | ||
| */ | ||
| getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; | ||
| } | ||
|
|
||
| export class KibanaSocket implements IKibanaSocket { | ||
| constructor(private readonly socket: Socket) {} | ||
|
|
||
| getPeerCertificate(detailed: true): DetailedPeerCertificate | null; | ||
| getPeerCertificate(detailed: false): PeerCertificate | null; | ||
| getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; | ||
|
|
||
| public getPeerCertificate(detailed?: boolean) { | ||
| if (this.socket instanceof TLSSocket) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: PKI authentication provider will consume certificate chain returned from this method, but it works on the assumption that So everything is fine right now, but in case we decide to expose /cc @kobelb |
||
| const peerCertificate = this.socket.getPeerCertificate(detailed); | ||
|
|
||
| // If the peer does not provide a certificate, it returns null (if the socket has been destroyed) | ||
| // or an empty object, so we should check for both these cases. | ||
| if (peerCertificate && Object.keys(peerCertificate).length > 0) return peerCertificate; | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,12 @@ | |
| import Boom from 'boom'; | ||
| import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; | ||
| import { ConfigOptions } from 'elasticsearch'; | ||
| import { DetailedPeerCertificate } from 'tls'; | ||
| import { Duration } from 'moment'; | ||
| import { IncomingHttpHeaders } from 'http'; | ||
| import { ObjectType } from '@kbn/config-schema'; | ||
| import { Observable } from 'rxjs'; | ||
| import { PeerCertificate } from 'tls'; | ||
| import { Readable } from 'stream'; | ||
| import { Request } from 'hapi'; | ||
| import { ResponseObject } from 'hapi'; | ||
|
|
@@ -246,6 +248,15 @@ export interface HttpServiceStart { | |
| isListening: (port: number) => boolean; | ||
| } | ||
|
|
||
| // @public | ||
| export interface IKibanaSocket { | ||
| // (undocumented) | ||
| getPeerCertificate(detailed: true): DetailedPeerCertificate | null; | ||
| // (undocumented) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect api-extractor to merge all overloads in the one file.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's kinda strange. You might be able to use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, neither
seems the problem is not solved yet microsoft/rushstack#881 |
||
| getPeerCertificate(detailed: false): PeerCertificate | null; | ||
| getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; | ||
| } | ||
|
|
||
| // @internal (undocumented) | ||
| export interface InternalCoreSetup { | ||
| // (undocumented) | ||
|
|
@@ -282,6 +293,8 @@ export class KibanaRequest<Params = unknown, Query = unknown, Body = unknown> { | |
| // (undocumented) | ||
| readonly query: Query; | ||
| readonly route: RecursiveReadonly<KibanaRequestRoute>; | ||
| // (undocumented) | ||
| readonly socket: IKibanaSocket; | ||
| readonly url: Url; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.