(opt *options)
| 240 | } |
| 241 | |
| 242 | func createCerts(opt *options) error { |
| 243 | if opt == nil { |
| 244 | return errors.New("nil options") |
| 245 | } |
| 246 | |
| 247 | if opt.dir == "" { |
| 248 | return errors.New("Invalid TLS directory") |
| 249 | } |
| 250 | |
| 251 | err := os.Mkdir(opt.dir, 0700) |
| 252 | if err != nil && !os.IsExist(err) { |
| 253 | return err |
| 254 | } |
| 255 | |
| 256 | switch { |
| 257 | case opt.keySize < keySizeTooSmall: |
| 258 | return errors.New("Key size value is too small (x < 512)") |
| 259 | case opt.keySize > keySizeTooLarge: |
| 260 | return errors.New("Key size value is too large (x > 4096)") |
| 261 | case opt.keySize%2 != 0: |
| 262 | return errors.New("Key size value must be a factor of 2") |
| 263 | } |
| 264 | |
| 265 | switch opt.curve { |
| 266 | case "": |
| 267 | case "P224", "P256", "P384", "P521": |
| 268 | default: |
| 269 | return errors.New(`Elliptic curve value must be one of: P224, P256, P384 or P521`) |
| 270 | } |
| 271 | |
| 272 | // no path then save it in certsDir. |
| 273 | if filepath.Base(opt.caKey) == opt.caKey { |
| 274 | opt.caKey = filepath.Join(opt.dir, opt.caKey) |
| 275 | } |
| 276 | opt.caCert = filepath.Join(opt.dir, defaultCACert) |
| 277 | |
| 278 | if err := createCAPair(opt); err != nil { |
| 279 | return err |
| 280 | } |
| 281 | if err := createNodePair(opt); err != nil { |
| 282 | return err |
| 283 | } |
| 284 | return createClientPair(opt) |
| 285 | } |
no test coverage detected
searching dependent graphs…