filerenewer.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
  18. )
  19. // FileRenewer define a certificate renewer implementation that uses given CA cert and key for generating new certficiates
  20. type FileRenewer struct {
  21. caCert *x509.Certificate
  22. caKey crypto.Signer
  23. }
  24. // NewFileRenewer returns a new certificate renewer that uses given CA cert and key for generating new certficiates
  25. func NewFileRenewer(caCert *x509.Certificate, caKey crypto.Signer) *FileRenewer {
  26. return &FileRenewer{
  27. caCert: caCert,
  28. caKey: caKey,
  29. }
  30. }
  31. // Renew a certificate using a given CA cert and key
  32. func (r *FileRenewer) Renew(cfg *pkiutil.CertConfig) (*x509.Certificate, crypto.Signer, error) {
  33. return pkiutil.NewCertAndKey(r.caCert, r.caKey, cfg)
  34. }