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

Erro ao validar assinatura cujo atributo 1.2.840.113549.1.9.5 (signing-time) está no formato GeneralizedTime e não UTCTime #401

Open
tobiaspetry opened this issue Jan 24, 2024 · 2 comments
Labels
Milestone

Comments

@tobiaspetry
Copy link

Ao tentar validar um arquivo assinado cuja assinatura tem o atributo signing-time (OID 1.2.840.113549.1.9.5) no formato GeneralizedTime, que possui 4 dígitos para o ano, é lançada uma exceção com o seguinte erro:

class org.bouncycastle.asn1.ASN1GeneralizedTime cannot be cast to class org.bouncycastle.asn1.ASN1UTCTime

Ao que parece, a classe CAdESChecker (linha 271) supõe que este atributo estará no formato UTCTime, com dois dígitos no ano, e faz um cast explícito para a classe correspondente do bouncy castle:

dataHora = (((ASN1UTCTime) timeAttribute.getAttrValues().getObjectAt(0)).getDate());

Parece que o ideal seria conseguir identificar se deve fazer o cast para org.bouncycastle.asn1.ASN1GeneralizedTime ou org.bouncycastle.asn1.ASN1UTCTime, conforme o tipo do objeto em runtime, pois ambos têm um método getDate() disponível.

@esaito
Copy link
Member

esaito commented Jan 25, 2024

Poderia anexar um documento com essa característica para que possamos testar e corrigir o código?
Ou se preferir, pode fazer a alteração, pode ser por comentário aqui mesmo ou um pull-request.

@tobiaspetry
Copy link
Author

tobiaspetry commented Jan 25, 2024

A alteração na classe CAdESChecker seria a seguinte:

a) Adicionar o import do novo tipo:
import org.bouncycastle.asn1.ASN1GeneralizedTime;

b) Colocar o código abaixo no lugar da linha 271 (originalmente):

if (timeAttribute.getAttrValues().getObjectAt(0) instanceof ASN1UTCTime) {
dataHora = (((ASN1UTCTime) timeAttribute.getAttrValues().getObjectAt(0)).getDate());
} else {
dataHora = (((ASN1GeneralizedTime) timeAttribute.getAttrValues().getObjectAt(0)).getDate());
}

@esaito esaito added this to the 4.4.0 milestone Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants