MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / handshake

Method handshake

modules/crypt/ssl/session_419.js:94–191  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

92 this.handshakeProcess = handshakeProtocol.helloRequest.msgType;
93 }
94 handshake(s) {
95 let state = 0;
96 switch (this.handshakeProcess) {
97 case handshakeProtocol.helloRequest.msgType: { // C
98 let cache = this.cacheManager && this.cacheManager.getByHost(this.options.tls_server_name);
99 if (cache) {
100 this.clientSessionID = cache.id;
101 this.masterSecret = cache.secret;
102 }
103 this.doProtocol(s, handshakeProtocol.clientHello);
104 } break;
105 case handshakeProtocol.clientHello.msgType: { // S
106 let masterSecret = this.clientSessionID && this.cacheManager && this.cacheManager.getByID(this.clientSessionID);
107 if (masterSecret) {
108 // resumed handshake
109 this.serverSessionID = this.clientSessionID;
110 this.masterSecret = masterSecret;
111 this.doProtocol(s, handshakeProtocol.serverHello);
112 this.doProtocol(s, changeCipherSpec);
113 this.doProtocol(s, handshakeProtocol.finished);
114 }
115 else {
116 // assign a new one
117 this.serverSessionID = ArrayBuffer.fromBigInt(BigInt(((new Date()).valueOf()).toString()));
118 this.doProtocol(s, handshakeProtocol.serverHello);
119 // S -> C: Certificate (always -- i.e. not support anonymous auth.)
120 let certs = this.certificateManager.getCerts();
121 if (!certs || !certs.length)
122 throw new TLSError("client_hello: no certificate");
123 this.doProtocol(s, handshakeProtocol.certificate, certs);
124 // S -> C: ServerKeyExchange (may not do anything depending on the chosen cipher)
125 this.doProtocol(s, handshakeProtocol.serverKeyExchange);
126 if (this.options.clientAuth)
127 // S -> C: CertificateRequest
128 this.doProtocol(s, handshakeProtocol.certificateRequest, this.options.clientAuth.cipherSuites, this.options.clientAuth.subjectDN);
129 // S -> C: ServerHelloDone
130 this.doProtocol(s, handshakeProtocol.serverHelloDone);
131 }
132 } break;
133 case handshakeProtocol.serverHelloDone.msgType: // C
134 if (this.clientCerts !== undefined)
135 this.doProtocol(s, handshakeProtocol.certificate, this.clientCerts);
136 this.doProtocol(s, handshakeProtocol.clientKeyExchange);
137 if (this.myCert) // client cert request && and the certs is not empty
138 this.doProtocol(s, handshakeProtocol.certificateVerify, this.myCert);
139 this.doProtocol(s, changeCipherSpec);
140 this.doProtocol(s, handshakeProtocol.finished);
141 break;
142 case handshakeProtocol.finished.msgType: { // C, S
143 let resumed = this.clientSessionID && Bin.comp(this.clientSessionID, this.serverSessionID) == 0;
144 if (!(this.connectionEnd ^ resumed)) {
145 this.doProtocol(s, changeCipherSpec);
146 this.doProtocol(s, handshakeProtocol.finished);
147 }
148 state = 2;
149 if (this.cacheManager) {
150 if (this.serverSessionID && this.options.tls_server_name)
151 this.cacheManager.saveSession(this.options.tls_server_name, this.serverSessionID, this.masterSecret);

Callers 2

messageHandlerMethod · 0.45
#messageHandlerMethod · 0.45

Calls 7

doProtocolMethod · 0.95
readPacketMethod · 0.95
startTraceMethod · 0.95
stopTraceMethod · 0.95
fromBigIntMethod · 0.80
getCertsMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected