private String asString(ASN1Primitive primitive) { if (primitive == null || primitive instanceof ASN1Null) { return ""; } if (primitive instanceof ASN1String) { return ((ASN1String) primitive).getString(); } if (primitive instanceof DERUTCTime) { return ((DERUTCTime) primitive).getAdjustedTime(); } if (primitive instanceof DERGeneralizedTime) { return ((DERGeneralizedTime) primitive).getTime(); } if (primitive instanceof ASN1ObjectIdentifier) { switch (((ASN1ObjectIdentifier) primitive).getId()) { case "1.3.6.1.5.5.7.8.5": return "xmppAddr"; default: return primitive.toString(); } } return primitive.toString(); } }
@Override public ASN1Set getValue() { SigningTime attribute = (SigningTime) super.getAttribute(); Date date = attribute.getValue(); return new DERSet(new DERUTCTime(date)); }
DERSet derSet = (DERSet) valorDateSigner.getDERObject(); DERUTCTime time = (DERUTCTime) derSet.getObjectAt(0); dataSigner = time.getAdjustedDate(); } catch (Throwable error) {
@Override public void parse(ASN1Primitive derObject) { if (derObject instanceof ASN1GeneralizedTime) { ASN1GeneralizedTime derGeneralizedTime = (ASN1GeneralizedTime) derObject; try { this.setTime(derGeneralizedTime.getDate()); } catch (ParseException ex) { this.setTime(null); } } else if (derObject instanceof DERUTCTime) { DERUTCTime derUTCTime = (DERUTCTime) derObject; try { this.setTime(derUTCTime.getDate()); } catch (ParseException exception) { this.setTime(null); } } }
/** * Creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. * * @param time a date object representing the time of interest. */ public Time( Date time) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
DERSet derSet = (DERSet) valorDateSigner.getDERObject(); DERUTCTime time = (DERUTCTime) derSet.getObjectAt(0); dataSigner = time.getAdjustedDate(); } catch (ParseException ex) {
/** * Creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. * * @param time a date object representing the time of interest. */ public Time( Date time) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
DERSet derSet = (DERSet) valorDateSigner.getDERObject(); DERUTCTime time = (DERUTCTime) derSet.getObjectAt(0); dataSigner = time.getAdjustedDate(); } catch (Throwable error) {
private String asString(ASN1Primitive primitive) { if (primitive == null || primitive instanceof ASN1Null) { return ""; } if (primitive instanceof ASN1String) { return ((ASN1String) primitive).getString(); } if (primitive instanceof DERUTCTime) { return ((DERUTCTime) primitive).getAdjustedTime(); } if (primitive instanceof DERGeneralizedTime) { return ((DERGeneralizedTime) primitive).getTime(); } if (primitive instanceof ASN1ObjectIdentifier) { switch (((ASN1ObjectIdentifier) primitive).getId()) { case "1.3.6.1.5.5.7.8.5": return "xmppAddr"; default: return primitive.toString(); } } return primitive.toString(); } }
/** * Creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. * * @param time a date object representing the time of interest. */ public Time( Date time) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
DERSet derSet = (DERSet) valorDateSigner.getDERObject(); DERUTCTime time = (DERUTCTime) derSet.getObjectAt(0); dataSigner = time.getAdjustedDate(); } catch (Throwable error) { throw new SignerException("SigningTime error", error);
/** * Creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. * * @param time a date object representing the time of interest. */ public Time( Date time) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
DERSet derSet = (DERSet) valorDateSigner.getDERObject(); DERUTCTime time = (DERUTCTime) derSet.getObjectAt(0); dataSigner = time.getAdjustedDate(); } catch (ParseException ex) { throw new SignerException("SigningTime error", ex);
/** * Creates a time object from a given date and locale - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public Time( Date time, Locale locale) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
/** * Creates a time object from a given date and locale - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public Time( Date time, Locale locale) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
/** * Creates a time object from a given date and locale - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public Time( Date time, Locale locale) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
/** * Creates a time object from a given date and locale - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public Time( Date time, Locale locale) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
final Attribute signingAttribute = new Attribute(CMSAttributes.signingTime, new DERSet(new DERUTCTime(new Date()))); signedAttributes.add(signingAttribute);
public static byte[] createSignature(byte[] digest, SMimeDigestMethod digestMethod, PrivateKey privateKey, X509Certificate certificate) throws OxalisSecurityException { try { ASN1EncodableVector signedAttributes = new ASN1EncodableVector(); signedAttributes.add(new Attribute(CMSAttributes.contentType, new DERSet(digestMethod.getOid()))); signedAttributes.add(new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(digest)))); signedAttributes.add(new Attribute(CMSAttributes.signingTime, new DERSet(new DERUTCTime(new Date())))); AttributeTable signedAttributesTable = new AttributeTable(signedAttributes); signedAttributesTable.toASN1EncodableVector(); DefaultSignedAttributeTableGenerator signedAttributeGenerator = new DefaultSignedAttributeTableGenerator(signedAttributesTable); /* Build the SignerInfo generator builder, that will build the generator... that will generate the SignerInformation... */ SignerInfoGeneratorBuilder signerInfoBuilder = new SignerInfoGeneratorBuilder( new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build()); signerInfoBuilder.setSignedAttributeGenerator(signedAttributeGenerator); CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); JcaContentSignerBuilder contentSigner = new JcaContentSignerBuilder(digestMethod.getMethod()).setProvider(BouncyCastleProvider.PROVIDER_NAME); generator.addSignerInfoGenerator(signerInfoBuilder.build( contentSigner.build(privateKey), new X509CertificateHolder(certificate.getEncoded()))); generator.addCertificates(new JcaCertStore(Collections.singletonList(certificate))); return generator.generate(new CMSAbsentContent()).getEncoded(); } catch (CMSException | IOException | CertificateEncodingException | OperatorCreationException e) { throw new OxalisSecurityException(e.getMessage(), e); } } }
public static byte[] createSignature(byte[] digest, SMimeDigestMethod digestMethod, PrivateKey privateKey, X509Certificate certificate) throws OxalisSecurityException { try { ASN1EncodableVector signedAttributes = new ASN1EncodableVector(); signedAttributes.add(new Attribute(CMSAttributes.contentType, new DERSet(digestMethod.getOid()))); signedAttributes.add(new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(digest)))); signedAttributes.add(new Attribute(CMSAttributes.signingTime, new DERSet(new DERUTCTime(new Date())))); AttributeTable signedAttributesTable = new AttributeTable(signedAttributes); signedAttributesTable.toASN1EncodableVector(); DefaultSignedAttributeTableGenerator signedAttributeGenerator = new DefaultSignedAttributeTableGenerator(signedAttributesTable); /* Build the SignerInfo generator builder, that will build the generator... that will generate the SignerInformation... */ SignerInfoGeneratorBuilder signerInfoBuilder = new SignerInfoGeneratorBuilder( new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build()); signerInfoBuilder.setSignedAttributeGenerator(signedAttributeGenerator); CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); JcaContentSignerBuilder contentSigner = new JcaContentSignerBuilder(digestMethod.getMethod()).setProvider(BouncyCastleProvider.PROVIDER_NAME); generator.addSignerInfoGenerator(signerInfoBuilder.build( contentSigner.build(privateKey), new X509CertificateHolder(certificate.getEncoded()))); generator.addCertificates(new JcaCertStore(Collections.singletonList(certificate))); return generator.generate(new CMSAbsentContent()).getEncoded(); } catch (CMSException | IOException | CertificateEncodingException | OperatorCreationException e) { throw new OxalisSecurityException(e.getMessage(), e); } } }