FindOriginCert will check to make sure that the certificate exists at the specified file path.
(originCertPath string, log *zerolog.Logger)
| 121 | |
| 122 | // FindOriginCert will check to make sure that the certificate exists at the specified file path. |
| 123 | func FindOriginCert(originCertPath string, log *zerolog.Logger) (string, error) { |
| 124 | if originCertPath == "" { |
| 125 | log.Error().Msgf("Cannot determine default origin certificate path. No file %s in %v. You need to specify the origin certificate path by specifying the origincert option in the configuration file, or set TUNNEL_ORIGIN_CERT environment variable", DefaultCredentialFile, config.DefaultConfigSearchDirectories()) |
| 126 | return "", fmt.Errorf("client didn't specify origincert path") |
| 127 | } |
| 128 | var err error |
| 129 | originCertPath, err = homedir.Expand(originCertPath) |
| 130 | if err != nil { |
| 131 | log.Err(err).Msgf("Cannot resolve origin certificate path") |
| 132 | return "", fmt.Errorf("cannot resolve path %s", originCertPath) |
| 133 | } |
| 134 | // Check that the user has acquired a certificate using the login command |
| 135 | ok := fileExists(originCertPath) |
| 136 | if !ok { |
| 137 | log.Error().Msgf(`Cannot find a valid certificate for your origin at the path: |
| 138 | |
| 139 | %s |
| 140 | |
| 141 | If the path above is wrong, specify the path with the -origincert option. |
| 142 | If you don't have a certificate signed by Cloudflare, run the command: |
| 143 | |
| 144 | cloudflared login |
| 145 | `, originCertPath) |
| 146 | return "", fmt.Errorf("cannot find a valid certificate at the path %s", originCertPath) |
| 147 | } |
| 148 | |
| 149 | return originCertPath, nil |
| 150 | } |
| 151 | |
| 152 | // FileExists checks to see if a file exist at the provided path. |
| 153 | func fileExists(path string) bool { |