Example #1
0
 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());
   }
 }
Example #2
0
  /**
   * Constructs a KeyImpl from a password.
   *
   * @param principal the principal from which to derive the salt
   * @param password the password that should be used to compute the key.
   * @param algorithm the name for the algorithm that this key wil be used for. This parameter may
   *     be null in which case "DES" will be assumed.
   */
  public KeyImpl(KerberosPrincipal principal, char[] password, String algorithm) {

    try {
      PrincipalName princ = new PrincipalName(principal.getName());
      EncryptionKey key = new EncryptionKey(password, princ.getSalt(), algorithm);
      this.keyBytes = key.getBytes();
      this.keyType = key.getEType();
    } catch (KrbException e) {
      throw new IllegalArgumentException(e.getMessage());
    }
  }
  static Krb5InitCredential getInstance(Krb5NameElement name, Credentials delegatedCred)
      throws GSSException {

    EncryptionKey sessionKey = delegatedCred.getSessionKey();

    /*
     * all of the following data is optional in a KRB-CRED
     * messages. This check for each field.
     */

    PrincipalName cPrinc = delegatedCred.getClient();
    PrincipalName sPrinc = delegatedCred.getServer();

    KerberosPrincipal client = null;
    KerberosPrincipal server = null;

    Krb5NameElement credName = null;

    if (cPrinc != null) {
      String fullName = cPrinc.getName();
      credName = Krb5NameElement.getInstance(fullName, Krb5MechFactory.NT_GSS_KRB5_PRINCIPAL);
      client = new KerberosPrincipal(fullName);
    }

    // XXX Compare name to credName

    if (sPrinc != null) {
      server = new KerberosPrincipal(sPrinc.getName(), KerberosPrincipal.KRB_NT_SRV_INST);
    }

    return new Krb5InitCredential(
        credName,
        delegatedCred,
        delegatedCred.getEncoded(),
        client,
        server,
        sessionKey.getBytes(),
        sessionKey.getEType(),
        delegatedCred.getFlags(),
        delegatedCred.getAuthTime(),
        delegatedCred.getStartTime(),
        delegatedCred.getEndTime(),
        delegatedCred.getRenewTill(),
        delegatedCred.getClientAddresses());
  }