package pkg import ( "errors" "strconv" "strings" ) type ServerSSLProfile struct { ProfileCommon AlertTimeout string `json:"alert_timeout"` AllowExpiredCRL string `json:"allow_expired_crl"` Authenticate string `json:"authenticate"` AuthenticateDepth int `json:"authenticate_depth"` AuthenticateName string `json:"authenticate_name"` CAFile string `json:"ca_file"` CacheSize int `json:"cache_size"` CacheTimeout int `json:"cache_timeout"` Cert string `json:"cert"` Chain string `json:"chain"` Ciphers string `json:"ciphers"` CRLFile string `json:"crl_file"` ExpireCertResponseControl string `json:"expire_cert_response_control"` GenericAlert string `json:"generic_alert"` HandshakeTimeout int `json:"handshake_timeout"` Key string `json:"key"` MaxActiveHandshakes string `json:"max_active_handshakes"` ModSSLMethods string `json:"mod_ssl_methods"` Mode string `json:"mode"` // this is an enabled / disabled, but for "mode" doesn't make sense to be a bool Options []string `json:"options"` Passphrase string `json:"passphrase"` PeerCertMode string `json:"peer_cert_mode"` ProxySSL string `json:"proxy_ssl"` ProxySSLPassthrough string `json:"proxy_ssl_passthrough"` RenegotiatePeriod string `json:"renegotiate_period"` RenegotiateSize string `json:"renegotiate_size"` Renegotiation string `json:"renegotiation"` RetainCertificate string `json:"retain_certificate"` SecureRenegotiation string `json:"secure_renegotiation"` ServerName string `json:"server_name"` SessionMirroing string `json:"session_mirroring"` SessionTicket string `json:"session_ticket"` SNIDefault string `json:"sni_default"` SNIRequire string `json:"sni_require"` SSLForwardProxy string `json:"ssl_forward_proxy"` SSLForwardProxyBypass string `json:"ssl_forward_proxy_bypass"` SSLSignHash string `json:"ssl_sign_hash"` StrictResume string `json:"strict_resume"` UncleanShutdown string `json:"unclean_shutdown"` UntrustedCertResponseControl string `json:"untrusted_cert_response_control"` } // ParseServerSSLProfile : Parse raw output in to a ServerSSLProfile structure func ParseServerSSLProfile(raw string) (*ServerSSLProfile, error) { p := new(ServerSSLProfile) p.Options = []string{} split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile server-ssl") { return nil, errors.New("not a server-ssl profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "alert-timeout": p.AlertTimeout = strings.Join(f[1:], " ") case "allow-expired-crl": p.AllowExpiredCRL = strings.Join(f[1:], " ") case "authenticate": p.Authenticate = strings.Join(f[1:], " ") case "authenticate-depth": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.AuthenticateDepth = i case "authenticate-name": p.AuthenticateName = strings.Join(f[1:], " ") case "ca-file": p.CAFile = strings.Join(f[1:], " ") case "cache-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.CacheSize = i case "cache-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.CacheTimeout = i case "cert": p.Cert = strings.Join(f[1:], " ") case "chain": p.Chain = strings.Join(f[1:], " ") case "ciphers": p.Ciphers = strings.Join(f[1:], " ") case "crl-file": p.CRLFile = strings.Join(f[1:], " ") case "expire-cert-response-control": p.ExpireCertResponseControl = strings.Join(f[1:], " ") case "generic-alert": p.GenericAlert = strings.Join(f[1:], " ") case "handshake-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.HandshakeTimeout = i case "key": p.Key = strings.Join(f[1:], " ") case "max-active-handshakes": p.MaxActiveHandshakes = strings.Join(f[1:], " ") case "mod-ssl-methods": p.ModSSLMethods = strings.Join(f[1:], " ") case "mode": p.Mode = strings.Join(f[1:], " ") case "options": if f[1] != "none" { p.Options = append(p.Options, f[2:len(f)-1]...) } case "passphrase": p.Passphrase = strings.Join(f[1:], " ") case "peer-cert-mode": p.PeerCertMode = strings.Join(f[1:], " ") case "proxy-ssl": p.ProxySSL = strings.Join(f[1:], " ") case "proxy-ssl-passthrough": p.ProxySSLPassthrough = strings.Join(f[1:], " ") case "renegotiate-period": p.RenegotiatePeriod = strings.Join(f[1:], " ") case "renegotiate-size": p.RenegotiateSize = strings.Join(f[1:], " ") case "renegotiation": p.Renegotiation = strings.Join(f[1:], " ") case "retain-certificate": p.RetainCertificate = f[1] case "secure-renegotiation": p.SecureRenegotiation = strings.Join(f[1:], " ") case "server-name": p.ServerName = strings.Join(f[1:], " ") case "session-mirroring": p.SessionMirroing = strings.Join(f[1:], " ") case "session-ticket": p.SessionTicket = strings.Join(f[1:], " ") case "sni-default": p.SNIDefault = f[1] case "sni-require": p.SNIRequire = f[1] case "ssl-forward-proxy": p.SSLForwardProxy = strings.Join(f[1:], " ") case "ssl-forward-proxy-bypass": p.SSLForwardProxyBypass = strings.Join(f[1:], " ") case "ssl-sign-hash": p.SSLSignHash = strings.Join(f[1:], " ") case "strict-resume": p.StrictResume = strings.Join(f[1:], " ") case "unclean-shutdown": p.UncleanShutdown = strings.Join(f[1:], " ") case "untrusted-cert-response-control": p.UntrustedCertResponseControl = strings.Join(f[1:], " ") } } return p, nil }