Java Code Examples for org.bouncycastle.asn1.DERTaggedObject
The following examples show how to use
org.bouncycastle.asn1.DERTaggedObject.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: hadoop-ozone Author: apache File: TestCertificateSignRequest.java License: Apache License 2.0 | 6 votes |
private void verifyServiceId(Extensions extensions) { GeneralNames gns = GeneralNames.fromExtensions( extensions, Extension.subjectAlternativeName); GeneralName[] names = gns.getNames(); for(int i=0; i < names.length; i++) { if(names[i].getTagNo() == GeneralName.otherName) { ASN1Encodable asn1Encodable = names[i].getName(); Iterator iterator = ((DLSequence) asn1Encodable).iterator(); while (iterator.hasNext()) { Object o = iterator.next(); if (o instanceof ASN1ObjectIdentifier) { String oid = o.toString(); Assert.assertEquals(oid, "2.16.840.1.113730.3.1.34"); } if (o instanceof DERTaggedObject) { String serviceName = ((DERTaggedObject)o).getObject().toString(); Assert.assertEquals(serviceName, "OzoneMarketingCluster003"); } } } } }
Example #2
Source Project: jcifs Author: codelibs File: KerberosRelevantAuthData.java License: GNU Lesser General Public License v2.1 | 6 votes |
public KerberosRelevantAuthData ( byte[] token, Map<Integer, KerberosKey> keys ) throws PACDecodingException { DLSequence authSequence; try { try ( ASN1InputStream stream = new ASN1InputStream(new ByteArrayInputStream(token)) ) { authSequence = ASN1Util.as(DLSequence.class, stream); } } catch ( IOException e ) { throw new PACDecodingException("Malformed kerberos ticket", e); } this.authorizations = new ArrayList<>(); Enumeration<?> authElements = authSequence.getObjects(); while ( authElements.hasMoreElements() ) { DLSequence authElement = ASN1Util.as(DLSequence.class, authElements); ASN1Integer authType = ASN1Util.as(ASN1Integer.class, ASN1Util.as(DERTaggedObject.class, authElement, 0)); DEROctetString authData = ASN1Util.as(DEROctetString.class, ASN1Util.as(DERTaggedObject.class, authElement, 1)); this.authorizations.addAll(KerberosAuthData.parse(authType.getValue().intValue(), authData.getOctets(), keys)); } }
Example #3
Source Project: signer Author: demoiselle File: PolicyInfo.java License: GNU Lesser General Public License v3.0 | 6 votes |
@Override public void parse(ASN1Primitive derObject) { ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject); ASN1Primitive firstObject = derSequence.getObjectAt(0).toASN1Primitive(); this.policyName = new DirectoryString(firstObject.toString()); ASN1Primitive secondObject = derSequence.getObjectAt(1).toASN1Primitive(); String fieldOfApplication = secondObject.toString(); this.fieldOfApplication = new DirectoryString(fieldOfApplication); this.signingPeriod = new SigningPeriod(); this.signingPeriod.parse(derSequence.getObjectAt(2).toASN1Primitive()); int indice = 3; ASN1Primitive revocationObject = derSequence.getObjectAt(indice).toASN1Primitive(); if (!(secondObject instanceof DERTaggedObject)) { indice = 4; } if (indice == 3) { this.revocationDate = new Time(); this.revocationDate.parse(revocationObject); } }
Example #4
Source Project: signer Author: demoiselle File: BasicCertificate.java License: GNU Lesser General Public License v3.0 | 6 votes |
/** * * * @return the authority key identifier of a certificate * */ public String getAuthorityKeyIdentifier() { // TODO - Precisa validar este metodo com a RFC try { DLSequence sequence = (DLSequence) getExtensionValue(Extension.authorityKeyIdentifier.getId()); if (sequence == null || sequence.size() == 0) { return null; } DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(0); DEROctetString oct = (DEROctetString) taggedObject.getObject(); return toString(oct.getOctets()); } catch (Exception error) { logger.info(error.getMessage()); return null; } }
Example #5
Source Project: ComplianceTester Author: iNPUTmice File: XmppDomainVerifier.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
private static OtherName parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new OtherName(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new OtherName(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example #6
Source Project: jcifs-ng Author: AgNO3 File: KerberosRelevantAuthData.java License: GNU Lesser General Public License v2.1 | 6 votes |
public KerberosRelevantAuthData ( byte[] token, Map<Integer, KerberosKey> keys ) throws PACDecodingException { DLSequence authSequence; try { try ( ASN1InputStream stream = new ASN1InputStream(new ByteArrayInputStream(token)) ) { authSequence = ASN1Util.as(DLSequence.class, stream); } } catch ( IOException e ) { throw new PACDecodingException("Malformed kerberos ticket", e); } this.authorizations = new ArrayList<>(); Enumeration<?> authElements = authSequence.getObjects(); while ( authElements.hasMoreElements() ) { DLSequence authElement = ASN1Util.as(DLSequence.class, authElements); ASN1Integer authType = ASN1Util.as(ASN1Integer.class, ASN1Util.as(DERTaggedObject.class, authElement, 0)); DEROctetString authData = ASN1Util.as(DEROctetString.class, ASN1Util.as(DERTaggedObject.class, authElement, 1)); this.authorizations.addAll(KerberosAuthData.parse(authType.getValue().intValue(), authData.getOctets(), keys)); } }
Example #7
Source Project: dss Author: esig File: CAdESTimestampDataBuilder.java License: GNU Lesser General Public License v2.1 | 6 votes |
private byte[] getCertificateDataBytes(final SignedData signedData) throws IOException { byte[] certificatesBytes = null; final ASN1Set certificates = signedData.getCertificates(); if (certificates != null) { /* * In order to calculate correct message imprint it is important * to use the correct encoding. */ if (certificates instanceof BERSet) { certificatesBytes = new BERTaggedObject(false, 0, new BERSequence(certificates.toArray())).getEncoded(); } else { certificatesBytes = new DERTaggedObject(false, 0, new DERSequence(certificates.toArray())).getEncoded(); } if (LOG.isTraceEnabled()) { LOG.trace("Certificates: {}", DSSUtils.toHex(certificatesBytes)); } } if (LOG.isDebugEnabled()) { LOG.debug("Certificates are not present in the SignedData."); } return certificatesBytes; }
Example #8
Source Project: dss Author: esig File: CAdESTimestampDataBuilder.java License: GNU Lesser General Public License v2.1 | 6 votes |
private byte[] getCRLDataBytes(final SignedData signedData) throws IOException { byte[] crlBytes = null; final ASN1Set crLs = signedData.getCRLs(); if (crLs != null) { if (signedData.getCRLs() instanceof BERSet) { crlBytes = new BERTaggedObject(false, 1, new BERSequence(crLs.toArray())).getEncoded(); } else { crlBytes = new DERTaggedObject(false, 1, new DERSequence(crLs.toArray())).getEncoded(); } if (LOG.isTraceEnabled()) { LOG.trace("CRLs: {}", DSSUtils.toHex(crlBytes)); } } if (LOG.isDebugEnabled()) { LOG.debug("CRLs are not present in the SignedData."); } return crlBytes; }
Example #9
Source Project: dss Author: esig File: CAdESTimestampSource.java License: GNU Lesser General Public License v2.1 | 6 votes |
private List<TimestampedReference> getSignedDataOCSPReferences(List<DEROctetString> crlsHashList, final DigestAlgorithm digestAlgorithm, final String timestampId) { List<TimestampedReference> references = new ArrayList<>(); if (signatureOCSPSource instanceof CMSOCSPSource) { CMSOCSPSource cmsocspSource = (CMSOCSPSource) signatureOCSPSource; for (EncapsulatedRevocationTokenIdentifier token : cmsocspSource.getCMSSignedDataRevocationBinaries()) { OCSPResponseBinary binary = (OCSPResponseBinary) token; // Compute DERTaggedObject with the same algorithm how it was created // See: org.bouncycastle.cms.CMSUtils getOthersFromStore() OtherRevocationInfoFormat otherRevocationInfoFormat = new OtherRevocationInfoFormat(binary.getAsn1ObjectIdentifier(), DSSASN1Utils.toASN1Primitive(binary.getBasicOCSPRespContent())); // false value specifies an implicit encoding method DERTaggedObject derTaggedObject = new DERTaggedObject(false, 1, otherRevocationInfoFormat); if (isDigestValuePresent(DSSUtils.digest(digestAlgorithm, DSSASN1Utils.getDEREncoded(derTaggedObject)), crlsHashList)) { addReference(references, binary, TimestampedObjectType.REVOCATION); } else { LOG.warn("The OCSP Token with id [{}] was not included to the message imprint of timestamp with id [{}] " + "or was added to the CMS SignedData after this ArchiveTimestamp!", binary.asXmlId(), timestampId); } } } return references; }
Example #10
Source Project: dss Author: esig File: SignerAttributeV2.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * <pre> * SignerAttributeV2 ::= SEQUENCE { * claimedAttributes [0] ClaimedAttributes OPTIONAL, * certifiedAttributesV2 [1] CertifiedAttributesV2 OPTIONAL, * signedAssertions [2] SignedAssertions OPTIONAL * } * </pre> */ @Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); for (int i = 0; i != values.length; i++) { if (values[i] instanceof Attribute[]) { v.add(new DERTaggedObject(0, new DERSequence((Attribute[]) values[i]))); } else if (values[i] instanceof CertifiedAttributesV2) { v.add(new DERTaggedObject(1, (CertifiedAttributesV2) values[i])); } else if (values[i] instanceof SignedAssertions) { v.add(new DERTaggedObject(2, (SignedAssertions) values[i])); } else { LOG.warn("Unsupported type {}", values[i]); } } return new DERSequence(v); }
Example #11
Source Project: dss Author: esig File: RevocationInfoArchival.java License: GNU Lesser General Public License v2.1 | 6 votes |
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(3); if (null != this.crlVals) { v.add(new DERTaggedObject(true, 0, this.crlVals)); } if (null != this.ocspVals) { v.add(new DERTaggedObject(true, 1, this.ocspVals)); } if (null != this.otherRevVals) { v.add(new DERTaggedObject(true, 2, this.otherRevVals.toASN1Primitive())); } return new DERSequence(v); }
Example #12
Source Project: Pix-Art-Messenger Author: kriztan File: XmppDomainVerifier.java License: GNU General Public License v3.0 | 6 votes |
private static Pair<String, String> parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new Pair<>(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new Pair<>(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example #13
Source Project: InflatableDonkey Author: horrorho File: PublicKeyInfo.java License: MIT License | 6 votes |
@Override public ASN1Primitive toASN1Primitive() { DERTaggedObject signatureInfoEncodable = signatureInfo.map(e -> new DERTaggedObject(SIGNATURE_INFO, e)) .orElse(null); DERTaggedObject signatureEncodable = signature.map(e -> new DERTaggedObject(SIGNATURE, e)) .orElse(null); DERTaggedObject extendedSignatureEncodable = extendedSignature.map(e -> new DERTaggedObject(EXTENDED_SIGNATURE, e)) .orElse(null); ASN1EncodableVector vector = DER.vector( new ASN1Integer(service), new ASN1Integer(type), new DEROctetString(key()), signatureInfoEncodable, signatureEncodable, extendedSignatureEncodable); DERSequence sequence = new DERSequence(vector); return DER.toApplicationSpecific(APPLICATION_TAG, sequence); }
Example #14
Source Project: InflatableDonkey Author: horrorho File: SECPrivateKey.java License: MIT License | 6 votes |
@Override public ASN1Primitive toASN1Primitive() { DERTaggedObject parametersEncodable = parameters() .map(DEROctetString::new) .map(e -> new DERTaggedObject(PARAMETERS, e)) .orElseGet(null); DERTaggedObject publicKeyEncodable = publicKey() .map(DERBitString::new) .map(e -> new DERTaggedObject(PUBLIC_KEY, e)) .orElseGet(null); ASN1EncodableVector vector = DER.vector( new ASN1Integer(version), new DEROctetString(privateKey), parametersEncodable, publicKeyEncodable); return new DERSequence(vector); }
Example #15
Source Project: xipki Author: xipki File: ProxyMessage.java License: Apache License 2.0 | 6 votes |
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new DERUTF8String(control.getLabel())); byte[] id = control.getId(); if (id != null) { vector.add(new DERTaggedObject(0, new DEROctetString(id))); } Set<P11KeyUsage> usages = control.getUsages(); if (CollectionUtil.isNotEmpty(usages)) { ASN1EncodableVector asn1Usages = new ASN1EncodableVector(); for (P11KeyUsage usage : usages) { int value = usageToValueMap.get(usage); asn1Usages.add(new ASN1Enumerated(value)); } vector.add(new DERTaggedObject(1, new DERSequence(asn1Usages))); } if (control.getExtractable() != null) { vector.add(new DERTaggedObject(2, ASN1Boolean.getInstance(control.getExtractable()))); } return new DERSequence(vector); }
Example #16
Source Project: Conversations Author: iNPUTmice File: XmppDomainVerifier.java License: GNU General Public License v3.0 | 6 votes |
private static Pair<String, String> parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new Pair<>(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new Pair<>(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example #17
Source Project: hadoop-ozone Author: apache File: CertificateSignRequest.java License: Apache License 2.0 | 5 votes |
/** * addOtherNameAsn1Object requires special handling since * Bouncy Castle does not support othername as string. * @param name * @return */ private ASN1Object addOtherNameAsn1Object(String name) { // Below oid is copied from this URL: // https://docs.microsoft.com/en-us/windows/win32/adschema/a-middlename final String otherNameOID = "2.16.840.1.113730.3.1.34"; ASN1EncodableVector otherName = new ASN1EncodableVector(); otherName.add(new ASN1ObjectIdentifier(otherNameOID)); otherName.add(new DERTaggedObject( true, GeneralName.otherName, new DERUTF8String(name))); return new DERTaggedObject( false, 0, new DERSequence(otherName)); }
Example #18
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private String getResponderIdByName() { RespID responderId = this.ocsp.getResponderId(); ResponderID responderIdAsASN1Object = responderId.toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderIdAsASN1Object.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { return null; } else { ASN1Primitive derObject = derTaggedObject.getObject(); X500Name name = X500Name.getInstance(derObject); return RFC2253Parser.normalize(name.toString()); } }
Example #19
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private byte[] getResponderIdByKey() { ResponderID responderID = this.ocsp.getResponderId().toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderID.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString)derTaggedObject.getObject(); return keyHashOctetString.getOctets(); } else { return new byte[0]; } }
Example #20
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private String getResponderIdByName() { RespID responderId = this.ocsp.getResponderId(); ResponderID responderIdAsASN1Object = responderId.toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderIdAsASN1Object.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { return null; } else { ASN1Primitive derObject = derTaggedObject.getObject(); X500Name name = X500Name.getInstance(derObject); return RFC2253Parser.normalize(name.toString()); } }
Example #21
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private byte[] getResponderIdByKey() { ResponderID responderID = this.ocsp.getResponderId().toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderID.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString)derTaggedObject.getObject(); return keyHashOctetString.getOctets(); } else { return new byte[0]; } }
Example #22
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private String getResponderIdByName() { RespID responderId = this.ocsp.getResponderId(); ResponderID responderIdAsASN1Object = responderId.toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderIdAsASN1Object.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { return null; } else { ASN1Primitive derObject = derTaggedObject.getObject(); X500Name name = X500Name.getInstance(derObject); return RFC2253Parser.normalize(name.toString()); } }
Example #23
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private byte[] getResponderIdByKey() { ResponderID responderID = this.ocsp.getResponderId().toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderID.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString)derTaggedObject.getObject(); return keyHashOctetString.getOctets(); } else { return new byte[0]; } }
Example #24
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private String getResponderIdByName() { RespID responderId = this.ocsp.getResponderId(); ResponderID responderIdAsASN1Object = responderId.toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderIdAsASN1Object.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { return null; } else { ASN1Primitive derObject = derTaggedObject.getObject(); X500Name name = X500Name.getInstance(derObject); return RFC2253Parser.normalize(name.toString()); } }
Example #25
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private byte[] getResponderIdByKey() { ResponderID responderID = this.ocsp.getResponderId().toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderID.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString)derTaggedObject.getObject(); return keyHashOctetString.getOctets(); } else { return new byte[0]; } }
Example #26
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private String getResponderIdByName() { RespID responderId = this.ocsp.getResponderId(); ResponderID responderIdAsASN1Object = responderId.toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderIdAsASN1Object.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { return null; } else { ASN1Primitive derObject = derTaggedObject.getObject(); X500Name name = X500Name.getInstance(derObject); return RFC2253Parser.normalize(name.toString()); } }
Example #27
Source Project: freehealth-connector Author: taktik File: OcspRef.java License: GNU Affero General Public License v3.0 | 5 votes |
private byte[] getResponderIdByKey() { ResponderID responderID = this.ocsp.getResponderId().toASN1Primitive(); DERTaggedObject derTaggedObject = (DERTaggedObject)responderID.toASN1Primitive(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString)derTaggedObject.getObject(); return keyHashOctetString.getOctets(); } else { return new byte[0]; } }
Example #28
Source Project: portecle Author: scop File: X509Ext.java License: GNU General Public License v2.0 | 5 votes |
/** * Get Policy Constraints (2.5.29.36) extension value as a string. * * <pre> * PolicyConstraints ::= SEQUENCE { * requireExplicitPolicy [0] SkipCerts OPTIONAL, * inhibitPolicyMapping [1] SkipCerts OPTIONAL } * SkipCerts ::= INTEGER (0..MAX) * </pre> * * @param bValue The octet string value * @return Extension value as a string * @throws IOException If an I/O problem occurs */ private String getPolicyConstraintsStringValue(byte[] bValue) throws IOException { // Get sequence of policy constraint ASN1Sequence policyConstraints = (ASN1Sequence) ASN1Primitive.fromByteArray(bValue); StringBuilder strBuff = new StringBuilder(); for (int i = 0, len = policyConstraints.size(); i < len; i++) { DERTaggedObject policyConstraint = (DERTaggedObject) policyConstraints.getObjectAt(i); ASN1Integer skipCerts = new ASN1Integer(((DEROctetString) policyConstraint.getObject()).getOctets()); int iSkipCerts = skipCerts.getValue().intValue(); switch (policyConstraint.getTagNo()) { case 0: // Require Explicit Policy Skip Certs if (strBuff.length() != 0) { strBuff.append("<br><br>"); } strBuff.append(MessageFormat.format(RB.getString("RequireExplicitPolicy"), iSkipCerts)); break; case 1: // Inhibit Policy Mapping Skip Certs if (strBuff.length() != 0) { strBuff.append("<br><br>"); } strBuff.append(MessageFormat.format(RB.getString("InhibitPolicyMapping"), iSkipCerts)); break; } } return strBuff.toString(); }
Example #29
Source Project: jcifs Author: codelibs File: NegTokenInit.java License: GNU Lesser General Public License v2.1 | 5 votes |
@Override public byte[] toByteArray () { try { ASN1EncodableVector fields = new ASN1EncodableVector(); ASN1ObjectIdentifier[] mechs = getMechanisms(); if ( mechs != null ) { ASN1EncodableVector vector = new ASN1EncodableVector(); for ( int i = 0; i < mechs.length; i++ ) { vector.add(mechs[ i ]); } fields.add(new DERTaggedObject(true, 0, new DERSequence(vector))); } int ctxFlags = getContextFlags(); if ( ctxFlags != 0 ) { fields.add(new DERTaggedObject(true, 1, new DERBitString(ctxFlags))); } byte[] mechanismToken = getMechanismToken(); if ( mechanismToken != null ) { fields.add(new DERTaggedObject(true, 2, new DEROctetString(mechanismToken))); } byte[] mechanismListMIC = getMechanismListMIC(); if ( mechanismListMIC != null ) { fields.add(new DERTaggedObject(true, 3, new DEROctetString(mechanismListMIC))); } ASN1EncodableVector ev = new ASN1EncodableVector(); ev.add(SPNEGO_OID); ev.add(new DERTaggedObject(true, 0, new DERSequence(fields))); ByteArrayOutputStream collector = new ByteArrayOutputStream(); DEROutputStream der = new DEROutputStream(collector); DERApplicationSpecific derApplicationSpecific = new DERApplicationSpecific(0, ev); der.writeObject(derApplicationSpecific); return collector.toByteArray(); } catch ( IOException ex ) { throw new IllegalStateException(ex.getMessage()); } }
Example #30
Source Project: jcifs Author: codelibs File: NegTokenTarg.java License: GNU Lesser General Public License v2.1 | 5 votes |
@Override public byte[] toByteArray () { try { ByteArrayOutputStream collector = new ByteArrayOutputStream(); DEROutputStream der = new DEROutputStream(collector); ASN1EncodableVector fields = new ASN1EncodableVector(); int res = getResult(); if ( res != UNSPECIFIED_RESULT ) { fields.add(new DERTaggedObject(true, 0, new ASN1Enumerated(res))); } ASN1ObjectIdentifier mech = getMechanism(); if ( mech != null ) { fields.add(new DERTaggedObject(true, 1, mech)); } byte[] mechanismToken = getMechanismToken(); if ( mechanismToken != null ) { fields.add(new DERTaggedObject(true, 2, new DEROctetString(mechanismToken))); } byte[] mechanismListMIC = getMechanismListMIC(); if ( mechanismListMIC != null ) { fields.add(new DERTaggedObject(true, 3, new DEROctetString(mechanismListMIC))); } der.writeObject(new DERTaggedObject(true, 1, new DERSequence(fields))); return collector.toByteArray(); } catch ( IOException ex ) { throw new IllegalStateException(ex.getMessage()); } }