add preshared key validator
This commit is contained in:
		
							parent
							
								
									24d8a4044b
								
							
						
					
					
						commit
						98edcd0d04
					
				| 
						 | 
					@ -187,15 +187,22 @@ func NewClient(db store.IStore) echo.HandlerFunc {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		presharedKey, err := wgtypes.GenerateKey()
 | 
							if client.PresharedKey == "" {
 | 
				
			||||||
		if err != nil {
 | 
								presharedKey, err := wgtypes.GenerateKey()
 | 
				
			||||||
			log.Error("Cannot generated preshared key: ", err)
 | 
								if err != nil {
 | 
				
			||||||
			return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
 | 
									log.Error("Cannot generated preshared key: ", err)
 | 
				
			||||||
				false, "Cannot generate Wireguard preshared key",
 | 
									return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
 | 
				
			||||||
			})
 | 
										false, "Cannot generate Wireguard preshared key",
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								client.PresharedKey = presharedKey.String()
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								_, err := wgtypes.ParseKey(client.PresharedKey)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Error("Cannot verify wireguard preshared key: ", err)
 | 
				
			||||||
 | 
									return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot verify Wireguard preshared key"})
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		client.PresharedKey = presharedKey.String()
 | 
					 | 
				
			||||||
		client.CreatedAt = time.Now().UTC()
 | 
							client.CreatedAt = time.Now().UTC()
 | 
				
			||||||
		client.UpdatedAt = client.CreatedAt
 | 
							client.UpdatedAt = client.CreatedAt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue