Skip to content

Commit

Permalink
Merge pull request #11837 from johngmyers/weaken-signer
Browse files Browse the repository at this point in the history
Weaken some interfaces
  • Loading branch information
k8s-ci-robot authored Jun 23, 2021
2 parents 82c050c + 5687b0d commit 698a187
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/model/awsmodel/oidc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// OIDCProviderBuilder configures IAM OIDC Provider
type OIDCProviderBuilder struct {
*AWSModelContext
KeyStore fi.CAStore
KeyStore fi.Keystore
Lifecycle fi.Lifecycle
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/pki/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package pki

import (
"bytes"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
Expand All @@ -42,7 +41,7 @@ func TestGenerateCertificate(t *testing.T) {

{
var b bytes.Buffer
pkData, err := x509.MarshalPKIXPublicKey(key.Key.(*rsa.PrivateKey).Public())
pkData, err := x509.MarshalPKIXPublicKey(key.Key.Public())
require.NoError(t, err, "MarshalPKIXPublicKey")

err = pem.Encode(&b, &pem.Block{Type: "RSA PUBLIC KEY", Bytes: pkData})
Expand Down
6 changes: 1 addition & 5 deletions pkg/pki/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package pki

import (
crypto_rand "crypto/rand"
"crypto/rsa"
"crypto/x509"
"fmt"
"math/big"
Expand Down Expand Up @@ -47,10 +46,7 @@ func BuildPKISerial(timestamp int64) *big.Int {

func signNewCertificate(privateKey *PrivateKey, template *x509.Certificate, signer *x509.Certificate, signerPrivateKey *PrivateKey) (*Certificate, error) {
if template.PublicKey == nil {
rsaPrivateKey, ok := privateKey.Key.(*rsa.PrivateKey)
if ok {
template.PublicKey = rsaPrivateKey.Public()
}
template.PublicKey = privateKey.Key.Public()
}

if template.PublicKey == nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/pki/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GeneratePrivateKey() (*PrivateKey, error) {
}

type PrivateKey struct {
Key crypto.PrivateKey
Key crypto.Signer
}

func (k *PrivateKey) AsString() (string, error) {
Expand Down Expand Up @@ -177,7 +177,7 @@ func (k *PrivateKey) WriteToFile(filename string, perm os.FileMode) error {
return err
}

func parsePEMPrivateKey(pemData []byte) (crypto.PrivateKey, error) {
func parsePEMPrivateKey(pemData []byte) (crypto.Signer, error) {
for {
block, rest := pem.Decode(pemData)
if block == nil {
Expand All @@ -193,7 +193,7 @@ func parsePEMPrivateKey(pemData []byte) (crypto.PrivateKey, error) {
if err != nil {
return nil, err
}
return k.(crypto.PrivateKey), nil
return k.(crypto.Signer), nil
} else {
klog.Infof("Ignoring unexpected PEM block: %q", block.Type)
}
Expand Down
3 changes: 1 addition & 2 deletions upup/pkg/fi/nodeup/nodetasks/bootstrap_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"bytes"
"context"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"encoding/json"
Expand Down Expand Up @@ -103,7 +102,7 @@ func (b *BootstrapClientTask) Run(c *fi.Context) error {
b.keys[name] = key
}

pkData, err := x509.MarshalPKIXPublicKey(key.Key.(*rsa.PrivateKey).Public())
pkData, err := x509.MarshalPKIXPublicKey(key.Key.Public())
if err != nil {
return fmt.Errorf("marshalling public key: %v", err)
}
Expand Down

0 comments on commit 698a187

Please sign in to comment.