Skip to content

Commit

Permalink
Validate RemoteIdentity only when NAT traversal is on (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Zhylinski committed Jul 13, 2016
1 parent e1ac428 commit 9c470a4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions models/vpn/create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package vpn

import (
"fmt"
"net"
)

type CreateReq struct {
Local LocalPropertiesCreateReq
Remote RemotePropertiesCreateReq
Expand All @@ -8,7 +13,7 @@ type CreateReq struct {
}

type LocalPropertiesCreateReq struct {
Alias string `valid:"required",json:"locationAlias"`
Alias string `json:"locationAlias" valid:"required"`
Subnets []string `valid:"required"`
}

Expand Down Expand Up @@ -36,5 +41,19 @@ type IkeCreateReq struct {
Mode string `oneOf:"main,aggresive"`
DeadPeerDetection string `oneOf:"true,false,optional"`
NatTraversal string `oneOf:"true,false,optional"`
RemoteIdentity string `valid:"required"`
RemoteIdentity string
}

func (r *IkeCreateReq) Validate() error {
if r.NatTraversal == "true" {
ip := r.RemoteIdentity
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return fmt.Errorf("remoteIdentity: %s is not valid IPv4", ip)
}
} else {
r.RemoteIdentity = ""
}

return nil
}

0 comments on commit 9c470a4

Please sign in to comment.