-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add socket.getPeerCertificate to KibanaRequest * update request mocks * update docs
- Loading branch information
Showing
15 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...elopment/core/server/kibana-plugin-server.ikibanasocket.getpeercertificate_1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
22 changes: 22 additions & 0 deletions
22
...elopment/core/server/kibana-plugin-server.ikibanasocket.getpeercertificate_2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
26 changes: 26 additions & 0 deletions
26
...elopment/core/server/kibana-plugin-server.ikibanasocket.getpeercertificate_3.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
22 changes: 22 additions & 0 deletions
22
docs/development/core/server/kibana-plugin-server.ikibanasocket.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
docs/development/core/server/kibana-plugin-server.kibanarequest.socket.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* @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) { | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters