< prev index next >

src/java.security.jgss/share/classes/sun/security/krb5/internal/KDCReq.java

Print this page




  42  * <pre>{@code
  43  * KDC-REQ              ::= SEQUENCE {
  44  *      -- NOTE: first tag is [1], not [0]
  45  *      pvno            [1] INTEGER (5) ,
  46  *      msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),
  47  *      padata          [3] SEQUENCE OF PA-DATA OPTIONAL
  48  *                            -- NOTE: not empty --,
  49  *      req-body        [4] KDC-REQ-BODY
  50  * }
  51  * }</pre>
  52  *
  53  * <p>
  54  * This definition reflects the Network Working Group RFC 4120
  55  * specification available at
  56  * <a href="http://www.ietf.org/rfc/rfc4120.txt">
  57  * http://www.ietf.org/rfc/rfc4120.txt</a>.
  58  */
  59 public class KDCReq {
  60 
  61     public KDCReqBody reqBody;
  62     public PAData[] pAData = null; //optional
  63     private int pvno;
  64     private int msgType;

  65 
  66     public KDCReq(PAData[] new_pAData, KDCReqBody new_reqBody,
  67             int req_type) throws IOException {
  68         pvno = Krb5.PVNO;
  69         msgType = req_type;
  70         if (new_pAData != null) {
  71             pAData = new PAData[new_pAData.length];
  72             for (int i = 0; i < new_pAData.length; i++) {
  73                 if (new_pAData[i] == null) {
  74                     throw new IOException("Cannot create a KDCRep");
  75                 } else {
  76                     pAData[i] = (PAData) new_pAData[i].clone();
  77                 }
  78             }
  79         }
  80         reqBody = new_reqBody;
  81     }
  82 
  83     public KDCReq() {
  84     }


 127         subDer = der.getData().getDerValue();
 128         if ((subDer.getTag() & 0x01F) == 0x01) {
 129             bint = subDer.getData().getBigInteger();
 130             this.pvno = bint.intValue();
 131             if (this.pvno != Krb5.PVNO) {
 132                 throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
 133             }
 134         } else {
 135             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 136         }
 137         subDer = der.getData().getDerValue();
 138         if ((subDer.getTag() & 0x01F) == 0x02) {
 139             bint = subDer.getData().getBigInteger();
 140             this.msgType = bint.intValue();
 141             if (this.msgType != req_type) {
 142                 throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
 143             }
 144         } else {
 145             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 146         }
 147         pAData = PAData.parseSequence(der.getData(), (byte) 0x03, true);
















 148         subDer = der.getData().getDerValue();
 149         if ((subDer.getTag() & 0x01F) == 0x04) {
 150             DerValue subsubDer = subDer.getData().getDerValue();
 151             reqBody = new KDCReqBody(subsubDer, msgType);
 152         } else {
 153             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 154         }
 155     }
 156 
 157     /**
 158      * Encodes this object to a byte array.
 159      *
 160      * @return an byte array of encoded data.
 161      * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 162      * @exception IOException if an I/O error occurs while reading encoded data.
 163      *
 164      */
 165     public byte[] asn1Encode() throws Asn1Exception, IOException {
 166         DerOutputStream temp, bytes, out;
 167         temp = new DerOutputStream();




  42  * <pre>{@code
  43  * KDC-REQ              ::= SEQUENCE {
  44  *      -- NOTE: first tag is [1], not [0]
  45  *      pvno            [1] INTEGER (5) ,
  46  *      msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),
  47  *      padata          [3] SEQUENCE OF PA-DATA OPTIONAL
  48  *                            -- NOTE: not empty --,
  49  *      req-body        [4] KDC-REQ-BODY
  50  * }
  51  * }</pre>
  52  *
  53  * <p>
  54  * This definition reflects the Network Working Group RFC 4120
  55  * specification available at
  56  * <a href="http://www.ietf.org/rfc/rfc4120.txt">
  57  * http://www.ietf.org/rfc/rfc4120.txt</a>.
  58  */
  59 public class KDCReq {
  60 
  61     public KDCReqBody reqBody;

  62     private int pvno;
  63     private int msgType;
  64     private PAData[] pAData = null; //optional
  65 
  66     public KDCReq(PAData[] new_pAData, KDCReqBody new_reqBody,
  67             int req_type) throws IOException {
  68         pvno = Krb5.PVNO;
  69         msgType = req_type;
  70         if (new_pAData != null) {
  71             pAData = new PAData[new_pAData.length];
  72             for (int i = 0; i < new_pAData.length; i++) {
  73                 if (new_pAData[i] == null) {
  74                     throw new IOException("Cannot create a KDCRep");
  75                 } else {
  76                     pAData[i] = (PAData) new_pAData[i].clone();
  77                 }
  78             }
  79         }
  80         reqBody = new_reqBody;
  81     }
  82 
  83     public KDCReq() {
  84     }


 127         subDer = der.getData().getDerValue();
 128         if ((subDer.getTag() & 0x01F) == 0x01) {
 129             bint = subDer.getData().getBigInteger();
 130             this.pvno = bint.intValue();
 131             if (this.pvno != Krb5.PVNO) {
 132                 throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
 133             }
 134         } else {
 135             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 136         }
 137         subDer = der.getData().getDerValue();
 138         if ((subDer.getTag() & 0x01F) == 0x02) {
 139             bint = subDer.getData().getBigInteger();
 140             this.msgType = bint.intValue();
 141             if (this.msgType != req_type) {
 142                 throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
 143             }
 144         } else {
 145             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 146         }
 147         if ((der.getData().peekByte() & 0x1F) == 0x03) {
 148             subDer = der.getData().getDerValue();
 149             DerValue subsubDer = subDer.getData().getDerValue();
 150             if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
 151                 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 152             }
 153             Vector<PAData> v = new Vector<>();
 154             while (subsubDer.getData().available() > 0) {
 155                 v.addElement(new PAData(subsubDer.getData().getDerValue()));
 156             }
 157             if (v.size() > 0) {
 158                 pAData = new PAData[v.size()];
 159                 v.copyInto(pAData);
 160             }
 161         } else {
 162             pAData = null;
 163         }
 164         subDer = der.getData().getDerValue();
 165         if ((subDer.getTag() & 0x01F) == 0x04) {
 166             DerValue subsubDer = subDer.getData().getDerValue();
 167             reqBody = new KDCReqBody(subsubDer, msgType);
 168         } else {
 169             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 170         }
 171     }
 172 
 173     /**
 174      * Encodes this object to a byte array.
 175      *
 176      * @return an byte array of encoded data.
 177      * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 178      * @exception IOException if an I/O error occurs while reading encoded data.
 179      *
 180      */
 181     public byte[] asn1Encode() throws Asn1Exception, IOException {
 182         DerOutputStream temp, bytes, out;
 183         temp = new DerOutputStream();


< prev index next >