Object built-in object

Object SslSocket

ssl Network socket object

SslSocket belongs to ssl Module, creation method

1
var s = new ssl.Socket();

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>Stream|fd|read();write();flush();close();copyTo()] [<this>SslSocket|new SslSocket()|verification;ca;peerCert;hostname;stream|connect();accept()] [object] <:- [Stream] [Stream] <:- [SslSocket] SslSocket new SslSocket() verification ca peerCert hostname stream connect() accept() Stream fd read() write() flush() close() copyTo() object toString() toJSON()

Constructor

SslSocket

SslSocket constructor to create a new SslSocket object

1
new SslSocket(Array certs = []);

Call parameters:

  • certs: Array, server certificate list

The format of certs is:

1 2 3 4 5 6 7 8 9 10 11
[{ name: "fibjs.org", crt: [X509Cert object], key: [PKey object] }, { name: "*.fibjs.org", crt: [X509Cert object], key: [PKey object] } ]

SslSocket constructor to create a new SslSocket object

1 2
new SslSocket(X509Cert crt, PKey key);

Call parameters:

  • crt: X509Cert, X509Cert Certificate for client authentication server
  • key: PKey, PKey Private key, used to talk to the client

Member attributes

verification

Integer, set the certificate verification mode, the default is VERIFY_REQUIRED

1
Integer SslSocket.verification;

ca

X509Cert, Certificate chain, automatically referenced when connect in client mode ssl.ca, Server mode accept generates SslSocket and automatically references the current SslSocket ca

1
readonly X509Cert SslSocket.ca;

peerCert

X509Cert, Connect to the other party's certificate

1
readonly X509Cert SslSocket.peerCert;

hostname

String, the host name of the connection

1
readonly String SslSocket.hostname;

stream

Stream, Query message ssl The lower stream object at the time of establishment

1
readonly Stream SslSocket.stream;

fd

Integer, query Stream The corresponding file descriptor value, implemented by the subclass

1
readonly Integer SslSocket.fd;

Member function

connect

Connect on the given connection ssl Connection, client mode

1 2
Integer SslSocket.connect(Stream s, String server_name = "") async;

Call parameters:

  • s: Stream, The given underlying connection
  • server_name: String, specify the server name, can be the default

Return result:

  • Integer, If the connection is successful, return 0. When the certificate is optional, it will return non-zero if the verification is unsuccessful. For details, see ssl Module

accept

Receive one on the given connection ssl Connect and generate a new SslSocket

1
SslSocket SslSocket.accept(Stream s) async;

Call parameters:

  • s: Stream, The given underlying connection

Return result:

  • SslSocket, Return the newly created SslSocket object

read

Read data of the specified size from the stream

1
Buffer SslSocket.read(Integer bytes = -1) async;

Call parameters:

  • bytes: Integer, specify the amount of data to be read, the default is to read a random size data block, the size of the data read depends on the device

Return result:

  • Buffer, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null

write

Write the given data to the stream

1
SslSocket.write(Buffer data) async;

Call parameters:

  • data: Buffer, Given the data to be written

flush

Write the contents of the file buffer to the physical device

1
SslSocket.flush() async;

close

Close the current stream object

1
SslSocket.close() async;

copyTo

Copy the stream data to the target stream

1 2
Long SslSocket.copyTo(Stream stm, Long bytes = -1) async;

Call parameters:

  • stm: Stream, The target stream object
  • bytes: Long, the number of bytes copied

Return result:

  • Long, Returns the number of bytes copied

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String SslSocket.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value SslSocket.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable