jdk/src/share/classes/sun/security/jgss/spnego/NegTokenTarg.java
changeset 9549 24b7de36d243
parent 5506 202f599c92aa
equal deleted inserted replaced
9548:225dbdc1cb74 9549:24b7de36d243
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   151             if (tmp1.tag != DerValue.tag_Sequence) {
   151             if (tmp1.tag != DerValue.tag_Sequence) {
   152                 throw new IOException("SPNEGO NegoTokenTarg : " +
   152                 throw new IOException("SPNEGO NegoTokenTarg : " +
   153                         "did not have the Sequence tag");
   153                         "did not have the Sequence tag");
   154             }
   154             }
   155 
   155 
   156             // parse negResult, if present
   156             // parse various fields if present
   157             if (tmp1.data.available() > 0) {
   157             int lastField = -1;
       
   158             while (tmp1.data.available() > 0) {
   158                 DerValue tmp2 = tmp1.data.getDerValue();
   159                 DerValue tmp2 = tmp1.data.getDerValue();
   159                 if (!tmp2.isContextSpecific((byte)0x00)) {
   160                 if (tmp2.isContextSpecific((byte)0x00)) {
   160                         throw new IOException("SPNEGO NegoTokenTarg : " +
   161                     lastField = checkNextField(lastField, 0);
   161                         "did not have the right context tag for negResult");
   162                     negResult = tmp2.data.getEnumerated();
       
   163                     if (DEBUG) {
       
   164                         System.out.println("SpNegoToken NegTokenTarg: negotiated" +
       
   165                                     " result = " + getNegoResultString(negResult));
       
   166                     }
       
   167                 } else if (tmp2.isContextSpecific((byte)0x01)) {
       
   168                     lastField = checkNextField(lastField, 1);
       
   169                     ObjectIdentifier mech = tmp2.data.getOID();
       
   170                     supportedMech = new Oid(mech.toString());
       
   171                     if (DEBUG) {
       
   172                         System.out.println("SpNegoToken NegTokenTarg: " +
       
   173                                     "supported mechanism = " + supportedMech);
       
   174                     }
       
   175                 } else if (tmp2.isContextSpecific((byte)0x02)) {
       
   176                     lastField = checkNextField(lastField, 2);
       
   177                     responseToken = tmp2.data.getOctetString();
       
   178                 } else if (tmp2.isContextSpecific((byte)0x03)) {
       
   179                     lastField = checkNextField(lastField, 3);
       
   180                     if (!GSSUtil.useMSInterop()) {
       
   181                         mechListMIC = tmp2.data.getOctetString();
       
   182                         if (DEBUG) {
       
   183                             System.out.println("SpNegoToken NegTokenTarg: " +
       
   184                                                 "MechListMIC Token = " +
       
   185                                                 getHexBytes(mechListMIC));
       
   186                         }
       
   187                     }
   162                 }
   188                 }
   163                 negResult = tmp2.data.getEnumerated();
   189             }
   164                 if (DEBUG) {
       
   165                     System.out.println("SpNegoToken NegTokenTarg: negotiated" +
       
   166                                 " result = " + getNegoResultString(negResult));
       
   167                 }
       
   168             }
       
   169 
       
   170             // parse supportedMech, if present
       
   171             if (tmp1.data.available() > 0) {
       
   172                 DerValue tmp3 = tmp1.data.getDerValue();
       
   173                 if (!tmp3.isContextSpecific((byte)0x01)) {
       
   174                     throw new IOException("SPNEGO NegoTokenTarg : " +
       
   175                         "did not have the right context tag for supportedMech");
       
   176                 }
       
   177                 ObjectIdentifier mech = tmp3.data.getOID();
       
   178                 supportedMech = new Oid(mech.toString());
       
   179                 if (DEBUG) {
       
   180                     System.out.println("SpNegoToken NegTokenTarg: " +
       
   181                                 "supported mechanism = " + supportedMech);
       
   182                 }
       
   183             }
       
   184 
       
   185             // parse ResponseToken, if present
       
   186             if (tmp1.data.available() > 0) {
       
   187                 DerValue tmp4 = tmp1.data.getDerValue();
       
   188                 if (!tmp4.isContextSpecific((byte)0x02)) {
       
   189                     throw new IOException("SPNEGO NegoTokenTarg : did not" +
       
   190                         " have the right context tag for response token");
       
   191                 }
       
   192                 responseToken = tmp4.data.getOctetString();
       
   193             }
       
   194 
       
   195             // parse mechListMIC if present and not in MS interop
       
   196             if (!GSSUtil.useMSInterop() && (tmp1.data.available() > 0)) {
       
   197                 if (DEBUG) {
       
   198                     System.out.println("SpNegoToken NegTokenTarg: " +
       
   199                                                 "receiving MechListMIC");
       
   200                 }
       
   201                 DerValue tmp5 = tmp1.data.getDerValue();
       
   202                 if (!tmp5.isContextSpecific((byte)0x03)) {
       
   203                     throw new IOException("SPNEGO NegoTokenTarg : " +
       
   204                         "did not have the right context tag for mechListMIC");
       
   205                 }
       
   206                 mechListMIC = tmp5.data.getOctetString();
       
   207                 if (DEBUG) {
       
   208                     System.out.println("SpNegoToken NegTokenTarg: " +
       
   209                                         "MechListMIC Token = " +
       
   210                                         getHexBytes(mechListMIC));
       
   211                 }
       
   212             } else {
       
   213                 if (DEBUG) {
       
   214                     System.out.println("SpNegoToken NegTokenTarg : " +
       
   215                                         "no MIC token included");
       
   216                 }
       
   217             }
       
   218 
       
   219         } catch (IOException e) {
   190         } catch (IOException e) {
   220             throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1,
   191             throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1,
   221                 "Invalid SPNEGO NegTokenTarg token : " + e.getMessage());
   192                 "Invalid SPNEGO NegTokenTarg token : " + e.getMessage());
   222         }
   193         }
   223     }
   194     }