filerenewer.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package renewal
  14. import (
  15. "crypto"
  16. "crypto/x509"
  17. certutil "k8s.io/client-go/util/cert"
  18. "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
  19. )
  20. // FileRenewer define a certificate renewer implementation that uses given CA cert and key for generating new certficiates
  21. type FileRenewer struct {
  22. caCert *x509.Certificate
  23. caKey crypto.Signer
  24. }
  25. // NewFileRenewer returns a new certificate renewer that uses given CA cert and key for generating new certficiates
  26. func NewFileRenewer(caCert *x509.Certificate, caKey crypto.Signer) *FileRenewer {
  27. return &FileRenewer{
  28. caCert: caCert,
  29. caKey: caKey,
  30. }
  31. }
  32. // Renew a certificate using a given CA cert and key
  33. func (r *FileRenewer) Renew(cfg *certutil.Config) (*x509.Certificate, crypto.Signer, error) {
  34. return pkiutil.NewCertAndKey(r.caCert, r.caKey, cfg)
  35. }