sun.security.krb5.Asn1Exception Java Examples
The following examples show how to use
sun.security.krb5.Asn1Exception.
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 File: KerberosTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static long toKerberosTime(String time) throws Asn1Exception { // ASN.1 GeneralizedTime format: // "19700101000000Z" // | | | | | | | // 0 4 6 8 | | | // 10 | | // 12 | // 14 if (time.length() != 15) throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT); if (time.charAt(14) != 'Z') throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT); int year = Integer.parseInt(time.substring(0, 4)); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.clear(); // so that millisecond is zero calendar.set(year, Integer.parseInt(time.substring(4, 6)) - 1, Integer.parseInt(time.substring(6, 8)), Integer.parseInt(time.substring(8, 10)), Integer.parseInt(time.substring(10, 12)), Integer.parseInt(time.substring(12, 14))); return calendar.getTimeInMillis(); }
Example #2
Source File: KRBError.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Try parsing the data as a sequence of PA-DATA. * @param data the data block */ private void parsePAData(byte[] data) throws IOException, Asn1Exception { DerValue derPA = new DerValue(data); List<PAData> paList = new ArrayList<>(); while (derPA.data.available() > 0) { // read the PA-DATA DerValue tmp = derPA.data.getDerValue(); PAData pa_data = new PAData(tmp); paList.add(pa_data); if (DEBUG) { System.out.println(pa_data); } } pa = paList.toArray(new PAData[paList.size()]); }
Example #3
Source File: KerberosTime.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Parse (unmarshal) a kerberostime from a DER input stream. This form * parsing might be used when expanding a value which is part of * a constructed sequence and uses explicitly tagged type. * * @exception Asn1Exception on error. * @param data the Der input stream value, which contains * one or more marshaled value. * @param explicitTag tag number. * @param optional indicates if this data field is optional * @return an instance of KerberosTime. * */ public static KerberosTime parse( DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException { if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag)) return null; DerValue der = data.getDerValue(); if (explicitTag != (der.getTag() & (byte)0x1F)) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } else { DerValue subDer = der.getData().getDerValue(); Date temp = subDer.getGeneralizedTime(); return new KerberosTime(temp.getTime(), 0); } }
Example #4
Source File: PAData.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Constructs a PAData object. * @param encoding a Der-encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public PAData(DerValue encoding) throws Asn1Exception, IOException { DerValue der = null; if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x01) { this.pADataType = der.getData().getBigInteger().intValue(); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x02) { this.pADataValue = der.getData().getOctetString(); } if (encoding.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #5
Source File: KRBPriv.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Encodes an KRBPriv object. * @return byte array of encoded EncAPRepPart object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream temp, bytes; temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(pvno)); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(msgType)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x15), temp); return bytes.toByteArray(); }
Example #6
Source File: KerberosTime.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static long toKerberosTime(String time) throws Asn1Exception { // ASN.1 GeneralizedTime format: // "19700101000000Z" // | | | | | | | // 0 4 6 8 | | | // 10 | | // 12 | // 14 if (time.length() != 15) throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT); if (time.charAt(14) != 'Z') throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT); int year = Integer.parseInt(time.substring(0, 4)); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.clear(); // so that millisecond is zero calendar.set(year, Integer.parseInt(time.substring(4, 6)) - 1, Integer.parseInt(time.substring(6, 8)), Integer.parseInt(time.substring(8, 10)), Integer.parseInt(time.substring(10, 12)), Integer.parseInt(time.substring(12, 14))); return calendar.getTimeInMillis(); }
Example #7
Source File: Ticket.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Encodes a Ticket object. * @return byte array of encoded ticket object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); DerValue der[] = new DerValue[4]; temp.putInteger(BigInteger.valueOf(tkt_vno)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), sname.getRealm().asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); DerOutputStream ticket = new DerOutputStream(); ticket.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x01), temp); return ticket.toByteArray(); }
Example #8
Source File: AuthorizationDataEntry.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Constructs an instance of AuthorizationDataEntry. * @param encoding a single DER-encoded value. */ public AuthorizationDataEntry(DerValue encoding) throws Asn1Exception, IOException { DerValue der; if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } der = encoding.getData().getDerValue(); if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) { adType = der.getData().getBigInteger().intValue(); } else { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } der = encoding.getData().getDerValue(); if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) { adData = der.getData().getOctetString(); } else { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } if (encoding.getData().available() > 0) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } }
Example #9
Source File: KRBPriv.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Encodes an KRBPriv object. * @return byte array of encoded EncAPRepPart object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream temp, bytes; temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(pvno)); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(msgType)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x15), temp); return bytes.toByteArray(); }
Example #10
Source File: KRBSafeBody.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Encodes an KRBSafeBody object. * @return the byte array of encoded KRBSafeBody object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putOctetString(userData); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); if (timestamp != null) bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), timestamp.asn1Encode()); if (usec != null) { temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(usec.intValue())); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp); } if (seqNumber != null) { temp = new DerOutputStream(); // encode as an unsigned integer (UInt32) temp.putInteger(BigInteger.valueOf(seqNumber.longValue())); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp); } bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sAddress.asn1Encode()); if (rAddress != null) temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #11
Source File: PAData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Encodes this object to an OutputStream. * * @return byte array of the encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception Asn1Exception on encoding errors. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putInteger(pADataType); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_PATYPE), temp); temp = new DerOutputStream(); temp.putOctetString(pADataValue); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_PAVALUE), temp); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #12
Source File: Ticket.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Initializes a Ticket object. * @param encoding a single DER-encoded value. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value. * @exception RealmException if an error occurs while parsing a Realm object. */ private void init(DerValue encoding) throws Asn1Exception, RealmException, KrbApErrException, IOException { DerValue der; DerValue subDer; if (((encoding.getTag() & (byte)0x1F) != Krb5.KRB_TKT) || (encoding.isApplication() != true) || (encoding.isConstructed() != true)) throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if (der.getTag() != DerValue.tag_Sequence) throw new Asn1Exception(Krb5.ASN1_BAD_ID); subDer = der.getData().getDerValue(); if ((subDer.getTag() & (byte)0x1F) != (byte)0x00) throw new Asn1Exception(Krb5.ASN1_BAD_ID); tkt_vno = subDer.getData().getBigInteger().intValue(); if (tkt_vno != Krb5.TICKET_VNO) throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); Realm srealm = Realm.parse(der.getData(), (byte)0x01, false); sname = PrincipalName.parse(der.getData(), (byte)0x02, false, srealm); encPart = EncryptedData.parse(der.getData(), (byte)0x03, false); if (der.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #13
Source File: ETypeInfo.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Encodes this object to an OutputStream. * * @return byte array of the encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception Asn1Exception on encoding errors. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putInteger(etype); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_TYPE), temp); if (salt != null) { temp = new DerOutputStream(); if (KerberosString.MSNAME) { temp.putOctetString(salt.getBytes("UTF8")); } else { temp.putOctetString(salt.getBytes()); } bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_VALUE), temp); } temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #14
Source File: PAEncTSEnc.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Constructs a PAEncTSEnc object. * @param encoding a Der-encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public PAEncTSEnc(DerValue encoding) throws Asn1Exception, IOException { DerValue der; if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } pATimeStamp = KerberosTime.parse(encoding.getData(), (byte)0x00, false); if (encoding.getData().available() > 0) { der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x01) { pAUSec = new Integer(der.getData().getBigInteger().intValue()); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); } if (encoding.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #15
Source File: HostAddress.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Parses (unmarshal) a host address from a DER input stream. This form * parsing might be used when expanding a value which is part of * a constructed sequence and uses explicitly tagged type. * * @exception Asn1Exception on error. * @exception IOException if an I/O error occurs while reading encoded data. * @param data the Der input stream value, which contains one or more marshaled value. * @param explicitTag tag number. * @param optional indicates if this data field is optional * @return an instance of HostAddress. * */ public static HostAddress parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException{ if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) { return null; } DerValue der = data.getDerValue(); if (explicitTag != (der.getTag() & (byte)0x1F)) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } else { DerValue subDer = der.getData().getDerValue(); return new HostAddress(subDer); } }
Example #16
Source File: LastReqEntry.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Constructs a LastReqEntry object. * @param encoding a Der-encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public LastReqEntry(DerValue encoding) throws Asn1Exception, IOException { if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } DerValue der; der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x00){ lrType = der.getData().getBigInteger().intValue(); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); lrValue = KerberosTime.parse(encoding.getData(), (byte)0x01, false); if (encoding.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #17
Source File: PAData.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Constructs a PAData object. * @param encoding a Der-encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public PAData(DerValue encoding) throws Asn1Exception, IOException { DerValue der = null; if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x01) { this.pADataType = der.getData().getBigInteger().intValue(); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x02) { this.pADataValue = der.getData().getOctetString(); } if (encoding.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #18
Source File: MethodData.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Encodes an MethodData object. * @return the byte array of encoded MethodData object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(methodType)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); if (methodData != null) { temp = new DerOutputStream(); temp.putOctetString(methodData); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); } temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #19
Source File: KRBError.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Try parsing the data as a sequence of PA-DATA. * @param data the data block */ private void parsePAData(byte[] data) throws IOException, Asn1Exception { DerValue derPA = new DerValue(data); List<PAData> paList = new ArrayList<>(); while (derPA.data.available() > 0) { // read the PA-DATA DerValue tmp = derPA.data.getDerValue(); PAData pa_data = new PAData(tmp); paList.add(pa_data); if (DEBUG) { System.out.println(pa_data); } } pa = paList.toArray(new PAData[paList.size()]); }
Example #20
Source File: KRBSafe.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Encodes an KRBSafe object. * @return byte array of encoded KRBSafe object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream temp = new DerOutputStream(); DerOutputStream bytes = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(pvno)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); temp = new DerOutputStream(); temp.putInteger(BigInteger.valueOf(msgType)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), safeBody.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), cksum.asn1Encode()); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x14), temp); return bytes.toByteArray(); }
Example #21
Source File: TransitedEncoding.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Constructs a TransitedEncoding object. * @param encoding a Der-encoded data. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public TransitedEncoding(DerValue encoding) throws Asn1Exception, IOException { if (encoding.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } DerValue der; der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x00) { trType = der.getData().getBigInteger().intValue(); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if ((der.getTag() & 0x1F) == 0x01) { contents = der.getData().getOctetString(); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); if (der.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #22
Source File: KRBError.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public KRBError( APOptions new_apOptions, KerberosTime new_cTime, Integer new_cuSec, KerberosTime new_sTime, Integer new_suSec, int new_errorCode, PrincipalName new_cname, PrincipalName new_sname, String new_eText, byte[] new_eData ) throws IOException, Asn1Exception { pvno = Krb5.PVNO; msgType = Krb5.KRB_ERROR; cTime = new_cTime; cuSec = new_cuSec; sTime = new_sTime; suSec = new_suSec; errorCode = new_errorCode; cname = new_cname; sname = new_sname; eText = new_eText; eData = new_eData; parseEData(eData); }
Example #23
Source File: Ticket.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Initializes a Ticket object. * @param encoding a single DER-encoded value. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value. * @exception RealmException if an error occurs while parsing a Realm object. */ private void init(DerValue encoding) throws Asn1Exception, RealmException, KrbApErrException, IOException { DerValue der; DerValue subDer; if (((encoding.getTag() & (byte)0x1F) != Krb5.KRB_TKT) || (encoding.isApplication() != true) || (encoding.isConstructed() != true)) throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if (der.getTag() != DerValue.tag_Sequence) throw new Asn1Exception(Krb5.ASN1_BAD_ID); subDer = der.getData().getDerValue(); if ((subDer.getTag() & (byte)0x1F) != (byte)0x00) throw new Asn1Exception(Krb5.ASN1_BAD_ID); tkt_vno = subDer.getData().getBigInteger().intValue(); if (tkt_vno != Krb5.TICKET_VNO) throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); Realm srealm = Realm.parse(der.getData(), (byte)0x01, false); sname = PrincipalName.parse(der.getData(), (byte)0x02, false, srealm); encPart = EncryptedData.parse(der.getData(), (byte)0x03, false); if (der.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #24
Source File: ETypeInfo.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Encodes this object to an OutputStream. * * @return byte array of the encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception Asn1Exception on encoding errors. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putInteger(etype); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_TYPE), temp); if (salt != null) { temp = new DerOutputStream(); if (KerberosString.MSNAME) { temp.putOctetString(salt.getBytes("UTF8")); } else { temp.putOctetString(salt.getBytes()); } bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_VALUE), temp); } temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #25
Source File: Ticket.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Encodes a Ticket object. * @return byte array of encoded ticket object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); DerValue der[] = new DerValue[4]; temp.putInteger(BigInteger.valueOf(tkt_vno)); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), sname.getRealm().asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode()); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); DerOutputStream ticket = new DerOutputStream(); ticket.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x01), temp); return ticket.toByteArray(); }
Example #26
Source File: APRep.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Initializes an APRep object. * @param encoding a single DER-encoded value. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception KrbApErrException if the value read from the DER-encoded data * stream does not match the pre-defined value. */ private void init(DerValue encoding) throws Asn1Exception, KrbApErrException, IOException { if (((encoding.getTag() & (byte) (0x1F)) != Krb5.KRB_AP_REP) || (encoding.isApplication() != true) || (encoding.isConstructed() != true)) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } DerValue der = encoding.getData().getDerValue(); if (der.getTag() != DerValue.tag_Sequence) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } DerValue subDer = der.getData().getDerValue(); if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } pvno = subDer.getData().getBigInteger().intValue(); if (pvno != Krb5.PVNO) { throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); } subDer = der.getData().getDerValue(); if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } msgType = subDer.getData().getBigInteger().intValue(); if (msgType != Krb5.KRB_AP_REP) { throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); } encPart = EncryptedData.parse(der.getData(), (byte) 0x02, false); if (der.getData().available() > 0) { throw new Asn1Exception(Krb5.ASN1_BAD_ID); } }
Example #27
Source File: KRBSafe.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Initializes an KRBSafe object. * @param encoding a single DER-encoded value. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * @exception RealmException if an error occurs while parsing a Realm object. * @exception KrbApErrException if the value read from the DER-encoded data * stream does not match the pre-defined value. */ private void init(DerValue encoding) throws Asn1Exception, RealmException, KrbApErrException, IOException { DerValue der, subDer; if (((encoding.getTag() & (byte)0x1F) != (byte)0x14) || (encoding.isApplication() != true) || (encoding.isConstructed() != true)) throw new Asn1Exception(Krb5.ASN1_BAD_ID); der = encoding.getData().getDerValue(); if (der.getTag() != DerValue.tag_Sequence) throw new Asn1Exception(Krb5.ASN1_BAD_ID); subDer = der.getData().getDerValue(); if ((subDer.getTag() & 0x1F) == 0x00) { pvno = subDer.getData().getBigInteger().intValue(); if (pvno != Krb5.PVNO) throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); subDer = der.getData().getDerValue(); if ((subDer.getTag() & 0x1F) == 0x01) { msgType = subDer.getData().getBigInteger().intValue(); if (msgType != Krb5.KRB_SAFE) throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE); } else throw new Asn1Exception(Krb5.ASN1_BAD_ID); safeBody = KRBSafeBody.parse(der.getData(), (byte)0x02, false); cksum = Checksum.parse(der.getData(), (byte)0x03, false); if (der.getData().available() > 0) throw new Asn1Exception(Krb5.ASN1_BAD_ID); }
Example #28
Source File: KeyImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * @serialData this {@code KeyImpl} is serialized by * writing out the ASN1 Encoded bytes of the encryption key. * The ASN1 encoding is defined in RFC4120 and as follows: * EncryptionKey ::= SEQUENCE { * keytype [0] Int32 -- actually encryption type --, * keyvalue [1] OCTET STRING * } */ private void writeObject(ObjectOutputStream ois) throws IOException { if (destroyed) { throw new IOException("This key is no longer valid"); } try { ois.writeObject((new EncryptionKey(keyType, keyBytes)).asn1Encode()); } catch (Asn1Exception ae) { throw new IOException(ae.getMessage()); } }
Example #29
Source File: HostAddress.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Encodes a HostAddress object. * @return a byte array of encoded HostAddress object. * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. * @exception IOException if an I/O error occurs while reading encoded data. * */ public byte[] asn1Encode() throws Asn1Exception, IOException { DerOutputStream bytes = new DerOutputStream(); DerOutputStream temp = new DerOutputStream(); temp.putInteger(this.addrType); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); temp = new DerOutputStream(); temp.putOctetString(address); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); temp = new DerOutputStream(); temp.write(DerValue.tag_Sequence, bytes); return temp.toByteArray(); }
Example #30
Source File: KeyImpl.java From Java8CN with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { try { EncryptionKey encKey = new EncryptionKey(new DerValue((byte[])ois.readObject())); keyType = encKey.getEType(); keyBytes = encKey.getBytes(); } catch (Asn1Exception ae) { throw new IOException(ae.getMessage()); } }