use of com.github.zhenwei.core.asn1.pkcs.SignedData in project XobotOS by xamarin.
the class PKIXCertPath method getEncoded.
/**
* Returns the encoded form of this certification path, using
* the specified encoding.
*
* @param encoding the name of the encoding to use
* @return the encoded bytes
* @exception CertificateEncodingException if an encoding error
* occurs or the encoding requested is not supported
*
**/
public byte[] getEncoded(String encoding) throws CertificateEncodingException {
if (encoding.equalsIgnoreCase("PkiPath")) {
ASN1EncodableVector v = new ASN1EncodableVector();
ListIterator iter = certificates.listIterator(certificates.size());
while (iter.hasPrevious()) {
v.add(toASN1Object((X509Certificate) iter.previous()));
}
return toDEREncoded(new DERSequence(v));
} else if (encoding.equalsIgnoreCase("PKCS7")) {
ContentInfo encInfo = new ContentInfo(PKCSObjectIdentifiers.data, null);
ASN1EncodableVector v = new ASN1EncodableVector();
for (int i = 0; i != certificates.size(); i++) {
v.add(toASN1Object((X509Certificate) certificates.get(i)));
}
SignedData sd = new SignedData(new DERInteger(1), new DERSet(), encInfo, new DERSet(v), null, new DERSet());
return toDEREncoded(new ContentInfo(PKCSObjectIdentifiers.signedData, sd));
} else // BEGIN android-removed
// else if (encoding.equalsIgnoreCase("PEM"))
// {
// ByteArrayOutputStream bOut = new ByteArrayOutputStream();
// PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut));
//
// try
// {
// for (int i = 0; i != certificates.size(); i++)
// {
// pWrt.writeObject(certificates.get(i));
// }
//
// pWrt.close();
// }
// catch (Exception e)
// {
// throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
// }
//
// return bOut.toByteArray();
// }
// END android-removed
{
throw new CertificateEncodingException("unsupported encoding: " + encoding);
}
}
use of com.github.zhenwei.core.asn1.pkcs.SignedData in project webcert by sklintyg.
the class ASN1UtilImpl method getValue.
@Override
public String getValue(String identifier, InputStream asn1Signature) {
ByteArrayInputStream bais = null;
ASN1InputStream asn1InputStream = null;
try {
bais = convertStream(asn1Signature);
asn1InputStream = new ASN1InputStream(bais);
DERObject obj = asn1InputStream.readObject();
ContentInfo contentInfo = ContentInfo.getInstance(obj);
// Extract certificates
SignedData signedData = SignedData.getInstance(contentInfo.getContent());
return findInCertificate(identifier, (DERObject) signedData.getCertificates().getObjectAt(0));
} catch (IOException e) {
LOG.error("Error parsing signature: {}", e.getMessage());
throw new IllegalStateException(e);
} finally {
IOUtils.closeQuietly(bais);
IOUtils.closeQuietly(asn1InputStream);
}
}
use of com.github.zhenwei.core.asn1.pkcs.SignedData in project BiglyBT by BiglySoftware.
the class JDKX509CertificateFactory method readDERCertificate.
private Certificate readDERCertificate(InputStream in) throws IOException {
DERInputStream dIn = new DERInputStream(in);
ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
if (seq.size() > 1 && seq.getObjectAt(0) instanceof DERObjectIdentifier) {
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) {
sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true));
return new X509CertificateObject(X509CertificateStructure.getInstance(sData.getCertificates().getObjectAt(sDataObjectCount++)));
}
}
return new X509CertificateObject(X509CertificateStructure.getInstance(seq));
}
use of com.github.zhenwei.core.asn1.pkcs.SignedData in project BiglyBT by BiglySoftware.
the class JDKX509CertificateFactory method readPKCS7Certificate.
/**
* read in a BER encoded PKCS7 certificate.
*/
private Certificate readPKCS7Certificate(InputStream in) throws IOException {
BERInputStream dIn = new BERInputStream(in);
ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
if (seq.size() > 1 && seq.getObjectAt(0) instanceof DERObjectIdentifier) {
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) {
sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true));
return new X509CertificateObject(X509CertificateStructure.getInstance(sData.getCertificates().getObjectAt(sDataObjectCount++)));
}
}
return new X509CertificateObject(X509CertificateStructure.getInstance(seq));
}
use of com.github.zhenwei.core.asn1.pkcs.SignedData in project LinLong-Java by zhenwei1108.
the class CMSSignedData method addDigestAlgorithm.
/**
* Return a new CMSSignedData which guarantees to have the passed in digestAlgorithm in it.
*
* @param signedData the signed data object to be used as a base.
* @param digestAlgorithm the digest algorithm to be added to the signed data.
* @return a new signed data object.
*/
public static CMSSignedData addDigestAlgorithm(CMSSignedData signedData, AlgorithmIdentifier digestAlgorithm) {
Set<AlgorithmIdentifier> digestAlgorithms = signedData.getDigestAlgorithmIDs();
AlgorithmIdentifier digestAlg = CMSSignedHelper.INSTANCE.fixDigestAlgID(digestAlgorithm, dgstAlgFinder);
//
if (digestAlgorithms.contains(digestAlg)) {
return signedData;
}
//
// copy
//
CMSSignedData cms = new CMSSignedData(signedData);
//
// build up the new set
//
Set<AlgorithmIdentifier> digestAlgs = new HashSet<AlgorithmIdentifier>();
Iterator it = digestAlgorithms.iterator();
while (it.hasNext()) {
digestAlgs.add(CMSSignedHelper.INSTANCE.fixDigestAlgID((AlgorithmIdentifier) it.next(), dgstAlgFinder));
}
digestAlgs.add(digestAlg);
ASN1Set digests = CMSUtils.convertToBERSet(digestAlgs);
ASN1Sequence sD = (ASN1Sequence) signedData.signedData.toASN1Primitive();
ASN1EncodableVector vec = new ASN1EncodableVector();
//
// signers are the last item in the sequence.
//
// version
vec.add(sD.getObjectAt(0));
vec.add(digests);
for (int i = 2; i != sD.size(); i++) {
vec.add(sD.getObjectAt(i));
}
cms.signedData = SignedData.getInstance(new BERSequence(vec));
//
// replace the contentInfo with the new one
//
cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);
return cms;
}
Aggregations