index
int64 0
0
| repo_id
stringlengths 9
205
| file_path
stringlengths 31
246
| content
stringlengths 1
12.2M
| __index_level_0__
int64 0
10k
|
---|---|---|---|---|
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/pkinit/PaPkAsRep.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.pkinit;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.ImplicitField;
import org.apache.kerby.asn1.type.Asn1Choice;
import org.apache.kerby.asn1.type.Asn1OctetString;
/**
PA-PK-AS-REP ::= CHOICE {
dhInfo [0] DhRepInfo,
encKeyPack [1] IMPLICIT OCTET STRING,
}
*/
public class PaPkAsRep extends Asn1Choice {
protected enum PaPkAsRepField implements EnumType {
DH_INFO,
ENCKEY_PACK;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(PaPkAsRepField.DH_INFO, DhRepInfo.class),
new ImplicitField(PaPkAsRepField.ENCKEY_PACK, Asn1OctetString.class)
};
public PaPkAsRep() {
super(fieldInfos);
}
public DhRepInfo getDHRepInfo() {
return getChoiceValueAs(PaPkAsRepField.DH_INFO, DhRepInfo.class);
}
public void setDHRepInfo(DhRepInfo dhRepInfo) {
setChoiceValue(PaPkAsRepField.DH_INFO, dhRepInfo);
}
public byte[] getEncKeyPack() {
return getChoiceValueAsOctets(PaPkAsRepField.ENCKEY_PACK);
}
public void setEncKeyPack(byte[] encKeyPack) {
setChoiceValueAsOctets(PaPkAsRepField.ENCKEY_PACK, encKeyPack);
}
}
| 100 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/pkinit/PkAuthenticator.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.pkinit;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
PKAuthenticator ::= SEQUENCE {
cusec [0] INTEGER (0..999999),
ctime [1] KerberosTime,
-- cusec and ctime are used as in [RFC4120], for
-- replay prevention.
nonce [2] INTEGER (0..4294967295),
-- Chosen randomly; this nonce does not need to
-- match with the nonce in the KDC-REQ-BODY.
paChecksum [3] OCTET STRING OPTIONAL,
-- MUST be present.
-- Contains the SHA1 checksum, performed over
-- KDC-REQ-BODY.
}
*/
public class PkAuthenticator extends KrbSequenceType {
protected enum PkAuthenticatorField implements EnumType {
CUSEC,
CTIME,
NONCE,
PA_CHECKSUM;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(PkAuthenticatorField.CUSEC, Asn1Integer.class),
new ExplicitField(PkAuthenticatorField.CTIME, KerberosTime.class),
new ExplicitField(PkAuthenticatorField.NONCE, Asn1Integer.class),
new ExplicitField(PkAuthenticatorField.PA_CHECKSUM, Asn1OctetString.class)
};
public PkAuthenticator() {
super(fieldInfos);
}
public int getCusec() {
return getFieldAsInt(PkAuthenticatorField.CUSEC);
}
public void setCusec(int cusec) {
setFieldAsInt(PkAuthenticatorField.CUSEC, cusec);
}
public KerberosTime getCtime() {
return getFieldAsTime(PkAuthenticatorField.CTIME);
}
public void setCtime(KerberosTime ctime) {
setFieldAs(PkAuthenticatorField.CTIME, ctime);
}
public int getNonce() {
return getFieldAsInt(PkAuthenticatorField.NONCE);
}
public void setNonce(int nonce) {
setFieldAsInt(PkAuthenticatorField.NONCE, nonce);
}
public byte[] getPaChecksum() {
return getFieldAsOctets(PkAuthenticatorField.PA_CHECKSUM);
}
public void setPaChecksum(byte[] paChecksum) {
setFieldAsOctets(PkAuthenticatorField.PA_CHECKSUM, paChecksum);
}
}
| 101 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/pkinit/KdcDhKeyInfo.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.pkinit;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1BitString;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
KDCDHKeyInfo ::= SEQUENCE {
subjectPublicKey [0] BIT STRING,
nonce [1] INTEGER (0..4294967295),
dhKeyExpiration [2] KerberosTime OPTIONAL,
}
*/
public class KdcDhKeyInfo extends KrbSequenceType {
protected enum KdcDhKeyInfoField implements EnumType {
SUBJECT_PUBLIC_KEY,
NONCE,
DH_KEY_EXPIRATION;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KdcDhKeyInfoField.SUBJECT_PUBLIC_KEY, Asn1BitString.class),
new ExplicitField(KdcDhKeyInfoField.NONCE, Asn1Integer.class),
new ExplicitField(KdcDhKeyInfoField.DH_KEY_EXPIRATION, KerberosTime.class)
};
public KdcDhKeyInfo() {
super(fieldInfos);
}
public Asn1BitString getSubjectPublicKey() {
return getFieldAs(KdcDhKeyInfoField.SUBJECT_PUBLIC_KEY, Asn1BitString.class);
}
public void setSubjectPublicKey(byte[] subjectPubKey) {
setFieldAs(KdcDhKeyInfoField.SUBJECT_PUBLIC_KEY, new Asn1BitString(subjectPubKey));
}
public int getNonce() {
return getFieldAsInt(KdcDhKeyInfoField.NONCE);
}
public void setNonce(int nonce) {
setFieldAsInt(KdcDhKeyInfoField.NONCE, nonce);
}
public KerberosTime getDHKeyExpiration() {
return getFieldAsTime(KdcDhKeyInfoField.DH_KEY_EXPIRATION);
}
public void setDHKeyExpiration(KerberosTime time) {
setFieldAs(KdcDhKeyInfoField.DH_KEY_EXPIRATION, time);
}
}
| 102 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/pkinit/Krb5PrincipalName.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.pkinit;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.base.Realm;
/**
KRB5PrincipalName ::= SEQUENCE {
realm [0] Realm,
principalName [1] PrincipalName
}
*/
public class Krb5PrincipalName extends KrbSequenceType {
protected enum Krb5PrincipalNameField implements EnumType {
REALM,
PRINCIPAL_NAME;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(Krb5PrincipalNameField.REALM, Realm.class),
new ExplicitField(Krb5PrincipalNameField.PRINCIPAL_NAME, PrincipalName.class)
};
public Krb5PrincipalName() {
super(fieldInfos);
}
public String getRelm() {
return getFieldAsString(Krb5PrincipalNameField.REALM);
}
public void setRealm(String realm) {
setFieldAsString(Krb5PrincipalNameField.REALM, realm);
}
public PrincipalName getPrincipalName() {
return getFieldAs(Krb5PrincipalNameField.PRINCIPAL_NAME, PrincipalName.class);
}
public void setPrincipalName(PrincipalName principalName) {
setFieldAs(Krb5PrincipalNameField.PRINCIPAL_NAME, principalName);
}
}
| 103 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/pkinit/TdDhParameters.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.pkinit;
/**
* TD-DH-PARAMETERS ::= SEQUENCE OF AlgorithmIdentifier
*/
public class TdDhParameters extends AlgorithmIdentifiers {
}
| 104 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/otp/OtpTokenInfo.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.otp;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.asn1.type.Asn1Utf8String;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.AlgorithmIdentifiers;
/**
OTP-TOKENINFO ::= SEQUENCE {
flags [0] OTPFlags,
otp-vendor [1] UTF8String OPTIONAL,
otp-challenge [2] OCTET STRING (SIZE(1..MAX)) OPTIONAL,
otp-length [3] Int32 OPTIONAL,
otp-format [4] OTPFormat OPTIONAL,
otp-tokenID [5] OCTET STRING OPTIONAL,
otp-algID [6] AnyURI OPTIONAL,
supportedHashAlg [7] SEQUENCE OF AlgorithmIdentifier OPTIONAL,
iterationCount [8] Int32 OPTIONAL
}
*/
public class OtpTokenInfo extends KrbSequenceType {
protected enum OtpTokenInfoField implements EnumType {
FLAGS,
OTP_VENDOR,
OTP_CHALLENGE,
OTP_LENGTH,
OTP_FORMAT,
OTP_TOKEN_ID,
OTP_ALG_ID,
SUPPORTED_HASH_ALG,
ITERATION_COUNT;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(OtpTokenInfoField.FLAGS, Asn1OctetString.class),
new ExplicitField(OtpTokenInfoField.OTP_VENDOR, Asn1Utf8String.class),
new ExplicitField(OtpTokenInfoField.OTP_CHALLENGE, Asn1OctetString.class),
new ExplicitField(OtpTokenInfoField.OTP_LENGTH, KerberosString.class),
new ExplicitField(OtpTokenInfoField.OTP_FORMAT, Asn1OctetString.class),
new ExplicitField(OtpTokenInfoField.OTP_TOKEN_ID, Asn1Utf8String.class),
new ExplicitField(OtpTokenInfoField.OTP_ALG_ID, Asn1OctetString.class),
new ExplicitField(OtpTokenInfoField.SUPPORTED_HASH_ALG, AlgorithmIdentifiers.class),
new ExplicitField(OtpTokenInfoField.ITERATION_COUNT, Asn1Integer.class)
};
public OtpTokenInfo() {
super(fieldInfos);
}
}
| 105 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/pa/otp/PaOtpChallenge.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.pa.otp;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.asn1.type.Asn1Utf8String;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
PA-OTP-CHALLENGE ::= SEQUENCE {
nonce [0] OCTET STRING,
otp-service [1] UTF8String OPTIONAL,
otp-tokenInfo [2] SEQUENCE (SIZE(1..MAX)) OF OTP-TOKENINFO,
salt [3] KerberosString OPTIONAL,
s2kparams [4] OCTET STRING OPTIONAL,
}
*/
public class PaOtpChallenge extends KrbSequenceType {
protected enum PaOtpChallengeField implements EnumType {
NONCE,
OTP_SERVICE,
OTP_TOKEN_INFO,
SALT,
S2KPARAMS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(PaOtpChallengeField.NONCE, Asn1OctetString.class),
new ExplicitField(PaOtpChallengeField.OTP_SERVICE, Asn1Utf8String.class),
new ExplicitField(PaOtpChallengeField.OTP_TOKEN_INFO, Asn1OctetString.class),
new ExplicitField(PaOtpChallengeField.SALT, KerberosString.class),
new ExplicitField(PaOtpChallengeField.S2KPARAMS, Asn1OctetString.class)
};
public PaOtpChallenge() {
super(fieldInfos);
}
}
| 106 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/AsRep.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
/**
AS-REP ::= [APPLICATION 11] KDC-REP
*/
public class AsRep extends KdcRep {
public AsRep() {
super(KrbMessageType.AS_REP);
}
}
| 107 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/EncKdcRepPart.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbAppSequenceType;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.LastReq;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
/**
EncKDCRepPart ::= SEQUENCE {
key [0] EncryptionKey,
last-req [1] LastReq,
nonce [2] UInt32,
key-expiration [3] KerberosTime OPTIONAL,
flags [4] TicketFlags,
authtime [5] KerberosTime,
starttime [6] KerberosTime OPTIONAL,
endtime [7] KerberosTime,
renew-till [8] KerberosTime OPTIONAL,
srealm [9] Realm,
sname [10] PrincipalName,
caddr [11] HostAddresses OPTIONAL
}
*/
public abstract class EncKdcRepPart extends KrbAppSequenceType {
protected enum EncKdcRepPartField implements EnumType {
KEY,
LAST_REQ,
NONCE,
KEY_EXPIRATION,
FLAGS,
AUTHTIME,
STARTTIME,
ENDTIME,
RENEW_TILL,
SREALM,
SNAME,
CADDR;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EncKdcRepPartField.KEY, EncryptionKey.class),
new ExplicitField(EncKdcRepPartField.LAST_REQ, LastReq.class),
new ExplicitField(EncKdcRepPartField.NONCE, Asn1Integer.class),
new ExplicitField(EncKdcRepPartField.KEY_EXPIRATION, KerberosTime.class),
new ExplicitField(EncKdcRepPartField.FLAGS, TicketFlags.class),
new ExplicitField(EncKdcRepPartField.AUTHTIME, KerberosTime.class),
new ExplicitField(EncKdcRepPartField.STARTTIME, KerberosTime.class),
new ExplicitField(EncKdcRepPartField.ENDTIME, KerberosTime.class),
new ExplicitField(EncKdcRepPartField.RENEW_TILL, KerberosTime.class),
new ExplicitField(EncKdcRepPartField.SREALM, KerberosString.class),
new ExplicitField(EncKdcRepPartField.SNAME, PrincipalName.class),
new ExplicitField(EncKdcRepPartField.CADDR, HostAddresses.class)
};
public EncKdcRepPart(int tagNo) {
super(tagNo, fieldInfos);
}
public EncryptionKey getKey() {
return getFieldAs(EncKdcRepPartField.KEY, EncryptionKey.class);
}
public void setKey(EncryptionKey key) {
setFieldAs(EncKdcRepPartField.KEY, key);
}
public LastReq getLastReq() {
return getFieldAs(EncKdcRepPartField.LAST_REQ, LastReq.class);
}
public void setLastReq(LastReq lastReq) {
setFieldAs(EncKdcRepPartField.LAST_REQ, lastReq);
}
public int getNonce() {
return getFieldAsInt(EncKdcRepPartField.NONCE);
}
public void setNonce(int nonce) {
setFieldAsInt(EncKdcRepPartField.NONCE, nonce);
}
public KerberosTime getKeyExpiration() {
return getFieldAsTime(EncKdcRepPartField.KEY_EXPIRATION);
}
public void setKeyExpiration(KerberosTime keyExpiration) {
setFieldAs(EncKdcRepPartField.KEY_EXPIRATION, keyExpiration);
}
public TicketFlags getFlags() {
return getFieldAs(EncKdcRepPartField.FLAGS, TicketFlags.class);
}
public void setFlags(TicketFlags flags) {
setFieldAs(EncKdcRepPartField.FLAGS, flags);
}
public KerberosTime getAuthTime() {
return getFieldAsTime(EncKdcRepPartField.AUTHTIME);
}
public void setAuthTime(KerberosTime authTime) {
setFieldAs(EncKdcRepPartField.AUTHTIME, authTime);
}
public KerberosTime getStartTime() {
return getFieldAsTime(EncKdcRepPartField.STARTTIME);
}
public void setStartTime(KerberosTime startTime) {
setFieldAs(EncKdcRepPartField.STARTTIME, startTime);
}
public KerberosTime getEndTime() {
return getFieldAsTime(EncKdcRepPartField.ENDTIME);
}
public void setEndTime(KerberosTime endTime) {
setFieldAs(EncKdcRepPartField.ENDTIME, endTime);
}
public KerberosTime getRenewTill() {
return getFieldAsTime(EncKdcRepPartField.RENEW_TILL);
}
public void setRenewTill(KerberosTime renewTill) {
setFieldAs(EncKdcRepPartField.RENEW_TILL, renewTill);
}
public String getSrealm() {
return getFieldAsString(EncKdcRepPartField.SREALM);
}
public void setSrealm(String srealm) {
setFieldAsString(EncKdcRepPartField.SREALM, srealm);
}
public PrincipalName getSname() {
return getFieldAs(EncKdcRepPartField.SNAME, PrincipalName.class);
}
public void setSname(PrincipalName sname) {
setFieldAs(EncKdcRepPartField.SNAME, sname);
}
public HostAddresses getCaddr() {
return getFieldAs(EncKdcRepPartField.CADDR, HostAddresses.class);
}
public void setCaddr(HostAddresses caddr) {
setFieldAs(EncKdcRepPartField.CADDR, caddr);
}
}
| 108 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/AsReq.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
/**
AS-REQ ::= [APPLICATION 10] KDC-REQ
*/
public class AsReq extends KdcReq {
public AsReq() {
super(KrbMessageType.AS_REQ);
}
}
| 109 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/EncAsRepPart.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
/**
EncASRepPart ::= [APPLICATION 25] EncKDCRepPart
*/
public class EncAsRepPart extends EncKdcRepPart {
public static final int TAG = 25;
public EncAsRepPart() {
super(TAG);
}
}
| 110 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/KdcOptions.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.asn1.type.Asn1Flags;
public class KdcOptions extends Asn1Flags {
public KdcOptions() {
this(0);
}
public KdcOptions(int value) {
setFlags(value);
}
}
| 111 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/KdcReq.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessage;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
/**
KDC-REQ ::= SEQUENCE {
-- NOTE: first tag is [1], not [0]
pvno [1] INTEGER (5) ,
msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --),
padata [3] SEQUENCE OF PA-DATA OPTIONAL
-- NOTE: not empty --,
req-encodeBody [4] KDC-REQ-BODY
}
*/
public class KdcReq extends KrbMessage {
protected enum KdcReqField implements EnumType {
PVNO,
MSG_TYPE,
PADATA,
REQ_BODY;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KdcReqField.PVNO, 1, Asn1Integer.class),
new ExplicitField(KdcReqField.MSG_TYPE, 2, Asn1Integer.class),
new ExplicitField(KdcReqField.PADATA, 3, PaData.class),
new ExplicitField(KdcReqField.REQ_BODY, 4, KdcReqBody.class)
};
public KdcReq(KrbMessageType msgType) {
super(msgType, fieldInfos);
}
public PaData getPaData() {
return getFieldAs(KdcReqField.PADATA, PaData.class);
}
public void setPaData(PaData paData) {
setFieldAs(KdcReqField.PADATA, paData);
}
public void addPaData(PaDataEntry paDataEntry) {
if (getPaData() == null) {
setPaData(new PaData());
}
getPaData().addElement(paDataEntry);
}
public KdcReqBody getReqBody() {
return getFieldAs(KdcReqField.REQ_BODY, KdcReqBody.class);
}
public void setReqBody(KdcReqBody reqBody) {
setFieldAs(KdcReqField.REQ_BODY, reqBody);
}
}
| 112 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/TgsRep.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
/**
TGS-REP ::= [APPLICATION 13] KDC-REP
*/
public class TgsRep extends KdcRep {
public TgsRep() {
super(KrbMessageType.TGS_REP);
}
}
| 113 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/KdcOption.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.asn1.EnumType;
public enum KdcOption implements EnumType {
NONE(-1),
//RESERVED(0x80000000),
FORWARDABLE(0x40000000),
FORWARDED(0x20000000),
PROXIABLE(0x10000000),
PROXY(0x08000000),
ALLOW_POSTDATE(0x04000000),
POSTDATED(0x02000000),
//UNUSED(0x01000000),
RENEWABLE(0x00800000),
//UNUSED(0x00400000),
//RESERVED(0x00200000),
//RESERVED(0x00100000),
//RESERVED(0x00080000),
//RESERVED(0x00040000),
CNAME_IN_ADDL_TKT(0x00020000),
CANONICALIZE(0x00010000),
REQUEST_ANONYMOUS(0x00008000),
//RESERVED(0x00004000),
//RESERVED(0x00002000),
//RESERVED(0x00001000),
//RESERVED(0x00000800),
//RESERVED(0x00000400),
//RESERVED(0x00000200),
//RESERVED(0x00000100),
//RESERVED(0x00000080),
//RESERVED(0x00000040),
DISABLE_TRANSITED_CHECK(0x00000020),
RENEWABLE_OK(0x00000010),
ENC_TKT_IN_SKEY(0x00000008),
//UNUSED(0x00000004),
RENEW(0x00000002),
VALIDATE(0x00000001);
private final int value;
KdcOption(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static KdcOption fromValue(int value) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (KdcOption) e;
}
}
return NONE;
}
}
| 114 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/KdcReqBody.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbIntegers;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.Tickets;
/**
KDC-REQ-BODY ::= SEQUENCE {
kdc-options [0] KDCOptions,
cname [1] PrincipalName OPTIONAL
-- Used only in AS-REQ --,
realm [2] Realm
-- Server's realm
-- Also client's in AS-REQ --,
sname [3] PrincipalName OPTIONAL,
from [4] KerberosTime OPTIONAL,
till [5] KerberosTime,
rtime [6] KerberosTime OPTIONAL,
nonce [7] UInt32,
etype [8] SEQUENCE OF Int32 -- EncryptionType
-- in preference order --,
addresses [9] HostAddresses OPTIONAL,
enc-authorization-data [10] EncryptedData OPTIONAL
-- AuthorizationData --,
additional-tickets [11] SEQUENCE OF Ticket OPTIONAL
-- NOTE: not empty
}
*/
public class KdcReqBody extends KrbSequenceType {
protected enum KdcReqBodyField implements EnumType {
KDC_OPTIONS,
CNAME,
REALM,
SNAME,
FROM,
TILL,
RTIME,
NONCE,
ETYPE,
ADDRESSES,
ENC_AUTHORIZATION_DATA,
ADDITIONAL_TICKETS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KdcReqBodyField.KDC_OPTIONS, KdcOptions.class),
new ExplicitField(KdcReqBodyField.CNAME, PrincipalName.class),
new ExplicitField(KdcReqBodyField.REALM, KerberosString.class),
new ExplicitField(KdcReqBodyField.SNAME, PrincipalName.class),
new ExplicitField(KdcReqBodyField.FROM, KerberosTime.class),
new ExplicitField(KdcReqBodyField.TILL, KerberosTime.class),
new ExplicitField(KdcReqBodyField.RTIME, KerberosTime.class),
new ExplicitField(KdcReqBodyField.NONCE, Asn1Integer.class),
new ExplicitField(KdcReqBodyField.ETYPE, KrbIntegers.class),
new ExplicitField(KdcReqBodyField.ADDRESSES, HostAddresses.class),
new ExplicitField(KdcReqBodyField.ENC_AUTHORIZATION_DATA, AuthorizationData.class),
new ExplicitField(KdcReqBodyField.ADDITIONAL_TICKETS, Tickets.class)
};
public KdcReqBody() {
super(fieldInfos);
}
private AuthorizationData authorizationData;
public KerberosTime getFrom() {
return getFieldAs(KdcReqBodyField.FROM, KerberosTime.class);
}
public void setFrom(KerberosTime from) {
setFieldAs(KdcReqBodyField.FROM, from);
}
public KerberosTime getTill() {
return getFieldAs(KdcReqBodyField.TILL, KerberosTime.class);
}
public void setTill(KerberosTime till) {
setFieldAs(KdcReqBodyField.TILL, till);
}
public KerberosTime getRtime() {
return getFieldAs(KdcReqBodyField.RTIME, KerberosTime.class);
}
public void setRtime(KerberosTime rtime) {
setFieldAs(KdcReqBodyField.RTIME, rtime);
}
public int getNonce() {
return getFieldAsInt(KdcReqBodyField.NONCE);
}
public void setNonce(int nonce) {
setFieldAsInt(KdcReqBodyField.NONCE, nonce);
}
public List<EncryptionType> getEtypes() {
KrbIntegers values = getFieldAs(KdcReqBodyField.ETYPE, KrbIntegers.class);
if (values == null) {
return Collections.emptyList();
}
List<EncryptionType> results = new ArrayList<>();
for (Integer value : values.getValues()) {
results.add(EncryptionType.fromValue(value));
}
return results;
}
public void setEtypes(List<EncryptionType> etypes) {
List<Integer> values = new ArrayList<>();
for (EncryptionType etype: etypes) {
values.add(etype.getValue());
}
KrbIntegers value = new KrbIntegers(values);
setFieldAs(KdcReqBodyField.ETYPE, value);
}
public HostAddresses getAddresses() {
return getFieldAs(KdcReqBodyField.ADDRESSES, HostAddresses.class);
}
public void setAddresses(HostAddresses addresses) {
setFieldAs(KdcReqBodyField.ADDRESSES, addresses);
}
public EncryptedData getEncryptedAuthorizationData() {
return getFieldAs(KdcReqBodyField.ENC_AUTHORIZATION_DATA, EncryptedData.class);
}
public void setEncryptedAuthorizationData(EncryptedData encAuthorizationData) {
setFieldAs(KdcReqBodyField.ENC_AUTHORIZATION_DATA, encAuthorizationData);
}
public AuthorizationData getAuthorizationData() {
return authorizationData;
}
public void setAuthorizationData(AuthorizationData authorizationData) {
this.authorizationData = authorizationData;
}
public Tickets getAdditionalTickets() {
return getFieldAs(KdcReqBodyField.ADDITIONAL_TICKETS, Tickets.class);
}
public void setAdditionalTickets(Tickets additionalTickets) {
setFieldAs(KdcReqBodyField.ADDITIONAL_TICKETS, additionalTickets);
}
public KdcOptions getKdcOptions() {
return getFieldAs(KdcReqBodyField.KDC_OPTIONS, KdcOptions.class);
}
public void setKdcOptions(KdcOptions kdcOptions) {
setFieldAs(KdcReqBodyField.KDC_OPTIONS, kdcOptions);
}
public PrincipalName getSname() {
return getFieldAs(KdcReqBodyField.SNAME, PrincipalName.class);
}
public void setSname(PrincipalName sname) {
setFieldAs(KdcReqBodyField.SNAME, sname);
}
public PrincipalName getCname() {
return getFieldAs(KdcReqBodyField.CNAME, PrincipalName.class);
}
public void setCname(PrincipalName cname) {
setFieldAs(KdcReqBodyField.CNAME, cname);
}
public String getRealm() {
return getFieldAsString(KdcReqBodyField.REALM);
}
public void setRealm(String realm) {
setFieldAs(KdcReqBodyField.REALM, new KerberosString(realm));
}
}
| 115 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/TgsReq.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
/**
TGS-REQ ::= [APPLICATION 12] KDC-REQ
*/
public class TgsReq extends KdcReq {
public TgsReq() {
super(KrbMessageType.TGS_REQ);
}
}
| 116 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/KdcRep.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessage;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
/**
KDC-REP ::= SEQUENCE {
pvno [0] INTEGER (5),
msg-type [1] INTEGER (11 -- AS -- | 13 -- TGS --),
padata [2] SEQUENCE OF PA-DATA OPTIONAL
-- NOTE: not empty --,
crealm [3] Realm,
cname [4] PrincipalName,
ticket [5] Ticket,
enc-part [6] EncryptedData
-- EncASRepPart or EncTGSRepPart,
-- as appropriate
}
*/
public class KdcRep extends KrbMessage {
protected enum KdcRepField implements EnumType {
PVNO,
MSG_TYPE,
PADATA,
CREALM,
CNAME,
TICKET,
ENC_PART;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KdcRepField.PVNO, Asn1Integer.class),
new ExplicitField(KdcRepField.MSG_TYPE, Asn1Integer.class),
new ExplicitField(KdcRepField.PADATA, PaData.class),
new ExplicitField(KdcRepField.CREALM, KerberosString.class),
new ExplicitField(KdcRepField.CNAME, PrincipalName.class),
new ExplicitField(KdcRepField.TICKET, Ticket.class),
new ExplicitField(KdcRepField.ENC_PART, EncryptedData.class)
};
private EncKdcRepPart encPart;
public KdcRep(KrbMessageType msgType) {
super(msgType, fieldInfos);
}
public PaData getPaData() {
return getFieldAs(KdcRepField.PADATA, PaData.class);
}
public void setPaData(PaData paData) {
setFieldAs(KdcRepField.PADATA, paData);
}
public PrincipalName getCname() {
return getFieldAs(KdcRepField.CNAME, PrincipalName.class);
}
public void setCname(PrincipalName sname) {
setFieldAs(KdcRepField.CNAME, sname);
}
public String getCrealm() {
return getFieldAsString(KdcRepField.CREALM);
}
public void setCrealm(String realm) {
setFieldAs(KdcRepField.CREALM, new KerberosString(realm));
}
public Ticket getTicket() {
return getFieldAs(KdcRepField.TICKET, Ticket.class);
}
public void setTicket(Ticket ticket) {
setFieldAs(KdcRepField.TICKET, ticket);
}
public EncryptedData getEncryptedEncPart() {
return getFieldAs(KdcRepField.ENC_PART, EncryptedData.class);
}
public void setEncryptedEncPart(EncryptedData encryptedEncPart) {
setFieldAs(KdcRepField.ENC_PART, encryptedEncPart);
}
public EncKdcRepPart getEncPart() {
return encPart;
}
public void setEncPart(EncKdcRepPart encPart) {
this.encPart = encPart;
}
}
| 117 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/kdc/EncTgsRepPart.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.kdc;
/**
EncTGSRepPart ::= [APPLICATION 26] EncKDCRepPart
*/
public class EncTgsRepPart extends EncKdcRepPart {
public static final int TAG = 26;
public EncTgsRepPart() {
super(TAG);
}
}
| 118 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/TicketFlags.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.asn1.type.Asn1Flags;
import static org.apache.kerby.kerberos.kerb.type.ticket.TicketFlag.INVALID;
public class TicketFlags extends Asn1Flags {
public TicketFlags() {
this(0);
}
public TicketFlags(int value) {
setFlags(value);
}
public boolean isInvalid() {
return isFlagSet(INVALID.getValue());
}
}
| 119 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/Tickets.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
SEQUENCE OF Ticket
*/
public class Tickets extends KrbSequenceOfType<Ticket> {
}
| 120 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/TicketFlag.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.asn1.EnumType;
public enum TicketFlag implements EnumType {
NONE(-1),
FORWARDABLE(0x40000000),
FORWARDED(0x20000000),
PROXIABLE(0x10000000),
PROXY(0x08000000),
MAY_POSTDATE(0x04000000),
POSTDATED(0x02000000),
INVALID(0x01000000),
RENEWABLE(0x00800000),
INITIAL(0x00400000),
PRE_AUTH(0x00200000),
HW_AUTH(0x00100000),
TRANSIT_POLICY_CHECKED(0x00080000),
OK_AS_DELEGATE(0x00040000),
ENC_PA_REP(0x00010000),
ANONYMOUS(0x00008000);
private final int value;
TicketFlag(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static TicketFlag fromValue(int value) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (TicketFlag) e;
}
}
return NONE;
}
}
| 121 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/TgtTicket.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.kdc.EncAsRepPart;
/**
* Ticket granting ticket.
*/
public class TgtTicket extends KrbTicket {
private PrincipalName clientPrincipal;
public TgtTicket(Ticket ticket, EncAsRepPart encKdcRepPart, PrincipalName clientPrincipal) {
super(ticket, encKdcRepPart);
this.clientPrincipal = clientPrincipal;
}
public PrincipalName getClientPrincipal() {
return clientPrincipal;
}
}
| 122 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/SgtTicket.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.kdc.EncTgsRepPart;
/**
* Service granting ticket.
*/
public class SgtTicket extends KrbTicket {
private PrincipalName clientPrincipal;
public SgtTicket(Ticket ticket, EncTgsRepPart encKdcRepPart) {
super(ticket, encKdcRepPart);
}
public PrincipalName getClientPrincipal() {
return clientPrincipal;
}
public void setClientPrincipal(PrincipalName clientPrincipal) {
this.clientPrincipal = clientPrincipal;
}
}
| 123 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/EncTicketPart.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbAppSequenceType;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.base.TransitedEncoding;
/**
-- Encrypted part of ticket
EncTicketPart ::= [APPLICATION 3] SEQUENCE {
flags [0] TicketFlags,
key [1] EncryptionKey,
crealm [2] Realm,
cname [3] PrincipalName,
transited [4] TransitedEncoding,
authtime [5] KerberosTime,
starttime [6] KerberosTime OPTIONAL,
endtime [7] KerberosTime,
renew-till [8] KerberosTime OPTIONAL,
caddr [9] HostAddresses OPTIONAL,
authorization-data [10] AuthorizationData OPTIONAL
}
*/
public class EncTicketPart extends KrbAppSequenceType {
public static final int TAG = 3;
protected enum EncTicketPartField implements EnumType {
FLAGS,
KEY,
CREALM,
CNAME,
TRANSITED,
AUTHTIME,
STARTTIME,
ENDTIME,
RENEW_TILL,
CADDR,
AUTHORIZATION_DATA;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EncTicketPartField.FLAGS, TicketFlags.class),
new ExplicitField(EncTicketPartField.KEY, EncryptionKey.class),
new ExplicitField(EncTicketPartField.CREALM, KerberosString.class),
new ExplicitField(EncTicketPartField.CNAME, PrincipalName.class),
new ExplicitField(EncTicketPartField.TRANSITED, TransitedEncoding.class),
new ExplicitField(EncTicketPartField.AUTHTIME, KerberosTime.class),
new ExplicitField(EncTicketPartField.STARTTIME, KerberosTime.class),
new ExplicitField(EncTicketPartField.ENDTIME, KerberosTime.class),
new ExplicitField(EncTicketPartField.RENEW_TILL, KerberosTime.class),
new ExplicitField(EncTicketPartField.CADDR, HostAddresses.class),
new ExplicitField(EncTicketPartField.AUTHORIZATION_DATA, AuthorizationData.class)
};
public EncTicketPart() {
super(TAG, fieldInfos);
}
public TicketFlags getFlags() {
return getFieldAs(EncTicketPartField.FLAGS, TicketFlags.class);
}
public void setFlags(TicketFlags flags) {
setFieldAs(EncTicketPartField.FLAGS, flags);
}
public EncryptionKey getKey() {
return getFieldAs(EncTicketPartField.KEY, EncryptionKey.class);
}
public void setKey(EncryptionKey key) {
setFieldAs(EncTicketPartField.KEY, key);
}
public String getCrealm() {
return getFieldAsString(EncTicketPartField.CREALM);
}
public void setCrealm(String crealm) {
setFieldAsString(EncTicketPartField.CREALM, crealm);
}
public PrincipalName getCname() {
return getFieldAs(EncTicketPartField.CNAME, PrincipalName.class);
}
public void setCname(PrincipalName cname) {
setFieldAs(EncTicketPartField.CNAME, cname);
}
public TransitedEncoding getTransited() {
return getFieldAs(EncTicketPartField.TRANSITED, TransitedEncoding.class);
}
public void setTransited(TransitedEncoding transited) {
setFieldAs(EncTicketPartField.TRANSITED, transited);
}
public KerberosTime getAuthTime() {
return getFieldAs(EncTicketPartField.AUTHTIME, KerberosTime.class);
}
public void setAuthTime(KerberosTime authTime) {
setFieldAs(EncTicketPartField.AUTHTIME, authTime);
}
public KerberosTime getStartTime() {
return getFieldAs(EncTicketPartField.STARTTIME, KerberosTime.class);
}
public void setStartTime(KerberosTime startTime) {
setFieldAs(EncTicketPartField.STARTTIME, startTime);
}
public KerberosTime getEndTime() {
return getFieldAs(EncTicketPartField.ENDTIME, KerberosTime.class);
}
public void setEndTime(KerberosTime endTime) {
setFieldAs(EncTicketPartField.ENDTIME, endTime);
}
public KerberosTime getRenewtill() {
return getFieldAs(EncTicketPartField.RENEW_TILL, KerberosTime.class);
}
public void setRenewtill(KerberosTime renewtill) {
setFieldAs(EncTicketPartField.RENEW_TILL, renewtill);
}
public HostAddresses getClientAddresses() {
return getFieldAs(EncTicketPartField.CADDR, HostAddresses.class);
}
public void setClientAddresses(HostAddresses clientAddresses) {
setFieldAs(EncTicketPartField.CADDR, clientAddresses);
}
public AuthorizationData getAuthorizationData() {
return getFieldAs(EncTicketPartField.AUTHORIZATION_DATA, AuthorizationData.class);
}
public void setAuthorizationData(AuthorizationData authorizationData) {
setFieldAs(EncTicketPartField.AUTHORIZATION_DATA, authorizationData);
}
}
| 124 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/Ticket.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.KrbConstant;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KrbAppSequenceType;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
/**
Ticket ::= [APPLICATION 1] SEQUENCE {
tkt-vno [0] INTEGER (5),
realm [1] Realm,
sname [2] PrincipalName,
enc-part [3] EncryptedData -- EncTicketPart
}
*/
public class Ticket extends KrbAppSequenceType {
public static final int TKT_KVNO = KrbConstant.KRB_V5;
public static final int TAG = 1;
protected enum TicketField implements EnumType {
TKT_VNO,
REALM,
SNAME,
ENC_PART;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(TicketField.TKT_VNO, 0, Asn1Integer.class),
new ExplicitField(TicketField.REALM, 1, KerberosString.class),
new ExplicitField(TicketField.SNAME, 2, PrincipalName.class),
new ExplicitField(TicketField.ENC_PART, 3, EncryptedData.class)
};
public Ticket() {
super(TAG, fieldInfos);
setTktKvno(TKT_KVNO);
}
private EncTicketPart encPart;
public int getTktvno() {
return getFieldAsInt(TicketField.TKT_VNO);
}
public void setTktKvno(int kvno) {
setFieldAsInt(TicketField.TKT_VNO, kvno);
}
public PrincipalName getSname() {
return getFieldAs(TicketField.SNAME, PrincipalName.class);
}
public void setSname(PrincipalName sname) {
setFieldAs(TicketField.SNAME, sname);
}
public String getRealm() {
return getFieldAsString(TicketField.REALM);
}
public void setRealm(String realm) {
setFieldAs(TicketField.REALM, new KerberosString(realm));
}
public EncryptedData getEncryptedEncPart() {
return getFieldAs(TicketField.ENC_PART, EncryptedData.class);
}
public void setEncryptedEncPart(EncryptedData encryptedEncPart) {
setFieldAs(TicketField.ENC_PART, encryptedEncPart);
}
public EncTicketPart getEncPart() {
return encPart;
}
public void setEncPart(EncTicketPart encPart) {
this.encPart = encPart;
}
}
| 125 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ticket/KrbTicket.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.ticket;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.kdc.EncKdcRepPart;
public class KrbTicket {
private Ticket ticket;
private EncKdcRepPart encKdcRepPart;
public KrbTicket(Ticket ticket, EncKdcRepPart encKdcRepPart) {
this.ticket = ticket;
this.encKdcRepPart = encKdcRepPart;
}
public Ticket getTicket() {
return ticket;
}
public EncKdcRepPart getEncKdcRepPart() {
return encKdcRepPart;
}
public EncryptionKey getSessionKey() {
return encKdcRepPart.getKey();
}
public String getRealm() {
return ticket.getRealm();
}
}
| 126 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EncryptionKey.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.util.Arrays;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
EncryptionKey ::= SEQUENCE {
keytype [0] Int32 -- actually encryption type --,
keyvalue [1] OCTET STRING
}
*/
public class EncryptionKey extends KrbSequenceType {
protected enum EncryptionKeyField implements EnumType {
KEY_TYPE,
KEY_VALUE;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
private int kvno = -1;
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EncryptionKeyField.KEY_TYPE, Asn1Integer.class),
new ExplicitField(EncryptionKeyField.KEY_VALUE, Asn1OctetString.class)
};
public EncryptionKey() {
super(fieldInfos);
}
public EncryptionKey(int keyType, byte[] keyData) {
this(keyType, keyData, -1);
}
public EncryptionKey(int keyType, byte[] keyData, int kvno) {
this(EncryptionType.fromValue(keyType), keyData, kvno);
}
public EncryptionKey(EncryptionType keyType, byte[] keyData) {
this(keyType, keyData, -1);
}
public EncryptionKey(EncryptionType keyType, byte[] keyData, int kvno) {
this();
setKeyType(keyType);
setKeyData(keyData);
setKvno(kvno);
}
public EncryptionType getKeyType() {
Integer value = getFieldAsInteger(EncryptionKeyField.KEY_TYPE);
return EncryptionType.fromValue(value);
}
public void setKeyType(EncryptionType keyType) {
setFieldAsInt(EncryptionKeyField.KEY_TYPE, keyType.getValue());
}
public byte[] getKeyData() {
return getFieldAsOctets(EncryptionKeyField.KEY_VALUE);
}
public void setKeyData(byte[] keyData) {
setFieldAsOctets(EncryptionKeyField.KEY_VALUE, keyData);
}
public void setKvno(int kvno) {
this.kvno = kvno;
}
public int getKvno() {
return kvno;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EncryptionKey that = (EncryptionKey) o;
if (kvno != -1 && that.kvno != -1 && kvno != that.kvno) {
return false;
}
if (getKeyType() != that.getKeyType()) {
return false;
}
return Arrays.equals(getKeyData(), that.getKeyData());
}
@Override
public int hashCode() {
int result = kvno;
if (getKeyType() != null) {
result = 31 * result + getKeyType().hashCode();
}
if (getKeyData() != null) {
result = 31 * result + Arrays.hashCode(getKeyData());
}
return result;
}
}
| 127 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/LastReqEntry.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
LastReq ::= SEQUENCE OF SEQUENCE {
lr-type [0] Int32,
lr-value [1] KerberosTime
}
*/
public class LastReqEntry extends KrbSequenceType {
protected enum LastReqEntryField implements EnumType {
LR_TYPE,
LR_VALUE;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(LastReqEntryField.LR_TYPE, Asn1Integer.class),
new ExplicitField(LastReqEntryField.LR_VALUE, KerberosTime.class)
};
public LastReqEntry() {
super(fieldInfos);
}
public LastReqType getLrType() {
Integer value = getFieldAsInteger(LastReqEntryField.LR_TYPE);
return LastReqType.fromValue(value);
}
public void setLrType(LastReqType lrType) {
setFieldAsInt(LastReqEntryField.LR_TYPE, lrType.getValue());
}
public KerberosTime getLrValue() {
return getFieldAs(LastReqEntryField.LR_VALUE, KerberosTime.class);
}
public void setLrValue(KerberosTime lrValue) {
setFieldAs(LastReqEntryField.LR_VALUE, lrValue);
}
}
| 128 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KrbTokenBase.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* KRB-TOKEN_VALUE ::= SEQUENCE {
* token-format [0] INTEGER,
* token-value [1] OCTET STRING,
* }
*/
public class KrbTokenBase extends KrbSequenceType {
protected enum KrbTokenField implements EnumType {
TOKEN_FORMAT,
TOKEN_VALUE;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[]{
new ExplicitField(KrbTokenField.TOKEN_FORMAT, Asn1Integer.class),
new ExplicitField(KrbTokenField.TOKEN_VALUE, Asn1OctetString.class)
};
/**
* Default constructor.
*/
public KrbTokenBase() {
super(fieldInfos);
}
/**
* Get token format.
* @return The token format
*/
public TokenFormat getTokenFormat() {
Integer value = getFieldAsInteger(KrbTokenField.TOKEN_FORMAT);
return TokenFormat.fromValue(value);
}
/**
* Set token format.
* @param tokenFormat The token format
*/
public void setTokenFormat(TokenFormat tokenFormat) {
setFieldAsInt(KrbTokenField.TOKEN_FORMAT, tokenFormat.getValue());
}
/**
* Get token value.
* @return The token value
*/
public byte[] getTokenValue() {
return getFieldAsOctets(KrbTokenField.TOKEN_VALUE);
}
/**
* Set token value.
* @param tokenValue The token value
*/
public void setTokenValue(byte[] tokenValue) {
setFieldAsOctets(KrbTokenField.TOKEN_VALUE, tokenValue);
}
}
| 129 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddresses.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.net.InetAddress;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
* The HostAddress as defined in RFC 4120 :
* <pre>
* -- NOTE: HostAddresses is always used as an OPTIONAL field and
* -- should not be empty.
* HostAddresses -- NOTE: subtly different from rfc1510,
* -- but has a value mapping and encodes the same
* ::= SEQUENCE OF HostAddress
* </pre>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class HostAddresses extends KrbSequenceOfType<HostAddress> {
/**
* Tells if the list of HostAddresses contain a given HostAddress
* @param address The {@link InetAddress} we are looking for
* @return <tt>true</tt> if it's present
*/
public boolean contains(InetAddress address) {
for (HostAddress hostAddress : getElements()) {
if (hostAddress.equalsWith(address)) {
return true;
}
}
return false;
}
}
| 130 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/MethodData.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
/**
METHOD-DATA ::= SEQUENCE OF PA-DATA
*/
public class MethodData extends KrbSequenceOfType<PaDataEntry> {
}
| 131 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* The various possible HostAddress types.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum HostAddrType implements EnumType {
/**
* Constant for the "null" host address type.
*/
NONE(0),
/**
* Constant for the "Internet" host address type.
*/
ADDRTYPE_INET(2),
/**
* Constant for the "Arpanet" host address type.
*/
ADDRTYPE_IMPLINK(3),
/**
* Constant for the "CHAOS" host address type.
*/
ADDRTYPE_CHAOS(5),
/**
* Constant for the "XEROX Network Services" host address type.
*/
ADDRTYPE_XNS(6),
/**
* Constant for the "OSI" host address type.
*/
ADDRTYPE_OSI(7),
/**
* Constant for the "DECnet" host address type.
*/
ADDRTYPE_DECNET(12),
/**
* Constant for the "AppleTalk" host address type.
*/
ADDRTYPE_APPLETALK(16),
/**
* Constant for the "NetBios" host address type.
*
* Not in RFC
*/
ADDRTYPE_NETBIOS(20),
/**
* Constant for the "Internet Protocol V6" host address type.
*/
ADDRTYPE_INET6(24);
/** the inner value */
private final int value;
/**
* Create a new enum instance
*/
HostAddrType(int value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
/**
* Get the HostAddrType associated with a value.
*
* @param value The integer value of the HostAddrType we are looking for
* @return The associated HostAddrType, or NULL if not found or if value is null
*/
public static HostAddrType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value.intValue()) {
return (HostAddrType) e;
}
}
}
return HostAddrType.NONE;
}
}
| 132 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/AuthToken.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* This is the token definition API according to TokenPreauth draft.
*/
public interface AuthToken {
/**
* Get the token subject
* @return token subject
*/
String getSubject();
/**
* Set token subject
* @param sub The token subject
*/
void setSubject(String sub);
/**
* Get the token issuer
* @return token issuer
*/
String getIssuer();
/**
* Set token issuer
* @param issuer The token issuer
*/
void setIssuer(String issuer);
/**
* Get token audiences
* @return token audiences
*/
List<String> getAudiences();
/**
* Set token audiences
* @param audiences The token audiences
*/
void setAudiences(List<String> audiences);
/**
* Is an Identity Token ?
* @return true if it's an identity token, false otherwise
*/
boolean isIdToken();
void isIdToken(boolean isIdToken);
/**
* Is an Access Token ?
* @return true if it's an access token, false otherwise
*/
boolean isAcToken();
void isAcToken(boolean isAcToken);
/**
* Is a Bearer Token ?
* @return true if it's an bearer token, false otherwise
*/
boolean isBearerToken();
/**
* Is an Holder-of-Key Token (HOK) ?
* @return true if it's a HOK token, false otherwise
*/
boolean isHolderOfKeyToken();
/**
* Get token expired data time.
* @return expired time
*/
Date getExpiredTime();
/**
* Set token expired time
* @param exp The token expired time
*/
void setExpirationTime(Date exp);
/**
* Get token not before time.
* @return not before time
*/
Date getNotBeforeTime();
/**
* Set token not before time.
* @param nbt The time
*/
void setNotBeforeTime(Date nbt);
/**
* Get token issued at time when the token is issued.
* @return issued at time
*/
Date getIssueTime();
/**
* Set token issued at time.
* @param iat Time time when token issued
*/
void setIssueTime(Date iat);
/**
* Get token attributes.
* @return token attributes
*/
Map<String, Object> getAttributes();
/**
* Add a token attribute.
* @param name The attribute name
* @param value The attribute value
*/
void addAttribute(String name, Object value);
}
| 133 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KrbMessageType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* The possible Kerberos Messages :
*
* <ul>
* <li>AS-REQ : [APPLICATION 10]</li>
* <li>AS-REP : [APPLICATION 11]</li>
* <li>TGS-REQ : [APPLICATION 12]</li>
* <li>TGS-REP : [APPLICATION 13]</li>
* <li>AP-REQ : [APPLICATION 14]</li>
* <li>AP-REP : [APPLICATION 15]</li>
* <li>KRB-SAFE : [APPLICATION 20]</li>
* <li>KRB-PRIV : [APPLICATION 21]</li>
* <li>KRB-CRED : [APPLICATION 22]</li>
* <li>KRB_ERROR : [APPLICATION 30]</li>
* </ul>
*
* @author elecharny
*
*/
public enum KrbMessageType implements EnumType {
NONE(-1),
AS_REQ(10),
AS_REP(11),
TGS_REQ(12),
TGS_REP(13),
AP_REQ(14),
AP_REP(15),
KRB_SAFE(20),
KRB_PRIV(21),
KRB_CRED(22),
KRB_ERROR(30);
/** The internal value */
private int value;
/**
* Create a new enum
*/
KrbMessageType(int value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
/**
* Get the KrbMessageType associated with a value.
*
* @param value The integer value of the KrbMessageType we are looking for
* @return The associated KrbMessageType, or NONE if not found or if value is null
*/
public static KrbMessageType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value.intValue()) {
return (KrbMessageType) e;
}
}
}
return NONE;
}
}
| 134 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EncryptionType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* According to krb5.hin
*/
public enum EncryptionType implements EnumType {
NONE(0, "none", "None encryption type"),
DES_CBC_CRC(0x0001, "des-cbc-crc", "DES cbc mode with CRC-32"),
DES_CBC_MD4(0x0002, "des-cbc-md4", "DES cbc mode with RSA-MD4"),
DES_CBC_MD5(0x0003, "des-cbc-md5", "DES cbc mode with RSA-MD5"),
DES(0x0003, "des", "DES cbc mode with RSA-MD5"),
DES_CBC_RAW(0x0004, "des-cbc-raw", "DES cbc mode raw"),
DES3_CBC_SHA(0x0005, "des3-cbc-sha", "DES-3 cbc with SHA1"),
DES3_CBC_RAW(0x0006, "des3-cbc-raw", "Triple DES cbc mode raw"),
DES_HMAC_SHA1(0x0008, "des-hmac-sha1", "DES with HMAC/sha1"),
DSA_SHA1_CMS(0x0009, "dsa-sha1-cms", "DSA with SHA1, CMS signature"),
MD5_RSA_CMS(0x000a, "md5-rsa-cms", "MD5 with RSA, CMS signature"),
SHA1_RSA_CMS(0x000b, "sha1-rsa-cms", "SHA1 with RSA, CMS signature"),
RC2_CBC_ENV(0x000c, "rc2-cbc-env", "RC2 cbc mode, CMS enveloped data"),
RSA_ENV(0x000d, "rsa-env", "RSA encryption, CMS enveloped data"),
RSA_ES_OAEP_ENV(0x000e, "rsa-es-oaep-env", "RSA w/OEAP encryption, CMS enveloped data"),
DES3_CBC_ENV(0x000f, "des3-cbc-env", "DES-3 cbc mode, CMS enveloped data"),
DES3_CBC_SHA1(0x0010, "des3-cbc-sha1", "Triple DES cbc mode with HMAC/sha1"),
DES3_HMAC_SHA1(0x0010, "des3-hmac-sha1", "Triple DES cbc mode with HMAC/sha1"),
DES3_CBC_SHA1_KD(0x0010, "des3-cbc-sha1-kd", "Triple DES cbc mode with HMAC/sha1"),
AES128_CTS_HMAC_SHA1_96 (0x0011, "aes128-cts-hmac-sha1-96", "AES-128 CTS mode with 96-bit SHA-1 HMAC"),
AES128_CTS (0x0011, "aes128-cts", "AES-128 CTS mode with 96-bit SHA-1 HMAC"),
AES256_CTS_HMAC_SHA1_96(0x0012, "aes256-cts-hmac-sha1-96", "AES-256 CTS mode with 96-bit SHA-1 HMAC"),
AES256_CTS(0x0012, "aes256-cts", "AES-256 CTS mode with 96-bit SHA-1 HMAC"),
ARCFOUR_HMAC(0x0017, "arcfour-hmac", "ArcFour with HMAC/md5"),
RC4_HMAC(0x0017, "rc4-hmac", "ArcFour with HMAC/md5"),
ARCFOUR_HMAC_MD5(0x0017, "arcfour-hmac-md5", "ArcFour with HMAC/md5"),
ARCFOUR_HMAC_EXP(0x0018, "arcfour-hmac-exp", "Exportable ArcFour with HMAC/md5"),
RC4_HMAC_EXP(0x0018, "rc4-hmac-exp", "Exportable ArcFour with HMAC/md5"),
ARCFOUR_HMAC_MD5_EXP(0x0018, "arcfour-hmac-md5-exp", "Exportable ArcFour with HMAC/md5"),
CAMELLIA128_CTS_CMAC(0x0019, "camellia128-cts-cmac", "Camellia-128 CTS mode with CMAC"),
CAMELLIA128_CTS(0x0019, "camellia128-cts", "Camellia-128 CTS mode with CMAC"),
CAMELLIA256_CTS_CMAC(0x001a, "camellia256-cts-cmac", "Camellia-256 CTS mode with CMAC"),
CAMELLIA256_CTS(0x001a, "camellia256-cts", "Camellia-256 CTS mode with CMAC");
//UNKNOWN(0x01ff, "UNKNOWN", "Unknown encryption type");
private final int value;
private final String name;
private final String displayName;
EncryptionType(int value, String name, String displayName) {
this.value = value;
this.name = name;
this.displayName = displayName;
}
@Override
public int getValue() {
return value;
}
public String getName() {
return name;
}
public String getDisplayName() {
return displayName;
}
/**
* Is the type uses AES256 or not
* @return true if uses AES256, false otherwise.
*/
public boolean usesAES256() {
return name.contains("aes256");
}
public static EncryptionType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (EncryptionType) e;
}
}
}
return NONE;
}
public static EncryptionType fromName(String name) {
if (name != null) {
for (EncryptionType e : values()) {
if (e.getName().equals(name)) {
return e;
}
}
}
return NONE;
}
}
| 135 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/PrincipalName.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.kerberos.kerb.type.KerberosStrings;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* The PrincipalName as defined in RFC 4120 :
*
* <pre>
* PrincipalName ::= SEQUENCE {
* name-type [0] Int32,
* name-string [1] SEQUENCE OF KerberosString
* }
* </pre>
*
* The possible <tt>name-type</tt> are :
* <ul>
* <li>NT-UNKNOWN (0) : Name type not known</li>
* <li>NT-PRINCIPAL (1) : Just the name of the principal as in DCE, or for users</li>
* <li>NT-SRV-INST (2) : Service and other unique instance (krbtgt)</li>
* <li>NT-SRV-HST (3) : Service with host name as instance (telnet, rcommands)</li>
* <li>NT-SRV-XHST (4) : Service with host as remaining components</li>
* <li>NT-UID (5) : Unique ID</li>
* <li>NT-X500-PRINCIPAL (6) : Encoded X.509 Distinguished name [RFC2253]</li>
* <li>NT-SMTP-NAME (7) : Name in form of SMTP email name (e.g., user@example.com)</li>
* <li>NT-ENTERPRISE (10) : Enterprise name - may be mapped to principal name</li>
* <li>NT_WELLKNOWN (11) : Well-known principal names (RFC 6111).
* </ul>
*
* The <tt>name-string</tt> contains
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PrincipalName extends KrbSequenceType {
/**
* The possible fields
*/
protected enum PrincipalNameField implements EnumType {
NAME_TYPE,
NAME_STRING;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The PrincipalName's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(PrincipalNameField.NAME_TYPE, Asn1Integer.class),
new ExplicitField(PrincipalNameField.NAME_STRING, KerberosStrings.class)
};
/** The PrincipalName's realm */
private String realm;
/**
* Creates a PrincipalName instance
*/
public PrincipalName() {
super(fieldInfos);
}
/**
* Creates a PrincipalName instance, using a NT_PRINCIPAL name
*
* @param nameString The PrincipalName as a String
*/
public PrincipalName(String nameString) {
super(fieldInfos);
setNameType(NameType.NT_PRINCIPAL);
fromNameString(nameString);
}
/**
* Creates a PrincipalName instance, using a given type
*
* @param nameString The PrincipalName as a String
* @param type The nameType to use
*/
public PrincipalName(String nameString, NameType type) {
super(fieldInfos);
fromNameString(nameString);
setNameType(type);
}
/**
* Creates a PrincipalName instance, using a given type and
* a list of components
*
* @param nameStrings The components to use
* @param nameType The nameType to use
*/
public PrincipalName(List<String> nameStrings, NameType nameType) {
super(fieldInfos);
setNameStrings(nameStrings);
setNameType(nameType);
}
/**
* Get the Realm from the name.
*
* @param principal The PrincipalName from which we want to extract the Realm
* @return The extracted Realm
*/
public static String extractRealm(String principal) {
int pos = principal.indexOf('@');
if (pos > 0) {
return principal.substring(pos + 1);
}
throw new IllegalArgumentException("Not a valid principal, missing realm name");
}
/**
* Get the name part of the PrincipalName, ie, discading the realm part of it.
*
* @param principal The PrincipalName to split
* @return The extracted components (primary/instances)
*/
public static String extractName(String principal) {
int pos = principal.indexOf('@');
if (pos < 0) {
return principal;
}
return principal.substring(0, pos);
}
/**
* Create a SALT based on the PrincipalName, accordingly to RFC 4120 :
* "The default salt string, if none is provided via pre-authentication
* data, is the concatenation of the principal's realm and name components,
* in order, with no separators."
*
* @param principalName The PrincipalName for which we want to create a salt
* @return The created salt
*/
public static String makeSalt(PrincipalName principalName) {
StringBuilder salt = new StringBuilder();
if (principalName.getRealm() != null) {
salt.append(principalName.getRealm());
}
List<String> nameStrings = principalName.getNameStrings();
for (String ns : nameStrings) {
salt.append(ns);
}
return salt.toString();
}
/**
* @return The NameType of this PirncipalName
*/
public NameType getNameType() {
Integer value = getFieldAsInteger(PrincipalNameField.NAME_TYPE);
return NameType.fromValue(value);
}
/**
* Set the NameType field of this PrincipalName
*
* @param nameType The NameType to store
*/
public void setNameType(NameType nameType) {
setFieldAsInt(PrincipalNameField.NAME_TYPE, nameType.getValue());
}
/**
* @return The PrincipalName's components as a list of String
*/
public List<String> getNameStrings() {
KerberosStrings krbStrings = getFieldAs(PrincipalNameField.NAME_STRING, KerberosStrings.class);
if (krbStrings != null) {
return krbStrings.getAsStrings();
}
return Collections.emptyList();
}
/**
* Stores the components of a PrincipalName into the associated ASN1 structure
* @param nameStrings The PrincipalName's components
*/
public void setNameStrings(List<String> nameStrings) {
setFieldAs(PrincipalNameField.NAME_STRING, new KerberosStrings(nameStrings));
}
/**
* @return The PrincipalName's Realm
*/
public String getRealm() {
return realm;
}
/**
* Store a Realm in this PrincipalName
* @param realm The Realm to store
*/
public void setRealm(String realm) {
this.realm = realm;
}
/**
* @return A String representation of this PrincipalName, as primary [ '/' instance ]* [ '@' realm ]
*/
public String getName() {
return makeSingleName();
}
/**
* Reconstruct the PrincipalName String from teh stored components
*/
private String makeSingleName() {
List<String> names = getNameStrings();
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (String name : names) {
if (isFirst) {
isFirst = false;
} else {
sb.append('/');
}
sb.append(name);
}
if (realm != null && !realm.isEmpty()) {
sb.append('@');
sb.append(realm);
}
return sb.toString();
}
/**
* Splits the given NameString into components (primary, instances and realm) :
* primary [ / instance]* [ @ realm ]
*
* Note : we will have only one instance, AFAICT...
*/
private void fromNameString(String nameString) {
if (nameString == null) {
return;
}
List<String> nameStrings;
int realmPos = nameString.indexOf('@');
String nameParts;
if (realmPos != -1) {
nameParts = nameString.substring(0, realmPos);
realm = nameString.substring(realmPos + 1);
} else {
nameParts = nameString;
}
String[] parts = nameParts.split("\\/");
nameStrings = Arrays.asList(parts);
setNameStrings(nameStrings);
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return getName().hashCode();
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof PrincipalName)) {
return false;
}
PrincipalName otherPrincipal = (PrincipalName) other;
return getNameType() == ((PrincipalName) other).getNameType()
&& getName().equals(otherPrincipal.getName());
}
/**
* @see Object#toString()
*/
@Override
public String toString() {
return getName();
}
}
| 136 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/CheckSumType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* The various Checksum types.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum CheckSumType implements EnumType {
NONE (0, "none", "None checksum type"),
/** Defined in RFC 3961, section 6.1.3 */
CRC32 (0x0001, "crc32", "CRC-32"),
/** Defined in RFC 3961, section 6.1.2 */
RSA_MD4 (0x0002, "md4", "RSA-MD4"),
/** Defined in RFC 3961, section 6.2.5 */
RSA_MD4_DES (0x0003, "md4-des", "RSA-MD4 with DES cbc mode"),
DES_CBC (0x0004, "des-cbc", "DES cbc mode"),
/** Defined in RFC 3961, section 6.2.7 */
DES_MAC (0x0004, "des-mac", "DES cbc mode"),
//des-mac-k
//rsa-md4-des-k
/** Defined in RFC 3961, section 6.1.1 */
RSA_MD5 (0x0007, "md5", "RSA-MD5"),
/** Defined in RFC 3961, section 6.2.4 */
RSA_MD5_DES (0x0008, "md5-des", "RSA-MD5 with DES cbc mode"),
NIST_SHA (0x0009, "sha", "NIST-SHA"),
/** Defined in RFC 3961, section 6.3 */
HMAC_SHA1_DES3 (0x000c, "hmac-sha1-des3", "HMAC-SHA1 DES3 key"),
HMAC_SHA1_DES3_KD (0x000c, "hmac-sha1-des3-kd", "HMAC-SHA1 DES3 key"),
////RFC 3962. Used with ENCTYPE_AES128_CTS_HMAC_SHA1_96
/** Defined in RFC 3962, section 7 */
HMAC_SHA1_96_AES128 (0x000f, "hmac-sha1-96-aes128", "HMAC-SHA1 AES128 key"),
//RFC 3962. Used with ENCTYPE_AES256_CTS_HMAC_SHA1_96
/** Defined in RFC 3962, section 7 */
HMAC_SHA1_96_AES256 (0x0010, "hmac-sha1-96-aes256", "HMAC-SHA1 AES256 key"),
/** Defined in RFC 6803, section 9 */
CMAC_CAMELLIA128 (0x0011, "cmac-camellia128", "CMAC Camellia128 key"),
/** Defined in RFC 6803, section 9 */
CMAC_CAMELLIA256 (0x0012, "cmac-camellia256", "CMAC Camellia256 key"),
//Microsoft netlogon cksumtype
MD5_HMAC_ARCFOUR (-137, "md5-hmac-rc4", "Microsoft MD5 HMAC"),
//Microsoft md5 hmac cksumtype
/** Defined in RFC 4757, section 4 */
HMAC_MD5_ARCFOUR (-138, "hmac-md5-arcfour", "Microsoft HMAC MD5"),
HMAC_MD5_ENC (-138, "hmac-md5-enc", "Microsoft HMAC MD5"),
HMAC_MD5_RC4 (-138, "hmac-md5-rc4", "Microsoft HMAC MD5");
/** The inner value */
private final int value;
/** The CheckSum name */
private final String name;
/** The CheckSum description */
private final String displayName;
/**
* Create a new enum instance
*/
CheckSumType(int value, String name, String displayName) {
this.value = value;
this.name = name;
this.displayName = displayName;
}
/**
* Get the CheckSumType associated with a value.
*
* @param value The integer value of the CheckSumType we are looking for
* @return The associated CheckSumType, or NONE if not found or if value is null
*/
public static CheckSumType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (CheckSumType) e;
}
}
}
return NONE;
}
/**
* Get the CheckSumType associated with a name.
*
* @param name The name of the CheckSumType we are looking for
* @return The associated CheckSumType, or NONE if not found or if name is null
*/
public static CheckSumType fromName(String name) {
if (name != null) {
for (CheckSumType cs : values()) {
if (cs.getName().equals(name)) {
return cs;
}
}
}
return NONE;
}
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* @return The CheckSum description
*/
public String getDisplayName() {
return displayName;
}
/**
* Is the type uses AES256 or not
*
* @return <tt>true</tt> if uses AES256, <tt>false</tt> otherwise.
*/
public boolean usesAES256() {
return name.contains("aes256");
}
}
| 137 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/LastReq.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
LastReq ::= SEQUENCE OF SEQUENCE {
lr-type [0] Int32,
lr-value [1] KerberosTime
}
*/
public class LastReq extends KrbSequenceOfType<LastReqEntry> {
}
| 138 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EtypeInfo2.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
ETYPE-INFO2 ::= SEQUENCE SIZE (1..MAX) OF ETYPE-INFO2-ENTRY
*/
public class EtypeInfo2 extends KrbSequenceOfType<EtypeInfo2Entry> {
}
| 139 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EtypeInfo2Entry.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
ETYPE-INFO2-ENTRY ::= SEQUENCE {
etype [0] Int32,
salt [1] KerberosString OPTIONAL,
s2kparams [2] OCTET STRING OPTIONAL
}
*/
public class EtypeInfo2Entry extends KrbSequenceType {
protected enum EtypeInfo2EntryField implements EnumType {
ETYPE,
SALT,
S2KPARAMS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EtypeInfo2EntryField.ETYPE, Asn1Integer.class),
new ExplicitField(EtypeInfo2EntryField.SALT, KerberosString.class),
new ExplicitField(EtypeInfo2EntryField.S2KPARAMS, Asn1OctetString.class)
};
public EtypeInfo2Entry() {
super(fieldInfos);
}
public EncryptionType getEtype() {
return EncryptionType.fromValue(getFieldAsInt(EtypeInfo2EntryField.ETYPE));
}
public void setEtype(EncryptionType etype) {
setField(EtypeInfo2EntryField.ETYPE, etype);
}
public String getSalt() {
return getFieldAsString(EtypeInfo2EntryField.SALT);
}
public void setSalt(String salt) {
setFieldAsString(EtypeInfo2EntryField.SALT, salt);
}
public byte[] getS2kParams() {
return getFieldAsOctets(EtypeInfo2EntryField.S2KPARAMS);
}
public void setS2kParams(byte[] s2kParams) {
setFieldAsOctets(EtypeInfo2EntryField.S2KPARAMS, s2kParams);
}
}
| 140 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/TransitedEncoding.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
TransitedEncoding ::= SEQUENCE {
tr-type [0] Int32 -- must be registered --,
contents [1] OCTET STRING
}
*/
public class TransitedEncoding extends KrbSequenceType {
protected enum TransitedEncodingField implements EnumType {
TR_TYPE,
CONTENTS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(TransitedEncodingField.TR_TYPE, Asn1Integer.class),
new ExplicitField(TransitedEncodingField.CONTENTS, Asn1OctetString.class)
};
public TransitedEncoding() {
super(fieldInfos);
}
public TransitedEncodingType getTrType() {
Integer value = getFieldAsInteger(TransitedEncodingField.TR_TYPE);
return TransitedEncodingType.fromValue(value);
}
public void setTrType(TransitedEncodingType trType) {
setField(TransitedEncodingField.TR_TYPE, trType);
}
public byte[] getContents() {
return getFieldAsOctets(TransitedEncodingField.CONTENTS);
}
public void setContents(byte[] contents) {
setFieldAsOctets(TransitedEncodingField.CONTENTS, contents);
}
}
| 141 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KrbError.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.KrbErrorCode;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
/**
KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
pvno [0] INTEGER (5),
msg-type [1] INTEGER (30),
ctime [2] KerberosTime OPTIONAL,
cusec [3] Microseconds OPTIONAL,
stime [4] KerberosTime,
susec [5] Microseconds,
error-code [6] Int32,
crealm [7] Realm OPTIONAL,
cname [8] PrincipalName OPTIONAL,
realm [9] Realm -- service realm --,
sname [10] PrincipalName -- service name --,
e-text [11] KerberosString OPTIONAL,
e-data [12] OCTET STRING OPTIONAL
}
*/
public class KrbError extends KrbMessage {
protected enum KrbErrorField implements EnumType {
PVNO,
MSG_TYPE,
CTIME,
CUSEC,
STIME,
SUSEC,
ERROR_CODE,
CREALM,
CNAME,
REALM,
SNAME,
ETEXT,
EDATA;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KrbErrorField.PVNO, Asn1Integer.class),
new ExplicitField(KrbErrorField.MSG_TYPE, Asn1Integer.class),
new ExplicitField(KrbErrorField.CTIME, KerberosTime.class),
new ExplicitField(KrbErrorField.CUSEC, Asn1Integer.class),
new ExplicitField(KrbErrorField.STIME, KerberosTime.class),
new ExplicitField(KrbErrorField.SUSEC, Asn1Integer.class),
new ExplicitField(KrbErrorField.ERROR_CODE, Asn1Integer.class),
new ExplicitField(KrbErrorField.CREALM, Realm.class),
new ExplicitField(KrbErrorField.CNAME, PrincipalName.class),
new ExplicitField(KrbErrorField.REALM, Realm.class),
new ExplicitField(KrbErrorField.SNAME, PrincipalName.class),
new ExplicitField(KrbErrorField.ETEXT, KerberosString.class),
new ExplicitField(KrbErrorField.EDATA, Asn1OctetString.class)
};
public KrbError() {
super(KrbMessageType.KRB_ERROR, fieldInfos);
}
public KerberosTime getCtime() {
return getFieldAs(KrbErrorField.CTIME, KerberosTime.class);
}
public void setCtime(KerberosTime ctime) {
setFieldAs(KrbErrorField.CTIME, ctime);
}
public int getCusec() {
return getFieldAsInt(KrbErrorField.CUSEC);
}
public void setCusec(int cusec) {
setFieldAsInt(KrbErrorField.CUSEC, cusec);
}
public KerberosTime getStime() {
return getFieldAs(KrbErrorField.STIME, KerberosTime.class);
}
public void setStime(KerberosTime stime) {
setFieldAs(KrbErrorField.STIME, stime);
}
public int getSusec() {
return getFieldAsInt(KrbErrorField.SUSEC);
}
public void setSusec(int susec) {
setFieldAsInt(KrbErrorField.SUSEC, susec);
}
public KrbErrorCode getErrorCode() {
return KrbErrorCode.fromValue(getFieldAsInt(KrbErrorField.ERROR_CODE));
}
public void setErrorCode(KrbErrorCode errorCode) {
setFieldAsInt(KrbErrorField.ERROR_CODE, errorCode.getValue());
}
public String getCrealm() {
return getFieldAsString(KrbErrorField.CREALM);
}
public void setCrealm(String realm) {
setFieldAs(KrbErrorField.CREALM, new Realm(realm));
}
public PrincipalName getCname() {
return getFieldAs(KrbErrorField.CNAME, PrincipalName.class);
}
public void setCname(PrincipalName cname) {
setFieldAs(KrbErrorField.CNAME, cname);
}
public PrincipalName getSname() {
return getFieldAs(KrbErrorField.SNAME, PrincipalName.class);
}
public void setSname(PrincipalName sname) {
setFieldAs(KrbErrorField.SNAME, sname);
}
public String getRealm() {
return getFieldAsString(KrbErrorField.REALM);
}
public void setRealm(String realm) {
setFieldAs(KrbErrorField.REALM, new Realm(realm));
}
public String getEtext() {
return getFieldAsString(KrbErrorField.ETEXT);
}
public void setEtext(String text) {
setFieldAs(KrbErrorField.ETEXT, new KerberosString(text));
}
public byte[] getEdata() {
return getFieldAsOctetBytes(KrbErrorField.EDATA);
}
public void setEdata(byte[] edata) {
setFieldAsOctetBytes(KrbErrorField.EDATA, edata);
}
}
| 142 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.net.InetAddress;
import java.util.Arrays;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* The HostAddress as defined in RFC 4120 :
* <pre>
* HostAddress ::= SEQUENCE {
* addr-type [0] Int32,
* address [1] OCTET STRING
* }
* </pre>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class HostAddress extends KrbSequenceType {
/**
* The HostAddress fields
*/
protected enum HostAddressField implements EnumType {
ADDR_TYPE,
ADDRESS;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The HostAddress' fields */
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(HostAddressField.ADDR_TYPE, Asn1Integer.class),
new ExplicitField(HostAddressField.ADDRESS, Asn1OctetString.class)
};
/**
* Creates a new (empty) instance of HostAddress
*/
public HostAddress() {
super(fieldInfos);
}
/**
* Creates a new instance of a HostAddress using an {@link InetAddress}
* @param inetAddress The {@link InetAddress} to use
*/
public HostAddress(InetAddress inetAddress) {
super(fieldInfos);
setAddrType(HostAddrType.ADDRTYPE_INET);
setAddress(inetAddress.getAddress());
}
/**
* @return The HostAddrType for this instance
*/
public HostAddrType getAddrType() {
Integer value = getFieldAsInteger(HostAddressField.ADDR_TYPE);
return HostAddrType.fromValue(value);
}
/**
* Sets the AddressType
* @param addrType The HostAddrType to set
*/
public void setAddrType(HostAddrType addrType) {
setField(HostAddressField.ADDR_TYPE, addrType);
}
/**
* @return The HostAddress as a byte[]
*/
public byte[] getAddress() {
return getFieldAsOctets(HostAddressField.ADDRESS);
}
/**
* Sets the address
*
* @param address The address to use, as a byte[]
*/
public void setAddress(byte[] address) {
setFieldAsOctets(HostAddressField.ADDRESS, address);
}
/**
* Compare a given {@link InetAddress} with the current HostAddress
* @param address The {@link InetAddress} we want to compare with the HostAddress
* @return <tt>true</tt> if they are equal
*/
public boolean equalsWith(InetAddress address) {
if (address == null) {
return false;
}
HostAddress that = new HostAddress(address);
return equals(that);
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof HostAddress)) {
return false;
}
HostAddress that = (HostAddress) other;
return getAddrType() == that.getAddrType()
&& Arrays.equals(getAddress(), that.getAddress());
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
int hash = 17 + getAddrType().getValue() * 31;
if (getAddress() != null) {
hash = 31 * hash + Arrays.hashCode(getAddress());
}
return hash;
}
}
| 143 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KrbMessage.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.kerberos.kerb.KrbConstant;
import org.apache.kerby.kerberos.kerb.type.KrbAppSequenceType;
/**
* A base class for every possible Kerberos messages :
*
* <ul>
* <li>AS-REQ : [APPLICATION 10]</li>
* <li>AS-REP : [APPLICATION 11]</li>
* <li>TGS-REQ : [APPLICATION 12]</li>
* <li>TGS-REP : [APPLICATION 13]</li>
* <li>AP-REQ : [APPLICATION 14]</li>
* <li>AP-REP : [APPLICATION 15]</li>
* <li>KRB-SAFE : [APPLICATION 20]</li>
* <li>KRB-PRIV : [APPLICATION 21]</li>
* <li>KRB-CRED : [APPLICATION 22]</li>
* <li>KRB_ERROR : [APPLICATION 30]</li>
* </ul>
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public abstract class KrbMessage extends KrbAppSequenceType {
/**
* The possible fields. We declare the PVNO and MSG_TYPE fields, which are already
* declared in every inherited classes, because we need to have access to them
* in this class to implement the common setters and getters. We can't reuse them
* in the inherited classes either...
*/
protected enum KrbMessageField implements EnumType {
PVNO,
MSG_TYPE;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The PVNO fields. Default to KRB_V5 */
private final int pvno = KrbConstant.KRB_V5;
/**
* Creates a new instance of a KrbMessage. It's not possible to invoque this
* constructor directly.
*
* @param msgType The Kerberos messag etype
* @param fieldInfos The fields to use
*/
protected KrbMessage(KrbMessageType msgType, Asn1FieldInfo[] fieldInfos) {
super(msgType.getValue(), fieldInfos);
setPvno(pvno);
setMsgType(msgType);
}
/**
* @return The PVNO field
*/
public int getPvno() {
return pvno;
}
/**
* Sets the PVNO field
* @param pvno The PVNO to set
*/
protected void setPvno(int pvno) {
setFieldAsInt(KrbMessageField.PVNO, pvno);
}
/**
* @return The Kerberos message type field
*/
public KrbMessageType getMsgType() {
Integer value = getFieldAsInteger(KrbMessageField.MSG_TYPE);
return KrbMessageType.fromValue(value);
}
/**
* Sets the Kerberos Message Type field
* @param msgType The Kerberos Message Type to set
*/
public void setMsgType(KrbMessageType msgType) {
setFieldAsInt(KrbMessageField.MSG_TYPE, msgType.getValue());
}
}
| 144 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KrbToken.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.kerby.asn1.parse.Asn1ParseResult;
import org.apache.kerby.kerberos.kerb.KrbConstant;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.KrbRuntime;
import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
/**
* KRB-TOKEN_VALUE ::= SEQUENCE {
* token-format [0] INTEGER,
* token-value [1] OCTET STRING,
* }
*/
public class KrbToken extends KrbTokenBase implements AuthToken {
private static TokenEncoder tokenEncoder;
private static TokenDecoder tokenDecoder;
private AuthToken innerToken = null;
/**
* Default constructor.
*/
public KrbToken() {
super();
}
/**
* Construct with prepared authToken and token format.
*
* @param authToken The authToken
* @param format The token format
*/
public KrbToken(AuthToken authToken, TokenFormat format) {
this();
this.innerToken = authToken;
setTokenType();
setTokenFormat(format);
try {
setTokenValue(getTokenEncoder(format).encodeAsBytes(innerToken));
} catch (KrbException e) {
throw new RuntimeException("Failed to encode AuthToken", e);
}
}
/**
* Get AuthToken.
*
* @return The inner token.
*/
public AuthToken getAuthToken() {
return innerToken;
}
/**
* {@inheritDoc}
*/
/*
@Override
public void decode(ByteBuffer content) throws IOException {
super.decode(content);
this.innerToken = getTokenDecoder().decodeFromBytes(getTokenValue());
setTokenType();
}*/
@Override
public void decode(Asn1ParseResult parseResult) throws IOException {
super.decode(parseResult);
if (getTokenValue() != null) {
this.innerToken = getTokenDecoder(getTokenFormat()).decodeFromBytes(getTokenValue());
setTokenType();
}
}
/**
* Set token type.
*/
public void setTokenType() {
List<String> audiences = this.innerToken.getAudiences();
if (audiences != null && audiences.size() == 1 && audiences.get(0).startsWith(KrbConstant.TGS_PRINCIPAL)) {
isIdToken(true);
} else {
isAcToken(true);
}
}
/**
* Get token encoder.
* @return The token encoder
*/
protected static TokenEncoder getTokenEncoder(TokenFormat format) {
if (tokenEncoder == null) {
tokenEncoder = KrbRuntime.getTokenProvider(format.getName()).createTokenEncoder();
}
return tokenEncoder;
}
/**
* Get token decoder.
* @return The token decoder
*/
protected static TokenDecoder getTokenDecoder(TokenFormat format) {
if (tokenDecoder == null) {
tokenDecoder = KrbRuntime.getTokenProvider(format.getName()).createTokenDecoder();
}
return tokenDecoder;
}
/**
* {@inheritDoc}
*/
@Override
public String getSubject() {
return innerToken.getSubject();
}
/**
* {@inheritDoc}
*/
@Override
public void setSubject(String sub) {
innerToken.setSubject(sub);
}
/**
* {@inheritDoc}
*/
@Override
public String getIssuer() {
return innerToken.getIssuer();
}
/**
* {@inheritDoc}
*/
@Override
public void setIssuer(String issuer) {
innerToken.setIssuer(issuer);
}
/**
* {@inheritDoc}
*/
@Override
public List<String> getAudiences() {
return innerToken.getAudiences();
}
/**
* {@inheritDoc}
*/
@Override
public void setAudiences(List<String> audiences) {
innerToken.setAudiences(audiences);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isIdToken() {
return innerToken.isIdToken();
}
/**
* {@inheritDoc}
*/
@Override
public void isIdToken(boolean isIdToken) {
innerToken.isIdToken(isIdToken);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAcToken() {
return innerToken.isAcToken();
}
/**
* {@inheritDoc}
*/
@Override
public void isAcToken(boolean isAcToken) {
innerToken.isAcToken(isAcToken);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isBearerToken() {
return innerToken.isBearerToken();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isHolderOfKeyToken() {
return innerToken.isHolderOfKeyToken();
}
/**
* {@inheritDoc}
*/
@Override
public Date getExpiredTime() {
return innerToken.getExpiredTime();
}
/**
* {@inheritDoc}
*/
@Override
public void setExpirationTime(Date exp) {
innerToken.setExpirationTime(exp);
}
/**
* {@inheritDoc}
*/
@Override
public Date getNotBeforeTime() {
return innerToken.getNotBeforeTime();
}
/**
* {@inheritDoc}
*/
@Override
public void setNotBeforeTime(Date nbt) {
innerToken.setNotBeforeTime(nbt);
}
/**
* {@inheritDoc}
*/
@Override
public Date getIssueTime() {
return innerToken.getIssueTime();
}
/**
* {@inheritDoc}
*/
@Override
public void setIssueTime(Date iat) {
innerToken.setIssueTime(iat);
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> getAttributes() {
return innerToken.getAttributes();
}
/**
* {@inheritDoc}
*/
@Override
public void addAttribute(String name, Object value) {
innerToken.addAttribute(name, value);
}
public void setInnerToken(AuthToken authToken) {
this.innerToken = authToken;
}
}
| 145 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/LastReqType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
public enum LastReqType implements EnumType {
NONE(0),
ALL_LAST_TGT(1),
THE_LAST_TGT(-1),
ALL_LAST_INITIAL(2),
THE_LAST_INITIAL(-2),
ALL_LAST_TGT_ISSUED(3),
THE_LAST_TGT_ISSUED(-3),
ALL_LAST_RENEWAL(4),
THE_LAST_RENEWAL(-4),
ALL_LAST_REQ(5),
THE_LAST_REQ(-5),
ALL_PW_EXPTIME(6),
THE_PW_EXPTIME(-6),
ALL_ACCT_EXPTIME(7),
THE_ACCT_EXPTIME(-7);
private int value;
LastReqType(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static LastReqType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (LastReqType) e;
}
}
}
return NONE;
}
}
| 146 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/NameType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* The various PrincipalName name-type values, as defined in RFC 4120 and 61111.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum NameType implements EnumType {
NT_UNKNOWN(0), // Name type not known (RFC 4120)
NT_PRINCIPAL(1), // Just the name of the principal as in DCE, or for users (RFC 4120)
NT_SRV_INST(2), // Service and other unique instance (krbtgt) (RFC 4120)
NT_SRV_HST(3), // Service with host name as instance (telnet, rcommands) (RFC 4120)
NT_SRV_XHST(4), // Service with host as remaining components (RFC 4120)
NT_UID(5), // Unique ID (RFC 4120)
NT_X500_PRINCIPAL(6), // Encoded X.509 Distinguished name (RFC 2253)
NT_SMTP_NAME(7), // Name in form of SMTP email name (e.g., user@example.com) (RFC 4120)
NT_ENTERPRISE(10), // Enterprise name - may be mapped to principal name (RFC 4120)
NT_WELLKNOWN(11); // Well-known principal names (RFC 6111)
/** The internal value */
private int value;
/**
* Create a new enum
*/
NameType(int value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
/**
* Get the NameType associated with a value.
*
* @param value The integer value of the NameType we are looking for
* @return The associated NameType, or NT_UNKNOWN if not found or if value is null
*/
public static NameType fromValue(Integer value) {
if (value != null) {
for (NameType nameType : values()) {
if (nameType.getValue() == value) {
return nameType;
}
}
}
return NT_UNKNOWN;
}
}
| 147 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EncryptedData.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.util.Arrays;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* The EncryptedData structure, as defined in RFC 4120 :
* <pre>
* EncryptedData ::= SEQUENCE {
* etype [0] Int32 -- EncryptionType --,
* kvno [1] UInt32 OPTIONAL,
* cipher [2] OCTET STRING -- ciphertext
* }
* </pre>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class EncryptedData extends KrbSequenceType {
/**
* The possible fields
*/
protected enum EncryptedDataField implements EnumType {
ETYPE,
KVNO,
CIPHER;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The EncryptedData's fields */
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EncryptedDataField.ETYPE, Asn1Integer.class),
new ExplicitField(EncryptedDataField.KVNO, Asn1Integer.class),
new ExplicitField(EncryptedDataField.CIPHER, Asn1OctetString.class)
};
/**
* Creates an instance of EncryptedData
*/
public EncryptedData() {
super(fieldInfos);
}
/**
* @return The {@link EncryptionType} of this instance
*/
public EncryptionType getEType() {
Integer value = getFieldAsInteger(EncryptedDataField.ETYPE);
return EncryptionType.fromValue(value);
}
/**
* Sets the {@link EncryptionType} value
*
* @param eType the {@link EncryptionType} value to store
*/
public void setEType(EncryptionType eType) {
setFieldAsInt(EncryptedDataField.ETYPE, eType.getValue());
}
/**
* @return The KVNO for this instance
*/
public int getKvno() {
Integer value = getFieldAsInteger(EncryptedDataField.KVNO);
if (value != null) {
return value.intValue();
}
return -1;
}
/**
* Sets the instance's KVNO
*
* @param kvno The KVNO for this instance
*/
public void setKvno(int kvno) {
setFieldAsInt(EncryptedDataField.KVNO, kvno);
}
/**
* @return The Cipher stored in this instance
*/
public byte[] getCipher() {
return getFieldAsOctets(EncryptedDataField.CIPHER);
}
/**
* Sets the Cipher in this instance
*
* @param cipher The Cipher to store
*/
public void setCipher(byte[] cipher) {
setFieldAsOctets(EncryptedDataField.CIPHER, cipher);
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EncryptedData)) {
return false;
}
EncryptedData that = (EncryptedData) o;
return getEType() == that.getEType() && Arrays.equals(getCipher(), that.getCipher());
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
int result = 17;
if (getEType() != null) {
result = 31 * result + getEType().hashCode();
}
if (getCipher() != null) {
result = 31 * result + Arrays.hashCode(getCipher());
}
return result;
}
}
| 148 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/TransitedEncodingType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
public enum TransitedEncodingType implements EnumType {
UNKNOWN(-1),
NULL(0),
DOMAIN_X500_COMPRESS(1);
private final int value;
TransitedEncodingType(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static TransitedEncodingType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value.intValue()) {
return (TransitedEncodingType) e;
}
}
}
return NULL;
}
}
| 149 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EtypeInfoEntry.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
ETYPE-INFO-ENTRY ::= SEQUENCE {
etype [0] Int32,
salt [1] OCTET STRING OPTIONAL
}
*/
public class EtypeInfoEntry extends KrbSequenceType {
protected enum EtypeInfoEntryField implements EnumType {
ETYPE,
SALT;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EtypeInfoEntryField.ETYPE, Asn1Integer.class),
new ExplicitField(EtypeInfoEntryField.SALT, Asn1OctetString.class)
};
public EtypeInfoEntry() {
super(fieldInfos);
}
public EncryptionType getEtype() {
return EncryptionType.fromValue(getFieldAsInt(EtypeInfoEntryField.ETYPE));
}
public void setEtype(EncryptionType etype) {
setField(EtypeInfoEntryField.ETYPE, etype);
}
public byte[] getSalt() {
return getFieldAsOctets(EtypeInfoEntryField.SALT);
}
public void setSalt(byte[] salt) {
setFieldAsOctets(EtypeInfoEntryField.SALT, salt);
}
}
| 150 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/Realm.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.kerberos.kerb.type.KerberosString;
/**
* The Realm, as defined by RFC 4120 :
*
* <pre>
* Realm ::= KerberosString
* </pre>
*
* There are some restrictions on the realm name :
* <ul>
* <li>The '0x00' char is not allowed</li>
* <li>
* The realm itself must enter into one of the three categories :
* <ul>
* <li>
* domain :<br>
* <domain> ::= <component> [ '.' <component>]*<br>
* <component> ::= [any KerberosString char but '0x00', '/' or ':']<br>
* </li>
* <li>X500 :<br>
* <X500> ::= <X500component> [ '/' <X500component>]*<br>
* <X500component> ::= <leftPart> '=' <rightPart><br>
* <leftPart> ::= [any KerberosString char but '0x00', '/' or ':']<br>
* <rightPart> ::= [any KerberosString char but '0x00' or '/']
* </li>
* <li>
* Other :<br>
* <other> ::= <prefix> ':' <rest of the name><br>
* <prefix> ::= [any KerberosString char but '0x00', '.' or '=']<br>
* <rest of the name> ::= [any KerberosString char but '0x00']
* </li>
* </ul>
* </li>
* </ul>
*
* Technically, we can detect the Realm's type by checking the presence of '/', '.' and ':'.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Realm extends KerberosString {
/**
* Creates a new Realm instance
*/
public Realm() {
}
/**
* Creates a new Realm instance with a value
*
* @param value the Realm value
*/
public Realm(String value) {
super(value);
// TODO : check that it's a valid REALM...
}
}
| 151 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/KeyUsage.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
/**
* From krb5.hin
*/
public enum KeyUsage implements EnumType {
UNKNOWN(-1),
NONE(0),
//AS-REQ PA-ENC-TIMESTAMP padata timestamp, encrypted with the client key
AS_REQ_PA_ENC_TS(1),
//AS-REP Ticket and TGS-REP Ticket (includes TGS session key or application session key),
//encrypted with the service key (Section 5.3)
KDC_REP_TICKET(2),
//AS-REP encrypted part (includes TGS session key or application session key),
//encrypted with the client key (Section 5.4.2)
AS_REP_ENCPART(3),
//TGS-REQ KDC-REQ-BODY AuthorizationData,
//encrypted with the TGS session key (Section 5.4.1)
TGS_REQ_AD_SESSKEY(4),
//TGS-REQ KDC-REQ-BODY AuthorizationData,
//encrypted with the TGS authenticator subkey (Section 5.4.1)
TGS_REQ_AD_SUBKEY(5),
//TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator cksum,
//keyed with the TGS session key (Section 5.5.1)
TGS_REQ_AUTH_CKSUM(6),
//TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator (includes TGS authenticator subkey),
//encrypted with the TGS session key (Section 5.5.1)
TGS_REQ_AUTH(7),
//TGS-REP encrypted part (includes application session key),
//encrypted with the TGS session key (Section 5.4.2)
TGS_REP_ENCPART_SESSKEY(8),
//TGS-REP encrypted part (includes application session key),
//encrypted with the TGS authenticator subkey (Section 5.4.2)
TGS_REP_ENCPART_SUBKEY(9),
//AP-REQ Authenticator cksum, keyed with the application session key (Section 5.5.1)
AP_REQ_AUTH_CKSUM(10),
//AP-REQ Authenticator (includes application authenticator subkey),
//encrypted with the application session key (Section 5.5.1)
AP_REQ_AUTH(11),
//AP-REP encrypted part (includes application session subkey),
//encrypted with the application session key (Section 5.5.2)
AP_REP_ENCPART(12),
//KRB-PRIV encrypted part, encrypted with a key chosen by the application (Section 5.7.1)
KRB_PRIV_ENCPART(13),
KRB_CRED_ENCPART(14),
KRB_SAFE_CKSUM(15),
APP_DATA_ENCRYPT(16),
APP_DATA_CKSUM(17),
KRB_ERROR_CKSUM(18),
AD_KDCISSUED_CKSUM(19),
AD_MTE(20),
AD_ITE(21),
GSS_TOK_MIC(22),
GSS_TOK_WRAP_INTEG(23),
GSS_TOK_WRAP_PRIV(24),
//Defined in Integrating SAM Mechanisms with Kerberos draft
PA_SAM_CHALLENGE_CKSUM(25),
//Note conflict with @ref PA_S4U_X509_USER_REQUEST
PA_SAM_CHALLENGE_TRACKID(26),
//Note conflict with @ref PA_S4U_X509_USER_REPLY
PA_SAM_RESPONSE(27),
//Defined in [MS-SFU]
//Note conflict with @ref PA_SAM_CHALLENGE_TRACKID
PA_S4U_X509_USER_REQUEST(26),
//Note conflict with @ref PA_SAM_RESPONSE
PA_S4U_X509_USER_REPLY(27),
//unused
PA_REFERRAL(26),
AD_SIGNEDPATH(-21),
IAKERB_FINISHED(42),
PA_PKINIT_KX(44),
PA_OTP_REQUEST(45), //See RFC 6560 section 4.2
//define in preauth-framework
FAST_REQ_CHKSUM(50),
FAST_ENC(51),
FAST_REP(52),
FAST_FINISHED(53),
ENC_CHALLENGE_CLIENT(54),
ENC_CHALLENGE_KDC(55),
AS_REQ(56),
//PA-TOKEN padata,encrypted with the client key
PA_TOKEN(57),
AD_CAMMAC_VERIFIER_MAC(64); //See RFC 7751
private int value;
KeyUsage(int value) {
this.value = value;
}
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static KeyUsage fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (KeyUsage) e;
}
}
}
return UNKNOWN;
}
public static boolean isValid(int usage) {
return usage > -1;
}
}
| 152 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/TokenFormat.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
public enum TokenFormat implements EnumType {
NONE (0),
JWT (1);
private final int value;
TokenFormat(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static TokenFormat fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value.intValue()) {
return (TokenFormat) e;
}
}
}
return NONE;
}
}
| 153 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/CheckSum.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import java.util.Arrays;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Integer;
import org.apache.kerby.asn1.type.Asn1OctetString;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* The CheckSum as defined in RFC 4120 :
* <pre>
* Checksum ::= SEQUENCE {
* cksumtype [0] Int32,
* checksum [1] OCTET STRING
* }
* </pre>
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class CheckSum extends KrbSequenceType {
/**
* The CheckSum fields
*/
protected enum CheckSumField implements EnumType {
CKSUM_TYPE,
CHECK_SUM;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The Checksum's fields */
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(CheckSumField.CKSUM_TYPE, Asn1Integer.class),
new ExplicitField(CheckSumField.CHECK_SUM, Asn1OctetString.class)
};
/**
* Creates a new (empty) instance of Checksum
*/
public CheckSum() {
super(fieldInfos);
}
/**
* Creates a new initialized instance of Checksum
*
* @param cksumType The {@link CheckSumType}
* @param checksum The checksum as a byte[]
*/
public CheckSum(CheckSumType cksumType, byte[] checksum) {
super(fieldInfos);
setCksumtype(cksumType);
setChecksum(checksum);
}
/**
* Creates a new initialized instance of Checksum
*
* @param cksumType The {@link CheckSumType} as an int
* @param checksum The checksum as a byte[]
*/
public CheckSum(int cksumType, byte[] checksum) {
this(CheckSumType.fromValue(cksumType), checksum);
}
/**
* @return The {@link CheckSumType} used for this instance
*/
public CheckSumType getCksumtype() {
Integer value = getFieldAsInteger(CheckSumField.CKSUM_TYPE);
return CheckSumType.fromValue(value);
}
/**
* Set the {@link CheckSumType}
*
* @param cksumtype The {@link CheckSumType} to set
*/
public void setCksumtype(CheckSumType cksumtype) {
setFieldAsInt(CheckSumField.CKSUM_TYPE, cksumtype.getValue());
}
/**
* @return The checksum
*/
public byte[] getChecksum() {
return getFieldAsOctets(CheckSumField.CHECK_SUM);
}
/**
* Set the checksum in this instance
*
* @param checksum The checksum to set
*/
public void setChecksum(byte[] checksum) {
setFieldAsOctets(CheckSumField.CHECK_SUM, checksum);
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CheckSum)) {
return false;
}
CheckSum that = (CheckSum) other;
return getCksumtype() == that.getCksumtype() && Arrays.equals(getChecksum(), that.getChecksum());
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
int result = 17;
if (getCksumtype() != null) {
result = 31 * result + getCksumtype().hashCode();
}
if (getChecksum() != null) {
result = 31 * result + Arrays.hashCode(getChecksum());
}
return result;
}
/**
* @param other The checksum to be compared
* @return <tt>true</tt> if the given Checksum is equal to the instance
*/
public boolean isEqual(CheckSum other) {
return this.equals(other);
}
/**
* Compare the checksum value of a given Checksum instance and this instance.
*
* @param cksumBytes The checksum bytes to be compared
* @return <tt>true</tt> if the given CheckSum's checksum is equal to the instance's checksum
*/
public boolean isEqual(byte[] cksumBytes) {
return Arrays.equals(getChecksum(), cksumBytes);
}
}
| 154 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/EtypeInfo.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
ETYPE-INFO ::= SEQUENCE OF ETYPE-INFO-ENTRY
*/
public class EtypeInfo extends KrbSequenceOfType<EtypeInfoEntry> {
}
| 155 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/SamType.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.type.base;
import org.apache.kerby.asn1.EnumType;
public enum SamType implements EnumType {
SAM_NONE(0),
/** safe SAM type enum for Enigma Logic */
SAM_TYPE_ENIGMA(1), // Enigma Logic"
/** safe SAM type enum for Digital Pathways */
SAM_TYPE_DIGI_PATH(2), // Digital Pathways
/** safe SAM type enum for S/key where KDC has key 0 */
SAM_TYPE_SKEY_K0(3), // S/key where KDC has key 0
/** safe SAM type enum for Traditional S/Key */
SAM_TYPE_SKEY(4), // Traditional S/Key
/** safe SAM type enum for Security Dynamics */
SAM_TYPE_SECURID(5), // Security Dynamics
/** safe SAM type enum for CRYPTOCard */
SAM_TYPE_CRYPTOCARD(6); // CRYPTOCard
private int value;
SamType(int value) {
this.value = value;
}
@Override
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public static SamType fromValue(Integer value) {
if (value != null) {
for (SamType st : SamType.values()) {
if (value == st.getValue()) {
return st;
}
}
}
return SAM_NONE;
}
}
| 156 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/CcacheTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.util;
import org.apache.kerby.kerberos.kerb.ccache.CredentialCache;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import static org.assertj.core.api.Assertions.assertThat;
/*
Default principal: drankye@SH.INTEL.COM
Valid starting Expires Service principal
08/05/2014 00:13:17 08/05/2014 10:13:17 krbtgt/SH.INTEL.COM@SH.INTEL.COM
Flags: FIA, Etype (skey, tkt): des3-cbc-sha1, des3-cbc-sha1
*/
public class CcacheTest {
private CredentialCache cc;
@BeforeEach
public void setUp() throws IOException {
try (InputStream cis = CcacheTest.class.getResourceAsStream("/test.cc")) {
cc = new CredentialCache();
cc.load(cis);
}
}
@Test
public void testCc() {
assertThat(cc).isNotNull();
PrincipalName princ = cc.getPrimaryPrincipal();
assertThat(princ).isNotNull();
assertThat(princ.getName().equals("drankye@SH.INTEL.COM")).isTrue();
}
}
| 157 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.util;
import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
import org.apache.kerby.kerberos.kerb.keytab.Keytab;
import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import static org.assertj.core.api.Assertions.fail;
/*
The principal was created with password '123456'
KVNO Principal
---- --------------------------------------------------------------------------
1 test@SH.INTEL.COM (des-cbc-crc)
1 test@SH.INTEL.COM (des3-cbc-sha1)
1 test@SH.INTEL.COM (des-hmac-sha1)
1 test@SH.INTEL.COM (aes256-cts-hmac-sha1-96)
1 test@SH.INTEL.COM (aes128-cts-hmac-sha1-96)
1 test@SH.INTEL.COM (arcfour-hmac)
1 test@SH.INTEL.COM (camellia256-cts-cmac)
1 test@SH.INTEL.COM (camellia128-cts-cmac)
*/
public class KeysTest {
private static final String TEST_PASSWORD = "123456";
private Keytab keytab;
@BeforeEach
public void setUp() throws IOException {
try (InputStream kis = KeysTest.class.getResourceAsStream("/test.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
}
@Test
public void testString2Key() throws KrbException {
List<PrincipalName> principals = keytab.getPrincipals();
PrincipalName principal = principals.get(0);
List<KeytabEntry> entries = keytab.getKeytabEntries(principal);
for (KeytabEntry ke : entries) {
EncryptionType keyType = ke.getKey().getKeyType();
if (keyType.usesAES256()) {
continue;
}
if (EncryptionHandler.isImplemented(keyType)) {
EncryptionKey genKey = EncryptionHandler.string2Key(principal.getName(),
TEST_PASSWORD, keyType);
if (!ke.getKey().equals(genKey)) {
fail("str2key failed for key type: " + keyType.getName());
//System.err.println("str2key failed for key type: " + keyType.getName());
}
}
}
}
}
| 158 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeytabTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.util;
import org.apache.kerby.kerberos.kerb.keytab.Keytab;
import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class KeytabTest {
@Test
public void testKeytab() throws IOException {
/*
The principal was created with password '123456'
KVNO Principal
---- --------------------------------------------------------------------------
1 test@SH.INTEL.COM (des-cbc-crc)
1 test@SH.INTEL.COM (des3-cbc-sha1)
1 test@SH.INTEL.COM (des-hmac-sha1)
1 test@SH.INTEL.COM (aes256-cts-hmac-sha1-96)
1 test@SH.INTEL.COM (aes128-cts-hmac-sha1-96)
1 test@SH.INTEL.COM (arcfour-hmac)
1 test@SH.INTEL.COM (camellia256-cts-cmac)
1 test@SH.INTEL.COM (camellia128-cts-cmac)
*/
Keytab keytab;
try (InputStream kis = KeytabTest.class.getResourceAsStream("/test.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
assertThat(keytab).isNotNull();
List<PrincipalName> principals = keytab.getPrincipals();
PrincipalName principal = principals.get(0);
List<KeytabEntry> entries = keytab.getKeytabEntries(principal);
for (KeytabEntry ke : entries) {
assertThat(ke.getKvno() == 1).isTrue();
}
assertEquals(8, entries.size());
}
@Test
public void testKeytabWithMultiplePrinciples() throws IOException {
/*
The principal was created with password 'test'
Keytab name: FILE:test.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (aes256-cts-hmac-sha1-96)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (aes128-cts-hmac-sha1-96)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (des3-cbc-sha1)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (arcfour-hmac)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (camellia256-cts-cmac)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (camellia128-cts-cmac)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (des-hmac-sha1)
3 04/11/17 14:16:34 test/examples.com@EXAMPLE.COM (des-cbc-md5)
3 04/11/17 14:16:51 HTTP/examples.com@EXAMPLE.COM (aes256-cts-hmac-sha1-96)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (aes128-cts-hmac-sha1-96)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (des3-cbc-sha1)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (arcfour-hmac)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (camellia256-cts-cmac)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (camellia128-cts-cmac)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (des-hmac-sha1)
3 04/11/17 14:16:52 HTTP/examples.com@EXAMPLE.COM (des-cbc-md5)
*/
Keytab keytab;
try (InputStream kis = KeytabTest.class.getResourceAsStream("/test_multiple_principles.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
assertThat(keytab).isNotNull();
List<PrincipalName> principals = keytab.getPrincipals();
assertEquals(2, keytab.getPrincipals().size());
int numEntries = keytab.getKeytabEntries(principals.get(0)).size()
+ keytab.getKeytabEntries(principals.get(1)).size();
assertEquals(16, numEntries);
}
@Test
public void testSKeytab() throws IOException {
Keytab keytab;
try (InputStream kis = KeytabTest.class.getResourceAsStream("/test_multiple_principles.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
assertThat(keytab).isNotNull();
List<PrincipalName> principals = keytab.getPrincipals();
assertEquals(2, keytab.getPrincipals().size());
int numEntries = keytab.getKeytabEntries(principals.get(0)).size()
+ keytab.getKeytabEntries(principals.get(1)).size();
assertEquals(16, numEntries);
}
@Test
public void testDIRKRB734() throws IOException {
Keytab keytab;
try (InputStream kis = KeytabTest.class.getResourceAsStream("/sample.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
assertThat(keytab).isNotNull();
List<PrincipalName> principals = keytab.getPrincipals();
assertEquals(2, principals.size());
}
public static void main(String[] args) throws IOException {
try (InputStream kis = KeytabTest.class.getResourceAsStream("test.keytab")) {
Keytab keytab = Keytab.loadKeytab(kis);
System.out.println("Principals:" + keytab.getPrincipals().size());
}
}
}
| 159 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/NewEncryptionTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.util;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.KeyUsage;
import org.apache.kerby.util.CryptoUtil;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class NewEncryptionTest {
@Test
public void testDesCbcCrc() throws IOException, KrbException {
testEncWith(EncryptionType.DES_CBC_CRC);
}
@Test
public void testDesCbcMd4() throws IOException, KrbException {
testEncWith(EncryptionType.DES_CBC_MD4);
}
@Test
public void testDesCbcMd5() throws IOException, KrbException {
testEncWith(EncryptionType.DES_CBC_MD5);
}
@Test
public void testCamellia128CtsCmac() throws IOException, KrbException {
testEncWith(EncryptionType.CAMELLIA128_CTS_CMAC);
}
@Test
public void testCamellia256CtsCmac() throws IOException, KrbException {
testEncWith(EncryptionType.CAMELLIA256_CTS_CMAC);
}
@Test
public void testAes128CtsHmacSha1() throws IOException, KrbException {
testEncWith(EncryptionType.AES128_CTS_HMAC_SHA1_96);
}
@Test
public void testAes256CtsHmacSha1() throws IOException, KrbException {
assumeTrue(CryptoUtil.isAES256Enabled());
testEncWith(EncryptionType.AES256_CTS_HMAC_SHA1_96);
}
@Test
public void testDes3CbcSha1() throws IOException, KrbException {
testEncWith(EncryptionType.DES3_CBC_SHA1);
}
@Test
public void testRc4Hmac() throws IOException, KrbException {
testEncWith(EncryptionType.RC4_HMAC);
}
@Test
public void testRc4HmacExp() throws IOException, KrbException {
testEncWith(EncryptionType.RC4_HMAC_EXP);
}
@Test
public void testArcfourHmacMd5() throws IOException, KrbException {
testEncWith(EncryptionType.ARCFOUR_HMAC_MD5);
}
/**
* Decryption can leave a little trailing cruft. For the current cryptosystems, this can be up to 7 bytes.
* @param inData
* @param outData
* @return
*/
private boolean compareResult(byte[] inData, byte[] outData) {
if (inData.length > outData.length || inData.length + 8 <= outData.length) {
return false;
}
byte[] resultData = Arrays.copyOf(outData, inData.length);
return Arrays.equals(inData, resultData);
}
private void testEncWith(EncryptionType eType) throws KrbException {
byte[] inData1 = "This is a test.\n".getBytes();
byte[] inData2 = "This is another test.\n".getBytes();
EncryptionKey key = EncryptionHandler.random2Key(eType);
EncryptedData enctryData1 = EncryptionHandler.encrypt(inData1, key, KeyUsage.AD_ITE);
EncryptedData enctryData2 = EncryptionHandler.encrypt(inData2, key, KeyUsage.AD_ITE);
byte[] outData1 = EncryptionHandler.decrypt(enctryData1, key, KeyUsage.AD_ITE);
byte[] outData2 = EncryptionHandler.decrypt(enctryData2, key, KeyUsage.AD_ITE);
if (!compareResult(inData1, outData1)) {
fail(eType + ": Failed, inData1 & outData1 are not the same!");
}
if (!compareResult(inData2, outData2)) {
fail(eType + ": Failed, inData2 & outData2 are not the same!");
}
}
}
| 160 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/EncryptionTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.util;
import org.apache.kerby.kerberos.kerb.KrbCodec;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.ccache.CredentialCache;
import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
import org.apache.kerby.kerberos.kerb.keytab.Keytab;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.KeyUsage;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.EncTicketPart;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.apache.kerby.util.CryptoUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/*
The principal keys for krbtgt/SH.INTEL.COM@SH.INTEL.COM
KVNO Principal
---- --------------------------------------------------------------------------
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (des-cbc-crc)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (des3-cbc-raw)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (des-hmac-sha1)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (aes256-cts-hmac-sha1-96)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (aes128-cts-hmac-sha1-96)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (arcfour-hmac)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (camellia256-cts-cmac)
2 krbtgt/SH.INTEL.COM@SH.INTEL.COM (camellia128-cts-cmac)
*/
public class EncryptionTest {
private Keytab keytab;
private CredentialCache cc;
@BeforeEach
public void setUp() throws IOException {
try (InputStream kis = EncryptionTest.class.getResourceAsStream("/krbtgt.keytab")) {
keytab = Keytab.loadKeytab(kis);
}
}
@Test
public void testAes128() throws IOException, KrbException {
testEncWith("aes128-cts-hmac-sha1-96.cc");
}
@Test
public void testAes256() throws IOException, KrbException {
assumeTrue(CryptoUtil.isAES256Enabled());
testEncWith("aes256-cts-hmac-sha1-96.cc");
}
@Test
public void testRc4() throws IOException, KrbException {
testEncWith("arcfour-hmac.cc");
}
@Test
public void testCamellia128() throws IOException, KrbException {
testEncWith("camellia128-cts-cmac.cc");
}
@Test
public void testCamellia256() throws IOException, KrbException {
testEncWith("camellia256-cts-cmac.cc");
}
@Test
public void testDesCbcCrc() throws IOException, KrbException {
testEncWith("des-cbc-crc.cc");
}
@Test
public void testDes3CbcSha1() throws IOException, KrbException {
testEncWith("des3-cbc-sha1.cc");
}
private void testEncWith(String ccFile) throws IOException, KrbException, KrbException {
InputStream cis = CcacheTest.class.getResourceAsStream("/" + ccFile);
cc = new CredentialCache();
cc.load(cis);
Ticket ticket = getTicket();
EncryptionType keyType = ticket.getEncryptedEncPart().getEType();
EncryptionKey key = getServerKey(keyType);
if (!EncryptionHandler.isImplemented(keyType)) {
System.err.println("Key type not supported yet: " + keyType.getName());
return;
}
byte[] decrypted = EncryptionHandler.decrypt(
ticket.getEncryptedEncPart(), key, KeyUsage.KDC_REP_TICKET);
assertThat(decrypted).isNotNull();
EncTicketPart encPart = KrbCodec.decode(decrypted, EncTicketPart.class);
assertThat(encPart).isNotNull();
ticket.setEncPart(encPart);
EncryptedData encrypted = EncryptionHandler.encrypt(
decrypted, key, KeyUsage.KDC_REP_TICKET);
byte[] decrypted2 = EncryptionHandler.decrypt(
encrypted, key, KeyUsage.KDC_REP_TICKET);
if (!Arrays.equals(decrypted, decrypted2)) {
System.err.println("Encryption checking failed after decryption for key type: "
+ keyType.getName());
}
}
private EncryptionKey getServerKey(EncryptionType keyType) {
return keytab.getKey(getServer(), keyType);
}
private PrincipalName getServer() {
// only one, krbtgt/SH.INTEL.COM@SH.INTEL.COM
List<PrincipalName> principals = keytab.getPrincipals();
PrincipalName server = principals.get(0);
return server;
}
private Ticket getTicket() {
return cc.getCredentials().get(0).getTicket();
}
}
| 161 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntryTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.assertj.core.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.io.ByteArrayInputStream;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
public class KeytabEntryTest {
@Test
public void exceptionThrownWhenLoadingInvalidKeytabEntry() throws Exception {
KeytabInputStream mockKeytabInputStream = spy(
new KeytabInputStream(
new ByteArrayInputStream(new String("randomtestarray").getBytes())));
doAnswer(new Answer<Integer>() {
private boolean isFirstCall = true;
@Override
public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
if (isFirstCall) {
isFirstCall = false;
return 200;
}
return 20;
}
}).when(mockKeytabInputStream).available();
//doReturn(120).when(mockKeytabInputStream).readOctetsCount();
doReturn(new byte[]{}).when(mockKeytabInputStream).readCountedOctets();
doReturn(null).when(mockKeytabInputStream).readPrincipal(ArgumentMatchers.any(Integer.class));
doReturn(new KerberosTime()).when(mockKeytabInputStream).readTime();
KeytabEntry keytabEntry = new KeytabEntry();
Assumptions.assumeThatIOException().isThrownBy(() -> {
keytabEntry.load(mockKeytabInputStream, 0x502, 100);
});
}
}
| 162 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbOutputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
public abstract class KrbOutputStream extends DataOutputStream {
public KrbOutputStream(OutputStream out) {
super(out);
}
public abstract void writePrincipal(PrincipalName principal, int version) throws IOException;
public void writeRealm(String realm) throws IOException {
writeCountedString(realm);
}
public abstract void writeKey(EncryptionKey key, int version) throws IOException;
public void writeTime(KerberosTime ktime) throws IOException {
int time = 0;
if (ktime != null) {
time = (int) (ktime.getValue().getTime() / 1000);
}
writeInt(time);
}
public void writeCountedString(String string) throws IOException {
byte[] data = string != null ? string.getBytes(StandardCharsets.UTF_8) : null; // ASCII
writeCountedOctets(data);
}
public void writeCountedOctets(byte[] data) throws IOException {
if (data != null) {
writeInt(data.length);
write(data);
} else {
writeInt(0);
}
}
}
| 163 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/KrbInputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public abstract class KrbInputStream extends DataInputStream {
public KrbInputStream(InputStream in) {
super(in);
}
public KerberosTime readTime() throws IOException {
long value = readInt();
KerberosTime time = new KerberosTime(value * 1000);
return time;
}
public abstract PrincipalName readPrincipal(int version) throws IOException;
public EncryptionKey readKey() throws IOException {
int eType = readShort();
EncryptionType encType = EncryptionType.fromValue(eType);
byte[] keyData = readCountedOctets();
if (encType == EncryptionType.NONE || keyData == null) {
return null;
}
EncryptionKey key = new EncryptionKey(encType, keyData);
return key;
}
public String readCountedString() throws IOException {
byte[] countedOctets = readCountedOctets();
if (countedOctets != null) {
// ASCII
return new String(countedOctets, StandardCharsets.UTF_8);
}
return null;
}
public byte[] readCountedOctets() throws IOException {
int len = readOctetsCount();
if (len == 0) {
return null;
}
if (len < 0 || len > available()) {
throw new IOException("Unexpected octets len: " + len);
}
byte[] data = new byte[len];
readFully(data);
return data;
}
public abstract int readOctetsCount() throws IOException;
}
| 164 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/KrbCredentialCache.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
public interface KrbCredentialCache {
PrincipalName getPrimaryPrincipal();
void setPrimaryPrincipal(PrincipalName principal);
int getVersion();
void setVersion(int version);
List<Credential> getCredentials();
void addCredential(Credential credential);
void addCredentials(List<Credential> credentials);
void removeCredentials(List<Credential> credentials);
void removeCredential(Credential credential);
void load(File ccacheFile) throws IOException;
void load(InputStream inputStream) throws IOException;
void store(File ccacheFile) throws IOException;
void store(OutputStream outputStream) throws IOException;
}
| 165 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredCacheOutputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
import org.apache.kerby.kerberos.kerb.KrbOutputStream;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationDataEntry;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddress;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
public class CredCacheOutputStream extends KrbOutputStream {
public CredCacheOutputStream(OutputStream out) {
super(out);
}
@Override
public void writePrincipal(PrincipalName principal, int version) throws IOException {
List<String> nameComponents = principal.getNameStrings();
if (version != CredentialCache.FCC_FVNO_1) {
writeInt(principal.getNameType().getValue());
}
int numComponents = nameComponents.size();
if (version == CredentialCache.FCC_FVNO_1) {
numComponents++;
}
writeInt(numComponents);
writeRealm(principal.getRealm());
for (String nameCom : nameComponents) {
writeCountedString(nameCom);
}
}
@Override
public void writeKey(EncryptionKey key, int version) throws IOException {
writeShort(key.getKeyType().getValue());
if (version == CredentialCache.FCC_FVNO_3) {
writeShort(key.getKeyType().getValue());
}
writeCountedOctets(key.getKeyData());
}
public void writeTimes(KerberosTime[] times) throws IOException {
for (KerberosTime time : times) {
writeTime(time);
}
}
public void writeAddresses(HostAddresses addrs) throws IOException {
if (addrs == null) {
writeInt(0);
} else {
List<HostAddress> addresses = addrs.getElements();
writeInt(addresses.size());
for (HostAddress addr : addresses) {
writeAddress(addr);
}
}
}
public void writeAddress(HostAddress address) throws IOException {
write(address.getAddrType().getValue());
write(address.getAddress().length);
write(address.getAddress(), 0,
address.getAddress().length);
}
public void writeAuthzData(AuthorizationData authData) throws IOException {
if (authData == null) {
writeInt(0);
} else {
for (AuthorizationDataEntry entry : authData.getElements()) {
write(entry.getAuthzType().getValue());
write(entry.getAuthzData().length);
write(entry.getAuthzData());
}
}
}
public void writeTicket(Ticket t) throws IOException {
if (t == null) {
writeInt(0);
} else {
byte[] bytes = t.encode();
writeInt(bytes.length);
write(bytes);
}
}
public void writeIsSkey(boolean isEncInSKey) throws IOException {
writeByte(isEncInSKey ? 1 : 0);
}
public void writeTicketFlags(TicketFlags ticketFlags) throws IOException {
writeInt(ticketFlags.getFlags());
}
}
| 166 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/Tag.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
public class Tag {
int tag = 0;
int tagLen = 8;
int time = 0;
int usec = 0;
int length = 2 + 2 + tagLen; // len(tag) + len(tagLen) + len(tagData);
public Tag(int tag, int time, int usec) {
this.tag = tag;
this.time = time;
this.usec = usec;
}
}
| 167 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredCacheInputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
import org.apache.kerby.kerberos.kerb.KrbInputStream;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationDataEntry;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationType;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddrType;
import org.apache.kerby.kerberos.kerb.type.base.HostAddress;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.NameType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class CredCacheInputStream extends KrbInputStream {
public CredCacheInputStream(InputStream in) {
super(in);
}
@Override
public PrincipalName readPrincipal(int version) throws IOException {
NameType nameType = NameType.NT_UNKNOWN;
if (version != CredentialCache.FCC_FVNO_1) {
int typeValue = readInt();
nameType = NameType.fromValue(typeValue);
}
int numComponents = readInt();
if (version == CredentialCache.FCC_FVNO_1) {
numComponents -= 1;
}
String realm = readCountedString();
List<String> nameStrings = new ArrayList<>();
String component;
for (int i = 0; i < numComponents; i++) { // sub 1 if version 0x501
component = readCountedString();
nameStrings.add(component);
}
PrincipalName principal = new PrincipalName(nameStrings, nameType);
principal.setRealm(realm);
return principal;
}
public EncryptionKey readKey(int version) throws IOException {
if (version == CredentialCache.FCC_FVNO_3) {
readShort(); // ignore keytype
}
return super.readKey();
}
public KerberosTime[] readTimes() throws IOException {
KerberosTime[] times = new KerberosTime[4];
for (int i = 0; i < times.length; ++i) {
times[i] = readTime();
}
return times;
}
public boolean readIsSkey() throws IOException {
int value = readByte();
return value == 1 ? true : false;
}
public HostAddresses readAddr() throws IOException {
int numAddresses = readInt();
if (numAddresses <= 0) {
return null;
}
HostAddress[] addresses = new HostAddress[numAddresses];
for (int i = 0; i < numAddresses; i++) {
addresses[i] = readAddress();
}
HostAddresses result = new HostAddresses();
result.addElements(addresses);
return result;
}
public HostAddress readAddress() throws IOException {
int typeValue = readShort();
HostAddrType addrType = HostAddrType.fromValue(typeValue);
if (addrType == HostAddrType.NONE) {
throw new IOException("Invalid host address type");
}
byte[] addrData = readCountedOctets();
if (addrData == null) {
throw new IOException("Invalid host address data");
}
HostAddress addr = new HostAddress();
addr.setAddrType(addrType);
addr.setAddress(addrData);
return addr;
}
public AuthorizationData readAuthzData() throws IOException {
int numEntries = readInt();
if (numEntries <= 0) {
return null;
}
AuthorizationDataEntry[] authzData = new AuthorizationDataEntry[numEntries];
for (int i = 0; i < numEntries; i++) {
authzData[i] = readAuthzDataEntry();
}
AuthorizationData result = new AuthorizationData();
result.addElements(authzData);
return result;
}
public AuthorizationDataEntry readAuthzDataEntry() throws IOException {
int typeValue = readShort();
AuthorizationType authzType = AuthorizationType.fromValue(typeValue);
if (authzType == AuthorizationType.NONE) {
throw new IOException("Invalid authorization data type");
}
byte[] authzData = readCountedOctets();
if (authzData == null) {
throw new IOException("Invalid authorization data");
}
AuthorizationDataEntry authzEntry = new AuthorizationDataEntry();
authzEntry.setAuthzType(authzType);
authzEntry.setAuthzData(authzData);
return authzEntry;
}
@Override
public int readOctetsCount() throws IOException {
return readInt();
}
public TicketFlags readTicketFlags() throws IOException {
int flags = readInt();
TicketFlags tktFlags = new TicketFlags(flags);
return tktFlags;
}
public Ticket readTicket() throws IOException {
byte[] ticketData = readCountedOctets();
if (ticketData == null) {
return null;
}
Ticket ticket = new Ticket();
ticket.decode(ticketData);
return ticket;
}
}
| 168 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/Credential.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.kdc.EncKdcRepPart;
import org.apache.kerby.kerberos.kerb.type.ticket.KrbTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
import java.io.IOException;
public class Credential {
private static final String CONF_REALM = "X-CACHECONF:";
private PrincipalName clientName;
private String clientRealm;
private PrincipalName serverName;
private String serverRealm;
private EncryptionKey key;
private KerberosTime authTime;
private KerberosTime startTime;
private KerberosTime endTime;
private KerberosTime renewTill;
private HostAddresses clientAddresses;
private AuthorizationData authzData;
private boolean isEncInSKey;
private TicketFlags ticketFlags;
private Ticket ticket;
private Ticket secondTicket;
public Credential() {
}
public Credential(TgtTicket tgt) {
PrincipalName clientPrincipal = tgt.getClientPrincipal();
clientPrincipal.setRealm(tgt.getRealm());
init(tgt, clientPrincipal);
}
public Credential(KrbTicket tkt, PrincipalName clientPrincipal) {
init(tkt, clientPrincipal);
}
private void init(KrbTicket tkt, PrincipalName clientPrincipal) {
EncKdcRepPart kdcRepPart = tkt.getEncKdcRepPart();
this.serverName = kdcRepPart.getSname();
this.serverRealm = kdcRepPart.getSrealm();
this.serverName.setRealm(serverRealm);
this.clientName = clientPrincipal;
this.key = kdcRepPart.getKey();
this.authTime = kdcRepPart.getAuthTime();
this.startTime = kdcRepPart.getStartTime();
this.endTime = kdcRepPart.getEndTime();
this.renewTill = kdcRepPart.getRenewTill();
this.ticketFlags = kdcRepPart.getFlags();
this.clientAddresses = kdcRepPart.getCaddr();
this.ticket = tkt.getTicket();
this.clientRealm = kdcRepPart.getSrealm();
this.isEncInSKey = false;
this.secondTicket = null;
}
public PrincipalName getServicePrincipal() {
return serverName;
}
public KerberosTime getAuthTime() {
return authTime;
}
public KerberosTime getEndTime() {
return endTime;
}
public int getEType() {
return key.getKeyType().getValue();
}
public PrincipalName getClientName() {
return clientName;
}
public PrincipalName getServerName() {
return serverName;
}
public String getClientRealm() {
return clientRealm;
}
public EncryptionKey getKey() {
return key;
}
public KerberosTime getStartTime() {
return startTime;
}
public KerberosTime getRenewTill() {
return renewTill;
}
public HostAddresses getClientAddresses() {
return clientAddresses;
}
public AuthorizationData getAuthzData() {
return authzData;
}
public boolean isEncInSKey() {
return isEncInSKey;
}
public TicketFlags getTicketFlags() {
return ticketFlags;
}
public Ticket getTicket() {
return ticket;
}
public Ticket getSecondTicket() {
return secondTicket;
}
public void load(CredCacheInputStream ccis, int version) throws IOException {
this.clientName = ccis.readPrincipal(version);
if (clientName == null) {
throw new IOException("Invalid client principal name");
}
this.serverName = ccis.readPrincipal(version);
if (serverName == null) {
throw new IOException("Invalid server principal name");
}
boolean isConfEntry = false;
if (serverName.getRealm().equals(CONF_REALM)) {
isConfEntry = true;
}
this.key = ccis.readKey(version);
KerberosTime[] times = ccis.readTimes();
this.authTime = times[0];
this.startTime = times[1];
this.endTime = times[2];
this.renewTill = times[3];
this.isEncInSKey = ccis.readIsSkey();
this.ticketFlags = ccis.readTicketFlags();
this.clientAddresses = ccis.readAddr();
this.authzData = ccis.readAuthzData();
if (isConfEntry) {
byte[] confData = ccis.readCountedOctets();
// ignoring confData for now
} else {
this.ticket = ccis.readTicket();
}
this.secondTicket = ccis.readTicket();
// might skip krb5_ccache_conf_data/fast_avail/krbtgt/REALM@REALM in MIT KRB5
}
public void store(CredCacheOutputStream ccos, int version) throws IOException {
ccos.writePrincipal(clientName, version);
ccos.writePrincipal(serverName, version);
ccos.writeKey(key, version);
ccos.writeTimes(new KerberosTime[]{authTime, startTime, endTime, renewTill});
ccos.writeIsSkey(isEncInSKey);
ccos.writeTicketFlags(ticketFlags);
ccos.writeAddresses(clientAddresses);
ccos.writeAuthzData(authzData);
ccos.writeTicket(ticket);
ccos.writeTicket(secondTicket);
}
}
| 169 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.ccache;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
public class CredentialCache implements KrbCredentialCache {
public static final int FCC_FVNO_1 = 0x501;
public static final int FCC_FVNO_2 = 0x502;
public static final int FCC_FVNO_3 = 0x503;
public static final int FCC_FVNO_4 = 0x504;
public static final int FCC_TAG_DELTATIME = 1;
private final List<Credential> credentials;
private int version = FCC_FVNO_4;
private List<Tag> tags;
private PrincipalName primaryPrincipal;
public CredentialCache() {
credentials = new ArrayList<>();
}
public CredentialCache(TgtTicket tgt) {
this();
addCredential(new Credential(tgt));
setPrimaryPrincipal(tgt.getClientPrincipal());
}
public CredentialCache(SgtTicket sgt) {
this();
addCredential(new Credential(sgt, sgt.getClientPrincipal()));
setPrimaryPrincipal(sgt.getClientPrincipal());
}
public CredentialCache(Credential credential) {
this();
addCredential(credential);
setPrimaryPrincipal(credential.getClientName());
}
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("Dump credential cache file");
System.err.println("Usage: CredentialCache <ccache-file>");
System.exit(1);
}
String cacheFile = args[1];
CredentialCache cc = new CredentialCache();
cc.load(new File(cacheFile));
for (Credential cred : cc.getCredentials()) {
Ticket tkt = cred.getTicket();
System.out.println("Tkt server name: " + tkt.getSname().getName());
System.out.println("Tkt client name: " + cred.getClientName().getName());
System.out.println("Tkt encrypt type: " + tkt.getEncryptedEncPart().getEType().getName());
}
}
@Override
public void store(File ccacheFile) throws IOException {
try (OutputStream outputStream = Files.newOutputStream(ccacheFile.toPath())) {
store(outputStream);
}
}
@Override
public void store(OutputStream outputStream) throws IOException {
if (outputStream == null) {
throw new IllegalArgumentException("Invalid and null output stream");
}
CredCacheOutputStream ccos = new CredCacheOutputStream(outputStream);
doStore(ccos);
ccos.close();
}
private void doStore(CredCacheOutputStream ccos) throws IOException {
this.version = FCC_FVNO_3;
writeVersion(ccos);
if (version == FCC_FVNO_4) {
writeTags(ccos);
}
ccos.writePrincipal(primaryPrincipal, version);
for (Credential cred : credentials) {
cred.store(ccos, version);
}
}
@Override
public PrincipalName getPrimaryPrincipal() {
return primaryPrincipal;
}
@Override
public void setPrimaryPrincipal(PrincipalName principal) {
primaryPrincipal = principal;
}
@Override
public int getVersion() {
return version;
}
@Override
public void setVersion(int version) {
this.version = version;
}
public List<Tag> getTags() {
return this.tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
@Override
public List<Credential> getCredentials() {
return credentials;
}
@Override
public void addCredential(Credential credential) {
if (credential != null) {
for (Credential cred : this.credentials) {
if (cred.getServerName().getName().equals(credential.getServerName().getName())) {
return;
}
}
this.credentials.add(credential);
}
}
@Override
public void addCredentials(List<Credential> credentials) {
if (credentials != null) {
this.credentials.addAll(credentials);
}
}
@Override
public void removeCredentials(List<Credential> credentials) {
if (credentials != null) {
for (Credential cred : credentials) {
removeCredential(cred);
}
}
}
@Override
public void removeCredential(Credential credential) {
if (credential != null) {
for (Credential cred : credentials) {
if (cred.equals(credential)) {
credentials.remove(cred);
break;
}
}
}
}
@Override
public void load(File ccacheFile) throws IOException {
if (!ccacheFile.exists() || !ccacheFile.canRead()) {
throw new IllegalArgumentException("Invalid ccache file: "
+ ccacheFile.getAbsolutePath());
}
try (InputStream inputStream = Files.newInputStream(ccacheFile.toPath())) {
load(inputStream);
}
}
@Override
public void load(InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new IllegalArgumentException("Invalid and null input stream");
}
CredCacheInputStream ccis = new CredCacheInputStream(inputStream);
doLoad(ccis);
ccis.close();
}
private void doLoad(CredCacheInputStream ccis) throws IOException {
this.version = readVersion(ccis);
if (version == FCC_FVNO_4) {
this.tags = readTags(ccis);
}
this.primaryPrincipal = ccis.readPrincipal(version);
this.credentials.addAll(readCredentials(ccis));
}
private List<Credential> readCredentials(CredCacheInputStream ccis)
throws IOException {
List<Credential> results = new ArrayList<>(2);
Credential cred;
while (ccis.available() > 0) {
cred = new Credential();
cred.load(ccis, version);
results.add(cred);
}
return results;
}
private int readVersion(CredCacheInputStream ccis) throws IOException {
int result = ccis.readShort();
return result;
}
private List<Tag> readTags(CredCacheInputStream ccis) throws IOException {
int len = ccis.readShort();
List<Tag> tags = new ArrayList<>();
int tag, tagLen, time, usec;
while (len > 0) {
tag = ccis.readShort();
tagLen = ccis.readShort();
switch (tag) {
case FCC_TAG_DELTATIME:
time = ccis.readInt();
usec = ccis.readInt();
tags.add(new Tag(tag, time, usec));
break;
default:
if (ccis.read(new byte[tagLen], 0, tagLen) == -1) { // ignore unknown tag
throw new IOException();
}
}
len = len - (4 + tagLen);
}
return tags;
}
private void writeVersion(CredCacheOutputStream ccos) throws IOException {
ccos.writeShort(version);
}
private void writeTags(CredCacheOutputStream ccos) throws IOException {
if (tags == null) {
ccos.writeShort(0);
return;
}
int length = 0;
for (Tag tag : tags) {
if (tag.tag != FCC_TAG_DELTATIME) {
continue;
}
length += tag.length;
}
ccos.writeShort(length);
for (Tag tag : tags) {
if (tag.tag != CredentialCache.FCC_TAG_DELTATIME) {
continue;
}
writeTag(ccos, tag);
}
}
private void writeTag(CredCacheOutputStream ccos, Tag tag) throws IOException {
ccos.writeShort(tag.tag);
ccos.writeShort(tag.length);
ccos.writeInt(tag.time);
ccos.writeInt(tag.usec);
}
}
| 170 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Keytab management util.
*/
public final class Keytab implements KrbKeytab {
public static final int V501 = 0x0501;
public static final int V502 = 0x0502;
private int version = V502;
private Map<PrincipalName, List<KeytabEntry>> principalEntries;
public Keytab() {
this.principalEntries = new HashMap<>();
}
public static Keytab loadKeytab(File keytabFile) throws IOException {
Keytab keytab = new Keytab();
keytab.load(keytabFile);
return keytab;
}
public static Keytab loadKeytab(InputStream inputStream) throws IOException {
Keytab keytab = new Keytab();
keytab.load(inputStream);
return keytab;
}
@Override
public List<PrincipalName> getPrincipals() {
return new ArrayList<PrincipalName>(principalEntries.keySet());
}
@Override
public void addKeytabEntries(List<KeytabEntry> entries) {
for (KeytabEntry entry : entries) {
addEntry(entry);
}
}
@Override
public void removeKeytabEntries(PrincipalName principal) {
principalEntries.remove(principal);
}
@Override
public void removeKeytabEntries(PrincipalName principal, int kvno) {
List<KeytabEntry> entries = getKeytabEntries(principal);
for (KeytabEntry entry : entries) {
if (entry.getKvno() == kvno) {
removeKeytabEntry(entry);
}
}
}
@Override
public void removeKeytabEntry(KeytabEntry entry) {
PrincipalName principal = entry.getPrincipal();
List<KeytabEntry> entries = principalEntries.get(principal);
if (entries != null) {
Iterator<KeytabEntry> iter = entries.iterator();
while (iter.hasNext()) {
KeytabEntry tmp = iter.next();
if (entry.equals(tmp)) {
iter.remove();
break;
}
}
}
}
@Override
public List<KeytabEntry> getKeytabEntries(PrincipalName principal) {
List<KeytabEntry> results = new ArrayList<>();
List<KeytabEntry> internal = principalEntries.get(principal);
if (internal == null) {
return results;
}
for (KeytabEntry entry : internal) {
results.add(entry);
}
return results;
}
@Override
public EncryptionKey getKey(PrincipalName principal, EncryptionType keyType) {
List<KeytabEntry> entries = getKeytabEntries(principal);
for (KeytabEntry ke : entries) {
if (ke.getKey().getKeyType() == keyType) {
return ke.getKey();
}
}
// Maybe we have a key stored under a different name for the same type
int keyTypeValue = keyType.getValue();
for (KeytabEntry ke : entries) {
if (keyTypeValue == ke.getKey().getKeyType().getValue()) {
return ke.getKey();
}
}
return null;
}
@Override
public void load(File keytabFile) throws IOException {
if (!keytabFile.exists() || !keytabFile.canRead()) {
throw new IllegalArgumentException("Invalid keytab file: " + keytabFile.getAbsolutePath());
}
try (InputStream is = Files.newInputStream(keytabFile.toPath())) {
load(is);
}
}
@Override
public void load(InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new IllegalArgumentException("Invalid and null input stream");
}
KeytabInputStream kis = new KeytabInputStream(inputStream);
doLoad(kis);
}
private void doLoad(KeytabInputStream kis) throws IOException {
this.version = readVersion(kis);
List<KeytabEntry> entries = readEntries(kis);
addKeytabEntries(entries);
}
@Override
public void addEntry(KeytabEntry entry) {
PrincipalName principal = entry.getPrincipal();
List<KeytabEntry> entries = principalEntries.get(principal);
if (entries == null) {
entries = new ArrayList<>();
principalEntries.put(principal, entries);
}
entries.add(entry);
}
private int readVersion(KeytabInputStream kis) throws IOException {
return kis.readShort();
}
private List<KeytabEntry> readEntries(KeytabInputStream kis) throws IOException {
List<KeytabEntry> entries = new ArrayList<>();
int bytesLeft = kis.available();
while (bytesLeft > 0) {
int entrySize = kis.readInt();
if (kis.available() < entrySize) {
throw new IOException("Bad input stream with less data than expected: " + entrySize);
}
KeytabEntry entry = readEntry(kis, entrySize);
entries.add(entry);
int bytesReadForEntry = bytesLeft - Integer.SIZE / 8 - kis.available();
if (bytesReadForEntry != entrySize) {
kis.skipBytes(entrySize - bytesReadForEntry); // reposition to the next keytab entry
}
bytesLeft = kis.available();
}
return entries;
}
private KeytabEntry readEntry(KeytabInputStream kis, int entrySize) throws IOException {
KeytabEntry entry = new KeytabEntry();
entry.load(kis, version, entrySize);
return entry;
}
@Override
public void store(File keytabFile) throws IOException {
try (OutputStream outputStream = Files.newOutputStream(keytabFile.toPath())) {
store(outputStream);
}
}
@Override
public void store(OutputStream outputStream) throws IOException {
if (outputStream == null) {
throw new IllegalArgumentException("Invalid and null output stream");
}
KeytabOutputStream kos = new KeytabOutputStream(outputStream);
writeVersion(kos);
writeEntries(kos);
}
private void writeVersion(KeytabOutputStream kos) throws IOException {
byte[] bytes = new byte[2];
bytes[0] = (byte) 0x05;
bytes[1] = version == V502 ? (byte) 0x02 : (byte) 0x01;
kos.write(bytes);
}
private void writeEntries(KeytabOutputStream kos) throws IOException {
for (Map.Entry<PrincipalName, List<KeytabEntry>> entryList : principalEntries.entrySet()) {
for (KeytabEntry entry : entryList.getValue()) {
entry.store(kos);
}
}
}
}
| 171 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class KeytabEntry {
private PrincipalName principal;
private KerberosTime timestamp;
private int kvno;
private EncryptionKey key;
public KeytabEntry(PrincipalName principal, KerberosTime timestamp,
int kvno, EncryptionKey key) {
this.principal = principal;
this.timestamp = timestamp;
this.kvno = kvno;
this.key = key;
}
public KeytabEntry() {
}
void load(KeytabInputStream kis, int version, int entrySize) throws IOException {
int bytesLeft = kis.available();
this.principal = kis.readPrincipal(version);
this.timestamp = kis.readTime();
this.kvno = kis.readByte();
this.key = kis.readKey();
int entryBytesRead = bytesLeft - kis.available();
// Some implementations of Kerberos recognize a 32-bit key version at the end of an entry, if record length is
// at least 4 bytes longer than the entry and the value of those 32 bits is not 0. If present, this key version
// supersedes the 8-bit key version.
if (entryBytesRead + 4 <= entrySize) {
int tmp = kis.readInt();
if (tmp != 0) {
this.kvno = tmp;
}
} else if (entryBytesRead != entrySize) {
throw new IOException(
String.format("Bad input stream with less data read [%d] than expected [%d] for keytab entry.",
entryBytesRead, entrySize));
}
}
void store(KeytabOutputStream kos) throws IOException {
byte[] body = null;
// compute entry body content first so that to get and write the size
ByteArrayOutputStream baos = new ByteArrayOutputStream();
KeytabOutputStream subKos = new KeytabOutputStream(baos);
writeBody(subKos, 0); // todo: consider the version
subKos.flush();
body = baos.toByteArray();
kos.writeInt(body.length);
kos.write(body);
}
public EncryptionKey getKey() {
return key;
}
public int getKvno() {
return kvno;
}
public PrincipalName getPrincipal() {
return principal;
}
public KerberosTime getTimestamp() {
return timestamp;
}
void writeBody(KeytabOutputStream kos, int version) throws IOException {
kos.writePrincipal(principal, version);
kos.writeTime(timestamp);
kos.writeByte(kvno);
kos.writeKey(key, version);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
KeytabEntry that = (KeytabEntry) o;
if (kvno != that.kvno) {
return false;
}
if (!key.equals(that.key)) {
return false;
}
if (!principal.equals(that.principal)) {
return false;
}
if (!timestamp.equals(that.timestamp)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = principal.hashCode();
result = 31 * result + timestamp.hashCode();
result = 31 * result + kvno;
result = 31 * result + key.hashCode();
return result;
}
}
| 172 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabOutputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.KrbOutputStream;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
public class KeytabOutputStream extends KrbOutputStream {
public KeytabOutputStream(OutputStream out) {
super(out);
}
public void writePrincipal(PrincipalName principal, int version) throws IOException {
List<String> nameStrings = principal.getNameStrings();
int numComponents = principal.getNameStrings().size();
String realm = principal.getRealm();
writeShort(numComponents);
writeCountedString(realm);
for (String nameCom : nameStrings) {
writeCountedString(nameCom);
}
writeInt(principal.getNameType().getValue()); // todo: consider the version
}
@Override
public void writeKey(EncryptionKey key, int version) throws IOException {
writeShort(key.getKeyType().getValue());
writeCountedOctets(key.getKeyData());
}
@Override
public void writeCountedOctets(byte[] data) throws IOException {
writeShort(data.length);
write(data);
}
}
| 173 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KrbKeytab.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
public interface KrbKeytab {
List<PrincipalName> getPrincipals();
void addKeytabEntries(List<KeytabEntry> entries);
void removeKeytabEntries(PrincipalName principal);
void removeKeytabEntries(PrincipalName principal, int kvno);
void removeKeytabEntry(KeytabEntry entry);
List<KeytabEntry> getKeytabEntries(PrincipalName principal);
EncryptionKey getKey(PrincipalName principal, EncryptionType keyType);
void load(File keytabFile) throws IOException;
void load(InputStream inputStream) throws IOException;
void addEntry(KeytabEntry entry);
void store(File keytabFile) throws IOException;
void store(OutputStream outputStream) throws IOException;
}
| 174 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.keytab;
import org.apache.kerby.kerberos.kerb.KrbInputStream;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.base.NameType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class KeytabInputStream extends KrbInputStream {
public KeytabInputStream(InputStream in) {
super(in);
}
public KerberosTime readTime() throws IOException {
long value = readInt();
KerberosTime time = new KerberosTime(value * 1000);
return time;
}
@Override
public PrincipalName readPrincipal(int version) throws IOException {
int numComponents = readShort();
if (version == Keytab.V501) {
numComponents -= 1;
}
String realm = readCountedString();
List<String> nameStrings = new ArrayList<>();
for (int i = 0; i < numComponents; i++) { // sub 1 if version 0x501
String component = readCountedString();
nameStrings.add(component);
}
int type = readInt(); // not present if version 0x501
NameType nameType = NameType.fromValue(type);
PrincipalName principal = new PrincipalName(nameStrings, nameType);
principal.setRealm(realm);
return principal;
}
@Override
public int readOctetsCount() throws IOException {
return readShort();
}
}
| 175 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/KerbyGssProvider.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* Proivder is used to register the implementation of gssapi mechanism into the system
*/
public final class KerbyGssProvider extends java.security.Provider {
private static final long serialVersionUID = 3787378212107821987L;
private static final String INFO = "Kerby Gssapi Provider";
private static final String MECHANISM_GSSAPI = "GssApiMechanism.1.2.840.113554.1.2.2";
private static final String MECHANISM_GSSAPI_CLASS = "org.apache.kerby.kerberos.kerb.gss.GssMechFactory";
public KerbyGssProvider() {
super("KerbyGssApi", 0.01d, INFO);
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
put(MECHANISM_GSSAPI, MECHANISM_GSSAPI_CLASS);
return null;
}
});
}
} | 176 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/GssMechFactory.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss;
import org.apache.kerby.kerberos.kerb.gss.impl.GssAcceptCred;
import org.apache.kerby.kerberos.kerb.gss.impl.GssContext;
import org.apache.kerby.kerberos.kerb.gss.impl.GssCredElement;
import org.apache.kerby.kerberos.kerb.gss.impl.GssInitCred;
import org.apache.kerby.kerberos.kerb.gss.impl.GssNameElement;
import org.ietf.jgss.GSSCredential;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
import sun.security.jgss.GSSCaller;
import sun.security.jgss.spi.GSSContextSpi;
import sun.security.jgss.spi.GSSCredentialSpi;
import sun.security.jgss.spi.GSSNameSpi;
import sun.security.jgss.spi.MechanismFactory;
import java.security.Provider;
import java.util.Arrays;
/**
* Kerby Kerberos V5 plugin for JGSS
*/
public class GssMechFactory implements MechanismFactory {
private static final Provider PROVIDER =
new KerbyGssProvider();
private static final String KRB5_OID_STRING = "1.2.840.113554.1.2.2";
private static final Oid KRB5_OID = createOid(KRB5_OID_STRING);
private static Oid[] nameTypes =
new Oid[] {
GSSName.NT_USER_NAME,
GSSName.NT_EXPORT_NAME,
GSSName.NT_HOSTBASED_SERVICE
};
private final GSSCaller caller;
public Oid getMechanismOid() {
return KRB5_OID;
}
public Provider getProvider() {
return PROVIDER;
}
public Oid[] getNameTypes() throws GSSException {
return nameTypes;
}
public GssMechFactory(GSSCaller caller) {
this.caller = caller;
}
public GSSNameSpi getNameElement(String nameStr, Oid nameType)
throws GSSException {
return GssNameElement.getInstance(nameStr, nameType);
}
public GSSNameSpi getNameElement(byte[] name, Oid nameType)
throws GSSException {
return GssNameElement.getInstance(Arrays.toString(name), nameType);
}
// Used by initiator
public GSSContextSpi getMechanismContext(GSSNameSpi peer,
GSSCredentialSpi myInitiatorCred,
int lifetime) throws GSSException {
if (peer != null && !(peer instanceof GssNameElement)) {
peer = GssNameElement.getInstance(peer.toString(), peer.getStringNameType());
}
if (myInitiatorCred == null) {
myInitiatorCred = getCredentialElement(null, lifetime, 0, GSSCredential.INITIATE_ONLY);
}
return new GssContext(caller, (GssNameElement) peer, (GssInitCred) myInitiatorCred, lifetime);
}
public GSSContextSpi getMechanismContext(GSSCredentialSpi myAcceptorCred)
throws GSSException {
if (myAcceptorCred == null) {
myAcceptorCred = getCredentialElement(null, 0,
GSSCredential.INDEFINITE_LIFETIME, GSSCredential.ACCEPT_ONLY);
}
return new GssContext(caller, (GssAcceptCred) myAcceptorCred);
}
// Reconstruct from previously exported context
public GSSContextSpi getMechanismContext(byte[] exportedContext)
throws GSSException {
return new GssContext(caller, exportedContext);
}
public GSSCredentialSpi getCredentialElement(GSSNameSpi name,
int initLifetime,
int acceptLifetime,
int usage)
throws GSSException {
if (name != null && !(name instanceof GssNameElement)) {
name = GssNameElement.getInstance(name.toString(), name.getStringNameType());
}
GssCredElement credElement;
if (usage == GSSCredential.INITIATE_ONLY) {
credElement = GssInitCred.getInstance(caller, (GssNameElement) name, initLifetime);
} else if (usage == GSSCredential.ACCEPT_ONLY) {
credElement = GssAcceptCred.getInstance(caller, (GssNameElement) name, acceptLifetime);
} else if (usage == GSSCredential.INITIATE_AND_ACCEPT) {
throw new GSSException(GSSException.FAILURE, -1, "Unsupported usage mode: INITIATE_AND_ACCEPT");
} else {
throw new GSSException(GSSException.FAILURE, -1, "Unknown usage mode: " + usage);
}
return credElement;
}
private static Oid createOid(String oidStr) {
Oid retVal;
try {
retVal = new Oid(oidStr);
} catch (GSSException e) {
retVal = null;
}
return retVal;
}
public static Oid getOid() {
return KRB5_OID;
}
}
| 177 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssEncryptor.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.crypto.CheckSumHandler;
import org.apache.kerby.kerberos.kerb.crypto.CheckSumTypeHandler;
import org.apache.kerby.kerberos.kerb.crypto.EncTypeHandler;
import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
import org.apache.kerby.kerberos.kerb.crypto.cksum.provider.Md5Provider;
import org.apache.kerby.kerberos.kerb.crypto.enc.provider.DesProvider;
import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Rc4Provider;
import org.apache.kerby.kerberos.kerb.type.base.CheckSumType;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.ietf.jgss.GSSException;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
/**
* This class implements encryption related function used in GSS tokens
*/
public class GssEncryptor {
private final EncryptionKey encKey;
private final EncryptionType encKeyType; // The following two variables used for convenience
private final byte[] encKeyBytes;
private CheckSumType checkSumTypeDef;
private int checkSumSize;
private boolean isV2 = false;
private int sgnAlg = 0xFFFF;
private int sealAlg = 0xFFFF;
private boolean isArcFourHmac = false;
private static final byte[] IV_ZEROR_8B = new byte[8];
public GssEncryptor(EncryptionKey key) throws GSSException {
encKey = key;
encKeyBytes = encKey.getKeyData();
encKeyType = key.getKeyType();
if (encKeyType == EncryptionType.AES128_CTS_HMAC_SHA1_96) {
checkSumSize = 12;
checkSumTypeDef = CheckSumType.HMAC_SHA1_96_AES128;
isV2 = true;
} else if (encKeyType == EncryptionType.AES256_CTS_HMAC_SHA1_96) {
checkSumSize = 12;
checkSumTypeDef = CheckSumType.HMAC_SHA1_96_AES256;
isV2 = true;
} else if (encKeyType == EncryptionType.DES_CBC_CRC || encKeyType == EncryptionType.DES_CBC_MD5) {
sgnAlg = GssTokenV1.SGN_ALG_DES_MAC_MD5;
sealAlg = GssTokenV1.SEAL_ALG_DES;
checkSumSize = 8;
} else if (encKeyType == EncryptionType.DES3_CBC_SHA1) {
sgnAlg = GssTokenV1.SGN_ALG_HMAC_SHA1_DES3_KD;
sealAlg = GssTokenV1.SEAL_ALG_DES3_KD;
checkSumSize = 20;
} else if (encKeyType == EncryptionType.ARCFOUR_HMAC) {
sgnAlg = GssTokenV1.SGN_ALG_RC4_HMAC;
sealAlg = GssTokenV1.SEAL_ALG_RC4_HMAC;
checkSumSize = 16;
isArcFourHmac = true;
} else {
throw new GSSException(GSSException.FAILURE, -1,
"Invalid encryption type: " + encKeyType.getDisplayName());
}
}
/**
* Return true if it is encryption type defined in RFC 4121
* @return
*/
public boolean isV2() {
return isV2;
}
public int getSgnAlg() {
return sgnAlg;
}
public int getSealAlg() {
return sealAlg;
}
public boolean isArcFourHmac() {
return isArcFourHmac;
}
public byte[] encryptData(byte[] tokenHeader, byte[] data,
int offset, int len, int keyUsage) throws GSSException {
byte[] ret;
byte[] toProcess = new byte[tokenHeader.length + len];
System.arraycopy(data, offset, toProcess, 0, len);
System.arraycopy(tokenHeader, 0, toProcess, len, tokenHeader.length);
ret = encryptData(toProcess, keyUsage);
return ret;
}
public byte[] encryptData(byte[] toProcess, int keyUsage) throws GSSException {
byte[] ret;
try {
EncTypeHandler encHandler = EncryptionHandler.getEncHandler(encKey.getKeyType());
ret = encHandler.encrypt(toProcess, encKey.getKeyData(), keyUsage);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
return ret;
}
public byte[] decryptData(byte[] dataEncrypted, int keyUsage) throws GSSException {
byte[] ret;
try {
EncTypeHandler encHandler = EncryptionHandler.getEncHandler(encKey.getKeyType());
ret = encHandler.decrypt(dataEncrypted, encKey.getKeyData(), keyUsage);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
return ret;
}
public byte[] calculateCheckSum(byte[] header, byte[] data, int offset, int len, int keyUsage)
throws GSSException {
int totalLen = len + (header == null ? 0 : header.length);
byte[] buffer = new byte[totalLen];
System.arraycopy(data, offset, buffer, 0, len);
if (header != null) {
System.arraycopy(header, 0, buffer, len, header.length);
}
try {
return CheckSumHandler.getCheckSumHandler(checkSumTypeDef)
.checksumWithKey(buffer, encKey.getKeyData(), keyUsage);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Exception in checksum calculation:" + e.getMessage());
}
}
/**
* Get the size of the corresponding checksum algorithm
* @return
* @throws GSSException
*/
public int getCheckSumSize() throws GSSException {
return checkSumSize;
}
private void addPadding(int paddingLen, byte[] outBuf, int offset) {
for (int i = 0; i < paddingLen; i++) {
outBuf[offset + i] = (byte) paddingLen;
}
}
private byte[] getFirstBytes(byte[] src, int len) {
if (len < src.length) {
byte[] ret = new byte[len];
System.arraycopy(src, 0, ret, 0, len);
return ret;
}
return src;
}
private byte[] getKeyBytesWithLength(int len) {
return getFirstBytes(encKeyBytes, len);
}
public byte[] calculateCheckSum(byte[] confounder, byte[] header,
byte[] data, int offset, int len, int paddingLen, boolean isMic)
throws GSSException {
byte[] ret;
int keyUsage = GssTokenV1.KG_USAGE_SIGN;
CheckSumTypeHandler handler;
int keySize;
byte[] key;
byte[] toProc;
int toOffset;
int toLen = (confounder == null ? 0 : confounder.length)
+ (header == null ? 0 : header.length) + len + paddingLen;
if (toLen == len) {
toProc = data;
toOffset = offset;
} else {
toOffset = 0;
int idx = 0;
toProc = new byte[toLen];
if (header != null) {
System.arraycopy(header, 0, toProc, idx, header.length);
idx += header.length;
}
if (confounder != null) {
System.arraycopy(confounder, 0, toProc, idx, confounder.length);
idx += confounder.length;
}
System.arraycopy(data, offset, toProc, idx, len);
addPadding(paddingLen, toProc, len + idx);
}
CheckSumType chksumType;
try {
switch (sgnAlg) {
case GssTokenV1.SGN_ALG_DES_MAC_MD5:
Md5Provider md5Provider = new Md5Provider();
md5Provider.hash(toProc);
toProc = md5Provider.output();
// fall through
case GssTokenV1.SGN_ALG_DES_MAC:
DesProvider desProvider = new DesProvider();
return desProvider.cbcMac(encKeyBytes, IV_ZEROR_8B, toProc);
case GssTokenV1.SGN_ALG_HMAC_SHA1_DES3_KD:
chksumType = CheckSumType.HMAC_SHA1_DES3_KD;
break;
case GssTokenV1.SGN_ALG_RC4_HMAC:
chksumType = CheckSumType.MD5_HMAC_ARCFOUR;
if (isMic) {
keyUsage = GssTokenV1.KG_USAGE_MS_SIGN;
}
break;
case GssTokenV1.SGN_ALG_MD25:
throw new GSSException(GSSException.FAILURE, -1, "CheckSum not implemented for SGN_ALG_MD25");
default:
throw new GSSException(GSSException.FAILURE, -1, "CheckSum not implemented for sgnAlg=" + sgnAlg);
}
handler = CheckSumHandler.getCheckSumHandler(chksumType);
keySize = handler.keySize();
key = getKeyBytesWithLength(keySize);
ret = handler.checksumWithKey(toProc, toOffset, toLen, key, keyUsage);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Exception in checksum calculation sgnAlg = " + sgnAlg + " : " + e.getMessage());
}
return ret;
}
public byte[] encryptSequenceNumber(byte[] seqBytes, byte[] ivSrc, boolean encrypt)
throws GSSException {
EncTypeHandler handler;
try {
switch (sgnAlg) {
case GssTokenV1.SGN_ALG_DES_MAC_MD5:
case GssTokenV1.SGN_ALG_DES_MAC:
DesProvider desProvider = new DesProvider();
byte[] data = seqBytes.clone();
if (encrypt) {
desProvider.encrypt(encKeyBytes, ivSrc, data);
} else {
desProvider.decrypt(encKeyBytes, ivSrc, data);
}
return data;
case GssTokenV1.SGN_ALG_HMAC_SHA1_DES3_KD:
handler = EncryptionHandler.getEncHandler(EncryptionType.DES3_CBC_SHA1_KD);
break;
case GssTokenV1.SGN_ALG_RC4_HMAC:
return encryptArcFourHmac(seqBytes, getKeyBytesWithLength(16), getFirstBytes(ivSrc, 8), encrypt);
case GssTokenV1.SGN_ALG_MD25:
throw new GSSException(GSSException.FAILURE, -1, "EncSeq not implemented for SGN_ALG_MD25");
default:
throw new GSSException(GSSException.FAILURE, -1, "EncSeq not implemented for sgnAlg=" + sgnAlg);
}
int keySize = handler.keySize();
byte[] key = getKeyBytesWithLength(keySize);
int ivLen = handler.encProvider().blockSize();
byte[] iv = getFirstBytes(ivSrc, ivLen);
if (encrypt) {
return handler.encryptRaw(seqBytes, key, iv, GssTokenV1.KG_USAGE_SEQ);
} else {
return handler.decryptRaw(seqBytes, key, iv, GssTokenV1.KG_USAGE_SEQ);
}
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Exception in encrypt seq number sgnAlg = " + sgnAlg + " : " + e.getMessage());
}
}
private byte[] getHmacMd5(byte[] key, byte[] salt) throws GSSException {
try {
SecretKey secretKey = new SecretKeySpec(key, "HmacMD5");
Mac mac = Mac.getInstance("HmacMD5");
mac.init(secretKey);
return mac.doFinal(salt);
} catch (Exception e) {
throw new GSSException(GSSException.FAILURE, -1, "Get HmacMD5 failed: " + e.getMessage());
}
}
private byte[] encryptArcFourHmac(byte[] data, byte[] key, byte[] iv, boolean encrypt)
throws GSSException {
byte[] sk1 = getHmacMd5(key, new byte[4]);
byte[] sk2 = getHmacMd5(sk1, iv);
Rc4Provider provider = new Rc4Provider();
try {
byte[] ret = data.clone();
if (encrypt) {
provider.encrypt(sk2, ret);
} else {
provider.decrypt(sk2, ret);
}
return ret;
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1,
"En/Decrypt sequence failed for ArcFourHmac: " + e.getMessage());
}
}
private byte[] encryptDataArcFourHmac(byte[] data, byte[] key, byte[] seqNum, boolean encrypt) throws GSSException {
byte[] dataKey = new byte[key.length];
for (int i = 0; i <= 15; i++) {
dataKey[i] = (byte) (key[i] ^ 0xF0);
}
return encryptArcFourHmac(data, dataKey, seqNum, encrypt);
}
public byte[] encryptTokenV1(byte[] confounder, byte[] data, int offset, int len,
int paddingLen, byte[] seqNumber, boolean encrypt) throws GSSException {
byte[] toProc;
if (encrypt) {
int toLen = (confounder == null ? 0 : confounder.length) + len + paddingLen;
int index = 0;
toProc = new byte[toLen];
if (confounder != null) {
System.arraycopy(confounder, 0, toProc, 0, confounder.length);
index += confounder.length;
}
System.arraycopy(data, offset, toProc, index, len);
addPadding(paddingLen, toProc, index + len);
} else {
toProc = data;
if (data.length != len) {
toProc = new byte[len];
System.arraycopy(data, offset, toProc, 0, len);
}
}
EncTypeHandler handler;
try {
switch (sealAlg) {
case GssTokenV1.SEAL_ALG_DES:
handler = EncryptionHandler.getEncHandler(EncryptionType.DES_CBC_MD5);
break;
case GssTokenV1.SEAL_ALG_DES3_KD:
handler = EncryptionHandler.getEncHandler(EncryptionType.DES3_CBC_SHA1_KD);
break;
case GssTokenV1.SEAL_ALG_RC4_HMAC:
return encryptDataArcFourHmac(toProc, getKeyBytesWithLength(16), seqNumber, encrypt);
default:
throw new GSSException(GSSException.FAILURE, -1, "Unknown encryption type sealAlg = " + sealAlg);
}
int keySize = handler.keySize();
byte[] key = getKeyBytesWithLength(keySize);
if (encrypt) {
return handler.encryptRaw(toProc, key, GssTokenV1.KG_USAGE_SEAL);
} else {
return handler.decryptRaw(toProc, key, GssTokenV1.KG_USAGE_SEAL);
}
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Exception in encrypt data sealAlg = " + sealAlg + " : " + e.getMessage());
}
}
} | 178 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssAcceptCred.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.security.jgss.GSSCaller;
import javax.security.auth.kerberos.KerberosKey;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KeyTab;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;
public final class GssAcceptCred extends GssCredElement {
private static final Logger LOG = LoggerFactory.getLogger(GssAcceptCred.class);
private final KeyTab keyTab;
private final Set<KerberosKey> kerberosKeySet;
public static GssAcceptCred getInstance(final GSSCaller caller,
GssNameElement name, int lifeTime) throws GSSException {
// Try to get a keytab first
KeyTab keyTab = getKeyTab(name);
Set<KerberosKey> kerberosKeySet = null;
if (keyTab == null) {
// Otherwise try to get a kerberos key
if (name == null) {
kerberosKeySet = CredUtils.getKerberosKeysFromContext(caller, null, null);
} else {
kerberosKeySet = CredUtils.getKerberosKeysFromContext(caller, name.getPrincipalName().getName(), null);
}
}
if (keyTab == null && kerberosKeySet == null) {
String error = "Failed to find any Kerberos credential";
if (name != null) {
error += " for " + name.getPrincipalName().getName();
}
throw new GSSException(GSSException.NO_CRED, -1, error);
}
if (name == null) {
if (keyTab != null) {
try {
Method m = keyTab.getClass().getDeclaredMethod("getPrincipal");
KerberosPrincipal princ = (KerberosPrincipal) m.invoke(keyTab);
name = GssNameElement.getInstance(princ.getName(),
GSSName.NT_HOSTBASED_SERVICE);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
String error = "Can't get a principal from the keytab";
LOG.info(error, e);
throw new GSSException(GSSException.NO_CRED, -1, error);
}
} else {
name = GssNameElement.getInstance(
kerberosKeySet.iterator().next().getPrincipal().getName(),
GSSName.NT_HOSTBASED_SERVICE);
}
}
return new GssAcceptCred(caller, name, keyTab, lifeTime, kerberosKeySet);
}
private static KeyTab getKeyTab(GssNameElement name) throws GSSException {
if (name == null) {
return CredUtils.getKeyTabFromContext(null);
} else {
KerberosPrincipal princ = new KerberosPrincipal(name.getPrincipalName().getName(),
name.getPrincipalName().getNameType().getValue());
return CredUtils.getKeyTabFromContext(princ);
}
}
private GssAcceptCred(GSSCaller caller, GssNameElement name, KeyTab keyTab,
int lifeTime, Set<KerberosKey> kerberosKeySet) {
super(caller, name);
this.keyTab = keyTab;
this.accLifeTime = lifeTime;
this.kerberosKeySet = kerberosKeySet;
}
public boolean isInitiatorCredential() throws GSSException {
return false;
}
public boolean isAcceptorCredential() throws GSSException {
return true;
}
public KeyTab getKeyTab() {
return this.keyTab;
}
public EncryptionKey getEncryptionKey(int encryptType, int kvno) {
if (kerberosKeySet != null) {
KerberosKey[] keys = kerberosKeySet.toArray(new KerberosKey[kerberosKeySet.size()]);
// We don't check the kvno here - see DIRKRB-638
return GssUtil.getEncryptionKey(keys, encryptType);
}
// Otherwise get it from the keytab
KerberosPrincipal princ = new KerberosPrincipal(name.getPrincipalName().getName(),
name.getPrincipalName().getNameType().getValue());
KerberosKey[] keys = keyTab.getKeys(princ);
return GssUtil.getEncryptionKey(keys, encryptType, kvno);
}
}
| 179 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssCredElement.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.gss.KerbyGssProvider;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;
import sun.security.jgss.GSSCaller;
import sun.security.jgss.spi.GSSCredentialSpi;
import sun.security.jgss.spi.GSSNameSpi;
import java.security.Provider;
public abstract class GssCredElement implements GSSCredentialSpi {
static final Oid KRB5_OID = createOid("1.2.840.113554.1.2.2");
protected GSSCaller caller;
protected GssNameElement name;
protected int initLifeTime;
protected int accLifeTime;
GssCredElement(GSSCaller caller, GssNameElement name) {
this.caller = caller;
this.name = name;
}
public Provider getProvider() {
return new KerbyGssProvider();
}
public void dispose() throws GSSException {
}
public GSSNameSpi getName() throws GSSException {
return name;
}
public int getInitLifetime() throws GSSException {
return initLifeTime;
}
public int getAcceptLifetime() throws GSSException {
return accLifeTime;
}
public Oid getMechanism() {
return KRB5_OID;
}
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
throw new GSSException(GSSException.FAILURE, -1, "Unsupported feature"); // TODO:
}
private static Oid createOid(String oidStr) {
Oid retVal;
try {
retVal = new Oid(oidStr);
} catch (GSSException e) {
retVal = null; // get rid of blank catch block warning
}
return retVal;
}
}
| 180 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/MicTokenV2.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import java.io.IOException;
import java.io.OutputStream;
public class MicTokenV2 extends GssTokenV2 {
private MessageProp prop;
// This is called to construct MicToken from user input
MicTokenV2(GssContext context,
byte[] inMsg,
int msgOffset,
int msgLength,
MessageProp messageProp) throws GSSException {
super(TOKEN_MIC_V2, context);
prop = messageProp;
if (prop == null) {
prop = new MessageProp(0, false);
}
generateCheckSum(prop, inMsg, msgOffset, msgLength);
}
// This is called to construct MicToken from MicToken bytes
MicTokenV2(GssContext context,
MessageProp messageProp,
byte[] inToken,
int tokenOffset,
int tokenLength) throws GSSException {
super(TOKEN_MIC_V2, context, messageProp, inToken, tokenOffset, tokenLength);
this.prop = messageProp;
}
public int getMic(byte[] outToken, int offset) {
encodeHeader(outToken, offset);
System.arraycopy(checkSum, 0, outToken, TOKEN_HEADER_SIZE + offset, checkSum.length);
return TOKEN_HEADER_SIZE + checkSum.length;
}
/**
* Get bytes for this Mic token
* @return
*/
public byte[] getMic() {
byte[] ret = new byte[TOKEN_HEADER_SIZE + checkSum.length];
getMic(ret, 0);
return ret;
}
public void getMic(OutputStream os) throws GSSException {
try {
encodeHeader(os);
os.write(checkSum);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Output MicTokenV2 error:" + e.getMessage());
}
}
/**
* Calculate the checksum for inMsg and compare with it with this token, throw GssException if not equal
* @param inMsg
* @param msgOffset
* @param msgLen
* @throws GSSException
*/
public void verify(byte[] inMsg, int msgOffset, int msgLen) throws GSSException {
if (!verifyCheckSum(inMsg, msgOffset, msgLen)) {
throw new GSSException(GSSException.BAD_MIC, -1, "Corrupt MIC token");
}
}
}
| 181 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import org.apache.kerby.kerberos.kerb.crypto.util.BytesUtil;
import sun.security.jgss.GSSHeader;
import sun.security.util.ObjectIdentifier;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
/**
* This class implements the token formats defined in RFC 1964 and its updates
*
* The GSS Wrap token has the following format:
*
* Byte no Name Description
* 0..1 TOK_ID 0201
*
* 2..3 SGN_ALG Checksum algorithm indicator.
* 00 00 DES MAC MD5
* 01 00 MD2.5
* 02 00 DES MAC
* 04 00 HMAC SHA1 DES3-KD
* 11 00 RC4-HMAC used by Microsoft Windows, RFC 4757
* 4..5 SEAL_ALG ff ff none
* 00 00 DES
* 02 00 DES3-KD
* 10 00 RC4-HMAC
* 6..7 Filler FF FF
* 8..15 SND_SEQ Encrypted sequence number field.
* 16..23 SNG_CKSUM Checksum of plaintext padded data,
* calculated according to algorithm
* specified in SGN_ALG field.
* 24.. Data Encrypted or plaintext padded data
*
*
*
* Use of the GSS MIC token has the following format:
* Byte no Name Description
* 0..1 TOK_ID 0101
* 2..3 SGN_ALG Integrity algorithm indicator.
* 4..7 Filler Contains ff ff ff ff
* 8..15 SND_SEQ Sequence number field.
* 16..23 SGN_CKSUM Checksum of "to-be-signed data",
* calculated according to algorithm
* specified in SGN_ALG field.
*
*/
abstract class GssTokenV1 extends GssTokenBase {
// SGN ALG
public static final int SGN_ALG_DES_MAC_MD5 = 0;
public static final int SGN_ALG_MD25 = 0x0100;
public static final int SGN_ALG_DES_MAC = 0x0200;
public static final int SGN_ALG_HMAC_SHA1_DES3_KD = 0x0400;
public static final int SGN_ALG_RC4_HMAC = 0x1100;
// SEAL ALG
public static final int SEAL_ALG_NONE = 0xFFFF;
public static final int SEAL_ALG_DES = 0x0; // "DES/CBC/NoPadding"
public static final int SEAL_ALG_DES3_KD = 0x0200;
public static final int SEAL_ALG_RC4_HMAC = 0x1000;
public static final int KG_USAGE_SEAL = 22;
public static final int KG_USAGE_SIGN = 23;
public static final int KG_USAGE_SEQ = 24;
public static final int KG_USAGE_MS_SIGN = 15;
private boolean isInitiator;
private boolean confState;
private int sequenceNumber;
protected GssEncryptor encryptor;
private GSSHeader gssHeader;
public static final int TOKEN_HEADER_COMM_SIZE = 8;
public static final int TOKEN_HEADER_SEQ_SIZE = 8;
// Token commHeader data
private int tokenType;
private byte[] commHeader = new byte[TOKEN_HEADER_COMM_SIZE];
private int sgnAlg;
private int sealAlg;
private byte[] plainSequenceBytes;
private byte[] encryptedSequenceNumber = new byte[TOKEN_HEADER_SEQ_SIZE];
private byte[] checkSum;
private int checkSumSize;
protected int reconHeaderLen; // only used for certain reason
public static ObjectIdentifier objId;
static {
try {
objId = new ObjectIdentifier("1.2.840.113554.1.2.2");
} catch (IOException ioe) { // NOPMD
}
}
protected int getTokenHeaderSize() {
return TOKEN_HEADER_COMM_SIZE + TOKEN_HEADER_SEQ_SIZE + checkSumSize;
}
protected byte[] getPlainSequenceBytes() {
byte[] ret = new byte[4];
ret[0] = plainSequenceBytes[0];
ret[1] = plainSequenceBytes[1];
ret[2] = plainSequenceBytes[2];
ret[3] = plainSequenceBytes[3];
return ret;
}
// Generate a new token
GssTokenV1(int tokenType, GssContext context) throws GSSException {
initialize(tokenType, context, false);
createTokenHeader();
}
// Reconstruct a token
GssTokenV1(int tokenType, GssContext context, MessageProp prop,
byte[] token, int offset, int size) throws GSSException {
int proxLen = size > 64 ? 64 : size;
InputStream is = new ByteArrayInputStream(token, offset, proxLen);
reconstructInitializaion(tokenType, context, prop, is);
reconHeaderLen = gssHeader.getLength() + getTokenHeaderSize();
}
// Reconstruct a token
GssTokenV1(int tokenType, GssContext context, MessageProp prop, InputStream is) throws GSSException {
reconstructInitializaion(tokenType, context, prop, is);
}
private void reconstructInitializaion(int tokenType, GssContext context, MessageProp prop, InputStream is)
throws GSSException {
initialize(tokenType, context, true);
if (!confState) {
prop.setPrivacy(false);
}
try {
gssHeader = new GSSHeader(is);
} catch (IOException e) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token:" + e.getMessage());
}
if (!gssHeader.getOid().equals((Object) objId)) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token OID");
}
reconstructTokenHeader(is, prop);
}
private void initialize(int tokenType,
GssContext context,
boolean reconstruct) throws GSSException {
this.tokenType = tokenType;
this.isInitiator = context.isInitiator();
this.confState = context.getConfState();
this.encryptor = context.getGssEncryptor();
this.checkSumSize = encryptor.getCheckSumSize();
if (!reconstruct) {
this.sequenceNumber = context.incMySequenceNumber();
} else {
checkSum = new byte[checkSumSize];
}
}
protected void calcPrivacyInfo(MessageProp prop, byte[] confounder, byte[] data,
int dataOffset, int dataLength, int paddingLen) throws GSSException {
prop.setQOP(0);
if (!confState) {
prop.setPrivacy(false);
}
checkSum = calcCheckSum(confounder, commHeader, data, dataOffset, dataLength, paddingLen);
encryptSequenceNumber();
}
protected void verifyToken(byte[] confounder, byte[] data, int dataOffset, int dataLength, int paddingLen)
throws GSSException {
byte[] sum = calcCheckSum(confounder, commHeader, data, dataOffset, dataLength, paddingLen);
if (!MessageDigest.isEqual(checkSum, sum)) {
throw new GSSException(GSSException.BAD_MIC, -1,
"Corrupt token checksum for " + (tokenType == TOKEN_MIC_V1 ? "Mic" : "Wrap") + "TokenV1");
}
}
private byte[] calcCheckSum(byte[] confounder, byte[] header, byte[] data,
int dataOffset, int dataLength, int paddingLen) throws GSSException {
return encryptor.calculateCheckSum(confounder, header, data, dataOffset, dataLength, paddingLen,
tokenType == TOKEN_MIC_V1);
}
private void encryptSequenceNumber() throws GSSException {
plainSequenceBytes = new byte[8];
if (encryptor.isArcFourHmac()) {
BytesUtil.int2bytes(sequenceNumber, plainSequenceBytes, 0, true);
} else {
BytesUtil.int2bytes(sequenceNumber, plainSequenceBytes, 0, false);
}
// Hex 0 - sender is the context initiator, Hex FF - sender is the context acceptor
if (!isInitiator) {
plainSequenceBytes[4] = (byte) 0xFF;
plainSequenceBytes[5] = (byte) 0xFF;
plainSequenceBytes[6] = (byte) 0xFF;
plainSequenceBytes[7] = (byte) 0xFF;
}
encryptedSequenceNumber = encryptor.encryptSequenceNumber(plainSequenceBytes, checkSum, true);
}
public void encodeHeader(OutputStream os) throws GSSException, IOException {
// | GSSHeader | TokenHeader |
GSSHeader gssHeader = new GSSHeader(objId, getTokenSizeWithoutGssHeader());
gssHeader.encode(os);
os.write(commHeader);
os.write(encryptedSequenceNumber);
os.write(checkSum);
}
private void createTokenHeader() {
commHeader[0] = (byte) (tokenType >>> 8);
commHeader[1] = (byte) tokenType;
sgnAlg = encryptor.getSgnAlg();
commHeader[2] = (byte) (sgnAlg >>> 8);
commHeader[3] = (byte) sgnAlg;
if (tokenType == TOKEN_WRAP_V1) {
sealAlg = encryptor.getSealAlg();
commHeader[4] = (byte) (sealAlg >>> 8);
commHeader[5] = (byte) sealAlg;
} else {
commHeader[4] = (byte) 0xFF;
commHeader[5] = (byte) 0xFF;
}
commHeader[6] = (byte) 0xFF;
commHeader[7] = (byte) 0xFF;
}
// Re-construct token commHeader
private void reconstructTokenHeader(InputStream is, MessageProp prop) throws GSSException {
try {
if (is.read(commHeader) != commHeader.length
|| is.read(encryptedSequenceNumber) != encryptedSequenceNumber.length
|| is.read(checkSum) != checkSum.length) {
throw new GSSException(GSSException.FAILURE, -1,
"Insufficient in reconstruct token header");
}
initTokenHeader(commHeader, prop);
plainSequenceBytes = encryptor.encryptSequenceNumber(encryptedSequenceNumber, checkSum, false);
byte dirc = isInitiator ? (byte) 0xFF : 0;
// Hex 0 - sender is the context initiator, Hex FF - sender is the context acceptor
if (!(plainSequenceBytes[4] == dirc && plainSequenceBytes[5] == dirc
&& plainSequenceBytes[6] == dirc && plainSequenceBytes[7] == dirc)) {
throw new GSSException(GSSException.BAD_MIC, -1,
"Corrupt token sequence for " + (tokenType == TOKEN_MIC_V1 ? "Mic" : "Wrap") + "TokenV1");
}
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Error in reconstruct token header:" + e.getMessage());
}
}
private void initTokenHeader(byte[] tokenBytes, MessageProp prop) throws GSSException {
int tokenIDRecv = (((int) tokenBytes[0]) << 8) + tokenBytes[1];
if (tokenType != tokenIDRecv) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1,
"Token ID should be " + tokenType + " instead of " + tokenIDRecv);
}
sgnAlg = (((int) tokenBytes[2]) << 8) + tokenBytes[3];
sealAlg = (((int) tokenBytes[4]) << 8) + tokenBytes[5];
if (tokenBytes[6] != (byte) 0xFF || tokenBytes[7] != (byte) 0xFF) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token head filler");
}
prop.setQOP(0);
prop.setPrivacy(sealAlg != SEAL_ALG_NONE);
}
protected GSSHeader getGssHeader() {
return gssHeader;
}
abstract int getTokenSizeWithoutGssHeader();
}
| 182 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/WrapTokenV2.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class WrapTokenV2 extends GssTokenV2 {
private MessageProp prop;
// Generate a token from user input data
WrapTokenV2(GssContext context,
byte[] data,
int dataOffset,
int dataLength,
MessageProp messageProp) throws GSSException {
super(TOKEN_WRAP_V2, context);
prop = messageProp;
if (prop.getQOP() != 0) {
prop.setQOP(0);
}
if (!context.getConfState()) {
prop.setPrivacy(false);
}
generateCheckSum(prop, data, dataOffset, dataLength);
if (prop.getPrivacy()) {
byte[] toProcess = new byte[dataLength + TOKEN_HEADER_SIZE];
System.arraycopy(data, dataOffset, toProcess, 0, dataLength);
encodeHeader(toProcess, dataLength);
tokenData = encryptor.encryptData(toProcess, getKeyUsage());
} else {
tokenData = data; // keep it for now
}
}
/**
* Get bytes of the token
* @return
*/
public byte[] wrap() {
int dataSize = tokenData.length;
int ckSize = checkSum == null ? 0 : checkSum.length;
byte[] ret = new byte[TOKEN_HEADER_SIZE + dataSize + ckSize];
encodeHeader(ret, 0);
System.arraycopy(tokenData, 0, ret, TOKEN_HEADER_SIZE, dataSize);
if (ckSize > 0) {
System.arraycopy(checkSum, 0, ret, TOKEN_HEADER_SIZE + dataSize, ckSize);
}
return ret;
}
public void wrap(OutputStream os) throws GSSException {
try {
encodeHeader(os);
os.write(tokenData);
int ckSize = checkSum == null ? 0 : checkSum.length;
if (ckSize > 0) {
os.write(checkSum);
}
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Output token error:" + e.getMessage());
}
}
// Reconstruct a token from token bytes
public WrapTokenV2(GssContext context, MessageProp prop, byte[] token, int offset, int len) throws GSSException {
super(TOKEN_WRAP_V2, context, prop, token, offset, len);
this.prop = prop;
}
// Reconstruct a token from token bytes stream
public WrapTokenV2(GssContext context, MessageProp prop, InputStream is) throws GSSException {
super(TOKEN_WRAP_V2, context, prop, is);
this.prop = prop;
}
/**
* Get plain text data from token bytes
* @param outBuffer
* @param offset
* @return plain text contained in the wrap token
* @throws GSSException
*/
public byte[] unwrap(byte[] outBuffer, int offset) throws GSSException {
int lenToCopy;
if (prop.getPrivacy()) {
byte[] plainText = encryptor.decryptData(tokenData, getKeyUsage());
lenToCopy = plainText.length - TOKEN_HEADER_SIZE;
if (outBuffer == null) {
outBuffer = new byte[lenToCopy];
offset = 0;
}
System.arraycopy(plainText, 0, outBuffer, offset, lenToCopy);
} else {
lenToCopy = tokenData.length - encryptor.getCheckSumSize();
if (outBuffer == null) {
outBuffer = new byte[lenToCopy];
offset = 0;
}
System.arraycopy(tokenData, 0, outBuffer, offset, lenToCopy);
if (!verifyCheckSum(outBuffer, offset, lenToCopy)) {
throw new GSSException(GSSException.BAD_MIC, -1, "Corrupt token checksum");
}
}
return outBuffer;
}
public byte[] unwrap() throws GSSException {
return unwrap(null, 0);
}
public void unwrap(OutputStream os) throws GSSException {
byte[] data = unwrap();
try {
os.write(data);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Output token error:" + e.getMessage());
}
}
public static int getMsgSizeLimit(int qop, boolean confReq, int maxTokSize, GssEncryptor encryptor)
throws GSSException {
if (confReq) {
return maxTokSize - encryptor.getCheckSumSize() - TOKEN_HEADER_SIZE * 2 - CONFOUNDER_SIZE;
} else {
return maxTokSize - encryptor.getCheckSumSize() - TOKEN_HEADER_SIZE;
}
}
}
| 183 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/WrapTokenV1.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.crypto.util.Random;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import sun.security.jgss.GSSHeader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class WrapTokenV1 extends GssTokenV1 {
public static final int CONFOUNDER_SIZE = 8;
private boolean privacy;
private byte[] inData;
private int inOffset;
private int inLen;
private int paddingLen;
private byte[] confounder;
private int tokenBodyLen;
private byte[] bodyData;
private int bodyOffset;
private int bodyLen;
// for reconstruct
private int rawDataLength;
private byte[] rawData;
private int rawDataOffset;
// Generate wrap token according user data
public WrapTokenV1(GssContext context,
byte[] inMsg,
int msgOffset,
int msgLength,
MessageProp prop) throws GSSException {
super(TOKEN_WRAP_V1, context);
paddingLen = getPaddingLength(msgLength);
confounder = Random.makeBytes(CONFOUNDER_SIZE);
tokenBodyLen = CONFOUNDER_SIZE + msgLength + paddingLen;
calcPrivacyInfo(prop, confounder, inMsg, msgOffset, msgLength, paddingLen);
if (!context.getConfState()) {
prop.setPrivacy(false);
}
privacy = prop.getPrivacy();
inData = inMsg;
inOffset = msgOffset;
inLen = msgLength;
}
// Reconstruct a token from token bytes
public WrapTokenV1(GssContext context, MessageProp prop,
byte[] token, int offset, int len) throws GSSException {
super(TOKEN_WRAP_V1, context, prop, token, offset, len);
// adjust the offset to the beginning of the body
bodyData = token;
bodyOffset = offset + reconHeaderLen;
bodyLen = len - reconHeaderLen;
getRawData(prop);
}
// Reconstruct a token from token bytes stream
public WrapTokenV1(GssContext context, MessageProp prop, InputStream is) throws GSSException {
super(TOKEN_WRAP_V1, context, prop, is);
byte[] token;
int len;
try {
len = is.available();
token = new byte[len];
is.read(token);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Read wrap token V1 error:" + e.getMessage());
}
bodyData = token;
bodyOffset = 0;
bodyLen = len;
getRawData(prop);
}
private void getRawData(MessageProp prop) throws GSSException {
privacy = prop.getPrivacy();
tokenBodyLen = getGssHeader().getMechTokenLength() - getTokenHeaderSize();
if (bodyLen < tokenBodyLen) {
throw new GSSException(GSSException.FAILURE, -1, "Insufficient data for Wrap token V1");
}
if (privacy) {
rawData = encryptor.encryptTokenV1(null, bodyData, bodyOffset, tokenBodyLen, 0,
encryptor.isArcFourHmac() ? getPlainSequenceBytes() : null, false);
paddingLen = rawData[rawData.length - 1];
rawDataOffset = CONFOUNDER_SIZE;
} else {
rawData = bodyData;
paddingLen = bodyData[bodyOffset + tokenBodyLen - 1];
rawDataOffset = bodyOffset + CONFOUNDER_SIZE;
}
rawDataLength = tokenBodyLen - CONFOUNDER_SIZE - paddingLen;
verifyToken(null, rawData, rawDataOffset - CONFOUNDER_SIZE, tokenBodyLen, 0);
}
// Get plain text data from token data bytes
public byte[] unwrap() throws GSSException {
byte[] ret = new byte[rawDataLength];
System.arraycopy(rawData, rawDataOffset, ret, 0, rawDataLength);
return ret;
}
public void unwrap(OutputStream os) throws GSSException {
try {
os.write(rawData, rawDataOffset, rawDataLength);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Error in output wrap token v1 data bytes:" + e.getMessage());
}
}
public byte[] wrap() throws GSSException {
ByteArrayOutputStream os = new ByteArrayOutputStream(getTokenSizeWithoutGssHeader() + inLen + 64);
wrap(os);
return os.toByteArray();
}
public void wrap(OutputStream os) throws GSSException {
try {
encodeHeader(os);
if (privacy) {
byte[] enc = encryptor.encryptTokenV1(confounder, inData, inOffset, inLen, paddingLen,
encryptor.isArcFourHmac() ? getPlainSequenceBytes() : null, true);
os.write(enc);
} else {
os.write(confounder);
os.write(inData, inOffset, inLen);
os.write(getPaddingBytes(paddingLen));
}
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Error in output wrap token v1 bytes:" + e.getMessage());
}
}
protected int getTokenSizeWithoutGssHeader() {
return tokenBodyLen + getTokenHeaderSize();
}
private int getPaddingLength(int dataLen) {
if (encryptor.isArcFourHmac()) {
return 1;
}
return 8 - (dataLen % 8);
}
private byte[] getPaddingBytes(int len) {
byte[] ret = new byte[len];
int i = 0;
while (i < len) {
ret[i++] = (byte) len;
}
return ret;
}
public static int getMsgSizeLimit(int qop, boolean confReq, int maxTokSize, GssEncryptor encryptor)
throws GSSException {
return GSSHeader.getMaxMechTokenSize(objId, maxTokSize)
- encryptor.getCheckSumSize()
- TOKEN_HEADER_COMM_SIZE - TOKEN_HEADER_SEQ_SIZE
- CONFOUNDER_SIZE - 8;
}
}
| 184 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import org.apache.kerby.kerberos.kerb.crypto.util.BytesUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
/**
* This class implements the token formats defined in RFC 4121.
*/
abstract class GssTokenV2 extends GssTokenBase {
public static final int CONFOUNDER_SIZE = 16;
public static final int TOKEN_HEADER_SIZE = 16;
private static final int OFFSET_EC = 4;
private static final int OFFSET_RRC = 6;
// context states
private boolean isInitiator = true;
private boolean acceptorSubKey = false;
private boolean confState = true;
private int sequenceNumber;
// token data
protected int tokenType;
private byte[] header = new byte[TOKEN_HEADER_SIZE];
protected byte[] tokenData;
protected byte[] checkSum;
private int ec;
private int rrc;
static final int KG_USAGE_ACCEPTOR_SEAL = 22;
static final int KG_USAGE_ACCEPTOR_SIGN = 23;
static final int KG_USAGE_INITIATOR_SEAL = 24;
static final int KG_USAGE_INITIATOR_SIGN = 25;
private int keyUsage;
private static final int FLAG_SENT_BY_ACCEPTOR = 1;
private static final int FLAG_SEALED = 2;
private static final int FLAG_ACCEPTOR_SUBKEY = 4;
protected GssEncryptor encryptor;
// Create a new token
GssTokenV2(int tokenType, GssContext context) throws GSSException {
initialize(tokenType, context, false);
}
private void initialize(int tokenType, GssContext context, boolean reconstruct) throws GSSException {
this.tokenType = tokenType;
this.isInitiator = context.isInitiator();
this.acceptorSubKey = context.getKeyComesFrom() == GssContext.ACCEPTOR_SUBKEY;
this.confState = context.getConfState();
boolean usageFlag = reconstruct ? !this.isInitiator : this.isInitiator;
if (tokenType == TOKEN_WRAP_V2) {
keyUsage = usageFlag ? KG_USAGE_INITIATOR_SEAL : KG_USAGE_ACCEPTOR_SEAL;
} else if (tokenType == TOKEN_MIC_V2) {
keyUsage = usageFlag ? KG_USAGE_INITIATOR_SIGN : KG_USAGE_ACCEPTOR_SIGN;
}
encryptor = context.getGssEncryptor();
if (!reconstruct) {
this.sequenceNumber = context.incMySequenceNumber();
}
}
// Reconstruct token from bytes received
GssTokenV2(int tokenType, GssContext context,
MessageProp prop, byte[] token, int offset, int len) throws GSSException {
this(tokenType, context, prop, new ByteArrayInputStream(token, offset, len));
}
// Reconstruct token from input stream
GssTokenV2(int tokenType, GssContext context,
MessageProp prop, InputStream is) throws GSSException {
initialize(tokenType, context, true);
if (!confState) {
prop.setPrivacy(false);
}
reconstructTokenHeader(prop, is);
int minSize;
if (tokenType == TOKEN_WRAP_V2 && prop.getPrivacy()) {
minSize = CONFOUNDER_SIZE + TOKEN_HEADER_SIZE + encryptor.getCheckSumSize();
} else {
minSize = encryptor.getCheckSumSize();
}
try {
int tokenLen = is.available();
if (tokenType == TOKEN_MIC_V2) {
tokenLen = minSize;
tokenData = new byte[tokenLen];
is.read(tokenData);
} else {
if (tokenLen >= minSize) {
tokenData = new byte[tokenLen];
is.read(tokenData);
} else {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token length");
}
}
if (tokenType == TOKEN_WRAP_V2) {
tokenData = rotate(tokenData);
}
if (tokenType == TOKEN_MIC_V2
|| tokenType == TOKEN_WRAP_V2 && !prop.getPrivacy()) {
int checksumLen = encryptor.getCheckSumSize();
if (tokenType != TOKEN_MIC_V2 && checksumLen != ec) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid EC");
}
checkSum = new byte[checksumLen];
System.arraycopy(tokenData, tokenLen - checksumLen, checkSum, 0, checksumLen);
}
} catch (IOException e) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token");
}
}
private byte[] rotate(byte[] data) {
int dataLen = data.length;
if (rrc % dataLen != 0) {
rrc = rrc % dataLen;
byte[] newBytes = new byte[dataLen];
System.arraycopy(data, rrc, newBytes, 0, dataLen - rrc);
System.arraycopy(data, 0, newBytes, dataLen - rrc, rrc);
data = newBytes;
}
return data;
}
public int getKeyUsage() {
return keyUsage;
}
public void generateCheckSum(MessageProp prop, byte[] data, int offset, int len) throws GSSException {
// generate token header
createTokenHeader(prop.getPrivacy());
if (tokenType == TOKEN_MIC_V2
|| !prop.getPrivacy() && tokenType == TOKEN_WRAP_V2) {
checkSum = getCheckSum(data, offset, len);
}
if (!prop.getPrivacy() && tokenType == TOKEN_WRAP_V2) {
header[4] = (byte) (checkSum.length >>> 8);
header[5] = (byte) (checkSum.length & 0xFF);
}
}
public byte[] getCheckSum(byte[] data, int offset, int len) throws GSSException {
int confidentialFlag = header[2] & 2;
if (confidentialFlag == 0 && tokenType == TOKEN_WRAP_V2) {
header[4] = 0;
header[5] = 0;
header[6] = 0;
header[7] = 0;
}
return encryptor.calculateCheckSum(header, data, offset, len, keyUsage);
}
public boolean verifyCheckSum(byte[] data, int offset, int len) throws GSSException {
byte[] dataCheckSum = getCheckSum(data, offset, len);
return MessageDigest.isEqual(checkSum, dataCheckSum);
}
// Create a new header
private void createTokenHeader(boolean privacy) {
header[0] = (byte) (tokenType >>> 8);
header[1] = (byte) tokenType;
int flags = isInitiator ? 0 : FLAG_SENT_BY_ACCEPTOR;
flags |= privacy && tokenType != TOKEN_MIC_V2 ? FLAG_SEALED : 0;
flags |= acceptorSubKey ? FLAG_ACCEPTOR_SUBKEY : 0;
header[2] = (byte) (flags & 0xFF);
header[3] = (byte) 0xFF;
if (tokenType == TOKEN_WRAP_V2) {
header[4] = (byte) 0;
header[5] = (byte) 0;
header[6] = (byte) 0;
header[7] = (byte) 0;
} else if (tokenType == TOKEN_MIC_V2) {
header[4] = (byte) 0xFF;
header[5] = (byte) 0xFF;
header[6] = (byte) 0xFF;
header[7] = (byte) 0xFF;
}
BytesUtil.int2bytes(sequenceNumber, header, 12, true);
}
// Reconstruct a token header
private void reconstructTokenHeader(MessageProp prop, InputStream is) throws GSSException {
try {
if (is.read(header, 0, header.length) != header.length) {
throw new GSSException(GSSException.FAILURE, -1, "Token header can not be read");
}
int tokenIDRecv = (((int) header[0]) << 8) + header[1];
if (tokenIDRecv != tokenType) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1,
"Token ID should be " + tokenType + " instead of " + tokenIDRecv);
}
int senderFlag = isInitiator ? FLAG_SENT_BY_ACCEPTOR : 0;
int senderFlagRecv = header[2] & FLAG_SENT_BY_ACCEPTOR;
if (senderFlagRecv != senderFlag) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid acceptor flag");
}
int confFlagRecv = header[2] & FLAG_SEALED;
if (confFlagRecv == FLAG_SEALED && tokenType == TOKEN_WRAP_V2) {
prop.setPrivacy(true);
} else {
prop.setPrivacy(false);
}
if (tokenType == TOKEN_WRAP_V2) {
if (header[3] != (byte) 0xFF) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token filler");
}
ec = BytesUtil.bytes2short(header, OFFSET_EC, true);
rrc = BytesUtil.bytes2short(header, OFFSET_RRC, true);
} else if (tokenType == TOKEN_MIC_V2) {
for (int i = 3; i < 8; i++) {
if ((header[i] & 0xFF) != 0xFF) {
throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token filler");
}
}
}
prop.setQOP(0);
sequenceNumber = (int) BytesUtil.bytes2long(header, 0, true);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Phrase token header failed");
}
}
public int encodeHeader(byte[] buf, int offset) {
System.arraycopy(header, 0, buf, offset, TOKEN_HEADER_SIZE);
return TOKEN_HEADER_SIZE;
}
public void encodeHeader(OutputStream os) throws IOException {
os.write(header);
}
}
| 185 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssContext.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import com.sun.security.jgss.InquireType;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.gss.GssMechFactory;
import org.apache.kerby.kerberos.kerb.gss.KerbyGssProvider;
import org.apache.kerby.kerberos.kerb.request.ApRequest;
import org.apache.kerby.kerberos.kerb.response.ApResponse;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.ap.ApRep;
import org.apache.kerby.kerberos.kerb.type.ap.ApReq;
import org.apache.kerby.kerberos.kerb.type.ap.Authenticator;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.kdc.EncKdcRepPart;
import org.apache.kerby.kerberos.kerb.type.ticket.EncTicketPart;
import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
import org.ietf.jgss.ChannelBinding;
import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import org.ietf.jgss.Oid;
import sun.security.jgss.GSSCaller;
import sun.security.jgss.spi.GSSContextSpi;
import sun.security.jgss.spi.GSSCredentialSpi;
import sun.security.jgss.spi.GSSNameSpi;
import javax.security.auth.kerberos.KerberosTicket;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.security.Provider;
@SuppressWarnings("PMD")
public class GssContext implements GSSContextSpi {
private static final int STATE_NONE = 0;
private static final int STATE_ESTABLISHING = 1;
private static final int STATE_ESTABLISHED = 2;
private static final int STATE_DESTROYED = 3;
private static final byte[] MSG_AP_REQ = {(byte) 0x1, (byte) 0};
private static final byte[] MSG_AP_REP = {(byte) 0x2, (byte) 0};
private int ctxState = STATE_NONE;
private final GSSCaller caller;
private GssCredElement myCred;
private boolean initiator;
private GssNameElement myName;
private GssNameElement peerName;
private int lifeTime;
private ChannelBinding channelBinding;
private boolean mutualAuth = true;
private boolean replayDet = true;
private boolean sequenceDet = true;
private boolean credDeleg = false;
private boolean confState = true;
private boolean integState = true;
private boolean delegPolicy = false;
public static final int INVALID_KEY = 0;
public static final int SESSION_KEY = 1;
public static final int INITIATOR_SUBKEY = 2;
public static final int ACCEPTOR_SUBKEY = 4;
private int keyComesFrom = INVALID_KEY;
private EncryptionKey sessionKey; // used between client and app server
private TicketFlags ticketFlags;
private ApReq outApReq;
private GssEncryptor gssEncryptor;
// Called on initiator's side.
public GssContext(GSSCaller caller, GssNameElement peerName, GssCredElement myCred,
int lifeTime)
throws GSSException {
if (peerName == null) {
throw new IllegalArgumentException("Cannot have null peer name");
}
this.caller = caller;
this.peerName = peerName;
this.myCred = myCred;
this.lifeTime = lifeTime;
this.initiator = true;
mySequenceNumberLock = new Object();
peerSequenceNumberLock = new Object();
}
public GssContext(GSSCaller caller, GssAcceptCred myCred)
throws GSSException {
this.caller = caller;
this.myCred = myCred;
this.initiator = false;
mySequenceNumberLock = new Object();
peerSequenceNumberLock = new Object();
}
public GssContext(GSSCaller caller, byte[] interProcessToken)
throws GSSException {
throw new GSSException(GSSException.UNAVAILABLE, -1, "Unsupported feature");
}
public Provider getProvider() {
return new KerbyGssProvider();
}
public void requestLifetime(int lifeTime) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
this.lifeTime = lifeTime;
}
}
public void requestMutualAuth(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
mutualAuth = state;
}
}
public void requestReplayDet(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
replayDet = state;
}
}
public void requestSequenceDet(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
replayDet = state;
}
}
public void requestCredDeleg(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator() && myCred == null) {
credDeleg = state;
}
}
public void requestAnonymity(boolean state) throws GSSException {
// anonymous context not supported
}
public void requestConf(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
confState = state;
}
}
public void requestInteg(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
integState = state;
}
}
public void requestDelegPolicy(boolean state) throws GSSException {
if (ctxState == STATE_NONE && isInitiator()) {
delegPolicy = state;
}
}
public void setChannelBinding(ChannelBinding cb) throws GSSException {
this.channelBinding = cb;
}
public boolean getCredDelegState() {
return credDeleg;
}
public boolean getMutualAuthState() {
return mutualAuth;
}
public boolean getReplayDetState() {
return replayDet || sequenceDet;
}
public boolean getSequenceDetState() {
return sequenceDet;
}
public boolean getAnonymityState() {
return false;
}
public boolean getDelegPolicyState() {
return delegPolicy;
}
public boolean isTransferable() throws GSSException {
return false;
}
public boolean isProtReady() {
return ctxState == STATE_ESTABLISHED;
}
public boolean isInitiator() {
return initiator;
}
public boolean getConfState() {
return confState;
}
public boolean getIntegState() {
return integState;
}
public int getLifetime() {
return GSSContext.INDEFINITE_LIFETIME;
}
public boolean isEstablished() {
return ctxState == STATE_ESTABLISHED;
}
public GSSNameSpi getSrcName() throws GSSException {
return isInitiator() ? myName : peerName;
}
public GSSNameSpi getTargName() throws GSSException {
return !isInitiator() ? myName : peerName;
}
public Oid getMech() throws GSSException {
return GssMechFactory.getOid();
}
public GSSCredentialSpi getDelegCred() throws GSSException {
throw new GSSException(GSSException.FAILURE, -1, "API not implemented"); // TODO:
}
public byte[] initSecContext(InputStream is, int mechTokenSize)
throws GSSException {
if (!isInitiator()) {
throw new GSSException(GSSException.FAILURE, -1, "initSecContext called on acceptor");
}
byte[] ret = null;
if (ctxState == STATE_NONE) {
if (!myCred.isInitiatorCredential()) {
throw new GSSException(GSSException.NO_CRED, -1, "No TGT available");
}
// check if service ticket already exists
// if not, prepare to get it through TGS_REQ
SgtTicket sgtTicket = null;
String serviceName = peerName.getPrincipalName().getName();
myName = (GssNameElement) myCred.getName();
PrincipalName clientPrincipal = myName.getPrincipalName();
sgtTicket = GssUtil.getSgtCredentialFromContext(caller, clientPrincipal.getName(), serviceName);
if (sgtTicket == null) {
sgtTicket = GssUtil.applySgtCredential(((GssInitCred) myCred).getKerberosTicket(),
((GssInitCred) myCred).getKrbToken(),
serviceName);
// add this service credential to context
final KerberosTicket ticket =
GssUtil.convertKrbTicketToKerberosTicket(sgtTicket, myName.getPrincipalName().getName());
CredUtils.addCredentialToSubject(ticket);
}
ApRequest apRequest = new ApRequest(clientPrincipal, sgtTicket);
try {
outApReq = apRequest.getApReq();
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, "Generate ApReq failed: " + e.getMessage());
}
setupInitiatorContext(sgtTicket, apRequest);
try {
ByteBuffer outBuffer = ByteBuffer.allocate(outApReq.encodingLength() + 2);
outBuffer.put(MSG_AP_REQ);
outApReq.encode(outBuffer);
outBuffer.flip();
ret = outBuffer.array();
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Generate ApReq bytes failed: " + e.getMessage());
}
ctxState = STATE_ESTABLISHING;
if (!getMutualAuthState()) {
gssEncryptor = new GssEncryptor(getSessionKey());
ctxState = STATE_ESTABLISHED;
}
} else if (ctxState == STATE_ESTABLISHING) {
verifyServerToken(is, mechTokenSize);
gssEncryptor = new GssEncryptor(getSessionKey());
outApReq = null;
ctxState = STATE_ESTABLISHED;
}
return ret;
}
private void setupInitiatorContext(SgtTicket sgt, ApRequest apRequest) throws GSSException {
EncKdcRepPart encKdcRepPart = sgt.getEncKdcRepPart();
TicketFlags ticketFlags = encKdcRepPart.getFlags();
setTicketFlags(ticketFlags);
setAuthTime(encKdcRepPart.getAuthTime().toString());
Authenticator auth;
try {
auth = apRequest.getApReq().getAuthenticator();
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, "ApReq failed in Initiator");
}
setMySequenceNumber(auth.getSeqNumber());
EncryptionKey subKey = auth.getSubKey();
if (subKey != null) {
setSessionKey(subKey, GssContext.INITIATOR_SUBKEY);
} else {
setSessionKey(sgt.getSessionKey(), GssContext.SESSION_KEY);
}
if (!getMutualAuthState()) {
setPeerSequenceNumber(0);
}
}
/**
* Verify the AP_REP from server and set context accordingly
* @param is
* @param mechTokenSize
* @return
* @throws GSSException
* @throws IOException
*/
private void verifyServerToken(InputStream is, int mechTokenSize)
throws GSSException {
byte[] token;
ApRep apRep;
try {
if (!(is.read() == MSG_AP_REP[0] && is.read() == MSG_AP_REP[1])) {
throw new GSSException(GSSException.FAILURE, -1, "Invalid ApRep message ID");
}
token = new byte[mechTokenSize - MSG_AP_REP.length];
is.read(token);
apRep = new ApRep();
apRep.decode(token);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Invalid ApRep " + e.getMessage());
}
try {
ApResponse.validate(getSessionKey(), apRep, outApReq);
} catch (KrbException e) {
throw new GSSException(GSSException.UNAUTHORIZED, -1, "ApRep verification failed");
}
EncryptionKey key = apRep.getEncRepPart().getSubkey();
if (key != null) {
setSessionKey(key, ACCEPTOR_SUBKEY);
}
int seqNum = apRep.getEncRepPart().getSeqNumber();
setPeerSequenceNumber(seqNum == -1 ? 0 : seqNum);
}
public byte[] acceptSecContext(InputStream is, int mechTokenSize)
throws GSSException {
byte[] ret = null;
if (isInitiator()) {
throw new GSSException(GSSException.FAILURE, -1, "acceptSecContext called on initiator");
}
if (ctxState == STATE_NONE) {
ctxState = STATE_ESTABLISHING;
if (!myCred.isAcceptorCredential()) {
throw new GSSException(GSSException.FAILURE, -1, "No acceptor credential available");
}
GssAcceptCred acceptCred = (GssAcceptCred) myCred;
CredUtils.checkPrincipalPermission(
((GssNameElement) acceptCred.getName()).getPrincipalName().getName(), "accept");
if (getMutualAuthState()) {
ret = verifyClientToken(acceptCred, is, mechTokenSize);
}
gssEncryptor = new GssEncryptor(getSessionKey());
myCred = null;
ctxState = STATE_ESTABLISHED;
}
return ret;
}
private byte[] verifyClientToken(GssAcceptCred acceptCred, InputStream is, int mechTokenSize)
throws GSSException {
byte[] token;
ApReq apReq;
try {
if (!(is.read() == MSG_AP_REQ[0] && is.read() == MSG_AP_REQ[1])) {
throw new GSSException(GSSException.FAILURE, -1, "Invalid ApReq message ID");
}
token = new byte[mechTokenSize - MSG_AP_REQ.length];
is.read(token);
apReq = new ApReq();
apReq.decode(token);
} catch (IOException e) {
throw new GSSException(GSSException.UNAUTHORIZED, -1, "ApReq invalid:" + e.getMessage());
}
int kvno = apReq.getTicket().getEncryptedEncPart().getKvno();
int encryptType = apReq.getTicket().getEncryptedEncPart().getEType().getValue();
EncryptionKey serverKey = acceptCred.getEncryptionKey(encryptType, kvno);
if (serverKey == null) {
throw new GSSException(GSSException.FAILURE, -1, "Server key not found");
}
peerName = (GssNameElement) acceptCred.getName();
try {
ApRequest.validate(serverKey, apReq,
channelBinding == null ? null : channelBinding.getInitiatorAddress(), 5 * 60 * 1000);
} catch (KrbException e) {
throw new GSSException(GSSException.UNAUTHORIZED, -1, "ApReq verification failed: " + e.getMessage());
}
ApResponse apResponse = new ApResponse(apReq);
ApRep apRep;
try {
apRep = apResponse.getApRep();
} catch (KrbException e) {
throw new GSSException(GSSException.UNAUTHORIZED, -1, "Generate ApRep failed");
}
EncTicketPart apReqTicketEncPart = apReq.getTicket().getEncPart();
EncryptionKey ssKey = apReqTicketEncPart.getKey();
Authenticator auth = apReq.getAuthenticator();
EncryptionKey subKey = auth.getSubKey();
if (subKey != null) {
setSessionKey(subKey, INITIATOR_SUBKEY);
} else {
setSessionKey(ssKey, SESSION_KEY);
}
// initial seqNumber
int seqNumber = auth.getSeqNumber();
setMySequenceNumber(seqNumber);
// initial authtime, tktflags, authdata,
setAuthTime(apReqTicketEncPart.getAuthTime().toString());
setTicketFlags(apReqTicketEncPart.getFlags());
setAuthData(apReqTicketEncPart.getAuthorizationData());
byte[] ret = null;
try {
ByteBuffer outBuffer = ByteBuffer.allocate(apRep.encodingLength() + 2);
outBuffer.put(MSG_AP_REP);
apRep.encode(outBuffer);
outBuffer.flip();
ret = outBuffer.array();
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Generate ApRep bytes failed:" + e.getMessage());
}
return ret;
}
public int getWrapSizeLimit(int qop, boolean confReq, int maxTokSize)
throws GSSException {
if (gssEncryptor.isV2()) {
return WrapTokenV2.getMsgSizeLimit(qop, confReq, maxTokSize, gssEncryptor);
} else {
return WrapTokenV1.getMsgSizeLimit(qop, confReq, maxTokSize, gssEncryptor);
}
}
public void wrap(InputStream is, OutputStream os, MessageProp msgProp)
throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for wrap");
}
int len;
byte[] inBuf;
try {
len = is.available();
inBuf = new byte[len];
is.read(inBuf);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Error when get user data:" + e.getMessage());
}
if (gssEncryptor.isV2()) {
WrapTokenV2 token = new WrapTokenV2(this, inBuf, 0, len, msgProp);
token.wrap(os);
} else {
WrapTokenV1 token = new WrapTokenV1(this, inBuf, 0, len, msgProp);
token.wrap(os);
}
}
public byte[] wrap(byte[] inBuf, int offset, int len,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for wrap");
}
byte[] ret;
if (gssEncryptor.isV2()) {
WrapTokenV2 token = new WrapTokenV2(this, inBuf, offset, len, msgProp);
ret = token.wrap();
} else {
WrapTokenV1 token = new WrapTokenV1(this, inBuf, offset, len, msgProp);
ret = token.wrap();
}
return ret;
}
public void unwrap(InputStream is, OutputStream os,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for unwrap");
}
if (gssEncryptor.isV2()) {
WrapTokenV2 token = new WrapTokenV2(this, msgProp, is);
token.unwrap(os);
} else {
WrapTokenV1 token = new WrapTokenV1(this, msgProp, is);
token.unwrap(os);
}
}
public byte[] unwrap(byte[] inBuf, int offset, int len,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for unwrap");
}
byte[] ret;
if (gssEncryptor.isV2()) {
WrapTokenV2 token = new WrapTokenV2(this, msgProp, inBuf, offset, len);
ret = token.unwrap();
} else {
WrapTokenV1 token = new WrapTokenV1(this, msgProp, inBuf, offset, len);
ret = token.unwrap();
}
return ret;
}
public void getMIC(InputStream is, OutputStream os,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for getMIC");
}
try {
int len = is.available();
byte[] inMsg = new byte[len];
is.read(inMsg);
if (gssEncryptor.isV2()) {
MicTokenV2 token = new MicTokenV2(this, inMsg, 0, len, msgProp);
token.getMic(os);
} else {
MicTokenV1 token = new MicTokenV1(this, inMsg, 0, len, msgProp);
token.getMic(os);
}
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Error when get user data in getMIC:" + e.getMessage());
}
}
public byte[] getMIC(byte[] inMsg, int offset, int len,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for getMIC");
}
byte[] ret;
if (gssEncryptor.isV2()) {
MicTokenV2 token = new MicTokenV2(this, inMsg, offset, len, msgProp);
ret = token.getMic();
} else {
MicTokenV1 token = new MicTokenV1(this, inMsg, offset, len, msgProp);
ret = token.getMic();
}
return ret;
}
public void verifyMIC(InputStream is, InputStream msgStr,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for verifyMIC");
}
try {
int tokLen = is.available();
byte[] inTok = new byte[tokLen];
int msgLen = msgStr.available();
byte[] inMsg = new byte[msgLen];
verifyMIC(inTok, 0, tokLen, inMsg, 0, msgLen, msgProp);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Error when get user data in verifyMIC:" + e.getMessage());
}
}
public void verifyMIC(byte[]inTok, int tokOffset, int tokLen,
byte[] inMsg, int msgOffset, int msgLen,
MessageProp msgProp) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Context invalid for verifyMIC");
}
if (gssEncryptor.isV2()) {
MicTokenV2 token = new MicTokenV2(this, msgProp, inTok, tokOffset, tokLen);
token.verify(inMsg, msgOffset, msgLen);
} else {
MicTokenV1 token = new MicTokenV1(this, msgProp, inTok, tokOffset, tokLen);
token.verify(inMsg, msgOffset, msgLen);
}
}
public byte[] export() throws GSSException {
throw new GSSException(GSSException.UNAVAILABLE, -1, "Unsupported export() method");
}
public void dispose() throws GSSException {
ctxState = STATE_DESTROYED;
setSessionKey(null, 0);
peerName = null;
myCred = null;
myName = null;
}
private String authTime;
private void setAuthTime(String authTime) {
this.authTime = authTime;
}
public Object inquireSecContext(String type) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Invalid context");
}
switch (type) {
case "KRB5_GET_SESSION_KEY":
return getSessionKey();
case "KRB5_GET_TKT_FLAGS":
return GssUtil.ticketFlagsToBooleans(ticketFlags);
case "KRB5_GET_AUTHZ_DATA":
if (isInitiator()) {
throw new GSSException(GSSException.UNAVAILABLE, -1,
"Authorization data not available for initiator");
} else {
return GssUtil.kerbyAuthorizationDataToJgssAuthorizationDataEntries(authData);
}
case "KRB5_GET_AUTHTIME":
return authTime;
}
throw new GSSException(GSSException.UNAVAILABLE, -1, "Unsupported inquire type");
}
public Object inquireSecContext(InquireType type) throws GSSException {
if (ctxState != STATE_ESTABLISHED) {
throw new GSSException(GSSException.NO_CONTEXT, -1, "Invalid context");
}
switch (type) {
case KRB5_GET_SESSION_KEY:
return getSessionKey();
case KRB5_GET_TKT_FLAGS:
return GssUtil.ticketFlagsToBooleans(ticketFlags);
case KRB5_GET_AUTHZ_DATA:
if (isInitiator()) {
throw new GSSException(GSSException.UNAVAILABLE, -1,
"Authorization data not available for initiator");
} else {
return GssUtil.kerbyAuthorizationDataToJgssAuthorizationDataEntries(authData);
}
case KRB5_GET_AUTHTIME:
return authTime;
}
throw new GSSException(GSSException.UNAVAILABLE, -1, "Unsupported inquire type");
}
// functions not belong to SPI
private void setSessionKey(EncryptionKey encryptionKey, int keyComesFrom) {
this.sessionKey = encryptionKey;
this.keyComesFrom = keyComesFrom;
}
public int getKeyComesFrom() {
return keyComesFrom;
}
private EncryptionKey getSessionKey() {
return sessionKey;
}
private void setTicketFlags(TicketFlags ticketFlags) {
this.ticketFlags = ticketFlags;
}
private AuthorizationData authData;
private void setAuthData(AuthorizationData authData) {
this.authData = authData;
}
private int mySequenceNumber;
private int peerSequenceNumber;
private Object mySequenceNumberLock;
private Object peerSequenceNumberLock;
public void setMySequenceNumber(int sequenceNumber) {
synchronized (mySequenceNumberLock) {
mySequenceNumber = sequenceNumber;
}
}
public int incMySequenceNumber() {
synchronized (mySequenceNumberLock) {
return mySequenceNumber++;
}
}
public void setPeerSequenceNumber(int sequenceNumber) {
synchronized (peerSequenceNumberLock) {
peerSequenceNumber = sequenceNumber;
}
}
public int incPeerSequenceNumber() {
synchronized (peerSequenceNumberLock) {
return peerSequenceNumber++;
}
}
public GssEncryptor getGssEncryptor() {
return gssEncryptor;
}
}
| 186 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
public abstract class GssTokenBase {
public static final int TOKEN_WRAP_V1 = 0x201;
public static final int TOKEN_MIC_V1 = 0x101;
public static final int TOKEN_WRAP_V2 = 0x504;
public static final int TOKEN_MIC_V2 = 0x404;
}
| 187 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/MicTokenV1.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.MessageProp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class MicTokenV1 extends GssTokenV1 {
public MicTokenV1(GssContext context,
byte[] inMsg,
int msgOffset,
int msgLength,
MessageProp messageProp) throws GSSException {
super(TOKEN_MIC_V1, context);
calcPrivacyInfo(messageProp, null, inMsg, msgOffset, msgLength, 0);
}
// This is called to construct MicToken from MicToken bytes
MicTokenV1(GssContext context,
MessageProp messageProp,
byte[] inToken,
int tokenOffset,
int tokenLength) throws GSSException {
super(TOKEN_MIC_V1, context, messageProp, inToken, tokenOffset, tokenLength);
}
public int getMic(byte[] outToken, int offset) throws GSSException, IOException {
byte[] data = getMic();
System.arraycopy(data, 0, outToken, offset, data.length);
return data.length;
}
/**
* Get bytes for this Mic token
* @return
*/
public byte[] getMic() throws GSSException {
ByteArrayOutputStream os = new ByteArrayOutputStream(64);
getMic(os);
return os.toByteArray();
}
public void getMic(OutputStream os) throws GSSException {
try {
encodeHeader(os);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, "Error in output MicTokenV1 bytes:" + e.getMessage());
}
}
public void verify(InputStream is) throws GSSException {
byte[] data;
try {
data = new byte[is.available()];
is.read(data);
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Read plain data for MicTokenV1 error:" + e.getMessage());
}
verify(data, 0, data.length);
}
public void verify(byte[] data, int offset, int len) throws GSSException {
verifyToken(null, data, offset, len, 0);
}
protected int getTokenSizeWithoutGssHeader() {
return getTokenHeaderSize();
}
}
| 188 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssInitCred.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.type.base.KrbToken;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSName;
import sun.security.jgss.GSSCaller;
import java.util.Set;
import javax.security.auth.kerberos.KerberosTicket;
public final class GssInitCred extends GssCredElement {
private KerberosTicket ticket;
private KrbToken krbToken;
private GssInitCred(GSSCaller caller, GssNameElement name,
KerberosTicket ticket, KrbToken krbToken, int lifeTime) {
super(caller, name);
this.ticket = ticket;
this.initLifeTime = lifeTime;
this.krbToken = krbToken;
}
public static GssInitCred getInstance(GSSCaller caller, GssNameElement name, int lifeTime) throws GSSException {
Set<KrbToken> krbTokens = CredUtils.getContextCredentials(KrbToken.class);
KrbToken krbToken = krbTokens != null && !krbTokens.isEmpty() ? krbTokens.iterator().next() : null;
if (name == null) {
KerberosTicket ticket = CredUtils.getKerberosTicketFromContext(caller, null, null);
GssNameElement clientName = GssNameElement.getInstance(ticket.getClient().getName(), GSSName.NT_USER_NAME);
return new GssInitCred(caller, clientName, ticket, krbToken, lifeTime);
}
KerberosTicket ticket = CredUtils.getKerberosTicketFromContext(caller, name.getPrincipalName().getName(), null);
return new GssInitCred(caller, name, ticket, krbToken, lifeTime);
}
public boolean isInitiatorCredential() throws GSSException {
return true;
}
public boolean isAcceptorCredential() throws GSSException {
return false;
}
public KerberosTicket getKerberosTicket() {
return ticket;
}
public KrbToken getKrbToken() {
return krbToken;
}
}
| 189 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssUtil.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.client.KrbClientBase;
import org.apache.kerby.kerberos.kerb.client.KrbTokenClient;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationData;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationDataEntry;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
import org.apache.kerby.kerberos.kerb.type.base.HostAddress;
import org.apache.kerby.kerberos.kerb.type.base.HostAddresses;
import org.apache.kerby.kerberos.kerb.type.base.KrbToken;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.kdc.EncAsRepPart;
import org.apache.kerby.kerberos.kerb.type.kdc.EncKdcRepPart;
import org.apache.kerby.kerberos.kerb.type.kdc.EncTgsRepPart;
import org.apache.kerby.kerberos.kerb.type.ticket.KrbTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.apache.kerby.kerberos.kerb.type.ticket.TicketFlags;
import org.ietf.jgss.GSSException;
import sun.security.jgss.GSSCaller;
import javax.crypto.SecretKey;
import javax.security.auth.kerberos.KerberosKey;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KerberosTicket;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Date;
import java.util.List;
/**
* Some utility functions to translate types between GSS and Kerby
*/
public class GssUtil {
private static final int KERBEROS_TICKET_NUM_FLAGS = 32; // KerberosTicket.NUM_LENGTH
/**
* Construct TgtTicket from info contained in KerberosTicket
* @param kerberosTicket
* @return
* @throws GSSException
*/
public static TgtTicket getTgtTicketFromKerberosTicket(KerberosTicket kerberosTicket) throws GSSException {
String clientName = kerberosTicket.getClient().getName();
PrincipalName clientPrincipal = new PrincipalName(clientName);
byte[] asn1Encoded = kerberosTicket.getEncoded();
Ticket ticket = getTicketFromAsn1Encoded(asn1Encoded);
EncAsRepPart encAsRepPart = new EncAsRepPart();
fillEncKdcRepPart(encAsRepPart, kerberosTicket);
TgtTicket tgt = new TgtTicket(ticket, encAsRepPart, clientPrincipal);
return tgt;
}
/**
* Init encKdcRepPart members with info from kerberosTicket
* @param encKdcRepPart
* @param kerberosTicket
*/
public static void fillEncKdcRepPart(EncKdcRepPart encKdcRepPart, KerberosTicket kerberosTicket) {
String clientName = kerberosTicket.getClient().getName();
PrincipalName clientPrincipal = new PrincipalName(clientName);
SecretKey secretKey = kerberosTicket.getSessionKey();
int keyType = kerberosTicket.getSessionKeyType();
EncryptionKey key = new EncryptionKey(keyType, secretKey.getEncoded());
encKdcRepPart.setKey(key);
encKdcRepPart.setSname(clientPrincipal);
Date authTimeDate = kerberosTicket.getAuthTime();
if (authTimeDate != null) {
encKdcRepPart.setAuthTime(new KerberosTime(authTimeDate.getTime()));
}
Date startTimeDate = kerberosTicket.getStartTime();
if (startTimeDate != null) {
encKdcRepPart.setStartTime(new KerberosTime(startTimeDate.getTime()));
}
KerberosTime endTime = new KerberosTime(kerberosTicket.getEndTime().getTime());
encKdcRepPart.setEndTime(endTime);
InetAddress[] clientAddresses = kerberosTicket.getClientAddresses();
HostAddresses hostAddresses = null;
if (clientAddresses != null) {
hostAddresses = new HostAddresses();
for (InetAddress iAddr : clientAddresses) {
hostAddresses.add(new HostAddress(iAddr));
}
}
encKdcRepPart.setCaddr(hostAddresses);
boolean[] tf = kerberosTicket.getFlags();
TicketFlags ticketFlags = getTicketFlags(tf);
encKdcRepPart.setFlags(ticketFlags);
/* encKdcRepPart.setKeyExpiration();
encKdcRepPart.setLastReq();
encKdcRepPart.setNonce(); */
Date renewTillDate = kerberosTicket.getRenewTill();
KerberosTime renewTill = renewTillDate == null ? null : new KerberosTime(renewTillDate.getTime());
encKdcRepPart.setRenewTill(renewTill);
String serverRealm = kerberosTicket.getServer().getRealm();
encKdcRepPart.setSrealm(serverRealm);
}
/**
* Generate TicketFlags instance from flags
* @param flags each item in flags identifies an bit setted or not
* @return
*/
public static TicketFlags getTicketFlags(boolean[] flags) {
if (flags == null || flags.length != KERBEROS_TICKET_NUM_FLAGS) {
return null;
}
int value = 0;
for (boolean flag : flags) {
value = (value << 1) + (flag ? 1 : 0);
}
return new TicketFlags(value);
}
/**
* Decode each flag in ticketFlags into an boolean array
* @param ticketFlags
* @return
*/
public static boolean[] ticketFlagsToBooleans(TicketFlags ticketFlags) {
boolean[] ret = new boolean[KERBEROS_TICKET_NUM_FLAGS];
int value = ticketFlags.getFlags();
for (int i = 0; i < KERBEROS_TICKET_NUM_FLAGS; i++) {
ret[KERBEROS_TICKET_NUM_FLAGS - i - 1] = (value & 0x1) != 0;
value = value >> 1;
}
return ret;
}
/**
* Construct a Ticket from bytes encoded by Asn1
* @param encoded
* @return
* @throws GSSException
*/
public static Ticket getTicketFromAsn1Encoded(byte[] encoded) throws GSSException {
Ticket ticket = new Ticket();
ByteBuffer byteBuffer = ByteBuffer.wrap(encoded);
try {
ticket.decode(byteBuffer);
return ticket;
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
}
/**
* Scan current context for SgtTicket
* @param client
* @param service
* @return
*/
public static SgtTicket getSgtCredentialFromContext(GSSCaller caller, String client, String service)
throws GSSException {
KerberosTicket ticket = CredUtils.getKerberosTicketFromContext(caller, client, service);
return getSgtTicketFromKerberosTicket(ticket);
}
/**
* Construct a SgtTicket from KerberosTicket
* @param kerberosTicket
* @return
* @throws GSSException
*/
public static SgtTicket getSgtTicketFromKerberosTicket(KerberosTicket kerberosTicket) throws GSSException {
if (kerberosTicket == null) {
return null;
}
Ticket ticket = getTicketFromAsn1Encoded(kerberosTicket.getEncoded());
EncTgsRepPart encTgsRepPart = new EncTgsRepPart();
fillEncKdcRepPart(encTgsRepPart, kerberosTicket);
SgtTicket sgt = new SgtTicket(ticket, encTgsRepPart);
return sgt;
}
/**
* Apply SgtTicket by sending TGS_REQ to KDC
* @param ticket
* @param krbToken
* @param service
* @return
*/
public static SgtTicket applySgtCredential(KerberosTicket ticket, KrbToken krbToken,
String service) throws GSSException {
TgtTicket tgt = getTgtTicketFromKerberosTicket(ticket);
if (krbToken == null) {
return applySgtCredential(tgt, service);
}
return applySgtCredential(tgt, krbToken, service);
}
public static SgtTicket applySgtCredential(TgtTicket tgt, String server) throws GSSException {
KrbClientBase client = getKrbClient();
try {
client.init();
return client.requestSgt(tgt, server);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
}
public static SgtTicket applySgtCredential(TgtTicket tgt, KrbToken krbToken, String server) throws GSSException {
KrbTokenClient client = getKrbTokenClient();
try {
client.init();
return client.requestSgt(krbToken, server, tgt);
} catch (KrbException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
}
public static KerberosTicket convertKrbTicketToKerberosTicket(KrbTicket krbTicket, String clientName)
throws GSSException {
byte[] asn1Encoding;
try {
asn1Encoding = krbTicket.getTicket().encode();
} catch (IOException e) {
throw new GSSException(GSSException.FAILURE, -1, e.getMessage());
}
byte[] sessionKey = krbTicket.getSessionKey().getKeyData();
int keyType = krbTicket.getSessionKey().getKeyType().getValue();
EncKdcRepPart encKdcRepPart = krbTicket.getEncKdcRepPart();
KerberosPrincipal client = new KerberosPrincipal(clientName);
PrincipalName serverPrinc = krbTicket.getTicket().getSname();
String serverName = serverPrinc.getName() + "@" + krbTicket.getTicket().getRealm();
KerberosPrincipal server = new KerberosPrincipal(serverName, serverPrinc.getNameType().getValue());
TicketFlags ticketFlags = encKdcRepPart.getFlags();
boolean[] flags = ticketFlagsToBooleans(ticketFlags);
Date authTime = new Date(encKdcRepPart.getAuthTime().getTime());
Date startTime = null;
if (encKdcRepPart.getStartTime() != null) {
startTime = new Date(encKdcRepPart.getStartTime().getTime());
}
Date endTime = new Date(encKdcRepPart.getEndTime().getTime());
Date renewTill = new Date(encKdcRepPart.getRenewTill().getTime());
InetAddress[] clientAddresses = null;
if (encKdcRepPart.getCaddr() != null) {
List<HostAddress> hostAddresses = encKdcRepPart.getCaddr().getElements();
if (hostAddresses != null) {
int i = 0;
clientAddresses = new InetAddress[hostAddresses.size()];
for (HostAddress hostAddr : hostAddresses) {
try {
InetAddress iAddr = InetAddress.getByAddress(hostAddr.getAddress());
clientAddresses[i++] = iAddr;
} catch (UnknownHostException e) {
throw new GSSException(GSSException.FAILURE, -1, "Bad client address");
}
}
}
}
KerberosTicket ticket = new KerberosTicket(
asn1Encoding,
client,
server,
sessionKey,
keyType,
flags,
authTime,
startTime,
endTime,
renewTill,
clientAddresses
);
return ticket;
}
public static KrbClientBase getKrbClient() {
try {
String systemProperty = getSystemProperty("java.security.krb5.conf");
if (systemProperty != null) {
File confSpecified = new File(systemProperty);
if (confSpecified.exists()) {
return new KrbClientBase(confSpecified);
}
}
// get configuration file from environment variable or default path
return new KrbClientBase();
} catch (KrbException e) {
return null;
}
}
public static KrbTokenClient getKrbTokenClient() {
try {
String systemProperty = getSystemProperty("java.security.krb5.conf");
if (systemProperty != null) {
File confSpecified = new File(systemProperty);
if (confSpecified.exists()) {
return new KrbTokenClient(confSpecified);
}
}
// get configuration file from environment variable or default path
return new KrbTokenClient();
} catch (KrbException e) {
return null;
}
}
public static EncryptionKey[] convertKerberosKeyToEncryptionKey(KerberosKey[] krbKeys) {
if (krbKeys == null) {
return null;
}
EncryptionKey[] keys = new EncryptionKey[krbKeys.length];
int i = 0;
for (KerberosKey krbKey : krbKeys) {
keys[i++] = new EncryptionKey(krbKey.getKeyType(), krbKey.getEncoded());
}
return keys;
}
/**
* Filter out an appropriate KerberosKey from krbKeys and generate a
* EncryptionKey accordingly
*
* @param krbKeys
* @param encType
* @param kvno
* @return
*/
public static EncryptionKey getEncryptionKey(KerberosKey[] krbKeys, int encType, int kvno) {
if (krbKeys == null) {
return null;
}
for (KerberosKey krbKey : krbKeys) {
if (krbKey.getKeyType() == encType && krbKey.getVersionNumber() == kvno && !krbKey.isDestroyed()) {
return new EncryptionKey(krbKey.getKeyType(), krbKey.getEncoded());
}
}
return null;
}
public static EncryptionKey getEncryptionKey(KerberosKey[] krbKeys, int encType) {
if (krbKeys == null) {
return null;
}
for (KerberosKey krbKey : krbKeys) {
if (krbKey.getKeyType() == encType && !krbKey.isDestroyed()) {
return new EncryptionKey(krbKey.getKeyType(), krbKey.getEncoded());
}
}
return null;
}
/**
* Get value of predefined system property
* @param name
* @return
*/
private static String getSystemProperty(String name) {
if (name == null) {
return null;
}
final String propertyName = name;
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<String>() {
public String run() {
return System.getProperty(propertyName);
}
});
} catch (PrivilegedActionException e) {
return null; // ignored
}
}
public static com.sun.security.jgss.AuthorizationDataEntry[]
kerbyAuthorizationDataToJgssAuthorizationDataEntries(AuthorizationData authData) {
if (authData == null) {
return null;
}
List<AuthorizationDataEntry> kerbyEntries = authData.getElements();
com.sun.security.jgss.AuthorizationDataEntry[] entries =
new com.sun.security.jgss.AuthorizationDataEntry[kerbyEntries.size()];
for (int i = 0; i < kerbyEntries.size(); i++) {
entries[i] = new com.sun.security.jgss.AuthorizationDataEntry(
kerbyEntries.get(i).getAuthzType().getValue(),
kerbyEntries.get(i).getAuthzData());
}
return entries;
}
}
| 190 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssNameElement.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.apache.kerby.kerberos.kerb.gss.GssMechFactory;
import org.apache.kerby.kerberos.kerb.gss.KerbyGssProvider;
import org.apache.kerby.kerberos.kerb.type.base.NameType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
import sun.security.jgss.spi.GSSNameSpi;
import java.nio.charset.StandardCharsets;
import java.security.Provider;
public class GssNameElement implements GSSNameSpi {
private PrincipalName principalName;
private Oid nameType = null;
GssNameElement(PrincipalName principalName,
Oid nameType) {
this.principalName = principalName;
this.nameType = nameType;
}
public PrincipalName toKerbyPrincipalName(sun.security.krb5.PrincipalName name) {
return new PrincipalName(name.getNameString(), toKerbyNameType(name.getNameType()));
}
private NameType toKerbyNameType(int intNameType) {
return NameType.fromValue(intNameType);
}
public static NameType toKerbyNameType(Oid nameType) throws GSSException {
NameType kerbyNameType;
if (nameType == null) {
throw new GSSException(GSSException.BAD_NAMETYPE);
}
if (nameType.equals(GSSName.NT_EXPORT_NAME) || nameType.equals(GSSName.NT_USER_NAME)) {
kerbyNameType = NameType.NT_PRINCIPAL;
} else if (nameType.equals(GSSName.NT_HOSTBASED_SERVICE)) {
kerbyNameType = NameType.NT_SRV_HST;
} else {
throw new GSSException(GSSException.BAD_NAMETYPE, 0, "Unsupported Oid name type");
}
return kerbyNameType;
}
public static GssNameElement getInstance(String name, Oid oidNameType)
throws GSSException {
if (oidNameType == null) {
PrincipalName principalName = new PrincipalName(name);
return new GssNameElement(principalName, null);
}
PrincipalName principalName = new PrincipalName(name, toKerbyNameType(oidNameType));
return new GssNameElement(principalName, oidNameType);
}
public Provider getProvider() {
return new KerbyGssProvider();
}
public boolean equals(GSSNameSpi name) throws GSSException {
if (name == null || name.isAnonymousName() || isAnonymousName()) {
return false;
}
return this.toString().equals(name.toString()) && this.getStringNameType().equals(name.getStringNameType());
}
public final PrincipalName getPrincipalName() {
return principalName;
}
public boolean equals(Object another) {
if (another == null) {
return false;
}
try {
if (another instanceof GSSNameSpi) {
return equals((GSSNameSpi) another);
}
} catch (GSSException e) {
return false;
}
return false;
}
public int hashCode() {
return principalName.hashCode();
}
public byte[] export() throws GSSException {
return principalName.getName().getBytes(StandardCharsets.UTF_8);
}
public Oid getMechanism() {
return GssMechFactory.getOid();
}
public String toString() {
return principalName.toString();
}
public Oid getStringNameType() {
return nameType;
}
public boolean isAnonymousName() {
return nameType.equals(GSSName.NT_ANONYMOUS);
}
}
| 191 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss | Create_ds/directory-kerby/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/CredUtils.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.gss.impl;
import org.ietf.jgss.GSSException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.security.jgss.GSSCaller;
import javax.security.auth.Subject;
import javax.security.auth.kerberos.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Set;
/**
* Utility functions to deal with credentials in Context
*/
public class CredUtils {
private static final Logger LOG = LoggerFactory.getLogger(CredUtils.class);
public static <T> Set<T> getContextPrivateCredentials(Class<T> credentialType, AccessControlContext acc) {
Subject subject = Subject.getSubject(acc);
Set<T> creds = subject.getPrivateCredentials(credentialType);
return creds;
}
public static <T> Set<T> getContextCredentials(final Class<T> credentialType) throws GSSException {
final AccessControlContext acc = AccessController.getContext();
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Set<T>>() {
public Set<T> run() throws Exception {
return CredUtils.getContextPrivateCredentials(credentialType, acc);
}
});
} catch (PrivilegedActionException e) {
throw new GSSException(GSSException.NO_CRED, -1, "Get credential from context failed");
}
}
public static Set<KerberosKey> getKerberosKeysFromContext(GSSCaller caller,
final String clientName,
final String serverName) throws GSSException {
return getContextCredentials(KerberosKey.class);
}
public static KerberosTicket getKerberosTicketFromContext(GSSCaller caller,
final String clientName,
final String serverName) throws GSSException {
Set<KerberosTicket> tickets = getContextCredentials(KerberosTicket.class);
for (KerberosTicket ticket : tickets) {
if (ticket.isCurrent() && (serverName == null || ticket.getServer().getName().equals(serverName))
&& (clientName == null || ticket.getClient().getName().equals(clientName))) {
return ticket;
}
}
return null;
}
public static KeyTab getKeyTabFromContext(KerberosPrincipal principal) throws GSSException {
Set<KeyTab> tabs = getContextCredentials(KeyTab.class);
for (KeyTab tab : tabs) {
// Use the supplied principal
KerberosPrincipal princ = principal;
if (princ == null) {
// fall back to the principal of the KeyTab (if JDK 1.8) if none is supplied
try {
Method m = tab.getClass().getDeclaredMethod("getPrincipal");
princ = (KerberosPrincipal) m.invoke(tab);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
LOG.info("Can't get a principal from the keytab", e);
}
}
if (princ != null) {
KerberosKey[] keys = tab.getKeys(princ);
if (keys != null && keys.length > 0) {
return tab;
}
}
}
return null;
}
public static void addCredentialToSubject(final KerberosTicket ticket) throws GSSException {
final AccessControlContext acc = AccessController.getContext();
final Subject subject = AccessController.doPrivileged(
new java.security.PrivilegedAction<Subject>() {
public Subject run() {
return Subject.getSubject(acc);
}
});
AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
subject.getPrivateCredentials().add(ticket);
return null;
}
});
}
public static void checkPrincipalPermission(String principalName, String action) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ServicePermission sp = new ServicePermission(principalName, action);
sm.checkPermission(sp);
}
}
}
| 192 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
import static org.assertj.core.api.Assertions.*;
public class KrbClientSettingTest {
@Test
public void testKdcServerMannualSetting() throws Exception {
URL confFileUrl = KrbConfigLoadForSpecialsTest.class.getResource(
"/krb5-specials.conf");
File confFile = new File(confFileUrl.toURI());
KrbConfig conf = new KrbConfig();
conf.addKrb5Config(confFile);
KrbClient krbClient = new KrbClient(conf);
KrbSetting krbSetting = krbClient.getSetting();
assertThat(krbSetting.getKdcRealm()).isEqualTo("KRB.COM");
assertThat(krbSetting.allowUdp()).isEqualTo(true);
assertThat(krbSetting.allowTcp()).isEqualTo(true);
assertThat(krbSetting.getKdcTcpPort()).isEqualTo(88);
assertThat(krbSetting.getKdcUdpPort()).isEqualTo(88);
krbClient.setKdcHost("localhost");
krbClient.setKdcRealm("TEST2.COM");
krbClient.setKdcTcpPort(12345);
assertThat(krbSetting.getKdcHost()).isEqualTo("localhost");
assertThat(krbSetting.getKdcTcpPort()).isEqualTo(12345);
assertThat(krbSetting.getKdcRealm()).isEqualTo("TEST2.COM");
}
} | 193 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for loading configurations form krb5.conf.
* krb5.conf is the configuration file in MIT Kerberos.
*/
public class KrbConfigLoadTest {
@Test
public void test() throws Exception {
URL confFileUrl = KrbConfigLoadTest.class.getResource("/krb5.conf");
File confFile = new File(confFileUrl.toURI());
KrbConfig krbConfig = new KrbConfig();
krbConfig.addKrb5Config(confFile);
assertThat(krbConfig.getDefaultRealm()).isEqualTo("KRB.COM");
assertThat(krbConfig.getKdcRealm()).isEqualTo("TEST.COM");
assertThat(krbConfig.getKdcHost()).isEqualTo("kdc-server.example.com");
assertThat(krbConfig.getDnsLookUpKdc()).isFalse();
assertThat(krbConfig.getDnsLookUpRealm()).isFalse();
assertThat(krbConfig.getAllowWeakCrypto()).isTrue();
assertThat(krbConfig.getTicketLifetime()).isEqualTo("86400");
assertThat(krbConfig.getRenewLifetime()).isEqualTo("604800");
assertThat(krbConfig.isForwardableAllowed()).isTrue();
assertThat(krbConfig.getEncryptionTypes()).hasSize(2)
.contains(EncryptionType.DES_CBC_CRC,
EncryptionType.AES128_CTS_HMAC_SHA1_96);
assertThat(krbConfig.getAllowableClockSkew()).isEqualTo(300);
assertThat(krbConfig.isProxiableAllowed()).isTrue();
assertThat(krbConfig.getDefaultTgsEnctypes()).hasSize(1)
.contains(EncryptionType.DES_CBC_CRC);
assertThat(krbConfig.getDefaultTktEnctypes()).hasSize(1)
.contains(EncryptionType.DES_CBC_CRC);
assertThat(krbConfig.getPkinitAnchors()).hasSize(1);
assertThat(krbConfig.getPkinitIdentities()).hasSize(2);
assertThat(krbConfig.getPkinitKdcHostName()).isEqualTo("kdc-server.example.com");
assertThat(krbConfig.getRealmSection("ATHENA.MIT.EDU")).hasSize(3);
assertThat(krbConfig.getRealmSectionItems("ATHENA.MIT.EDU", "admin_server")).hasSize(1);
assertThat(krbConfig.getCapath("ATHENA.MIT.EDU", "ANDREW.CMU.EDU")).hasSize(3);
}
@Test
public void testIncludeDir() throws Exception {
URL confFileUrl = KrbConfigLoadTest.class.getResource("/krb5include.conf");
File confFile = new File(confFileUrl.toURI());
KrbConfig krbConfig = new KrbConfig();
krbConfig.addKrb5Config(confFile);
}
}
| 194 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadForSpecialsTest.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
import static org.assertj.core.api.Assertions.*;
/**
* Test for loading configurations form krb5.conf with default kdc realm.
* krb5.conf is the configuration file in MIT Kerberos.
*/
public class KrbConfigLoadForSpecialsTest {
@Test
public void test() throws Exception {
URL confFileUrl = KrbConfigLoadForSpecialsTest.class.getResource(
"/krb5-specials.conf");
File confFile = new File(confFileUrl.toURI());
KrbConfig krbConfig = new KrbConfig();
krbConfig.addKrb5Config(confFile);
assertThat(krbConfig.getKdcRealm()).isEqualTo("KRB.COM");
assertThat(krbConfig.getKdcPort()).isEqualTo(88);
assertThat(krbConfig.allowUdp()).isEqualTo(true);
assertThat(krbConfig.allowTcp()).isEqualTo(true);
assertThat(krbConfig.getKdcTcpPort()).isEqualTo(88);
assertThat(krbConfig.getKdcUdpPort()).isEqualTo(88);
}
}
| 195 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptionGroup.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.apache.kerby.KOptionGroup;
/**
* This defines option groups to categorize the options defined in client side.
*/
public enum KrbOptionGroup implements KOptionGroup {
NONE,
KRB,
KDC_FLAGS,
PKINIT,
TOKEN;
@Override
public String getGroupName() {
return name().toLowerCase();
}
}
| 196 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.apache.kerby.KOption;
import org.apache.kerby.KOptionInfo;
import org.apache.kerby.KOptionType;
/**
* This defines all the options that come across the client side.
*/
public enum KrbOption implements KOption {
NONE(null),
KDC_REALM(new KOptionInfo("kdc-realm", "kdc realm",
KOptionType.STR)),
KDC_HOST(new KOptionInfo("kdc-host", "kdc host",
KOptionType.STR)),
KDC_TCP_PORT(new KOptionInfo("kdc-tcp-port", "kdc tcp port",
KOptionType.INT)),
ALLOW_UDP(new KOptionInfo("allow-udp", "allow udp",
KOptionType.BOOL)),
ALLOW_TCP(new KOptionInfo("allow-tcp", "allow tcp",
KOptionType.BOOL)),
KDC_UDP_PORT(new KOptionInfo("kdc-udp-port", "kdc udp port",
KOptionType.INT)),
CONN_TIMEOUT(new KOptionInfo("conn-timeout", "connection timeout",
KOptionType.INT)),
LIFE_TIME(new KOptionInfo("-l", "life time",
KOptionType.INT)),
START_TIME(new KOptionInfo("-s", "start time",
KOptionType.INT)),
RENEWABLE_TIME(new KOptionInfo("-r", "renewable lifetime",
KOptionType.INT)),
INCLUDE_ADDRESSES(new KOptionInfo("include_addresses",
"include addresses")),
AS_ENTERPRISE_PN(new KOptionInfo("as-enterprise-pn",
"client is enterprise principal name")),
CLIENT_PRINCIPAL(new KOptionInfo("client-principal", "Client principal",
KOptionType.STR)),
USE_PASSWD(new KOptionInfo("using-password", "using password")),
USER_PASSWD(new KOptionInfo("user-passwd", "User plain password")),
USE_KEYTAB(new KOptionInfo("-k", "use keytab")),
USE_DFT_KEYTAB(new KOptionInfo("-i", "use default client keytab (with -k)")),
KEYTAB_FILE(new KOptionInfo("-t", "filename of keytab to use",
KOptionType.FILE)),
KRB5_CACHE(new KOptionInfo("krb5-cache", "K5 cache name",
KOptionType.FILE)),
SERVICE_PRINCIPAL(new KOptionInfo("service-principal", "service principal",
KOptionType.STR)),
SERVER_PRINCIPAL(new KOptionInfo("server-principal", "server principal",
KOptionType.STR)),
ARMOR_CACHE(new KOptionInfo("armor-cache", "armor credential cache",
KOptionType.STR)),
TGT(new KOptionInfo("tgt", "tgt ticket", KOptionType.OBJ)),
USE_TGT(new KOptionInfo("use-tgt", "use tgt to get service ticket",
KOptionType.OBJ)),
CONF_DIR(new KOptionInfo("-conf", "conf dir", KrbOptionGroup.KRB, KOptionType.DIR));
private final KOptionInfo optionInfo;
KrbOption(KOptionInfo optionInfo) {
this.optionInfo = optionInfo;
}
@Override
public KOptionInfo getOptionInfo() {
return optionInfo;
}
public static KrbOption fromOptionName(String optionName) {
if (optionName != null) {
for (KrbOption ko : values()) {
if (ko.optionInfo != null
&& ko.optionInfo.getName().equals(optionName)) {
return ko;
}
}
}
return NONE;
}
}
| 197 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/PkinitOption.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.apache.kerby.KOption;
import org.apache.kerby.KOptionInfo;
import org.apache.kerby.KOptionType;
/**
* This defines all the options that come across the client side.
*/
public enum PkinitOption implements KOption {
NONE(null),
USE_PKINIT(new KOptionInfo("use-pkinit", "using pkinit", KrbOptionGroup.PKINIT)),
X509_IDENTITY(new KOptionInfo("x509-identities", "X509 user private key and cert", KrbOptionGroup.PKINIT,
KOptionType.STR)),
X509_PRIVATE_KEY(new KOptionInfo("x509-privatekey", "X509 user private key", KrbOptionGroup.PKINIT,
KOptionType.STR)),
X509_CERTIFICATE(new KOptionInfo("x509-cert", "X509 user certificate", KrbOptionGroup.PKINIT, KOptionType.STR)),
X509_ANCHORS(new KOptionInfo("x509-anchors", "X509 anchors", KrbOptionGroup.PKINIT, KOptionType.STR)),
USING_RSA(new KOptionInfo("using-rsa-or-dh", "Using RSA or DH", KrbOptionGroup.PKINIT)),
USE_ANONYMOUS(new KOptionInfo("use-pkinit-anonymous", "X509 anonymous", KrbOptionGroup.PKINIT));
private final KOptionInfo optionInfo;
PkinitOption(KOptionInfo optionInfo) {
this.optionInfo = optionInfo;
}
@Override
public KOptionInfo getOptionInfo() {
return optionInfo;
}
public static PkinitOption fromOptionName(String optionName) {
if (optionName != null) {
for (PkinitOption ko : values()) {
if (ko.optionInfo != null
&& ko.optionInfo.getName().equals(optionName)) {
return ko;
}
}
}
return NONE;
}
}
| 198 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbTokenClient.java | /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.kerby.kerberos.kerb.client;
import org.apache.kerby.KOptions;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.base.KrbToken;
import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket;
import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket;
import java.io.File;
/**
* A krb token client API for applications to interact with KDC using token.
*/
public class KrbTokenClient extends KrbClientBase {
/**
* Default constructor.
* @throws KrbException e
*/
public KrbTokenClient() throws KrbException {
super();
}
/**
* Construct with prepared KrbConfig.
* @param krbConfig The krb config
*/
public KrbTokenClient(KrbConfig krbConfig) {
super(krbConfig);
}
/**
* Constructor with conf dir
* @param confDir The conf dir
* @throws KrbException e
*/
public KrbTokenClient(File confDir) throws KrbException {
super(confDir);
}
/**
* Constructor with prepared KrbClient.
* @param krbClient The krb client
*/
public KrbTokenClient(KrbClient krbClient) {
super(krbClient);
}
/**
* Request a TGT with user token credential and armor cache
* @param token The KrbToken
* @param armorCache The armor cache
* @return TGT
* @throws KrbException e
*/
public TgtTicket requestTgt(KrbToken token, String armorCache) throws KrbException {
if (!token.isIdToken()) {
throw new IllegalArgumentException("Identity token is expected");
}
KOptions requestOptions = new KOptions();
requestOptions.add(TokenOption.USER_ID_TOKEN, token);
requestOptions.add(KrbOption.ARMOR_CACHE, armorCache);
return requestTgt(requestOptions);
}
/**
* Request a TGT with user token credential and tgt
* @param token The KrbToken
* @param tgt The tgt ticket
* @return TGT
* @throws KrbException e
*/
public TgtTicket requestTgt(KrbToken token, TgtTicket tgt) throws KrbException {
if (!token.isIdToken()) {
throw new IllegalArgumentException("Identity token is expected");
}
KOptions requestOptions = new KOptions();
requestOptions.add(TokenOption.USER_ID_TOKEN, token);
requestOptions.add(KrbOption.TGT, tgt);
return requestTgt(requestOptions);
}
/**
* Request a service ticket using an Access Token.
* @param token The KrbToken
* @param serverPrincipal The server principal
* @param armorCache The armor cache
* @return service ticket
* @throws KrbException e
*/
public SgtTicket requestSgt(
KrbToken token, String serverPrincipal, String armorCache) throws KrbException {
if (!token.isAcToken()) {
throw new IllegalArgumentException("Access token is expected");
}
KOptions requestOptions = new KOptions();
requestOptions.add(TokenOption.USER_AC_TOKEN, token);
requestOptions.add(KrbOption.ARMOR_CACHE, armorCache);
requestOptions.add(KrbOption.SERVER_PRINCIPAL, serverPrincipal);
return requestSgt(requestOptions);
}
public SgtTicket requestSgt(KrbToken token, String serverPrincipal, TgtTicket tgt) throws KrbException {
if (!token.isAcToken()) {
throw new IllegalArgumentException("Access token is expected");
}
KOptions requestOptions = new KOptions();
requestOptions.add(TokenOption.USER_AC_TOKEN, token);
requestOptions.add(KrbOption.TGT, tgt);
requestOptions.add(KrbOption.SERVER_PRINCIPAL, serverPrincipal);
return requestSgt(requestOptions);
}
}
| 199 |
Subsets and Splits