mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-28 10:51:44 +01:00 
			
		
		
		
	Added func to expire PAKs
This commit is contained in:
		
							parent
							
								
									3007c0ec4f
								
							
						
					
					
						commit
						226cb89d97
					
				| @ -67,6 +67,13 @@ func (h *Headscale) GetPreAuthKeys(namespaceName string) (*[]PreAuthKey, error) | ||||
| 	return &keys, nil | ||||
| } | ||||
| 
 | ||||
| func (h *Headscale) MarkExpirePreAuthKey(k *PreAuthKey) error { | ||||
| 	if err := h.db.Model(&k).Update("Expiration", time.Now()).Error; err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| // checkKeyValidity does the heavy lifting for validation of the PreAuthKey coming from a node
 | ||||
| // If returns no error and a PreAuthKey, it can be used
 | ||||
| func (h *Headscale) checkKeyValidity(k string) (*PreAuthKey, error) { | ||||
|  | ||||
| @ -163,3 +163,20 @@ func (*Suite) TestEphemeralKey(c *check.C) { | ||||
| 	_, err = h.GetMachine("test7", "testest") | ||||
| 	c.Assert(err, check.NotNil) | ||||
| } | ||||
| 
 | ||||
| func (*Suite) TestExpirePreauthKey(c *check.C) { | ||||
| 	n, err := h.CreateNamespace("test3") | ||||
| 	c.Assert(err, check.IsNil) | ||||
| 
 | ||||
| 	pak, err := h.CreatePreAuthKey(n.Name, true, false, nil) | ||||
| 	c.Assert(err, check.IsNil) | ||||
| 	c.Assert(pak.Expiration, check.IsNil) | ||||
| 
 | ||||
| 	err = h.MarkExpirePreAuthKey(pak) | ||||
| 	c.Assert(err, check.IsNil) | ||||
| 	c.Assert(pak.Expiration, check.NotNil) | ||||
| 
 | ||||
| 	p, err := h.checkKeyValidity(pak.Key) | ||||
| 	c.Assert(err, check.Equals, errorAuthKeyExpired) | ||||
| 	c.Assert(p, check.IsNil) | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user