How to use Len method of session Package

Best Selenoid code snippet using session.Len

handshake_messages.go

Source:handshake_messages.go Github

copy

Full Screen

...48 return m.raw49 }50 length := 2 + 32 + 1 + len(m.sessionId) + 2 + len(m.cipherSuites)*2 + 1 + len(m.compressionMethods)51 numExtensions := 052 extensionsLength := 053 if m.nextProtoNeg {54 numExtensions++55 }56 if m.ocspStapling {57 extensionsLength += 1 + 2 + 258 numExtensions++59 }60 if len(m.serverName) > 0 {61 extensionsLength += 5 + len(m.serverName)62 numExtensions++63 }64 if len(m.supportedCurves) > 0 {65 extensionsLength += 2 + 2*len(m.supportedCurves)66 numExtensions++67 }68 if len(m.supportedPoints) > 0 {69 extensionsLength += 1 + len(m.supportedPoints)70 numExtensions++71 }72 if m.ticketSupported {73 extensionsLength += len(m.sessionTicket)74 numExtensions++75 }76 if len(m.signatureAndHashes) > 0 {77 extensionsLength += 2 + 2*len(m.signatureAndHashes)78 numExtensions++79 }80 if m.secureRenegotiation {81 extensionsLength += 182 numExtensions++83 }84 if len(m.alpnProtocols) > 0 {85 extensionsLength += 286 for _, s := range m.alpnProtocols {87 if l := len(s); l == 0 || l > 255 {88 panic("invalid ALPN protocol")89 }90 extensionsLength++91 extensionsLength += len(s)92 }93 numExtensions++94 }95 if numExtensions > 0 {96 extensionsLength += 4 * numExtensions97 length += 2 + extensionsLength98 }99 x := make([]byte, 4+length)100 x[0] = typeClientHello101 x[1] = uint8(length >> 16)102 x[2] = uint8(length >> 8)103 x[3] = uint8(length)104 x[4] = uint8(m.vers >> 8)105 x[5] = uint8(m.vers)106 copy(x[6:38], m.random)107 x[38] = uint8(len(m.sessionId))108 copy(x[39:39+len(m.sessionId)], m.sessionId)109 y := x[39+len(m.sessionId):]110 y[0] = uint8(len(m.cipherSuites) >> 7)111 y[1] = uint8(len(m.cipherSuites) << 1)112 for i, suite := range m.cipherSuites {113 y[2+i*2] = uint8(suite >> 8)114 y[3+i*2] = uint8(suite)115 }116 z := y[2+len(m.cipherSuites)*2:]117 z[0] = uint8(len(m.compressionMethods))118 copy(z[1:], m.compressionMethods)119 z = z[1+len(m.compressionMethods):]120 if numExtensions > 0 {121 z[0] = byte(extensionsLength >> 8)122 z[1] = byte(extensionsLength)123 z = z[2:]124 }125 if m.nextProtoNeg {126 z[0] = byte(extensionNextProtoNeg >> 8)127 z[1] = byte(extensionNextProtoNeg & 0xff)128 // The length is always 0129 z = z[4:]130 }131 if len(m.serverName) > 0 {132 z[0] = byte(extensionServerName >> 8)133 z[1] = byte(extensionServerName & 0xff)134 l := len(m.serverName) + 5135 z[2] = byte(l >> 8)136 z[3] = byte(l)137 z = z[4:]138 // RFC 3546, section 3.1139 //140 // struct {141 // NameType name_type;142 // select (name_type) {143 // case host_name: HostName;144 // } name;145 // } ServerName;146 //147 // enum {148 // host_name(0), (255)149 // } NameType;150 //151 // opaque HostName<1..2^16-1>;152 //153 // struct {154 // ServerName server_name_list<1..2^16-1>155 // } ServerNameList;156 z[0] = byte((len(m.serverName) + 3) >> 8)157 z[1] = byte(len(m.serverName) + 3)158 z[3] = byte(len(m.serverName) >> 8)159 z[4] = byte(len(m.serverName))160 copy(z[5:], []byte(m.serverName))161 z = z[l:]162 }163 if m.ocspStapling {164 // RFC 4366, section 3.6165 z[0] = byte(extensionStatusRequest >> 8)166 z[1] = byte(extensionStatusRequest)167 z[2] = 0168 z[3] = 5169 z[4] = 1 // OCSP type170 // Two zero valued uint16s for the two lengths.171 z = z[9:]172 }173 if len(m.supportedCurves) > 0 {174 // http://tools.ietf.org/html/rfc4492#section-5.5.1175 z[0] = byte(extensionSupportedCurves >> 8)176 z[1] = byte(extensionSupportedCurves)177 l := 2 + 2*len(m.supportedCurves)178 z[2] = byte(l >> 8)179 z[3] = byte(l)180 l -= 2181 z[4] = byte(l >> 8)182 z[5] = byte(l)183 z = z[6:]184 for _, curve := range m.supportedCurves {185 z[0] = byte(curve >> 8)186 z[1] = byte(curve)187 z = z[2:]188 }189 }190 if len(m.supportedPoints) > 0 {191 // http://tools.ietf.org/html/rfc4492#section-5.5.2192 z[0] = byte(extensionSupportedPoints >> 8)193 z[1] = byte(extensionSupportedPoints)194 l := 1 + len(m.supportedPoints)195 z[2] = byte(l >> 8)196 z[3] = byte(l)197 l--198 z[4] = byte(l)199 z = z[5:]200 for _, pointFormat := range m.supportedPoints {201 z[0] = byte(pointFormat)202 z = z[1:]203 }204 }205 if m.ticketSupported {206 // http://tools.ietf.org/html/rfc5077#section-3.2207 z[0] = byte(extensionSessionTicket >> 8)208 z[1] = byte(extensionSessionTicket)209 l := len(m.sessionTicket)210 z[2] = byte(l >> 8)211 z[3] = byte(l)212 z = z[4:]213 copy(z, m.sessionTicket)214 z = z[len(m.sessionTicket):]215 }216 if len(m.signatureAndHashes) > 0 {217 // https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1218 z[0] = byte(extensionSignatureAlgorithms >> 8)219 z[1] = byte(extensionSignatureAlgorithms)220 l := 2 + 2*len(m.signatureAndHashes)221 z[2] = byte(l >> 8)222 z[3] = byte(l)223 z = z[4:]224 l -= 2225 z[0] = byte(l >> 8)226 z[1] = byte(l)227 z = z[2:]228 for _, sigAndHash := range m.signatureAndHashes {229 z[0] = sigAndHash.hash230 z[1] = sigAndHash.signature231 z = z[2:]232 }233 }234 if m.secureRenegotiation {235 z[0] = byte(extensionRenegotiationInfo >> 8)236 z[1] = byte(extensionRenegotiationInfo & 0xff)237 z[2] = 0238 z[3] = 1239 z = z[5:]240 }241 if len(m.alpnProtocols) > 0 {242 z[0] = byte(extensionALPN >> 8)243 z[1] = byte(extensionALPN & 0xff)244 lengths := z[2:]245 z = z[6:]246 stringsLength := 0247 for _, s := range m.alpnProtocols {248 l := len(s)249 z[0] = byte(l)250 copy(z[1:], s)251 z = z[1+l:]252 stringsLength += 1 + l253 }254 lengths[2] = byte(stringsLength >> 8)255 lengths[3] = byte(stringsLength)256 stringsLength += 2257 lengths[0] = byte(stringsLength >> 8)258 lengths[1] = byte(stringsLength)259 }260 m.raw = x261 return x262}263func (m *clientHelloMsg) unmarshal(data []byte) bool {264 if len(data) < 42 {265 return false266 }267 m.raw = data268 m.vers = uint16(data[4])<<8 | uint16(data[5])269 m.random = data[6:38]270 sessionIdLen := int(data[38])271 if sessionIdLen > 32 || len(data) < 39+sessionIdLen {272 return false273 }274 m.sessionId = data[39 : 39+sessionIdLen]275 data = data[39+sessionIdLen:]276 if len(data) < 2 {277 return false278 }279 // cipherSuiteLen is the number of bytes of cipher suite numbers. Since280 // they are uint16s, the number must be even.281 cipherSuiteLen := int(data[0])<<8 | int(data[1])282 if cipherSuiteLen%2 == 1 || len(data) < 2+cipherSuiteLen {283 return false284 }285 numCipherSuites := cipherSuiteLen / 2286 m.cipherSuites = make([]uint16, numCipherSuites)287 for i := 0; i < numCipherSuites; i++ {288 m.cipherSuites[i] = uint16(data[2+2*i])<<8 | uint16(data[3+2*i])289 if m.cipherSuites[i] == scsvRenegotiation {290 m.secureRenegotiation = true291 }292 }293 data = data[2+cipherSuiteLen:]294 if len(data) < 1 {295 return false296 }297 compressionMethodsLen := int(data[0])298 if len(data) < 1+compressionMethodsLen {299 return false300 }301 m.compressionMethods = data[1 : 1+compressionMethodsLen]302 data = data[1+compressionMethodsLen:]303 m.nextProtoNeg = false304 m.serverName = ""305 m.ocspStapling = false306 m.ticketSupported = false307 m.sessionTicket = nil308 m.signatureAndHashes = nil309 m.alpnProtocols = nil310 if len(data) == 0 {311 // ClientHello is optionally followed by extension data312 return true313 }314 if len(data) < 2 {315 return false316 }317 extensionsLength := int(data[0])<<8 | int(data[1])318 data = data[2:]319 if extensionsLength != len(data) {320 return false321 }322 for len(data) != 0 {323 if len(data) < 4 {324 return false325 }326 extension := uint16(data[0])<<8 | uint16(data[1])327 length := int(data[2])<<8 | int(data[3])328 data = data[4:]329 if len(data) < length {330 return false331 }332 switch extension {333 case extensionServerName:334 if length < 2 {335 return false336 }337 numNames := int(data[0])<<8 | int(data[1])338 d := data[2:]339 for i := 0; i < numNames; i++ {340 if len(d) < 3 {341 return false342 }343 nameType := d[0]344 nameLen := int(d[1])<<8 | int(d[2])345 d = d[3:]346 if len(d) < nameLen {347 return false348 }349 if nameType == 0 {350 m.serverName = string(d[0:nameLen])351 break352 }353 d = d[nameLen:]354 }355 case extensionNextProtoNeg:356 if length > 0 {357 return false358 }359 m.nextProtoNeg = true360 case extensionStatusRequest:361 m.ocspStapling = length > 0 && data[0] == statusTypeOCSP362 case extensionSupportedCurves:363 // http://tools.ietf.org/html/rfc4492#section-5.5.1364 if length < 2 {365 return false366 }367 l := int(data[0])<<8 | int(data[1])368 if l%2 == 1 || length != l+2 {369 return false370 }371 numCurves := l / 2372 m.supportedCurves = make([]CurveID, numCurves)373 d := data[2:]374 for i := 0; i < numCurves; i++ {375 m.supportedCurves[i] = CurveID(d[0])<<8 | CurveID(d[1])376 d = d[2:]377 }378 case extensionSupportedPoints:379 // http://tools.ietf.org/html/rfc4492#section-5.5.2380 if length < 1 {381 return false382 }383 l := int(data[0])384 if length != l+1 {385 return false386 }387 m.supportedPoints = make([]uint8, l)388 copy(m.supportedPoints, data[1:])389 case extensionSessionTicket:390 // http://tools.ietf.org/html/rfc5077#section-3.2391 m.ticketSupported = true392 m.sessionTicket = data[:length]393 case extensionSignatureAlgorithms:394 // https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1395 if length < 2 || length&1 != 0 {396 return false397 }398 l := int(data[0])<<8 | int(data[1])399 if l != length-2 {400 return false401 }402 n := l / 2403 d := data[2:]404 m.signatureAndHashes = make([]signatureAndHash, n)405 for i := range m.signatureAndHashes {406 m.signatureAndHashes[i].hash = d[0]407 m.signatureAndHashes[i].signature = d[1]408 d = d[2:]409 }410 case extensionRenegotiationInfo + 1:411 if length != 1 || data[0] != 0 {412 return false413 }414 m.secureRenegotiation = true415 case extensionALPN:416 if length < 2 {417 return false418 }419 l := int(data[0])<<8 | int(data[1])420 if l != length-2 {421 return false422 }423 d := data[2:length]424 for len(d) != 0 {425 stringLen := int(d[0])426 d = d[1:]427 if stringLen == 0 || stringLen > len(d) {428 return false429 }430 m.alpnProtocols = append(m.alpnProtocols, string(d[:stringLen]))431 d = d[stringLen:]432 }433 }434 data = data[length:]435 }436 return true437}438type serverHelloMsg struct {439 raw []byte440 vers uint16441 random []byte442 sessionId []byte443 cipherSuite uint16444 compressionMethod uint8445 nextProtoNeg bool446 nextProtos []string447 ocspStapling bool448 ticketSupported bool449 secureRenegotiation bool450 alpnProtocol string451}452func (m *serverHelloMsg) equal(i interface{}) bool {453 m1, ok := i.(*serverHelloMsg)454 if !ok {455 return false456 }457 return bytes.Equal(m.raw, m1.raw) &&458 m.vers == m1.vers &&459 bytes.Equal(m.random, m1.random) &&460 bytes.Equal(m.sessionId, m1.sessionId) &&461 m.cipherSuite == m1.cipherSuite &&462 m.compressionMethod == m1.compressionMethod &&463 m.nextProtoNeg == m1.nextProtoNeg &&464 eqStrings(m.nextProtos, m1.nextProtos) &&465 m.ocspStapling == m1.ocspStapling &&466 m.ticketSupported == m1.ticketSupported &&467 m.secureRenegotiation == m1.secureRenegotiation &&468 m.alpnProtocol == m1.alpnProtocol469}470func (m *serverHelloMsg) marshal() []byte {471 if m.raw != nil {472 return m.raw473 }474 length := 38 + len(m.sessionId)475 numExtensions := 0476 extensionsLength := 0477 nextProtoLen := 0478 if m.nextProtoNeg {479 numExtensions++480 for _, v := range m.nextProtos {481 nextProtoLen += len(v)482 }483 nextProtoLen += len(m.nextProtos)484 extensionsLength += nextProtoLen485 }486 if m.ocspStapling {487 numExtensions++488 }489 if m.ticketSupported {490 numExtensions++491 }492 if m.secureRenegotiation {493 extensionsLength += 1494 numExtensions++495 }496 if alpnLen := len(m.alpnProtocol); alpnLen > 0 {497 if alpnLen >= 256 {498 panic("invalid ALPN protocol")499 }500 extensionsLength += 2 + 1 + alpnLen501 numExtensions++502 }503 if numExtensions > 0 {504 extensionsLength += 4 * numExtensions505 length += 2 + extensionsLength506 }507 x := make([]byte, 4+length)508 x[0] = typeServerHello509 x[1] = uint8(length >> 16)510 x[2] = uint8(length >> 8)511 x[3] = uint8(length)512 x[4] = uint8(m.vers >> 8)513 x[5] = uint8(m.vers)514 copy(x[6:38], m.random)515 x[38] = uint8(len(m.sessionId))516 copy(x[39:39+len(m.sessionId)], m.sessionId)517 z := x[39+len(m.sessionId):]518 z[0] = uint8(m.cipherSuite >> 8)519 z[1] = uint8(m.cipherSuite)520 z[2] = uint8(m.compressionMethod)521 z = z[3:]522 if numExtensions > 0 {523 z[0] = byte(extensionsLength >> 8)524 z[1] = byte(extensionsLength)525 z = z[2:]526 }527 if m.nextProtoNeg {528 z[0] = byte(extensionNextProtoNeg >> 8)529 z[1] = byte(extensionNextProtoNeg & 0xff)530 z[2] = byte(nextProtoLen >> 8)531 z[3] = byte(nextProtoLen)532 z = z[4:]533 for _, v := range m.nextProtos {534 l := len(v)535 if l > 255 {536 l = 255537 }538 z[0] = byte(l)539 copy(z[1:], []byte(v[0:l]))540 z = z[1+l:]541 }542 }543 if m.ocspStapling {544 z[0] = byte(extensionStatusRequest >> 8)545 z[1] = byte(extensionStatusRequest)546 z = z[4:]547 }548 if m.ticketSupported {549 z[0] = byte(extensionSessionTicket >> 8)550 z[1] = byte(extensionSessionTicket)551 z = z[4:]552 }553 if m.secureRenegotiation {554 z[0] = byte(extensionRenegotiationInfo >> 8)555 z[1] = byte(extensionRenegotiationInfo & 0xff)556 z[2] = 0557 z[3] = 1558 z = z[5:]559 }560 if alpnLen := len(m.alpnProtocol); alpnLen > 0 {561 z[0] = byte(extensionALPN >> 8)562 z[1] = byte(extensionALPN & 0xff)563 l := 2 + 1 + alpnLen564 z[2] = byte(l >> 8)565 z[3] = byte(l)566 l -= 2567 z[4] = byte(l >> 8)568 z[5] = byte(l)569 l -= 1570 z[6] = byte(l)571 copy(z[7:], []byte(m.alpnProtocol))572 z = z[7+alpnLen:]573 }574 m.raw = x575 return x576}577func (m *serverHelloMsg) unmarshal(data []byte) bool {578 if len(data) < 42 {579 return false580 }581 m.raw = data582 m.vers = uint16(data[4])<<8 | uint16(data[5])583 m.random = data[6:38]584 sessionIdLen := int(data[38])585 if sessionIdLen > 32 || len(data) < 39+sessionIdLen {586 return false587 }588 m.sessionId = data[39 : 39+sessionIdLen]589 data = data[39+sessionIdLen:]590 if len(data) < 3 {591 return false592 }593 m.cipherSuite = uint16(data[0])<<8 | uint16(data[1])594 m.compressionMethod = data[2]595 data = data[3:]596 m.nextProtoNeg = false597 m.nextProtos = nil598 m.ocspStapling = false599 m.ticketSupported = false600 m.alpnProtocol = ""601 if len(data) == 0 {602 // ServerHello is optionally followed by extension data603 return true604 }605 if len(data) < 2 {606 return false607 }608 extensionsLength := int(data[0])<<8 | int(data[1])609 data = data[2:]610 if len(data) != extensionsLength {611 return false612 }613 for len(data) != 0 {614 if len(data) < 4 {615 return false616 }617 extension := uint16(data[0])<<8 | uint16(data[1])618 length := int(data[2])<<8 | int(data[3])619 data = data[4:]620 if len(data) < length {621 return false622 }623 switch extension {624 case extensionNextProtoNeg:625 m.nextProtoNeg = true626 d := data[:length]627 for len(d) > 0 {628 l := int(d[0])629 d = d[1:]630 if l == 0 || l > len(d) {631 return false632 }633 m.nextProtos = append(m.nextProtos, string(d[:l]))634 d = d[l:]635 }636 case extensionStatusRequest:637 if length > 0 {638 return false639 }640 m.ocspStapling = true641 case extensionSessionTicket:642 if length > 0 {643 return false644 }645 m.ticketSupported = true646 case extensionRenegotiationInfo:647 if length != 1 || data[0] != 0 {648 return false649 }650 m.secureRenegotiation = true651 case extensionALPN:652 d := data[:length]653 if len(d) < 3 {654 return false655 }656 l := int(d[0])<<8 | int(d[1])657 if l != len(d)-2 {658 return false659 }660 d = d[2:]661 l = int(d[0])662 if l != len(d)-1 {663 return false664 }665 d = d[1:]666 m.alpnProtocol = string(d)667 }668 data = data[length:]669 }670 return true671}672type certificateMsg struct {673 raw []byte674 certificates [][]byte675}676func (m *certificateMsg) equal(i interface{}) bool {677 m1, ok := i.(*certificateMsg)678 if !ok {679 return false680 }681 return bytes.Equal(m.raw, m1.raw) &&682 eqByteSlices(m.certificates, m1.certificates)683}684func (m *certificateMsg) marshal() (x []byte) {685 if m.raw != nil {686 return m.raw687 }688 var i int689 for _, slice := range m.certificates {690 i += len(slice)691 }692 length := 3 + 3*len(m.certificates) + i693 x = make([]byte, 4+length)694 x[0] = typeCertificate695 x[1] = uint8(length >> 16)696 x[2] = uint8(length >> 8)697 x[3] = uint8(length)698 certificateOctets := length - 3699 x[4] = uint8(certificateOctets >> 16)700 x[5] = uint8(certificateOctets >> 8)701 x[6] = uint8(certificateOctets)702 y := x[7:]703 for _, slice := range m.certificates {704 y[0] = uint8(len(slice) >> 16)705 y[1] = uint8(len(slice) >> 8)706 y[2] = uint8(len(slice))707 copy(y[3:], slice)708 y = y[3+len(slice):]709 }710 m.raw = x711 return712}713func (m *certificateMsg) unmarshal(data []byte) bool {714 if len(data) < 7 {715 return false716 }717 m.raw = data718 certsLen := uint32(data[4])<<16 | uint32(data[5])<<8 | uint32(data[6])719 if uint32(len(data)) != certsLen+7 {720 return false721 }722 numCerts := 0723 d := data[7:]724 for certsLen > 0 {725 if len(d) < 4 {726 return false727 }728 certLen := uint32(d[0])<<16 | uint32(d[1])<<8 | uint32(d[2])729 if uint32(len(d)) < 3+certLen {730 return false731 }732 d = d[3+certLen:]733 certsLen -= 3 + certLen734 numCerts++735 }736 m.certificates = make([][]byte, numCerts)737 d = data[7:]738 for i := 0; i < numCerts; i++ {739 certLen := uint32(d[0])<<16 | uint32(d[1])<<8 | uint32(d[2])740 m.certificates[i] = d[3 : 3+certLen]741 d = d[3+certLen:]742 }743 return true744}745type serverKeyExchangeMsg struct {746 raw []byte747 key []byte748}749func (m *serverKeyExchangeMsg) equal(i interface{}) bool {750 m1, ok := i.(*serverKeyExchangeMsg)751 if !ok {752 return false753 }754 return bytes.Equal(m.raw, m1.raw) &&755 bytes.Equal(m.key, m1.key)756}757func (m *serverKeyExchangeMsg) marshal() []byte {758 if m.raw != nil {759 return m.raw760 }761 length := len(m.key)762 x := make([]byte, length+4)763 x[0] = typeServerKeyExchange764 x[1] = uint8(length >> 16)765 x[2] = uint8(length >> 8)766 x[3] = uint8(length)767 copy(x[4:], m.key)768 m.raw = x769 return x770}771func (m *serverKeyExchangeMsg) unmarshal(data []byte) bool {772 m.raw = data773 if len(data) < 4 {774 return false775 }776 m.key = data[4:]777 return true778}779type certificateStatusMsg struct {780 raw []byte781 statusType uint8782 response []byte783}784func (m *certificateStatusMsg) equal(i interface{}) bool {785 m1, ok := i.(*certificateStatusMsg)786 if !ok {787 return false788 }789 return bytes.Equal(m.raw, m1.raw) &&790 m.statusType == m1.statusType &&791 bytes.Equal(m.response, m1.response)792}793func (m *certificateStatusMsg) marshal() []byte {794 if m.raw != nil {795 return m.raw796 }797 var x []byte798 if m.statusType == statusTypeOCSP {799 x = make([]byte, 4+4+len(m.response))800 x[0] = typeCertificateStatus801 l := len(m.response) + 4802 x[1] = byte(l >> 16)803 x[2] = byte(l >> 8)804 x[3] = byte(l)805 x[4] = statusTypeOCSP806 l -= 4807 x[5] = byte(l >> 16)808 x[6] = byte(l >> 8)809 x[7] = byte(l)810 copy(x[8:], m.response)811 } else {812 x = []byte{typeCertificateStatus, 0, 0, 1, m.statusType}813 }814 m.raw = x815 return x816}817func (m *certificateStatusMsg) unmarshal(data []byte) bool {818 m.raw = data819 if len(data) < 5 {820 return false821 }822 m.statusType = data[4]823 m.response = nil824 if m.statusType == statusTypeOCSP {825 if len(data) < 8 {826 return false827 }828 respLen := uint32(data[5])<<16 | uint32(data[6])<<8 | uint32(data[7])829 if uint32(len(data)) != 4+4+respLen {830 return false831 }832 m.response = data[8:]833 }834 return true835}836type serverHelloDoneMsg struct{}837func (m *serverHelloDoneMsg) equal(i interface{}) bool {838 _, ok := i.(*serverHelloDoneMsg)839 return ok840}841func (m *serverHelloDoneMsg) marshal() []byte {842 x := make([]byte, 4)843 x[0] = typeServerHelloDone844 return x845}846func (m *serverHelloDoneMsg) unmarshal(data []byte) bool {847 return len(data) == 4848}849type clientKeyExchangeMsg struct {850 raw []byte851 ciphertext []byte852}853func (m *clientKeyExchangeMsg) equal(i interface{}) bool {854 m1, ok := i.(*clientKeyExchangeMsg)855 if !ok {856 return false857 }858 return bytes.Equal(m.raw, m1.raw) &&859 bytes.Equal(m.ciphertext, m1.ciphertext)860}861func (m *clientKeyExchangeMsg) marshal() []byte {862 if m.raw != nil {863 return m.raw864 }865 length := len(m.ciphertext)866 x := make([]byte, length+4)867 x[0] = typeClientKeyExchange868 x[1] = uint8(length >> 16)869 x[2] = uint8(length >> 8)870 x[3] = uint8(length)871 copy(x[4:], m.ciphertext)872 m.raw = x873 return x874}875func (m *clientKeyExchangeMsg) unmarshal(data []byte) bool {876 m.raw = data877 if len(data) < 4 {878 return false879 }880 l := int(data[1])<<16 | int(data[2])<<8 | int(data[3])881 if l != len(data)-4 {882 return false883 }884 m.ciphertext = data[4:]885 return true886}887type finishedMsg struct {888 raw []byte889 verifyData []byte890}891func (m *finishedMsg) equal(i interface{}) bool {892 m1, ok := i.(*finishedMsg)893 if !ok {894 return false895 }896 return bytes.Equal(m.raw, m1.raw) &&897 bytes.Equal(m.verifyData, m1.verifyData)898}899func (m *finishedMsg) marshal() (x []byte) {900 if m.raw != nil {901 return m.raw902 }903 x = make([]byte, 4+len(m.verifyData))904 x[0] = typeFinished905 x[3] = byte(len(m.verifyData))906 copy(x[4:], m.verifyData)907 m.raw = x908 return909}910func (m *finishedMsg) unmarshal(data []byte) bool {911 m.raw = data912 if len(data) < 4 {913 return false914 }915 m.verifyData = data[4:]916 return true917}918type nextProtoMsg struct {919 raw []byte920 proto string921}922func (m *nextProtoMsg) equal(i interface{}) bool {923 m1, ok := i.(*nextProtoMsg)924 if !ok {925 return false926 }927 return bytes.Equal(m.raw, m1.raw) &&928 m.proto == m1.proto929}930func (m *nextProtoMsg) marshal() []byte {931 if m.raw != nil {932 return m.raw933 }934 l := len(m.proto)935 if l > 255 {936 l = 255937 }938 padding := 32 - (l+2)%32939 length := l + padding + 2940 x := make([]byte, length+4)941 x[0] = typeNextProtocol942 x[1] = uint8(length >> 16)943 x[2] = uint8(length >> 8)944 x[3] = uint8(length)945 y := x[4:]946 y[0] = byte(l)947 copy(y[1:], []byte(m.proto[0:l]))948 y = y[1+l:]949 y[0] = byte(padding)950 m.raw = x951 return x952}953func (m *nextProtoMsg) unmarshal(data []byte) bool {954 m.raw = data955 if len(data) < 5 {956 return false957 }958 data = data[4:]959 protoLen := int(data[0])960 data = data[1:]961 if len(data) < protoLen {962 return false963 }964 m.proto = string(data[0:protoLen])965 data = data[protoLen:]966 if len(data) < 1 {967 return false968 }969 paddingLen := int(data[0])970 data = data[1:]971 if len(data) != paddingLen {972 return false973 }974 return true975}976type certificateRequestMsg struct {977 raw []byte978 // hasSignatureAndHash indicates whether this message includes a list979 // of signature and hash functions. This change was introduced with TLS980 // 1.2.981 hasSignatureAndHash bool982 certificateTypes []byte983 signatureAndHashes []signatureAndHash984 certificateAuthorities [][]byte985}986func (m *certificateRequestMsg) equal(i interface{}) bool {987 m1, ok := i.(*certificateRequestMsg)988 if !ok {989 return false990 }991 return bytes.Equal(m.raw, m1.raw) &&992 bytes.Equal(m.certificateTypes, m1.certificateTypes) &&993 eqByteSlices(m.certificateAuthorities, m1.certificateAuthorities) &&994 eqSignatureAndHashes(m.signatureAndHashes, m1.signatureAndHashes)995}996func (m *certificateRequestMsg) marshal() (x []byte) {997 if m.raw != nil {998 return m.raw999 }1000 // See http://tools.ietf.org/html/rfc4346#section-7.4.41001 length := 1 + len(m.certificateTypes) + 21002 casLength := 01003 for _, ca := range m.certificateAuthorities {1004 casLength += 2 + len(ca)1005 }1006 length += casLength1007 if m.hasSignatureAndHash {1008 length += 2 + 2*len(m.signatureAndHashes)1009 }1010 x = make([]byte, 4+length)1011 x[0] = typeCertificateRequest1012 x[1] = uint8(length >> 16)1013 x[2] = uint8(length >> 8)1014 x[3] = uint8(length)1015 x[4] = uint8(len(m.certificateTypes))1016 copy(x[5:], m.certificateTypes)1017 y := x[5+len(m.certificateTypes):]1018 if m.hasSignatureAndHash {1019 n := len(m.signatureAndHashes) * 21020 y[0] = uint8(n >> 8)1021 y[1] = uint8(n)1022 y = y[2:]1023 for _, sigAndHash := range m.signatureAndHashes {1024 y[0] = sigAndHash.hash1025 y[1] = sigAndHash.signature1026 y = y[2:]1027 }1028 }1029 y[0] = uint8(casLength >> 8)1030 y[1] = uint8(casLength)1031 y = y[2:]1032 for _, ca := range m.certificateAuthorities {1033 y[0] = uint8(len(ca) >> 8)1034 y[1] = uint8(len(ca))1035 y = y[2:]1036 copy(y, ca)1037 y = y[len(ca):]1038 }1039 m.raw = x1040 return1041}1042func (m *certificateRequestMsg) unmarshal(data []byte) bool {1043 m.raw = data1044 if len(data) < 5 {1045 return false1046 }1047 length := uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])1048 if uint32(len(data))-4 != length {1049 return false1050 }1051 numCertTypes := int(data[4])1052 data = data[5:]1053 if numCertTypes == 0 || len(data) <= numCertTypes {1054 return false1055 }1056 m.certificateTypes = make([]byte, numCertTypes)1057 if copy(m.certificateTypes, data) != numCertTypes {1058 return false1059 }1060 data = data[numCertTypes:]1061 if m.hasSignatureAndHash {1062 if len(data) < 2 {1063 return false1064 }1065 sigAndHashLen := uint16(data[0])<<8 | uint16(data[1])1066 data = data[2:]1067 if sigAndHashLen&1 != 0 {1068 return false1069 }1070 if len(data) < int(sigAndHashLen) {1071 return false1072 }1073 numSigAndHash := sigAndHashLen / 21074 m.signatureAndHashes = make([]signatureAndHash, numSigAndHash)1075 for i := range m.signatureAndHashes {1076 m.signatureAndHashes[i].hash = data[0]1077 m.signatureAndHashes[i].signature = data[1]1078 data = data[2:]1079 }1080 }1081 if len(data) < 2 {1082 return false1083 }1084 casLength := uint16(data[0])<<8 | uint16(data[1])1085 data = data[2:]1086 if len(data) < int(casLength) {1087 return false1088 }1089 cas := make([]byte, casLength)1090 copy(cas, data)1091 data = data[casLength:]1092 m.certificateAuthorities = nil1093 for len(cas) > 0 {1094 if len(cas) < 2 {1095 return false1096 }1097 caLen := uint16(cas[0])<<8 | uint16(cas[1])1098 cas = cas[2:]1099 if len(cas) < int(caLen) {1100 return false1101 }1102 m.certificateAuthorities = append(m.certificateAuthorities, cas[:caLen])1103 cas = cas[caLen:]1104 }1105 if len(data) > 0 {1106 return false1107 }1108 return true1109}1110type certificateVerifyMsg struct {1111 raw []byte1112 hasSignatureAndHash bool1113 signatureAndHash signatureAndHash1114 signature []byte1115}1116func (m *certificateVerifyMsg) equal(i interface{}) bool {1117 m1, ok := i.(*certificateVerifyMsg)1118 if !ok {1119 return false1120 }1121 return bytes.Equal(m.raw, m1.raw) &&1122 m.hasSignatureAndHash == m1.hasSignatureAndHash &&1123 m.signatureAndHash.hash == m1.signatureAndHash.hash &&1124 m.signatureAndHash.signature == m1.signatureAndHash.signature &&1125 bytes.Equal(m.signature, m1.signature)1126}1127func (m *certificateVerifyMsg) marshal() (x []byte) {1128 if m.raw != nil {1129 return m.raw1130 }1131 // See http://tools.ietf.org/html/rfc4346#section-7.4.81132 siglength := len(m.signature)1133 length := 2 + siglength1134 if m.hasSignatureAndHash {1135 length += 21136 }1137 x = make([]byte, 4+length)1138 x[0] = typeCertificateVerify1139 x[1] = uint8(length >> 16)1140 x[2] = uint8(length >> 8)1141 x[3] = uint8(length)1142 y := x[4:]1143 if m.hasSignatureAndHash {1144 y[0] = m.signatureAndHash.hash1145 y[1] = m.signatureAndHash.signature1146 y = y[2:]1147 }1148 y[0] = uint8(siglength >> 8)1149 y[1] = uint8(siglength)1150 copy(y[2:], m.signature)1151 m.raw = x1152 return1153}1154func (m *certificateVerifyMsg) unmarshal(data []byte) bool {1155 m.raw = data1156 if len(data) < 6 {1157 return false1158 }1159 length := uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])1160 if uint32(len(data))-4 != length {1161 return false1162 }1163 data = data[4:]1164 if m.hasSignatureAndHash {1165 m.signatureAndHash.hash = data[0]1166 m.signatureAndHash.signature = data[1]1167 data = data[2:]1168 }1169 if len(data) < 2 {1170 return false1171 }1172 siglength := int(data[0])<<8 + int(data[1])1173 data = data[2:]1174 if len(data) != siglength {1175 return false1176 }1177 m.signature = data1178 return true1179}1180type newSessionTicketMsg struct {1181 raw []byte1182 ticket []byte1183}1184func (m *newSessionTicketMsg) equal(i interface{}) bool {1185 m1, ok := i.(*newSessionTicketMsg)1186 if !ok {1187 return false1188 }1189 return bytes.Equal(m.raw, m1.raw) &&1190 bytes.Equal(m.ticket, m1.ticket)1191}1192func (m *newSessionTicketMsg) marshal() (x []byte) {1193 if m.raw != nil {1194 return m.raw1195 }1196 // See http://tools.ietf.org/html/rfc5077#section-3.31197 ticketLen := len(m.ticket)1198 length := 2 + 4 + ticketLen1199 x = make([]byte, 4+length)1200 x[0] = typeNewSessionTicket1201 x[1] = uint8(length >> 16)1202 x[2] = uint8(length >> 8)1203 x[3] = uint8(length)1204 x[8] = uint8(ticketLen >> 8)1205 x[9] = uint8(ticketLen)1206 copy(x[10:], m.ticket)1207 m.raw = x1208 return1209}1210func (m *newSessionTicketMsg) unmarshal(data []byte) bool {1211 m.raw = data1212 if len(data) < 10 {1213 return false1214 }1215 length := uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])1216 if uint32(len(data))-4 != length {1217 return false1218 }1219 ticketLen := int(data[8])<<8 + int(data[9])1220 if len(data)-10 != ticketLen {1221 return false1222 }1223 m.ticket = data[10:]1224 return true1225}1226func eqUint16s(x, y []uint16) bool {1227 if len(x) != len(y) {1228 return false1229 }1230 for i, v := range x {1231 if y[i] != v {1232 return false1233 }1234 }...

Full Screen

Full Screen

ticket.go

Source:ticket.go Github

copy

Full Screen

...74 return false75 }76 s.vers = uint16(data[0])<<8 | uint16(data[1])77 s.cipherSuite = uint16(data[2])<<8 | uint16(data[3])78 masterSecretLen := int(data[4])<<8 | int(data[5])79 data = data[6:]80 if len(data) < masterSecretLen {81 return false82 }83 s.masterSecret = data[:masterSecretLen]84 data = data[masterSecretLen:]85 if len(data) < 2 {86 return false87 }88 numCerts := int(data[0])<<8 | int(data[1])89 data = data[2:]90 s.certificates = make([][]byte, numCerts)91 for i := range s.certificates {92 if len(data) < 4 {93 return false94 }95 certLen := int(data[0])<<24 | int(data[1])<<16 | int(data[2])<<8 | int(data[3])96 data = data[4:]97 if certLen < 0 {98 return false99 }100 if len(data) < certLen {101 return false102 }103 s.certificates[i] = data[:certLen]104 data = data[certLen:]105 }106 if len(data) > 0 {107 return false108 }109 return true110}111func (c *Conn) encryptTicket(state *sessionState) ([]byte, error) {112 serialized := state.marshal()113 encrypted := make([]byte, aes.BlockSize+len(serialized)+sha256.Size)114 iv := encrypted[:aes.BlockSize]115 macBytes := encrypted[len(encrypted)-sha256.Size:]116 if _, err := io.ReadFull(c.config.rand(), iv); err != nil {117 return nil, err118 }...

Full Screen

Full Screen

Len

Using AI Code Generation

copy

Full Screen

1s := session.NewSession()2s.Len()3s := session.NewSession()4s.Len()5s := session.NewSession()6s.Len()7s := session.NewSession()8s.Len()9s := session.NewSession()10s.Len()11s := session.NewSession()12s.Len()13s := session.NewSession()14s.Len()15s := session.NewSession()16s.Len()17s := session.NewSession()18s.Len()19s := session.NewSession()20s.Len()21s := session.NewSession()22s.Len()23s := session.NewSession()24s.Len()25s := session.NewSession()26s.Len()27s := session.NewSession()28s.Len()29s := session.NewSession()30s.Len()31s := session.NewSession()32s.Len()33s := session.NewSession()34s.Len()35s := session.NewSession()36s.Len()37s := session.NewSession()38s.Len()

Full Screen

Full Screen

Len

Using AI Code Generation

copy

Full Screen

1import (2type Session struct {3}4func (s *Session) Len() int {5}6func main() {7 s := Session{8 }9 fmt.Println(s.Len())10}11import (12type Session struct {13}14func (s *Session) Len() int {15}16func main() {17 s := Session{18 }19 fmt.Println(s.Len())20}21import (22type Session struct {23}24func (s *Session) Len() int {25}26func main() {27 s := Session{28 }29 fmt.Println(s.Len())30}31import (32type Session struct {33}34func (s *Session) Len() int {35}36func main() {37 s := Session{38 }39 fmt.Println(s.Len())40}41import (42type Session struct {43}44func (s *Session) Len() int {45}46func main() {47 s := Session{48 }49 fmt.Println(s.Len())50}51import (52type Session struct {53}54func (s *Session) Len() int {55}56func main() {57 s := Session{58 }59 fmt.Println(s.Len())60}61import (62type Session struct {63}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenoid automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful