Both fields should be identical. The redundancy was apparently meant to defeat an obscure attack vector relying on weaknesses that existing signature algorithms do not have, and for unspecified goals. As Peter Gutmann says in his X.509 style guide, when talking about the signature
field in the TBS:
There doesn't seem to be
much use for this field, although you should check that the algorithm
identifier matches the one of the signature on the cert (if someone can forge
the signature on the cert then they can also change the inner algorithm
identifier, it's possible that this was included because of some obscure attack
where someone who could convince (broken) signature algorithm A to produce the
same signature value as (secure) algorithm B could change the outer,
unprotected algorithm identifier from B to A, but couldn't change the inner
identifier without invalidating the signature. What this would achieve is
unclear).
A sane implementation of X.509 certificate validation will use the outer field (signatureAlgorithm
) to verify the signature, and will just check afterwards that the inner signature
field matches the outer field (but failing to do that last verification will not actually harm security).