use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class CertificateLoaderImpl method loadFromToken.
/**
* When a PIN(Personal Identification Number) was informed,
* obtain the certificate from a Token or Smartcard, defined by ICP-BRASIL with the name A3.
*
* @param pinNumber personal id number
* @return the certificate information in X509Certificate format
*/
@Override
public X509Certificate loadFromToken(String pinNumber) {
if (this.keyStore == null) {
KeyStoreLoader keyStoreLoader = KeyStoreLoaderFactory.factoryKeyStoreLoader();
this.keyStore = keyStoreLoader.getKeyStore();
}
String alias;
try {
alias = this.keyStore.aliases().nextElement();
return (X509Certificate) this.keyStore.getCertificateChain(alias)[0];
} catch (KeyStoreException e) {
throw new CertificateCoreException("", e);
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class CAdESSigner method validateTimestamp.
/**
* validade a timestampo on signature
* @param attributeTimeStamp
* @param varSignature
* @return
*/
@Deprecated
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 Utils method readContent.
/**
* Loads the contents of a file from the disk
*
* @param parmFile Filename and path
* @return The array of bytes in the file
*/
public static byte[] readContent(String parmFile) throws CertificateCoreException {
try {
File file = new File(parmFile);
InputStream is = new FileInputStream(file);
byte[] result = new byte[(int) file.length()];
is.read(result);
is.close();
return result;
} catch (FileNotFoundException ex) {
throw new CertificateCoreException(ex.getMessage(), ex.getCause());
} catch (IOException ex) {
throw new CertificateCoreException(ex.getMessage(), ex.getCause());
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class Utils method writeContent.
/**
* Writes a set of bytes to a file on disk
*
* @param content Content to be written to disk
* @param parmFile Filename and path
* @throws CertificateCoreException
*/
public static void writeContent(byte[] content, String parmFile) throws CertificateCoreException {
try {
File file = new File(parmFile);
OutputStream os = new FileOutputStream(file);
os.write(content);
os.flush();
os.close();
} catch (IOException ex) {
throw new CertificateCoreException(ex.getMessage(), ex.getCause());
}
}
use of org.demoiselle.signer.core.exception.CertificateCoreException in project signer by demoiselle.
the class TimeStampOperator method createRequest.
/**
* Creates a time stamp request using a certificate of type PKCS12
*
* @param keystoreLocation key store location
* @param pin personal identification number
* @param alias alias
* @param content content of the request
* @return request as a byte[]
* @throws CertificateCoreException exception
*/
public byte[] createRequest(String keystoreLocation, String pin, String alias, byte[] content, byte[] hash) throws CertificateCoreException {
try {
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream(keystoreLocation), pin.toCharArray());
PrivateKey pk = (PrivateKey) ks.getKey(alias, pin.toCharArray());
Certificate[] certs = ks.getCertificateChain(alias);
return this.createRequest(pk, certs, content, hash);
} catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | UnrecoverableKeyException | IOException ex) {
throw new CertificateCoreException(ex.getMessage());
}
}
Aggregations