MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / handleAuthResult

Method handleAuthResult

IceFireDB-SQLProxy/pkg/mysql/client/resp.go:91–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

89}
90
91func (c *Conn) handleAuthResult() error {
92 data, switchToPlugin, err := c.readAuthResult()
93 if err != nil {
94 return err
95 }
96 // handle auth switch, only support 'sha256_password', and 'caching_sha2_password'
97 if switchToPlugin != "" {
98 // fmt.Printf("now switching auth plugin to '%s'\n", switchToPlugin)
99 if data == nil {
100 data = c.salt
101 } else {
102 copy(c.salt, data)
103 }
104 c.authPluginName = switchToPlugin
105 auth, addNull, err := c.genAuthResponse(data)
106 if err != nil {
107 return err
108 }
109
110 if err = c.WriteAuthSwitchPacket(auth, addNull); err != nil {
111 return err
112 }
113
114 // Read Result Packet
115 data, switchToPlugin, err = c.readAuthResult()
116 if err != nil {
117 return err
118 }
119
120 // Do not allow to change the auth plugin more than once
121 if switchToPlugin != "" {
122 return errors.Errorf("can not switch auth plugin more than once")
123 }
124 }
125
126 // handle caching_sha2_password
127 if c.authPluginName == AUTH_CACHING_SHA2_PASSWORD {
128 if data == nil {
129 return nil // auth already succeeded
130 }
131 if data[0] == CACHE_SHA2_FAST_AUTH {
132 if _, err = c.readOK(); err == nil {
133 return nil // auth successful
134 }
135 } else if data[0] == CACHE_SHA2_FULL_AUTH {
136 // need full authentication
137 if c.tlsConfig != nil || c.proto == "unix" {
138 if err = c.WriteClearAuthPacket(c.password); err != nil {
139 return err
140 }
141 } else {
142 if err = c.WritePublicKeyAuthPacket(c.password, c.salt); err != nil {
143 return err
144 }
145 }
146 } else {
147 return errors.Errorf("invalid packet %x", data[0])
148 }

Callers 1

handshakeMethod · 0.95

Calls 8

readAuthResultMethod · 0.95
genAuthResponseMethod · 0.95
WriteAuthSwitchPacketMethod · 0.95
readOKMethod · 0.95
WriteClearAuthPacketMethod · 0.95
DecodeMethod · 0.45

Tested by

no test coverage detected