use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class CAdESChecker method validateTimestamp.
/**
* validade a timestampo on signature
* @param attributeTimeStamp
* @param varSignature
* @return
*/
private Timestamp validateTimestamp(Attribute attributeTimeStamp, byte[] varSignature) {
try {
TimeStampOperator timeStampOperator = new TimeStampOperator();
byte[] varTimeStamp = attributeTimeStamp.getAttrValues().getObjectAt(0).toASN1Primitive().getEncoded();
TimeStampToken timeStampToken = new TimeStampToken(new CMSSignedData(varTimeStamp));
Timestamp timeStampSigner = new Timestamp(timeStampToken);
timeStampOperator.validate(varSignature, varTimeStamp, null);
return timeStampSigner;
} catch (CertificateCoreException | IOException | TSPException | CMSException e) {
throw new SignerException(e);
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class CertificateManager method load.
/**
* Load a java.security.cert.X509Certificate
* @param object destiny of load operation
*/
public void load(Object object) {
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
for (Annotation annotation : field.getAnnotations()) {
if (annotation.annotationType().isAnnotationPresent(OIDExtension.class)) {
OIDExtension oid = annotation.annotationType().getAnnotation(OIDExtension.class);
Class<? extends IOIDExtensionLoader> loaderClass = oid.loader();
try {
IOIDExtensionLoader loader = loaderClass.newInstance();
loader.load(object, field, x509);
} catch (IllegalAccessException | InstantiationException e) {
throw new CertificateCoreException(coreMessagesBundle.getString("error.initialize.attribute", field.getName()), e);
}
}
}
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class CertificateManager method load.
/**
* New Instance for a class
* @param <T> Type parameter for returned instance
* @param clazz class to be instantiated
* @return new instance of class
*/
public <T> T load(Class<T> clazz) {
T object;
try {
object = clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new CertificateCoreException(coreMessagesBundle.getString("error.new.instace", clazz.getName()), e);
}
load(object);
return object;
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class ICPBrasilExtensionLoader method load.
@Override
public void load(Object object, Field field, X509Certificate x509) {
if (field.isAnnotationPresent(ICPBrasilExtension.class)) {
ICPBrasilExtension annotation = field.getAnnotation(ICPBrasilExtension.class);
Object keyValue;
try {
BasicCertificate cert = new BasicCertificate(x509);
switch(annotation.type()) {
case CPF:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getCPF();
} else {
keyValue = "";
}
break;
case CNPJ:
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getCNPJ();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getCNPJ();
} else {
keyValue = "";
}
}
break;
case PIS_PASEP:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getNis();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getNis();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getNis();
} else {
keyValue = "";
}
}
}
break;
case NIS:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getNis();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getNis();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getNis();
} else {
keyValue = "";
}
}
}
break;
case CEI:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getCEI();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getCEI();
} else {
keyValue = "";
}
}
break;
case CEI_PESSOA_FISICA:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getCEI();
} else {
keyValue = "";
}
break;
case CEI_PESSOA_JURIDICA:
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getCEI();
} else {
keyValue = "";
}
break;
case NAME:
keyValue = cert.getNome();
break;
case NAME_RESPONSIBLE_PESSOA_JURIDICA:
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getResponsibleName();
} else {
keyValue = "";
}
break;
case CPF_RESPONSIBLE_PESSOA_JURIDICA:
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getResponsibleCPF();
} else {
keyValue = "";
}
break;
case EMAIL:
keyValue = cert.getEmail();
break;
case BIRTH_DATE:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getBirthDate();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getBirthDate();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getBirthDate().toString();
} else {
keyValue = "";
}
}
}
break;
case ID_NUMBER:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getRg();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getRg();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getRg();
} else {
keyValue = "";
}
}
}
break;
case IDENTITY_DISPATCHER:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getIssuingAgencyRg();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getIssuingAgencyRg();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getIssuingAgencyRg();
} else {
keyValue = "";
}
}
}
break;
case UF_IDENTITY_DISPATCHER:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getUfIssuingAgencyRg();
} else {
if (cert.hasCertificatePJ()) {
keyValue = cert.getICPBRCertificatePJ().getUfIssuingAgencyRg();
} else {
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getUfIssuingAgencyRg();
} else {
keyValue = "";
}
}
}
break;
case NUMBER_ELECTORAL_DOCUMENT:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getElectoralDocument();
} else {
keyValue = "";
}
break;
case ZONE_ELECTORAL_DOCUMENT:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getZoneElectoralDocument();
} else {
keyValue = "";
}
break;
case SECTION_ELECTORAL_DOCUMENT:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getSectionElectoralDocument();
} else {
keyValue = "";
}
break;
case CITY_ELECTORAL_DOCUMENT:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getCityElectoralDocument();
} else {
keyValue = "";
}
break;
case UF_ELECTORAL_DOCUMENT:
if (cert.hasCertificatePF()) {
keyValue = cert.getICPBRCertificatePF().getUFElectoralDocument();
} else {
keyValue = "";
}
break;
case BUSINESS_NAME:
if (cert.hasCertificateEquipment()) {
keyValue = cert.getICPBRCertificateEquipment().getCorporateName();
} else {
keyValue = "";
}
break;
case CERTIFICATE_TYPE:
if (cert.hasCertificatePF()) {
keyValue = "PF";
} else {
if (cert.hasCertificatePJ()) {
keyValue = "PJ";
} else {
if (cert.hasCertificateEquipment()) {
keyValue = "EA";
} else {
keyValue = "";
}
}
}
break;
case CERTIFICATE_LEVEL:
keyValue = cert.getCertificateLevel();
break;
default:
throw new CertificateCoreException(coreMessagesBundle.getString("error.field.not.implemented", annotation.type()));
}
try {
field.setAccessible(true);
field.set(object, keyValue);
} catch (Exception e) {
throw new CertificateCoreException(coreMessagesBundle.getString("error.load.value.field", field.getName()), e);
}
} catch (Exception e) {
throw new CertificateCoreException(coreMessagesBundle.getString("error.get.value.field", field.getName()), e);
}
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class TimeStampGeneratorSelector method getPriority.
/**
* verify if have a @Priotity annotation
* @param clazz
* @return
*/
private static int getPriority(TimeStampGenerator clazz) {
int result = Priority.MAX_PRIORITY;
Priority priority = clazz.getClass().getAnnotation(Priority.class);
if (priority != null) {
result = priority.value();
}
if (priority == null) {
new CertificateCoreException(coreMessagesBundle.getString("error.priority.null", clazz.getClass().getName()));
}
return result;
}
Aggregations