简体   繁体   中英

Cordova WebSocket with client side certificates (Javascript)

I'd like to create a secure Connection (SSL/TLS) between my client and my server. Only a specific client is authorised to connect to the server. Therefore, I created on the server a client certificate (openssl) to provided mutual authorization. On the serverside I already set up my WebSocketServer using require(ws)(Node.js) using the created server certs. On the clientside I don't how the standard WebSocket API is providing me a way to attach my client certs. Can anyone tell me how to create a client WebSocket passing certs to the server ?

I am developing in Cordova using Javascript.

The basic clientside API seems to be limited to this: https://www.w3.org/TR/websockets/

Interface:

interface WebSocket extends EventTarget {
binaryType: string;
readonly bufferedAmount: number;
readonly extensions: string;
onclose: (this: WebSocket, ev: CloseEvent) => any;
onerror: (this: WebSocket, ev: Event) => any;
onmessage: (this: WebSocket, ev: MessageEvent) => any;
onopen: (this: WebSocket, ev: Event) => any;
readonly protocol: string;
readonly readyState: number;
readonly url: string;
close(code?: number, reason?: string): void;
send(data: any): void;
readonly CLOSED: number;
readonly CLOSING: number;
readonly CONNECTING: number;
readonly OPEN: number;
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, useCapture?: boolean): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;}

Class:

declare var WebSocket: {
prototype: WebSocket;
new(url: string, protocols?: string | string[]): WebSocket;
readonly CLOSED: number;
readonly CLOSING: number;
readonly CONNECTING: number;
readonly OPEN: number;}

Thanks in advance.

I am closing this issue now.

Possible solution to my question I found finally was this plugin: https://github.com/flynetworks/cordova-websocket-clientcert Using the pkcs12 archive.

I am not happy with this solution and will change the client authentication from TLS client certificates to simple HTTP authentication.

See possibilites for authentication with WebSockets here: https://tools.ietf.org/html/rfc6455#section-10.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM