ParseServerSecret parse a secret for a server to a key pair
(secret *corev1.Secret)
| 407 | |
| 408 | // ParseServerSecret parse a secret for a server to a key pair |
| 409 | func ParseServerSecret(secret *corev1.Secret) (*KeyPair, error) { |
| 410 | privateKey, ok := secret.Data[TLSPrivateKeyKey] |
| 411 | if !ok { |
| 412 | return nil, fmt.Errorf("missing %v secret data", TLSPrivateKeyKey) |
| 413 | } |
| 414 | |
| 415 | publicKey, ok := secret.Data[TLSCertKey] |
| 416 | if !ok { |
| 417 | return nil, fmt.Errorf("missing %s secret data", TLSCertKey) |
| 418 | } |
| 419 | |
| 420 | // Verify the key matches the certificate |
| 421 | _, err := tls.X509KeyPair(publicKey, privateKey) |
| 422 | if err != nil { |
| 423 | return nil, err |
| 424 | } |
| 425 | |
| 426 | return &KeyPair{ |
| 427 | Private: privateKey, |
| 428 | Certificate: publicKey, |
| 429 | }, nil |
| 430 | } |
| 431 | |
| 432 | // createCAWithValidity create a CA with a certain validity, with a parent certificate and signed by a certain |
| 433 | // private key. If the latest two parameters are nil, the CA will be a root one (self-signed) |
no outgoing calls
no test coverage detected