use of com.github.zhenwei.core.asn1.ASN1Object in project candlepin by candlepin.
the class X509CRLStreamWriter method readAndReplaceTime.
/**
* Replace a time in the ASN1 with the current time.
*
* @param out
* @param tagNo
* @return the time that was replaced
* @throws IOException
*/
protected Date readAndReplaceTime(OutputStream out, int tagNo) throws IOException {
int originalLength = readLength(crlIn, null);
byte[] oldBytes = new byte[originalLength];
readFullyAndTrack(crlIn, oldBytes, null);
ASN1Object oldTime;
ASN1Object newTime;
if (tagNo == UTC_TIME) {
ASN1TaggedObject t = new DERTaggedObject(UTC_TIME, new DEROctetString(oldBytes));
oldTime = ASN1UTCTime.getInstance(t, false);
newTime = new DERUTCTime(new Date());
} else {
ASN1TaggedObject t = new DERTaggedObject(GENERALIZED_TIME, new DEROctetString(oldBytes));
oldTime = ASN1GeneralizedTime.getInstance(t, false);
newTime = new DERGeneralizedTime(new Date());
}
writeNewTime(out, newTime, originalLength);
return Time.getInstance(oldTime).getDate();
}
use of com.github.zhenwei.core.asn1.ASN1Object in project xades4j by luisgoncalves.
the class CrlExtensionsUtils method getCrlNumber.
public static BigInteger getCrlNumber(X509CRL crl) throws IOException {
byte[] crlNumEnc = crl.getExtensionValue(X509Extension.cRLNumber.getId());
BigInteger crlNum = null;
// XAdES 7.4.2: "The 'number' element is an optional hint ..."
if (crlNumEnc != null) {
ASN1Object derCrlNum = X509ExtensionUtil.fromExtensionValue(crlNumEnc);
crlNum = CRLNumber.getInstance(derCrlNum).getCRLNumber();
}
return crlNum;
}
use of com.github.zhenwei.core.asn1.ASN1Object in project pdfbox by apache.
the class CertInformationCollector method addTimestampCerts.
/**
* Processes an embedded signed timestamp, that has been placed into a signature. The
* certificates and its chain(s) will be processed the same way as the signature itself.
*
* @param signerInformation of the signature, to get unsigned attributes from it.
* @throws IOException
* @throws CertificateProccessingException
*/
private void addTimestampCerts(SignerInformation signerInformation) throws IOException, CertificateProccessingException {
AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
if (unsignedAttributes == null) {
return;
}
Attribute tsAttribute = unsignedAttributes.get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
if (tsAttribute == null) {
return;
}
ASN1Encodable obj0 = tsAttribute.getAttrValues().getObjectAt(0);
if (!(obj0 instanceof ASN1Object)) {
return;
}
ASN1Object tsSeq = (ASN1Object) obj0;
try {
CMSSignedData signedData = new CMSSignedData(tsSeq.getEncoded("DER"));
rootCertInfo.tsaCerts = new CertSignatureInformation();
processSignerStore(signedData, rootCertInfo.tsaCerts);
} catch (CMSException e) {
throw new IOException("Error parsing timestamp token", e);
}
}
use of com.github.zhenwei.core.asn1.ASN1Object in project xipki by xipki.
the class ProxyP11Slot method getPublicKey.
private PublicKey getPublicKey(P11ObjectIdentifier objectId) throws P11TokenException {
ASN1Object req = new SlotIdAndObjectId(asn1SlotId, new ObjectIdentifier(objectId));
byte[] resp = module.send(P11ProxyConstants.ACTION_GET_PUBLICKEY, req);
if (resp == null) {
return null;
}
SubjectPublicKeyInfo pkInfo = SubjectPublicKeyInfo.getInstance(resp);
try {
return KeyUtil.generatePublicKey(pkInfo);
} catch (InvalidKeySpecException ex) {
throw new P11TokenException("could not generate Public Key from SubjectPublicKeyInfo:" + ex.getMessage(), ex);
}
}
use of com.github.zhenwei.core.asn1.ASN1Object in project churchkey by tomitribe.
the class FooTest method test3.
@Ignore
@Test
public void test3() throws Exception {
final Resource resource = Resource.resource(BeginPrivateKeyTest.class.getSimpleName());
final byte[] bytes = resource.bytes("openssl-rsaprivatekey-3072.pem");
final Pem pem = Pem.parse(bytes);
{
final DerParser d1 = new DerParser(pem.getData());
final Asn1Object d1o1 = d1.readObject().assertType(Asn1Type.SEQUENCE);
{
final DerParser d2 = new DerParser(d1o1.getValue());
final Asn1Object d2o1 = d2.readObject().assertType(Asn1Type.INTEGER);
final Asn1Object d2o2 = d2.readObject().assertType(Asn1Type.SEQUENCE);
{
final DerParser d3 = new DerParser(d2o2.getValue());
final Asn1Object d3o1 = d3.readObject().assertType(Asn1Type.OBJECT_IDENTIFIER);
final Asn1Object d3o2 = d3.readObject().assertType(Asn1Type.NULL);
}
final Asn1Object d2o3 = d2.readObject().assertType(OCTET_STRING);
{
final DerParser d3 = new DerParser(d2o3.getValue());
final Asn1Object d3o1 = d3.readObject().assertType(Asn1Type.SEQUENCE);
{
final DerParser d4 = new DerParser(d3o1.getValue());
final BigInteger version = d4.readBigInteger();
final RSAPrivateCrtKey privateKey = Rsa.Private.builder().modulus(d4.readBigInteger()).publicExponent(d4.readBigInteger()).privateExponent(d4.readBigInteger()).primeP(d4.readBigInteger()).primeQ(d4.readBigInteger()).primeExponentP(d4.readBigInteger()).primeExponentQ(d4.readBigInteger()).crtCoefficient(d4.readBigInteger()).build().toKey();
final Key key1 = new Key(privateKey, Key.Type.PRIVATE, RSA, Key.Format.PEM);
System.out.println(key1);
}
}
}
}
}
Aggregations