| 379 | } |
| 380 | |
| 381 | func (k *Kite) updateAuth(reg *protocol.RegisterResult) { |
| 382 | k.configMu.Lock() |
| 383 | defer k.configMu.Unlock() |
| 384 | |
| 385 | switch { |
| 386 | case reg.KiteKey != "": |
| 387 | k.Config.KiteKey = reg.KiteKey |
| 388 | |
| 389 | ex := &kitekey.Extractor{ |
| 390 | Claims: &kitekey.KiteClaims{}, |
| 391 | } |
| 392 | |
| 393 | if _, err := jwt.ParseWithClaims(reg.KiteKey, ex.Claims, ex.Extract); err != nil { |
| 394 | k.Log.Error("auth update: unable to extract kontrol key: %s", err) |
| 395 | |
| 396 | break |
| 397 | } |
| 398 | |
| 399 | if ex.Claims.KontrolKey != "" { |
| 400 | reg.PublicKey = ex.Claims.KontrolKey |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // we also received a new public key (means the old one was invalidated). |
| 405 | // Use it now. |
| 406 | if reg.PublicKey != "" { |
| 407 | k.Config.KontrolKey = reg.PublicKey |
| 408 | |
| 409 | key, err := jwt.ParseRSAPublicKeyFromPEM([]byte(reg.PublicKey)) |
| 410 | if err != nil { |
| 411 | k.Log.Error("auth update: unable to update kontrol key: %s", err) |
| 412 | |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | k.kontrolKey = key |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | // RSAKey returns the corresponding public key for the issuer of the token. |
| 421 | // It is called by jwt-go package when validating the signature in the token. |