Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certificate validation for RSA is optional #226

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions xmlenc/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func getCiphertext(encryptedKey *etree.Element) ([]byte, error) {
return ciphertext, nil
}

func validateRSAKey(key interface{}, encryptedKey *etree.Element) (*rsa.PrivateKey, error) {
func validateRSAKeyIfPresent(key interface{}, encryptedKey *etree.Element) (*rsa.PrivateKey, error) {
rsaKey, ok := key.(*rsa.PrivateKey)
if !ok {
return nil, errors.New("expected key to be a *rsa.PrivateKey")
Expand Down Expand Up @@ -110,8 +110,6 @@ func validateRSAKey(key interface{}, encryptedKey *etree.Element) (*rsa.PrivateK
}
} else if el = encryptedKey.FindElement("./KeyInfo/X509Data/X509IssuerSerial"); el != nil {
// TODO: determine how to validate the issuer serial information
} else {
return nil, ErrCannotFindRequiredElement("X509Certificate or X509IssuerSerial")
}
return rsaKey, nil
}
2 changes: 1 addition & 1 deletion xmlenc/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (e RSA) Encrypt(certificate interface{}, plaintext []byte) (*etree.Element,

// Decrypt implements Decryptor. `key` must be an *rsa.PrivateKey.
func (e RSA) Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
rsaKey, err := validateRSAKey(key, ciphertextEl)
rsaKey, err := validateRSAKeyIfPresent(key, ciphertextEl)
if err != nil {
return nil, err
}
Expand Down