| 361 | } |
| 362 | |
| 363 | func (k *Kontrol) registerUser(username, publicKey, privateKey string) (kiteKey string, err error) { |
| 364 | id, err := uuid.NewV4() |
| 365 | if err != nil { |
| 366 | return "", err |
| 367 | } |
| 368 | claims := &kitekey.KiteClaims{ |
| 369 | StandardClaims: jwt.StandardClaims{ |
| 370 | Issuer: k.Kite.Kite().Username, |
| 371 | Subject: username, |
| 372 | IssuedAt: time.Now().Add(-k.tokenLeeway()).UTC().Unix(), |
| 373 | Id: id.String(), |
| 374 | }, |
| 375 | KontrolURL: k.Kite.Config.KontrolURL, |
| 376 | KontrolKey: strings.TrimSpace(publicKey), |
| 377 | } |
| 378 | |
| 379 | rsaPrivate, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(privateKey)) |
| 380 | if err != nil { |
| 381 | return "", err |
| 382 | } |
| 383 | |
| 384 | k.Kite.Log.Info("Registered machine on user: %s", username) |
| 385 | |
| 386 | return jwt.NewWithClaims(jwt.GetSigningMethod("RS256"), claims).SignedString(rsaPrivate) |
| 387 | } |
| 388 | |
| 389 | // registerSelf adds Kontrol itself to the storage as a kite. |
| 390 | func (k *Kontrol) registerSelf() { |