(s)
| 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); |
no test coverage detected