Skip to content

Conversation

@timlegge
Copy link
Contributor

libtom (CryptX <= 0.077) does not support specifying the a MGF and OEAPparam digest that differ.

This sorts out most of the issues. Thinking now I suspect that it will still allow you to generate XML that will not properly decrypt but basically, the two must use the same hash in both

@timlegge timlegge force-pushed the mgf1_issues branch 3 times, most recently from 60768bd to 544cb81 Compare March 16, 2023 22:00
timlegge added a commit that referenced this pull request Mar 19, 2023
    [ Major change since 0.08 ]

    @NGEfreak asked if Crypt::Random could be replaced with Crypt::PRNG
    to eliminate the need for pari which requires network connectivity.
    Makes sense because CryptX is already a dependency.

    Known issue:

    rsa-oaep with different digests for the MGF and the label is broken and
    was broken from the initial implementation.

    This is being resolved via #4

    - f04a0d5 Increment version for official release
    - 33cccb7 v0.10
@timlegge timlegge force-pushed the mgf1_issues branch 4 times, most recently from ad69a86 to 544b250 Compare March 25, 2023 01:49
my $self = shift;
my $method = shift;

return if ! defined $method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same exists logic.

my $self = shift;
my $method = shift;

return if ! defined $method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same exists logic.

my $self = shift;
my $method = shift;

return if ! defined $method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do an exists later on, shouldn't it either croak/die/warn about method not being specified or use the default which is used later on?

So, method having value '' or 0 is fine, but undef isn't. I would perhaps do $method //= ''; and continue with the function. Or just croak if it is undef.

my $self = shift;
my $method = shift;

return if ! defined $method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same exists logic.

$method{OAEPparams} = $keyinfo->[0]->findvalue('//xenc:EncryptedKey/xenc:EncryptionMethod/xenc:OAEPparams', $context);
$method{MGF} = $keyinfo->[0]->findvalue('//xenc:EncryptedKey/xenc:EncryptionMethod/xenc:MGF/@Algorithm', $context);

if ($method{Algorithm} eq 'http://www.w3.org/2009/xmlenc11#rsa-oaep') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L511-519 and 529-540 are the same. Perhaps make a function for it?

}
elsif ($keymethod->{Algorithm} eq 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p') {
return $self->{key_obj}->decrypt($encryptedkey, 'oaep', 'SHA1', decode_base64($keymethod->{OAEPparams}));
my $oaep_params = defined $keymethod->{OAEPparams} ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also almost the same as the additions starting at 652.

}
elsif ($keymethod eq 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p') {
${$key} = $rsa_pub->encrypt(${$key}, 'oaep', 'SHA1', $self->{oaep_params});
my $oaep_label_hash = (defined $self->{oaep_label_hash} && $self->{oaep_label_hash} ne '') ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

683 and below matches 692 and below as well.

@timlegge
Copy link
Contributor Author

Closing in favour of #12 which is a rebase and seems to fix most of these issues

@timlegge timlegge closed this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants