Esempio n. 1
0
  /**
   * Returns a flat name representation for this object. The name format is defined in RFC 2743:
   *
   * <pre>
   * Length           Name          Description
   * 2               TOK_ID          Token Identifier
   *                                 For exported name objects, this
   *                                 must be hex 04 01.
   * 2               MECH_OID_LEN    Length of the Mechanism OID
   * MECH_OID_LEN    MECH_OID        Mechanism OID, in DER
   * 4               NAME_LEN        Length of name
   * NAME_LEN        NAME            Exported name; format defined in
   *                                 applicable mechanism draft.
   * </pre>
   *
   * Note that it is not required to canonicalize a name before calling export(). i.e., the name
   * need not be an MN. If it is not an MN, an implementation defined algorithm can be used for
   * choosing the mechanism which should export this name.
   *
   * @return the flat name representation for this object
   * @exception GSSException with major codes NAME_NOT_MN, BAD_NAME, BAD_NAME, FAILURE.
   */
  public byte[] export() throws GSSException {

    if (mechElement == null) {
      /* Use default mech */
      mechElement = getElement(ProviderList.DEFAULT_MECH_OID);
    }

    byte[] mechPortion = mechElement.export();
    byte[] oidBytes = null;
    ObjectIdentifier oid = null;

    try {
      oid = new ObjectIdentifier(mechElement.getMechanism().toString());
    } catch (IOException e) {
      throw new GSSExceptionImpl(GSSException.FAILURE, "Invalid OID String ");
    }
    DerOutputStream dout = new DerOutputStream();
    try {
      dout.putOID(oid);
    } catch (IOException e) {
      throw new GSSExceptionImpl(GSSException.FAILURE, "Could not ASN.1 Encode " + oid.toString());
    }
    oidBytes = dout.toByteArray();

    byte[] retVal = new byte[2 + 2 + oidBytes.length + 4 + mechPortion.length];
    int pos = 0;
    retVal[pos++] = 0x04;
    retVal[pos++] = 0x01;
    retVal[pos++] = (byte) (oidBytes.length >>> 8);
    retVal[pos++] = (byte) oidBytes.length;
    System.arraycopy(oidBytes, 0, retVal, pos, oidBytes.length);
    pos += oidBytes.length;
    retVal[pos++] = (byte) (mechPortion.length >>> 24);
    retVal[pos++] = (byte) (mechPortion.length >>> 16);
    retVal[pos++] = (byte) (mechPortion.length >>> 8);
    retVal[pos++] = (byte) mechPortion.length;
    System.arraycopy(mechPortion, 0, retVal, pos, mechPortion.length);
    return retVal;
  }
Esempio n. 2
0
  private void importName(GSSManagerImpl gssManager, Object appName) throws GSSException {

    int pos = 0;
    byte[] bytes = null;

    if (appName instanceof String) {
      try {
        bytes = ((String) appName).getBytes("UTF-8");
      } catch (UnsupportedEncodingException e) {
        // Won't happen
      }
    } else bytes = (byte[]) appName;

    if ((bytes[pos++] != 0x04) || (bytes[pos++] != 0x01))
      throw new GSSExceptionImpl(GSSException.BAD_NAME, "Exported name token id is corrupted!");

    int oidLen = (((0xFF & bytes[pos++]) << 8) | (0xFF & bytes[pos++]));
    ObjectIdentifier temp = null;
    try {
      DerInputStream din = new DerInputStream(bytes, pos, oidLen);
      temp = new ObjectIdentifier(din);
    } catch (IOException e) {
      throw new GSSExceptionImpl(
          GSSException.BAD_NAME, "Exported name Object identifier is corrupted!");
    }
    Oid oid = new Oid(temp.toString());
    pos += oidLen;
    int mechPortionLen =
        (((0xFF & bytes[pos++]) << 24)
            | ((0xFF & bytes[pos++]) << 16)
            | ((0xFF & bytes[pos++]) << 8)
            | (0xFF & bytes[pos++]));
    byte[] mechPortion = new byte[mechPortionLen];
    System.arraycopy(bytes, pos, mechPortion, 0, mechPortionLen);

    init(gssManager, mechPortion, NT_EXPORT_NAME, oid);
  }