Skip to content

RSA key import can succeed with an invalid/undefined version #803

Description

@headscott

In rsa_import_pkcs1, after handling version == 0 and version == 1, there is no fallback case:

Affected Code
src/pk/rsa/rsa_import.c:57-78

if (version == 0) {
    ...
} else if (version == 1) {
    ...
}
err = CRYPT_OK;

An unsupported version or a not set version retaining its initial value (-1) could therefore fall through and return CRYPT_OK even though no key fields were decoded. The key could be uninitialized.

Suggested Fix
add this branch:

} else {
   err = CRYPT_PK_INVALID_TYPE;
   goto LBL_OUT;
}

This ensures that rsa_import_pkcs1 never reports successful key import unless a supported RSA key version was actually decoded.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions