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-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteAddPrincipalCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
/**
* Remote add principal command
*/
public class RemoteAddPrincipalCommand extends RemoteCommand {
public static final String USAGE = "Usage: add_principal [options] <principal-name>\n"
+ "\toptions are:\n"
+ "\t\t[-randkey|-nokey]\n"
+ "\t\t[-pw password]"
+ "\tExample:\n"
+ "\t\tadd_principal -pw mypassword alice\n";
public RemoteAddPrincipalCommand(AdminClient adminClient) {
super(adminClient);
}
@Override
public void execute(String input) throws KrbException {
String[] items = input.split("\\s+");
if (items.length < 2) {
System.err.println(USAGE);
return;
}
String adminRealm = adminClient.getAdminConfig().getAdminRealm();
String clientPrincipal = items[items.length - 1] + "@" + adminRealm;
if (!items[1].startsWith("-")) {
adminClient.requestAddPrincipal(clientPrincipal);
} else if (items[1].startsWith("-nokey")) {
adminClient.requestAddPrincipal(clientPrincipal);
} else if (items[1].startsWith("-pw")) {
String password = items[2];
adminClient.requestAddPrincipal(clientPrincipal, password);
} else {
System.err.println("add_principal command format error.");
System.err.println(USAGE);
}
}
}
| 0 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteListPrincsCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
import java.util.List;
public class RemoteListPrincsCommand extends RemoteCommand {
private static final String USAGE = "Usage: list_principals [expression]\n"
+ "\t'expression' is a shell-style glob expression that can contain the wild-card characters ?, *, and []."
+ "\tExample:\n"
+ "\t\tlist_principals [expression]\n";
public RemoteListPrincsCommand(AdminClient adminClient) {
super(adminClient);
}
@Override
public void execute(String input) throws KrbException {
String[] items = input.split("\\s+");
//String param = items[0];
if (items.length > 2) {
System.err.println(USAGE);
return;
}
List<String> principalLists = null;
if (items.length == 1) {
principalLists = adminClient.requestGetprincs();
} else {
//have expression
String exp = items[1];
principalLists = adminClient.requestGetprincsWithExp(exp);
}
if (principalLists.size() == 0 || principalLists.size() == 1 && principalLists.get(0).isEmpty()) {
return;
} else {
System.out.println("Principals are listed:");
for (String principal : principalLists) {
System.out.println(principal);
}
}
}
}
| 1 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteDeletePrincipalCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
import java.io.Console;
import java.util.Scanner;
/**
* Remote delete principal command
*/
public class RemoteDeletePrincipalCommand extends RemoteCommand {
public static final String USAGE = "Usage: delete_principal <principal-name>\n"
+ "\tExample:\n"
+ "\t\tdelete_principal alice\n";
public RemoteDeletePrincipalCommand(AdminClient adminClient) {
super(adminClient);
}
@Override
public void execute(String input) throws KrbException {
String[] items = input.split("\\s+");
if (items.length < 2) {
System.err.println(USAGE);
return;
}
String principal = items[items.length - 1] + "@"
+ adminClient.getAdminConfig().getAdminRealm();
String reply;
Console console = System.console();
String prompt = "Are you sure to delete the principal? (yes/no, YES/NO, y/n, Y/N) ";
if (console == null) {
System.out.println("Couldn't get Console instance, "
+ "maybe you're running this from within an IDE. "
+ "Use scanner to read password.");
Scanner scanner = new Scanner(System.in, "UTF-8");
reply = getReply(scanner, prompt);
} else {
reply = getReply(console, prompt);
}
if (reply.equals("yes") || reply.equals("YES") || reply.equals("y") || reply.equals("Y")) {
adminClient.requestDeletePrincipal(principal);
} else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) {
System.out.println("Principal \"" + principal + "\" not deleted.");
} else {
System.err.println("Unknown request, fail to delete the principal.");
System.err.println(USAGE);
}
}
private String getReply(Scanner scanner, String prompt) {
System.out.println(prompt);
return scanner.nextLine().trim();
}
private String getReply(Console console, String prompt) {
console.printf(prompt);
String line = console.readLine();
return line;
}
}
| 2 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
/**
* Abstract class of all remote kadmin commands
*/
public abstract class RemoteCommand {
AdminClient adminClient;
public RemoteCommand(AdminClient adminClient) {
this.adminClient = adminClient;
}
/**
* Execute the remote kadmin command
* @param input String includes commands
* @throws KrbException If there is an a problem executing the remote command
*/
public abstract void execute(String input) throws KrbException;
}
| 3 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteGetPrincipalCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
import org.apache.kerby.kerberos.kerb.request.KrbIdentity;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
public class RemoteGetPrincipalCommand extends RemoteCommand {
private static final String USAGE = "Usage: getprinc principalName\n"
+ "\tExample:\n"
+ "\t\tgetprinc hello@TEST.COM\n";
public RemoteGetPrincipalCommand(AdminClient adminClient) {
super(adminClient);
}
@Override
public void execute(String input) throws KrbException {
String[] items = input.split("\\s+");
if (items.length != 2) {
System.err.println(USAGE);
return;
}
String clientPrincipalName = items[items.length - 1];
KrbIdentity identity = null;
try {
identity = adminClient.requestGetPrincipal(clientPrincipalName);
} catch (KrbException e) {
System.err.println("Failed to get principal: " + clientPrincipalName + ". " + e.toString());
}
if (identity == null) {
return;
} else {
System.out.println("Principal is listed:");
System.out.println(
"Principal: " + identity.getPrincipalName() + "\n"
+ "Expiration date: " + identity.getExpireTime() + "\n"
+ "Created time: " + identity.getCreatedTime() + "\n"
+ "KDC flags: " + identity.getKdcFlags() + "\n"
+ "Key version: " + identity.getKeyVersion() + "\n"
+ "Number of keys: " + identity.getKeys().size()
);
for (EncryptionType keyType: identity.getKeys().keySet()) {
System.out.println("key: " + keyType);
}
}
}
} | 4 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemotePrintUsageCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
public class RemotePrintUsageCommand extends RemoteCommand {
private static final String LISTPRINCSUSAGE = "Usage: list_principals [expression]\n"
+ "\t'expression' is a shell-style glob expression that can contain "
+ "the wild-card characters ?, *, and [].\n"
+ "\tExample:\n"
+ "\t\tlist_principals [expression]\n";
public RemotePrintUsageCommand() {
super(null);
}
@Override
public void execute(String input) throws KrbException {
if (input.startsWith("listprincs")) {
System.out.println(LISTPRINCSUSAGE);
}
}
}
| 5 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote | Create_ds/directory-kerby/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteKeytabAddCommand.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.admin.kadmin.remote.command;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
import java.io.File;
import java.util.List;
public class RemoteKeytabAddCommand extends RemoteCommand {
private static final String USAGE = "Usage: ktadd [-k[eytab] keytab] "
+ "[principal | -glob princ-exp] [...]\n"
+ "\tExample:\n"
+ "\t\tktadd hello@TEST.COM -k /keytab/location\n";
private static final String DEFAULT_KEYTAB_FILE_LOCATION = "/etc/krb5.keytab";
public RemoteKeytabAddCommand(AdminClient adminClient) {
super(adminClient);
}
@Override
public void execute(String input) throws KrbException {
String[] items = input.split("\\s+");
if (items.length < 2) {
System.err.println(USAGE);
return;
}
String principal = null;
String keytabFileLocation = null;
boolean glob = false;
int index = 1;
while (index < items.length) {
String command = items[index];
if (command.equals("-k")) {
index++;
if (index >= items.length) {
System.err.println(USAGE);
return;
}
keytabFileLocation = items[index].trim();
} else if (command.equals("-glob")) {
glob = true;
} else if (!command.startsWith("-")) {
principal = command;
}
index++;
}
if (keytabFileLocation == null) {
keytabFileLocation = DEFAULT_KEYTAB_FILE_LOCATION;
}
File keytabFile = new File(keytabFileLocation);
if (principal == null) {
System.out.println((glob ? "princ-exp" : "principal") + " not specified!");
System.err.println(USAGE);
return;
}
try {
if (glob) {
List<String> principals = adminClient.requestGetprincsWithExp(principal);
adminClient.requestExportKeytab(keytabFile, principals);
} else {
adminClient.requestExportKeytab(keytabFile, principal);
}
System.out.println("Export Keytab to " + keytabFileLocation);
} catch (KrbException e) {
System.err.println("Principal \"" + principal + "\" fail to add entry to keytab. "
+ e.toString());
}
}
}
| 6 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsReqCodecTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
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.KrbMessageType;
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.kdc.AsReq;
import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.SimpleTimeZone;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test AsReq message using a real 'correct' network packet captured from MS-AD
* to detective programming errors and compatibility issues particularly
* regarding Kerberos crypto.
*/
public class AsReqCodecTest {
@Test
public void test() throws IOException, ParseException {
byte[] bytes = CodecTestUtil.readBinaryFile("/asreq.token");
Asn1.decodeAndDump(bytes);
ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
AsReq asReq = new AsReq();
asReq.decode(asReqToken);
Asn1.dump(asReq);
assertThat(asReq.getPvno()).isEqualTo(5);
assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
PaData paData = asReq.getPaData();
PaDataEntry encTimestampEntry = paData.findEntry(PaDataType.ENC_TIMESTAMP);
assertThat(encTimestampEntry.getPaDataType()).isEqualTo(PaDataType.ENC_TIMESTAMP);
assertThat(encTimestampEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 33, 96));
PaDataEntry pacRequestEntry = paData.findEntry(PaDataType.PAC_REQUEST);
assertThat(pacRequestEntry.getPaDataType()).isEqualTo(PaDataType.PAC_REQUEST);
assertThat(pacRequestEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 108, 115));
KdcReqBody body = asReq.getReqBody();
assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 126, 130));
PrincipalName cName = body.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
assertThat(cName.getName()).isEqualTo("des");
assertThat(body.getRealm()).isEqualTo("DENYDC");
PrincipalName sName = body.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("krbtgt", "DENYDC");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
Date date = sdf.parse("20370913024805");
assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
assertThat(body.getRtime().getTime()).isEqualTo(date.getTime());
assertThat(body.getNonce()).isEqualTo(197451134);
List<EncryptionType> types = body.getEtypes();
assertThat(types).hasSize(7);
assertThat(types.get(0).getValue()).isEqualTo(0x0017);
//assertThat(types.get(1).getValue()).isEqualTo(0xff7b);//FIXME
//assertThat(types.get(2).getValue()).isEqualTo(0x0080);//FIXME
assertThat(types.get(3).getValue()).isEqualTo(0x0003);
assertThat(types.get(4).getValue()).isEqualTo(0x0001);
assertThat(types.get(5).getValue()).isEqualTo(0x0018);
//assertThat(types.get(6).getValue()).isEqualTo(0xff79);//FIXME
List<HostAddress> hostAddress = body.getAddresses().getElements();
assertThat(hostAddress).hasSize(1);
assertThat(hostAddress.get(0).getAddrType()).isEqualTo(HostAddrType.ADDRTYPE_NETBIOS);
}
}
| 7 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/CodecTest.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.codec;
import org.apache.kerby.kerberos.kerb.KrbCodec;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.base.CheckSum;
import org.apache.kerby.kerberos.kerb.type.base.CheckSumType;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
public class CodecTest {
@Test
public void testCodec() throws KrbException, IOException {
CheckSum mcs = new CheckSum();
mcs.setCksumtype(CheckSumType.CRC32);
mcs.setChecksum(new byte[] {0x10});
byte[] bytes = KrbCodec.encode(mcs);
assertThat(bytes).isNotNull();
CheckSum restored = KrbCodec.decode(bytes, CheckSum.class);
assertThat(restored).isNotNull();
assertThat(restored.getCksumtype()).isEqualTo(mcs.getCksumtype());
assertThat(mcs.getChecksum()).isEqualTo(restored.getChecksum());
assertThat(restored.tag()).isEqualTo(mcs.tag());
}
}
| 8 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsRepCodecTest.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.codec;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.TgsRep;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test TgsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
* and compatibility issues particularly regarding Kerberos crypto.
*/
public class TgsRepCodecTest {
@Test
public void test() throws IOException {
byte[] bytes = CodecTestUtil.readBinaryFile("/tgsrep.token");
TgsRep tgsRep = new TgsRep();
tgsRep.decode(bytes);
assertThat(tgsRep.getPvno()).isEqualTo(5);
assertThat(tgsRep.getMsgType()).isEqualTo(KrbMessageType.TGS_REP);
assertThat(tgsRep.getCrealm()).isEqualTo("DENYDC.COM");
PrincipalName cName = tgsRep.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
assertThat(cName.getNameStrings()).hasSize(1).contains("des");
Ticket ticket = tgsRep.getTicket();
assertThat(ticket.getTktvno()).isEqualTo(5);
assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
PrincipalName sName = ticket.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("host", "xp1.denydc.com");
//FIXME
//EncTicketPart encTicketPart = ticket.getEncPart();
//assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(23);
//assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
//EncKdcRepPart encKdcRepPart = tgsRep.getEncPart();
//assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(3);
}
}
| 9 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/ADTest.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.codec;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.kerby.asn1.type.Asn1Utf8String;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.ad.ADAuthenticationIndicator;
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.AuthorizationDataWrapper;
import org.apache.kerby.kerberos.kerb.type.ad.AuthorizationDataWrapper.WrapperType;
import org.junit.jupiter.api.Test;
/**
* Test class for Authorization data codec.
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADTest {
private static final String FOO = "Foo";
private static final String BAR = "Bar";
/**
* Test the Authorization Data codec.
*
* @throws KrbException Exception
* @throws IOException Exception
*/
@Test
public void testADCodec() throws KrbException, IOException {
int i = -1;
// Construct an AD_AUTHENTICATION_INDICATOR entry
ADAuthenticationIndicator indicators = new ADAuthenticationIndicator();
indicators.add(new Asn1Utf8String(FOO));
indicators.add(new Asn1Utf8String(BAR));
// Encode
System.out.println("\nIndicators prior to encoding:");
for (Asn1Utf8String ind : indicators.getAuthIndicators()) {
System.out.println(ind.toString());
}
byte[] enIndicators = indicators.encode();
// Decode get this out of asn1 tests
indicators.decode(enIndicators);
System.out.println("\nIndicators after decoding:");
for (Asn1Utf8String ind : indicators.getAuthIndicators()) {
System.out.println(ind.toString());
}
// Create an AD_IF_RELEVENT container
AuthorizationData adirData = new AuthorizationData();
adirData.add(indicators);
AuthorizationDataWrapper adirWrap = new AuthorizationDataWrapper(WrapperType.AD_IF_RELEVANT, adirData);
// Encode
System.out.println("\nADE (IR) Wrapper prior to encoding:");
for (AuthorizationDataEntry ade : adirWrap.getAuthorizationData().getElements()) {
ADAuthenticationIndicator ad = (ADAuthenticationIndicator) ade;
for (Asn1Utf8String ind : ad.getAuthIndicators()) {
System.out.println(ind.toString());
}
}
byte[] enAdir = adirWrap.encode();
// Decode
adirWrap.decode(enAdir);
System.out.println("\nADE (IR) Wrapper after decoding:");
for (AuthorizationDataEntry ade : adirWrap.getAuthorizationData().getElements()) {
ADAuthenticationIndicator ad = (ADAuthenticationIndicator) ade;
i = 0;
for (Asn1Utf8String ind : ad.getAuthIndicators()) {
System.out.println(ind.toString());
if (i == 0) {
assertEquals(ind.getValue(), FOO);
} else {
assertEquals(ind.getValue(), BAR);
}
i++;
}
}
// Create an AD_MANDATORY_FOR_KDC container
AuthorizationData admfkData = new AuthorizationData();
admfkData.add(indicators);
AuthorizationDataWrapper admfkWrap = new AuthorizationDataWrapper(WrapperType.AD_MANDATORY_FOR_KDC, admfkData);
// Encode
System.out.println("\nADE (MFK) Wrapper prior to encoding:");
for (AuthorizationDataEntry ade : admfkWrap.getAuthorizationData().getElements()) {
ADAuthenticationIndicator ad = (ADAuthenticationIndicator) ade;
for (Asn1Utf8String ind : ad.getAuthIndicators()) {
System.out.println(ind.toString());
}
}
byte[] enAdmfk = admfkWrap.encode();
// Decode
admfkWrap.decode(enAdmfk);
System.out.println("\nADE (MFK) Wrapper after decoding:");
for (AuthorizationDataEntry ade : admfkWrap.getAuthorizationData().getElements()) {
ADAuthenticationIndicator ad = (ADAuthenticationIndicator) ade;
for (Asn1Utf8String ind : ad.getAuthIndicators()) {
System.out.println(ind.toString());
}
i = 0;
for (Asn1Utf8String ind : ad.getAuthIndicators()) {
System.out.println(ind.toString());
if (i == 0) {
assertEquals(ind.getValue(), FOO);
} else {
assertEquals(ind.getValue(), BAR);
}
i++;
}
}
}
}
| 10 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsReqCodecTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.cms.type.ContentInfo;
import org.apache.kerby.cms.type.SignedData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.AsReq;
import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
public class PkinitRsaAsReqCodecTest {
@Test
public void test() throws IOException, ParseException {
byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asreq.token");
Asn1.parseAndDump(bytes);
ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
AsReq asReq = new AsReq();
asReq.decode(asReqToken);
//Asn1.decodeAndDump(asReq);
assertThat(asReq.getPvno()).isEqualTo(5);
assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
PaData paData = asReq.getPaData();
PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 2138));
PaPkAsReq paPkAsReq = new PaPkAsReq();
paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
ContentInfo contentInfo = new ContentInfo();
//Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
contentInfo.decode(paPkAsReq.getSignedAuthPack());
assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
//Asn1.dump(contentInfo);
SignedData signedData = contentInfo.getContentAs(SignedData.class);
assertThat(signedData.getCertificates().getElements().size()).isEqualTo(1);
assertThat(signedData.getEncapContentInfo().getContentType()).isEqualTo("1.3.6.1.5.2.3.1");
PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 2148, 2148));
KdcReqBody body = asReq.getReqBody();
assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 2161, 2165));
PrincipalName cName = body.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
PrincipalName sName = body.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("krbtgt", "EXAMPLE.COM");
assertThat(body.getNonce()).isEqualTo(658979657);
List<EncryptionType> types = body.getEtypes();
assertThat(types).hasSize(6);
assertThat(types.get(0).getValue()).isEqualTo(0x0012);
assertThat(types.get(1).getValue()).isEqualTo(0x0011);
assertThat(types.get(2).getValue()).isEqualTo(0x0010);
assertThat(types.get(3).getValue()).isEqualTo(0x0017);
assertThat(types.get(4).getValue()).isEqualTo(0x0019);
assertThat(types.get(5).getValue()).isEqualTo(0x001A);
// Test encode PaPkAsReq
byte[] encodedPaPkAsReq = paPkAsReq.encode();
PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
decodedPaPkAsReq.decode(encodedPaPkAsReq);
}
}
| 11 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsRepCodecTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.cms.type.EncapsulatedContentInfo;
import org.apache.kerby.cms.type.SignedContentInfo;
import org.apache.kerby.cms.type.SignedData;
import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.AsRep;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.KdcDhKeyInfo;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.assertj.core.api.Assertions.assertThat;
public class PkinitAnonymousAsRepCodecTest {
@Test
public void test() throws IOException {
byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asrep.token");
ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
AsRep asRep = new AsRep();
asRep.decode(asRepToken);
assertThat(asRep.getPvno()).isEqualTo(5);
assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
PaData paData = asRep.getPaData();
PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
PaPkAsRep paPkAsRep = new PaPkAsRep();
byte[] padataValue = pkAsRepEntry.getPaDataValue();
//Asn1.parseAndDump(padataValue);
paPkAsRep.decode(padataValue);
testPaPkAsRep(paPkAsRep);
PaDataEntry etypeInfo2Entry = paData.findEntry(PaDataType.ETYPE_INFO2);
assertThat(etypeInfo2Entry.getPaDataType()).isEqualTo(PaDataType.ETYPE_INFO2);
PaDataEntry pkinitKxEntry = paData.findEntry(PaDataType.PKINIT_KX);
assertThat(pkinitKxEntry.getPaDataType()).isEqualTo(PaDataType.PKINIT_KX);
assertThat(asRep.getPvno()).isEqualTo(5);
assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
assertThat(asRep.getCrealm()).isEqualTo("WELLKNOWN:ANONYMOUS");
PrincipalName cName = asRep.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
assertThat(cName.getNameStrings()).hasSize(2).contains("WELLKNOWN", "ANONYMOUS");
Ticket ticket = asRep.getTicket();
assertThat(ticket.getTktvno()).isEqualTo(5);
assertThat(ticket.getRealm()).isEqualTo("EXAMPLE.COM");
PrincipalName sName = ticket.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("krbtgt", "EXAMPLE.COM");
EncryptedData encryptedData = ticket.getEncryptedEncPart();
assertThat(encryptedData.getKvno()).isEqualTo(1);
assertThat(encryptedData.getEType().getValue()).isEqualTo(0x0012);
// Test encode PaPkAsRep
byte[] encodedPaPkAsRep = paPkAsRep.encode();
Asn1.parseAndDump(encodedPaPkAsRep);
PaPkAsRep decodedPaPkAsRep = new PaPkAsRep();
decodedPaPkAsRep.decode(encodedPaPkAsRep);
testPaPkAsRep(decodedPaPkAsRep);
}
private void testPaPkAsRep(PaPkAsRep paPkAsRep) throws IOException {
assertThat(paPkAsRep.getDHRepInfo()).isNotNull();
DhRepInfo dhRepInfo = paPkAsRep.getDHRepInfo();
byte[] dhSignedData = dhRepInfo.getDHSignedData();
SignedContentInfo contentInfo = new SignedContentInfo();
contentInfo.decode(dhSignedData);
assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
SignedData signedData = contentInfo.getContentAs(SignedData.class);
assertThat(signedData.getCertificates()).isNotNull();
EncapsulatedContentInfo encapsulatedContentInfo = signedData.getEncapContentInfo();
assertThat(encapsulatedContentInfo.getContentType()).isEqualTo("1.3.6.1.5.2.3.2");
byte[] eContentInfo = encapsulatedContentInfo.getContent();
KdcDhKeyInfo kdcDhKeyInfo = new KdcDhKeyInfo();
kdcDhKeyInfo.decode(eContentInfo);
assertThat(kdcDhKeyInfo.getSubjectPublicKey()).isNotNull();
assertThat(kdcDhKeyInfo.getDHKeyExpiration()).isNull();
assertThat(kdcDhKeyInfo.getNonce()).isNotNull();
}
}
| 12 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsReqCodecTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.cms.type.DigestAlgorithmIdentifiers;
import org.apache.kerby.cms.type.SignedContentInfo;
import org.apache.kerby.cms.type.SignedData;
import org.apache.kerby.cms.type.SignerInfos;
import org.apache.kerby.kerberos.kerb.KrbConstant;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.AsReq;
import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.AuthPack;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
import org.apache.kerby.x509.type.DhParameter;
import org.apache.kerby.x509.type.SubjectPublicKeyInfo;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class PkinitAnonymousAsReqCodecTest {
@Test
public void test() throws IOException, ParseException {
byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asreq.token");
//Asn1.dump(bytes, true);
ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
AsReq asReq = new AsReq();
asReq.decode(asReqToken);
//Asn1.dump(asReq, false);
assertThat(asReq.getPvno()).isEqualTo(5);
assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
PaData paData = asReq.getPaData();
PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 1366));
PaPkAsReq paPkAsReq = new PaPkAsReq();
paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
testPaPkAsReq(paPkAsReq);
PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 1376, 1376));
KdcReqBody body = asReq.getReqBody();
assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 1389, 1393));
PrincipalName cName = body.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
assertThat(cName.getName()).isEqualTo(KrbConstant.ANONYMOUS_PRINCIPAL);
assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
PrincipalName sName = body.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("krbtgt", "EXAMPLE.COM");
assertThat(body.getNonce()).isEqualTo(1797404543);
List<EncryptionType> types = body.getEtypes();
assertThat(types).hasSize(6);
assertThat(types.get(0).getValue()).isEqualTo(0x0012);
assertThat(types.get(1).getValue()).isEqualTo(0x0011);
assertThat(types.get(2).getValue()).isEqualTo(0x0010);
assertThat(types.get(3).getValue()).isEqualTo(0x0017);
assertThat(types.get(4).getValue()).isEqualTo(0x0019);
assertThat(types.get(5).getValue()).isEqualTo(0x001A);
// Test encode PaPkAsReq
byte[] encodedPaPkAsReq = paPkAsReq.encode();
PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
decodedPaPkAsReq.decode(encodedPaPkAsReq);
testPaPkAsReq(decodedPaPkAsReq);
}
private void testPaPkAsReq(PaPkAsReq paPkAsReq) throws IOException {
SignedContentInfo contentInfo = new SignedContentInfo();
Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
contentInfo.decode(paPkAsReq.getSignedAuthPack());
assertThat(contentInfo.getContentType()) .isEqualTo("1.2.840.113549.1.7.2");
Asn1.dump(contentInfo);
SignedData signedData = contentInfo.getSignedData();
assertThat(signedData.getVersion()).isEqualTo(3);
DigestAlgorithmIdentifiers dais = signedData.getDigestAlgorithms();
assertThat(dais).isNotNull();
if (dais != null) {
assertThat(dais.getElements()).isEmpty();
}
assertThat(signedData.getCertificates()).isNull();
assertThat(signedData.getCrls()).isNull();
SignerInfos signerInfos = signedData.getSignerInfos();
assertThat(signerInfos).isNotNull();
if (signerInfos != null) {
assertThat(signerInfos.getElements()).isEmpty();
}
assertThat(signedData.getEncapContentInfo().getContentType())
.isEqualTo("1.3.6.1.5.2.3.1");
AuthPack authPack = new AuthPack();
Asn1.parseAndDump(signedData.getEncapContentInfo().getContent());
authPack.decode(signedData.getEncapContentInfo().getContent());
assertThat(authPack.getsupportedCmsTypes().getElements().size()).isEqualTo(1);
assertThat(authPack.getsupportedCmsTypes().getElements().get(0).getAlgorithm())
.isEqualTo("1.2.840.113549.3.7");
SubjectPublicKeyInfo subjectPublicKeyInfo = authPack.getClientPublicValue();
assertThat(subjectPublicKeyInfo.getAlgorithm().getAlgorithm())
.isEqualTo("1.2.840.10046.2.1");
DhParameter dhParameter =
subjectPublicKeyInfo.getAlgorithm().getParametersAs(DhParameter.class);
assertThat(dhParameter.getG()).isEqualTo(BigInteger.valueOf(2));
assertThat(authPack.getsupportedKDFs().getElements().size()).isEqualTo(3);
assertThat(authPack.getsupportedKDFs().getElements().get(0).getKdfId())
.isEqualTo("1.3.6.1.5.2.3.6.2");
assertThat(authPack.getsupportedKDFs().getElements().get(1).getKdfId())
.isEqualTo("1.3.6.1.5.2.3.6.1");
assertThat(authPack.getsupportedKDFs().getElements().get(2).getKdfId())
.isEqualTo("1.3.6.1.5.2.3.6.3");
}
}
| 13 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsRepCodecTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.cms.type.ContentInfo;
import org.apache.kerby.cms.type.EnvelopedData;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.assertj.core.api.Assertions.*;
public class PkinitRsaAsRepCodecTest {
@Test
public void test() throws IOException {
byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asrep.token");
ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
AsRep asRep = new AsRep();
asRep.decode(asRepToken);
assertThat(asRep.getPvno()).isEqualTo(5);
assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
PaData paData = asRep.getPaData();
PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
PaPkAsRep paPkAsRep = new PaPkAsRep();
byte[] padataValue = pkAsRepEntry.getPaDataValue();
paPkAsRep.decode(padataValue);
assertThat(paPkAsRep.getEncKeyPack()).isNotNull();
byte[] encKeyPack = paPkAsRep.getEncKeyPack();
Asn1.parseAndDump(encKeyPack);
ContentInfo contentInfo = new ContentInfo();
contentInfo.decode(encKeyPack);
assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.3");
EnvelopedData envelopedData = contentInfo.getContentAs(EnvelopedData.class);
Asn1.dump(envelopedData);
}
}
| 14 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/KerberosTimeTest.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.codec;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.kerby.kerberos.kerb.type.KerberosTime;
import org.junit.jupiter.api.Test;
/**
* Testing the KerberosTime class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class KerberosTimeTest {
@Test
public void testLessThan() {
KerberosTime kerberosTime = new KerberosTime();
assertTrue(kerberosTime.lessThan(System.currentTimeMillis() + 100));
assertFalse(kerberosTime.lessThan(System.currentTimeMillis() - 10000));
}
@Test
public void testGreaterThan() {
KerberosTime kerberosTime = new KerberosTime();
assertTrue(kerberosTime.greaterThan(new KerberosTime(System.currentTimeMillis() - 10000)));
assertFalse(kerberosTime.greaterThan(new KerberosTime(System.currentTimeMillis() + 100)));
}
@Test
public void testExtend() {
KerberosTime kerberosTime = new KerberosTime();
KerberosTime extended = kerberosTime.extend(1000);
assertTrue(kerberosTime.lessThan(extended));
assertFalse(kerberosTime.greaterThan(extended));
assertEquals(-1000L, kerberosTime.diff(extended));
}
}
| 15 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsReqCodecTest.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.codec;
import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.KdcReqBody;
import org.apache.kerby.kerberos.kerb.type.kdc.TgsReq;
import org.apache.kerby.kerberos.kerb.type.pa.PaData;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.SimpleTimeZone;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test TgsReq message using a real 'correct' network packet captured from MS-AD to detective programming errors
* and compatibility issues particularly regarding Kerberos crypto.
*/
public class TgsReqCodecTest {
@Test
public void test() throws IOException, ParseException {
byte[] bytes = CodecTestUtil.readBinaryFile("/tgsreq.token");
TgsReq tgsReq = new TgsReq();
tgsReq.decode(bytes);
assertThat(tgsReq.getPvno()).isEqualTo(5);
assertThat(tgsReq.getMsgType()).isEqualTo(KrbMessageType.TGS_REQ);
PaData paData = tgsReq.getPaData();
assertThat(paData.getElements()).hasSize(1);
PaDataEntry entry = paData.getElements().iterator().next();
assertThat(entry.getPaDataType()).isEqualTo(PaDataType.TGS_REQ);
//request body
KdcReqBody body = tgsReq.getReqBody();
assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
byte[] kdcOptionsValue = {64, (byte) 128, 0, 0};
assertThat(body.getKdcOptions().getValue()).isEqualTo(kdcOptionsValue);
assertThat(body.getRealm()).isEqualTo("DENYDC.COM");
PrincipalName sName = body.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("host", "xp1.denydc.com");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
Date date = sdf.parse("20370913024805");
assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
assertThat(body.getNonce()).isEqualTo(197296424);
List<EncryptionType> eTypes = body.getEtypes();
assertThat(eTypes).hasSize(7);
assertThat(eTypes.get(0).getValue()).isEqualTo(0x0017);
//assertThat(eTypes.get(1).getValue()).isEqualTo(-133);//FIXME
//assertThat(eTypes.get(2).getValue()).isEqualTo(-128);//FIXME
assertThat(eTypes.get(3).getValue()).isEqualTo(0x0003);
assertThat(eTypes.get(4).getValue()).isEqualTo(0x0001);
assertThat(eTypes.get(5).getValue()).isEqualTo(0x0018);
//assertThat(eTypes.get(6).getValue()).isEqualTo(-135);//FIXME
}
}
| 16 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PaPkAsRepTest.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.codec;
import org.apache.kerby.asn1.Asn1;
import org.apache.kerby.cms.type.ContentInfo;
import org.apache.kerby.kerberos.kerb.KrbCodec;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
import org.junit.jupiter.api.Test;
import java.io.IOException;
public class PaPkAsRepTest {
@Test
public void test() throws IOException, KrbException {
PaPkAsRep paPkAsRep = new PaPkAsRep();
DhRepInfo dhRepInfo = new DhRepInfo();
ContentInfo contentInfo = new ContentInfo();
contentInfo.setContentType("1.2.840.113549.1.7.2");
dhRepInfo.setDHSignedData(contentInfo.encode());
paPkAsRep.setDHRepInfo(dhRepInfo);
Asn1.parseAndDump(paPkAsRep.encode());
KrbCodec.decode(paPkAsRep.encode(), PaPkAsRep.class);
}
}
| 17 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsRepCodecTest.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.codec;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
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.kdc.AsRep;
import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test AsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
* and compatibility issues particularly regarding Kerberos crypto.
*/
public class AsRepCodecTest {
@Test
public void test() throws IOException {
byte[] bytes = CodecTestUtil.readBinaryFile("/asrep.token");
ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
AsRep asRep = new AsRep();
asRep.decode(asRepToken);
assertThat(asRep.getPvno()).isEqualTo(5);
assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
assertThat(asRep.getCrealm()).isEqualTo("DENYDC.COM");
PrincipalName cName = asRep.getCname();
assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
assertThat(cName.getNameStrings()).hasSize(1).contains("u5");
Ticket ticket = asRep.getTicket();
assertThat(ticket.getTktvno()).isEqualTo(5);
assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
PrincipalName sName = ticket.getSname();
assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
assertThat(sName.getNameStrings()).hasSize(2)
.contains("krbtgt", "DENYDC.COM");
//FIXME
//EncTicketPart encTicketPart = ticket.getEncPart();
//assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
//assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
//EncKdcRepPart encKdcRepPart = asRep.getEncPart();
//assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
//assertThat(encKdcRepPart.getKey().getKvno()).isEqualTo(7);
}
}
| 18 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/CodecTestUtil.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.codec;
import org.apache.kerby.asn1.util.HexUtil;
import org.apache.kerby.asn1.util.IOUtil;
import java.io.IOException;
import java.io.InputStream;
public class CodecTestUtil {
static byte[] readBinaryFile(String path) throws IOException {
try (InputStream is = CodecTestUtil.class.getResourceAsStream(path)) {
byte[] bytes = new byte[is.available()];
is.read(bytes);
return bytes;
}
}
static byte[] readDataFile(String resource) throws IOException {
try (InputStream is = CodecTestUtil.class.getResourceAsStream(resource)) {
String hexStr = IOUtil.readInput(is);
return HexUtil.hex2bytes(hexStr);
}
}
}
| 19 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbException.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;
public class KrbException extends Exception {
private static final long serialVersionUID = 7305497872367599428L;
private KrbErrorCode errorCode;
public KrbException(String message) {
super(message);
}
public KrbException(String message, Throwable cause) {
super(message, cause);
}
public KrbException(KrbErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}
public KrbException(KrbErrorCode errorCode, Throwable cause) {
super(errorCode.getMessage(), cause);
this.errorCode = errorCode;
}
public KrbException(KrbErrorCode errorCode, String message) {
super(message + " with error code: " + errorCode.name());
this.errorCode = errorCode;
}
public KrbErrorCode getKrbErrorCode() {
return errorCode;
}
}
| 20 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbErrorCode.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.asn1.EnumType;
public enum KrbErrorCode implements EnumType {
KDC_ERR_NONE(0, "No error"),
KDC_ERR_NAME_EXP(1, "Client's entry in database has expired"),
KDC_ERR_SERVICE_EXP(2, "Server's entry in database has expired"),
KDC_ERR_BAD_PVNO(3, "Requested protocol version number not supported"),
KDC_ERR_C_OLD_MAST_KVNO(4, "Client's key encrypted in old master key"),
KDC_ERR_S_OLD_MAST_KVNO(5, "Server's key encrypted in old master key"),
KDC_ERR_C_PRINCIPAL_UNKNOWN(6, "Client not found in Kerberos database"),
KDC_ERR_S_PRINCIPAL_UNKNOWN(7, "Server not found in Kerberos database"),
KDC_ERR_PRINCIPAL_NOT_UNIQUE(8, "Multiple principal entries in database"),
KDC_ERR_NULL_KEY(9, "The client or server has a null key"),
KDC_ERR_CANNOT_POSTDATE(10, "Ticket not eligible for postdating"),
KDC_ERR_NEVER_VALID(11, "Requested start time is later than end time"),
KDC_ERR_POLICY(12, "KDC policy rejects request"),
KDC_ERR_BADOPTION(13, "KDC cannot accommodate requested option"),
KDC_ERR_ETYPE_NOSUPP(14, "KDC has no support for encryption type"),
KDC_ERR_SUMTYPE_NOSUPP(15, "KDC has no support for checksum type"),
KDC_ERR_PADATA_TYPE_NOSUPP(16, "KDC has no support for padata type"),
KDC_ERR_TRTYPE_NOSUPP(17, "KDC has no support for transited type"),
KDC_ERR_CLIENT_REVOKED(18, "Clients credentials have been revoked"),
KDC_ERR_SERVICE_REVOKED(19, "Credentials for server have been revoked"),
KDC_ERR_TGT_REVOKED(20, "TGT has been revoked"),
KDC_ERR_CLIENT_NOTYET(21, "Client not yet valid; try again later"),
KDC_ERR_SERVICE_NOTYET(22, "Server not yet valid; try again later"),
KDC_ERR_KEY_EXPIRED(23, "Password has expired; change password to reset"),
KDC_ERR_PREAUTH_FAILED(24, "Pre-authentication information was invalid"),
KDC_ERR_PREAUTH_REQUIRED(25, "Additional pre-authentication required"),
KDC_ERR_SERVER_NOMATCH(26, "Requested server and ticket don't match"),
KDC_ERR_MUST_USE_USER2USER(27, "Server valid for user2user only"),
KDC_ERR_PATH_NOT_ACCEPTED(28, "KDC Policy rejects transited path"),
KDC_ERR_SVC_UNAVAILABLE(29, "A service is not available"),
KRB_AP_ERR_BAD_INTEGRITY(31, "Integrity check on decrypted field failed"),
KRB_AP_ERR_TKT_EXPIRED(32, "Ticket expired"),
KRB_AP_ERR_TKT_NYV(33, "Ticket not yet valid"),
KRB_AP_ERR_REPEAT(34, "Request is a replay"),
KRB_AP_ERR_NOT_US(35, "The ticket isn't for us"),
KRB_AP_ERR_BADMATCH(36, "Ticket and authenticator don't match"),
KRB_AP_ERR_SKEW(37, "Clock skew too great"),
KRB_AP_ERR_BADADDR(38, "Incorrect net address"),
KRB_AP_ERR_BADVERSION(39, "Protocol version mismatch"),
KRB_AP_ERR_MSG_TYPE(40, "Invalid msg type"),
KRB_AP_ERR_MODIFIED(41, "Message stream modified"),
KRB_AP_ERR_BADORDER(42, "Message out of order"),
KRB_AP_ERR_BADKEYVER(44, "Specified version of key is not available"),
KRB_AP_ERR_NOKEY(45, "Service key not available"),
KRB_AP_ERR_MUT_FAIL(46, "Mutual authentication failed"),
KRB_AP_ERR_BADDIRECTION(47, "Incorrect message direction"),
KRB_AP_ERR_METHOD(48, "Alternative authentication method required"),
KRB_AP_ERR_BADSEQ(49, "Incorrect sequence number in message"),
KRB_AP_ERR_INAPP_CKSUM(50, "Inappropriate type of checksum in message"),
KRB_AP_PATH_NOT_ACCEPTED(51, "Policy rejects transited path"),
RESPONSE_TOO_BIG(52, "Response too big for UDP; retry with TCP"),
KRB_ERR_GENERIC(60, "Generic error (description in e-text)"),
FIELD_TOOLONG(61, "Field is too long for this implementation"),
KDC_ERR_CLIENT_NOT_TRUSTED(62, "Client is not trusted"),
KDC_NOT_TRUSTED(63, "KDC is not trusted"),
KDC_ERR_INVALID_SIG(64, "Signature is invalid"),
KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED(65, "Diffie-Hellman (DH) key parameters not accepted."),
CERTIFICATE_MISMATCH(66, "Certificates do not match"),
KRB_AP_ERR_NO_TGT(67, "No TGT available to validate USER-TO-USER"),
WRONG_REALM(68, "Wrong realm"),
KRB_AP_ERR_USER_TO_USER_REQUIRED(69, "Ticket must be for USER-TO-USER"),
KDC_ERR_CANT_VERIFY_CERTIFICATE(70, "Can't verify certificate"),
KDC_ERR_INVALID_CERTIFICATE(71, "Invalid certificate"),
KDC_ERR_REVOKED_CERTIFICATE(72, "Revoked certificate"),
KDC_ERR_REVOCATION_STATUS_UNKNOWN(73, "Revocation status unknown"),
REVOCATION_STATUS_UNAVAILABLE(74, "Revocation status unavailable"),
KDC_ERR_CLIENT_NAME_MISMATCH(75, "Client names do not match"),
KDC_NAME_MISMATCH(76, "KDC names do not match"),
KDC_ERR_INCONSISTENT_KEY_PURPOSE(77, "Inconsistent key purpose"),
KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED(78, "Digest in certificate not accepted"),
KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED(79, "PA checksum must be included"),
KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED(80, "Digest in signed data not accepted"),
KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED(81, "Public key encryption not supported"),
KRB_AP_ERR_PRINCIPAL_UNKNOWN(82, "A well-known Kerberos principal name is used but not supported"),
TOKEN_PREAUTH_NOT_ALLOWED(83, "Token preauth is not allowed"),
KRB_TIMEOUT(5000, "Network timeout"),
UNKNOWN_ERR(5001, "Unknown error");
private final int value;
private final String message;
KrbErrorCode(int value, String message) {
this.value = value;
this.message = message;
}
public static KrbErrorCode fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value.intValue()) {
return (KrbErrorCode) e;
}
}
}
return KRB_ERR_GENERIC;
}
public int getValue() {
return value;
}
@Override
public String getName() {
return name();
}
public String getMessage() {
return message;
}
}
| 21 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/TokenProviderRegistry.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.provider.TokenProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class TokenProviderRegistry {
static final Logger LOG = LoggerFactory.getLogger(TokenProviderRegistry.class);
private static Map<String, Class> allProvider = new ConcurrentHashMap<>();
static {
ServiceLoader<TokenProvider> providers = ServiceLoader.load(TokenProvider.class);
for (TokenProvider provider : providers) {
allProvider.put(provider.getTokenType(), provider.getClass());
}
}
public static Set<String> registeredProviders() {
return Collections.unmodifiableSet(allProvider.keySet());
}
public static boolean registeredProvider(String name) {
return allProvider.containsKey(name);
}
public static TokenProvider createProvider(String name) {
if (!registeredProvider(name)) {
LOG.error("Unregistered token provider " + name);
throw new RuntimeException("Unregistered token provider " + name);
}
try {
return (TokenProvider) allProvider.get(name).newInstance();
} catch (Exception e) {
LOG.error("Create {} token provider failed", name, e);
throw new RuntimeException("Create " + name + "token provider failed" + e);
}
}
}
| 22 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbRuntime.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.provider.TokenProvider;
/**
* This runtime allows hook external dependencies thru ServiceProvider interface.
* The hook behavior should be done at the very initial time during startup.
*
* TODO: to be enhanced to allow arbitrary provider to be hooked into.
*/
public class KrbRuntime {
private static TokenProvider tokenProvider;
/**
* Set up token provider, should be done at very initial time
* @return token provider
*/
public static synchronized TokenProvider getTokenProvider(String tokenType) {
if (tokenProvider == null || !tokenType.equals(tokenProvider.getTokenType())) {
tokenProvider = TokenProviderRegistry.createProvider(tokenType);
}
if (tokenProvider == null) {
throw new RuntimeException("No token provider is available");
}
return tokenProvider;
}
/**
* Set token provider.
* @param tokenProvider The token provider
*/
public static synchronized void setTokenProvider(TokenProvider tokenProvider) {
KrbRuntime.tokenProvider = tokenProvider;
}
}
| 23 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbErrorException.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.base.KrbError;
public class KrbErrorException extends KrbException {
private static final long serialVersionUID = -6726737724490205771L;
private KrbError krbError;
public KrbErrorException(KrbError krbError) {
super(krbError.getErrorCode().getMessage());
this.krbError = krbError;
}
public KrbError getKrbError() {
return krbError;
}
}
| 24 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.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.asn1.Asn1;
import org.apache.kerby.asn1.Tag;
import org.apache.kerby.asn1.parse.Asn1ParseResult;
import org.apache.kerby.asn1.type.Asn1Type;
import org.apache.kerby.kerberos.kerb.type.ap.ApReq;
import org.apache.kerby.kerberos.kerb.type.base.KrbError;
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.kdc.AsRep;
import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
import org.apache.kerby.kerberos.kerb.type.kdc.TgsRep;
import org.apache.kerby.kerberos.kerb.type.kdc.TgsReq;
import java.io.IOException;
import java.nio.ByteBuffer;
public class KrbCodec {
public static byte[] encode(Asn1Type krbObj) throws KrbException {
try {
return krbObj.encode();
} catch (IOException e) {
throw new KrbException("encode failed", e);
}
}
public static void encode(Asn1Type krbObj, ByteBuffer buffer) throws KrbException {
try {
krbObj.encode(buffer);
} catch (IOException e) {
throw new KrbException("Encoding failed", e);
}
}
public static void decode(byte[] content, Asn1Type value) throws KrbException {
decode(ByteBuffer.wrap(content), value);
}
public static void decode(ByteBuffer content, Asn1Type value) throws KrbException {
try {
value.decode(content);
} catch (IOException e) {
throw new KrbException("Decoding failed", e);
}
}
public static <T extends Asn1Type> T decode(
byte[] content, Class<T> krbType) throws KrbException {
return decode(ByteBuffer.wrap(content), krbType);
}
public static <T extends Asn1Type> T decode(
ByteBuffer content, Class<T> krbType) throws KrbException {
Asn1Type implObj;
try {
implObj = krbType.newInstance();
} catch (Exception e) {
throw new KrbException("Decoding failed", e);
}
try {
implObj.decode(content);
} catch (IOException e) {
throw new KrbException("Decoding failed", e);
}
return (T) implObj;
}
public static KrbMessage decodeMessage(ByteBuffer buffer) throws IOException {
Asn1ParseResult parsingResult = Asn1.parse(buffer);
Tag tag = parsingResult.tag();
KrbMessage msg;
KrbMessageType msgType = KrbMessageType.fromValue(tag.tagNo());
if (msgType == KrbMessageType.TGS_REQ) {
msg = new TgsReq();
} else if (msgType == KrbMessageType.AS_REP) {
msg = new AsRep();
} else if (msgType == KrbMessageType.AS_REQ) {
msg = new AsReq();
} else if (msgType == KrbMessageType.TGS_REP) {
msg = new TgsRep();
} else if (msgType == KrbMessageType.AP_REQ) {
msg = new ApReq();
} else if (msgType == KrbMessageType.AP_REP) {
msg = new ApReq();
} else if (msgType == KrbMessageType.KRB_ERROR) {
msg = new KrbError();
} else {
throw new IOException("To be supported krb message type with tag: " + tag);
}
msg.decode(parsingResult);
return msg;
}
}
| 25 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbConstant.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;
public class KrbConstant {
public static final int KRB_V5 = 5;
public static final String TGS_PRINCIPAL = "krbtgt";
public static final String ANONYMOUS_PRINCIPAL = "WELLKNOWN/ANONYMOUS";
}
| 26 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenFactory.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.provider;
import org.apache.kerby.kerberos.kerb.type.base.AuthToken;
/**
* A token factory.
*/
public interface TokenFactory {
AuthToken createToken();
}
| 27 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenDecoder.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.provider;
import org.apache.kerby.kerberos.kerb.type.base.AuthToken;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.PublicKey;
/**
* An AuthToken decoder.
*/
public interface TokenDecoder {
/**
* Decode a token from a bytes array.
* @param content The content
* @return token
* @throws IOException e
*/
AuthToken decodeFromBytes(byte[] content) throws IOException;
/**
* Decode a token from a string.
* @param content The content
* @return token
* @throws IOException e
*/
AuthToken decodeFromString(String content) throws IOException;
/**
* set the verify key
*
* @param key a public key
*/
void setVerifyKey(PublicKey key);
/**
* set the verify key
*
* @param key a byte[] key
*/
void setVerifyKey(byte[] key);
/**
* Set the decryption key
*
* @param key a private key
*/
void setDecryptionKey(PrivateKey key);
/**
* Set the decryption key
*
* @param key a secret key
*/
void setDecryptionKey(byte[] key);
/**
* The token signed or not
*
* @return signed or not signed
*/
boolean isSigned();
}
| 28 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.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.provider;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.type.base.AuthToken;
import java.security.PrivateKey;
import java.security.PublicKey;
/**
* An AuthToken encoder.
*/
public interface TokenEncoder {
/**
* Encode a token resulting in a bytes array.
* @param token The auth token
* @return bytes array
* @throws KrbException e
*/
byte[] encodeAsBytes(AuthToken token) throws KrbException;
/**
* Encode a token resulting in a string.
* @param token The auth token
* @return string representation
* @throws KrbException e
*/
String encodeAsString(AuthToken token) throws KrbException;
/**
* set the encryption key
*
* @param key a public key
*/
void setEncryptionKey(PublicKey key);
/**
* set the encryption key
*
* @param key a secret key
*/
void setEncryptionKey(byte[] key);
/**
* set the sign key
*
* @param key a private key
*/
void setSignKey(PrivateKey key);
/**
* set the sign key
*
* @param key a secret key
*/
void setSignKey(byte[] key);
}
| 29 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.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.provider;
/**
* Token provider for TokenPreauth mechanism. This is needed because JWT token
* encoding and decoding require various facilities that can be provided by 3rd
* libraries. We need them but would not allow them to invade into the core.
*/
public interface TokenProvider extends KrbProvider {
/**
* Get the token type
*
* @return login type
*/
String getTokenType();
/**
* Create a token encoder.
* @return token encoder
*/
TokenEncoder createTokenEncoder();
/**
* Create a token decoder.
* @return token decoder
*/
TokenDecoder createTokenDecoder();
/**
* Create a token factory that can be used to construct concrete token.
* @return token factory
*/
TokenFactory createTokenFactory();
}
| 30 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/KrbProvider.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.provider;
/**
* Krb provider for allowing to hook external dependencies.
*/
public interface KrbProvider {
// no op, just an interface mark.
}
| 31 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KerberosString.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;
import org.apache.kerby.asn1.type.Asn1GeneralString;
/**
* The Kerberos String, as defined in RFC 4120. It restricts the set of chars that
* can be used to [0x00..0x7F]
*
* <pre>
* KerberosString ::= GeneralString -- (IA5String)
* </pre>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class KerberosString extends Asn1GeneralString {
/**
* Creates a new KerberosString
*/
public KerberosString() {
super();
}
/**
* Creates a new KerberosString with an initial value
*
* @param value The String to store in the KerberosString
*/
public KerberosString(String value) {
super(value);
// Check that the value is valid
if (value != null) {
for (char c:value.toCharArray()) {
if ((c & 0xFF80) != 0x0000) {
throw new IllegalArgumentException("The value contains non ASCII chars " + value);
}
}
}
}
}
| 32 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KrbSequenceType.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;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.type.Asn1SequenceType;
public abstract class KrbSequenceType extends Asn1SequenceType {
public KrbSequenceType(Asn1FieldInfo[] fieldInfos) {
super(fieldInfos);
}
protected int getFieldAsInt(EnumType index) {
Integer value = getFieldAsInteger(index);
if (value != null) {
return value.intValue();
}
return -1;
}
protected void setFieldAsString(EnumType index, String value) {
setFieldAs(index, new KerberosString(value));
}
protected KerberosTime getFieldAsTime(EnumType index) {
return getFieldAs(index, KerberosTime.class);
}
protected void setFieldAsTime(EnumType index, long value) {
setFieldAs(index, new KerberosTime(value));
}
protected void setField(EnumType index, EnumType value) {
setFieldAsInt(index, value.getValue());
}
}
| 33 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KerberosTime.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;
import java.util.Date;
import org.apache.kerby.asn1.type.Asn1GeneralizedTime;
/**
* A specialization of the ASN.1 GeneralTime. The Kerberos time contains date and
* time up to the seconds, but with no fractional seconds. It's also always
* expressed as UTC timeZone, thus the 'Z' at the end of its string representation.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class KerberosTime extends Asn1GeneralizedTime {
/** Constant for the {@link KerberosTime} "infinity." */
public static final KerberosTime NEVER = new KerberosTime(Long.MAX_VALUE);
/** The number of milliseconds in a minute. */
public static final int MINUTE = 60000;
/** The number of milliseconds in a day. */
public static final int DAY = MINUTE * 1440;
/** The number of milliseconds in a week. */
public static final int WEEK = MINUTE * 10080;
/**
* Creates a new instance of a KerberosTime object with the current time
*/
public KerberosTime() {
// divide current time by 1000 to drop the ms then multiply by 1000 to convert to ms
super((System.currentTimeMillis() / 1000L) * 1000L);
}
/**
* @param time in milliseconds
*/
public KerberosTime(long time) {
super(time);
}
/**
* @return time in milliseconds
*/
public long getTime() {
return getValue().getTime();
}
/**
* Set the Kerberos time
* @param time set time in milliseconds
*/
public void setTime(long time) {
setValue(new Date(time));
}
/**
* Gets the time in seconds
*
* @return The time
*/
public long getTimeInSeconds() {
return getTime() / 1000;
}
/**
* Compare the KerberosTime with another one, and return <tt>true</tt>
* if it's lesser than the provided one
*
* @param ktime in milliseconds
* @return <tt>true</tt> if less
*/
public boolean lessThan(KerberosTime ktime) {
return getValue().compareTo(ktime.getValue()) < 0;
}
/**
* Compare the KerberosTime with a time, and return <tt>true</tt>
* if it's lesser than the provided one
*
* @param time in milliseconds
* @return <tt>true</tt> if less
*/
public boolean lessThan(long time) {
return getValue().getTime() < time;
}
/**
* Compare the KerberosTime with another one, and return <tt>true</tt>
* if it's lesser than the provided one with time skew
* @param ktime
* @param skew Maximum time skew in milliseconds
* @return <tt>true</tt> if less
*/
public boolean lessThanWithSkew(KerberosTime ktime, long skew) {
return diff(ktime) - skew <= 0;
}
/**
* Compare the KerberosTime with another one, and return <tt>true</tt>
* if it's greater than the provided one
*
* @param ktime compare with milliseconds
* @return <tt>true</tt> if greater
*/
public boolean greaterThan(KerberosTime ktime) {
return getValue().compareTo(ktime.getValue()) > 0;
}
/**
* Compare the KerberosTime with another one, and return <tt>true</tt>
* if it's greater than the provided one with time skew
* @param ktime
* @param skew Maximum time skew in milliseconds
* @return <tt>true</tt> if greater
*/
public boolean greaterThanWithSkew(KerberosTime ktime, long skew) {
return diff(ktime) + skew >= 0;
}
/**
* Check if the KerberosTime is within the provided clock skew
*
* @param clockSkew The clock skew
* @return true if in clock skew
*/
public boolean isInClockSkew(long clockSkew) {
long delta = Math.abs(getTime() - System.currentTimeMillis());
return delta < clockSkew;
}
/**
* @return A copy of the KerbeorsTime
*/
public KerberosTime copy() {
long time = getTime();
return new KerberosTime(time);
}
/**
* Create a KerberosTime based on a time in milliseconds.
*
* @param duration The duration
* @return The created kerberos time
*/
public KerberosTime extend(long duration) {
long result = getTime() + duration;
return new KerberosTime(result);
}
/**
* Return the difference between the currentKerberosTime and the provided one
*
* @param kerberosTime The kerberos time
* @return The difference between the two KerberosTime
*/
public long diff(KerberosTime kerberosTime) {
return getTime() - kerberosTime.getTime();
}
/**
* @return The current KerberosTime
*/
public static KerberosTime now() {
return new KerberosTime(System.currentTimeMillis());
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (!(that instanceof KerberosTime)) {
return false;
}
return this.getValue().equals(((KerberosTime) that).getValue());
}
} | 34 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KrbPriv.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;
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.EncryptedData;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessage;
import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
/**
* The KRB_PRIV message, as defined in RFC 1510 :
* The KRB_PRIV message contains user data encrypted in the Session Key.
* The message fields are:
* <pre>
* KRB-PRIV ::= [APPLICATION 21] SEQUENCE {
* pvno[0] INTEGER,
* msg-type[1] INTEGER,
* enc-part[3] EncryptedData
* </pre>
*/
public class KrbPriv extends KrbMessage {
protected enum KrbPrivField implements EnumType {
PVNO,
MSG_TYPE,
UNUSED,
ENC_PART;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KrbPriv.KrbPrivField.PVNO, Asn1Integer.class),
new ExplicitField(KrbPriv.KrbPrivField.MSG_TYPE, Asn1Integer.class),
new ExplicitField(KrbPriv.KrbPrivField.UNUSED, null),
new ExplicitField(KrbPriv.KrbPrivField.ENC_PART, EncryptedData.class)
};
/**
* Creates a new instance of a KRB-PRIv message
*/
public KrbPriv() {
super(KrbMessageType.KRB_PRIV, fieldInfos);
}
private EncKrbPrivPart encPart;
public EncryptedData getEncryptedEncPart() {
return getFieldAs(KrbPriv.KrbPrivField.ENC_PART, EncryptedData.class);
}
public void setEncryptedEncPart(EncryptedData encryptedEncPart) {
setFieldAs(KrbPriv.KrbPrivField.ENC_PART, encryptedEncPart);
}
public EncKrbPrivPart getEncPart() {
return encPart;
}
public void setEncPart(EncKrbPrivPart encPart) {
this.encPart = encPart;
}
}
| 35 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KerberosStrings.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;
import java.util.List;
public class KerberosStrings extends KrbSequenceOfType<KerberosString> {
public KerberosStrings() {
super();
}
public KerberosStrings(List<String> strings) {
super();
setValues(strings);
}
public void setValues(List<String> values) {
clear();
if (values != null) {
for (String value : values) {
addElement(new KerberosString(value));
}
}
}
}
| 36 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KrbAppSequenceType.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;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.type.Asn1TaggingSequence;
/**
* This is for application specific sequence tagged with a number.
*/
public abstract class KrbAppSequenceType extends Asn1TaggingSequence {
public KrbAppSequenceType(int tagNo, Asn1FieldInfo[] fieldInfos) {
super(tagNo, fieldInfos, true, false); // Kerberos favors explicit
}
protected int getFieldAsInt(EnumType index) {
Integer value = getFieldAsInteger(index);
if (value != null) {
return value.intValue();
}
return -1;
}
protected void setFieldAsString(EnumType index, String value) {
setFieldAs(index, new KerberosString(value));
}
protected KerberosTime getFieldAsTime(EnumType index) {
return getFieldAs(index, KerberosTime.class);
}
protected void setFieldAsTime(EnumType index, long value) {
setFieldAs(index, new KerberosTime(value));
}
protected void setField(EnumType index, EnumType krbEnum) {
setFieldAsInt(index, krbEnum.getValue());
}
}
| 37 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/EncKrbPrivPart.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;
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.base.HostAddress;
/**
EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE {
user-data[0] OCTET STRING,
timestamp[1] KerberosTime OPTIONAL,
usec[2] INTEGER OPTIONAL,
seq-number[3] INTEGER OPTIONAL,
s-address[4] HostAddress, -- sender's addr
r-address[5] HostAddress OPTIONAL
-- recip's addr
}
*/
public class EncKrbPrivPart extends KrbAppSequenceType {
public static final int TAG = 28;
protected enum EncKrbPrivPartField implements EnumType {
USER_DATA,
TIMESTAMP,
USEC,
SEQ_NUMBER,
S_ADDRESS,
R_ADDRESS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.USER_DATA, Asn1OctetString.class),
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.TIMESTAMP, KerberosTime.class),
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.USEC, Asn1Integer.class),
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.SEQ_NUMBER, Asn1Integer.class),
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.S_ADDRESS, HostAddress.class),
new ExplicitField(EncKrbPrivPart.EncKrbPrivPartField.R_ADDRESS, HostAddress.class)
};
public EncKrbPrivPart() {
super(TAG, fieldInfos);
}
public byte[] getUserData() {
return getFieldAsOctets(EncKrbPrivPart.EncKrbPrivPartField.USER_DATA);
}
public void setUserData(byte[] userData) {
setFieldAsOctets(EncKrbPrivPart.EncKrbPrivPartField.USER_DATA, userData);
}
public KerberosTime getTimeStamp() {
return getFieldAsTime(EncKrbPrivPart.EncKrbPrivPartField.TIMESTAMP);
}
public void setTimeStamp(KerberosTime timeStamp) {
setFieldAs(EncKrbPrivPart.EncKrbPrivPartField.TIMESTAMP, timeStamp);
}
public int getUsec() {
return getFieldAsInt(EncKrbPrivPart.EncKrbPrivPartField.USEC);
}
public void setUsec(int usec) {
setFieldAsInt(EncKrbPrivPart.EncKrbPrivPartField.USEC, usec);
}
public int getSeqNumber() {
return getFieldAsInt(EncKrbPrivPart.EncKrbPrivPartField.SEQ_NUMBER);
}
public void setSeqNumber(int seqNumber) {
setFieldAsInt(EncKrbPrivPart.EncKrbPrivPartField.SEQ_NUMBER, seqNumber);
}
public HostAddress getSAddress() {
return getFieldAs(EncKrbPrivPart.EncKrbPrivPartField.S_ADDRESS, HostAddress.class);
}
public void setSAddress(HostAddress hostAddress) {
setFieldAs(EncKrbPrivPart.EncKrbPrivPartField.S_ADDRESS, hostAddress);
}
public HostAddress getRAddress() {
return getFieldAs(EncKrbPrivPart.EncKrbPrivPartField.R_ADDRESS, HostAddress.class);
}
public void setRAddress(HostAddress hostAddress) {
setFieldAs(EncKrbPrivPart.EncKrbPrivPartField.R_ADDRESS, hostAddress);
}
}
| 38 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KrbIntegers.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;
import org.apache.kerby.asn1.type.Asn1Integer;
import java.util.ArrayList;
import java.util.List;
public class KrbIntegers extends KrbSequenceOfType<Asn1Integer> {
public KrbIntegers() {
super();
}
public KrbIntegers(List<Integer> values) {
super();
setValues(values);
}
public void setValues(List<Integer> values) {
clear();
if (values != null) {
for (Integer value : values) {
addElement(new Asn1Integer(value));
}
}
}
public List<Integer> getValues() {
List<Integer> results = new ArrayList<>();
for (Asn1Integer value : getElements()) {
results.add(value.getValue().intValue());
}
return results;
}
}
| 39 |
0 | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb | Create_ds/directory-kerby/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/KrbSequenceOfType.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;
import java.util.ArrayList;
import java.util.List;
import org.apache.kerby.asn1.type.Asn1SequenceOf;
import org.apache.kerby.asn1.type.Asn1String;
import org.apache.kerby.asn1.type.Asn1Type;
/**
* A class that represents a SequenceOf Kerberos elements.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*
* @param <T> The KrbSequence type
*/
public class KrbSequenceOfType<T extends Asn1Type> extends Asn1SequenceOf<T> {
/**
* @return A String List of the Kerberos Elements in this sequenceOf.
*/
public List<String> getAsStrings() {
List<T> elements = getElements();
// may be spurious... Careful check of the elements nullity.
if (elements == null) {
return new ArrayList<String>();
}
List<String> results = new ArrayList<>(elements.size());
for (T ele : elements) {
if (ele instanceof Asn1String) {
results.add(((Asn1String) ele).getValue());
} else {
throw new RuntimeException("The targeted field type isn't of string");
}
}
return results;
}
}
| 40 |
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/ad/AndOr.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.ad;
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.KrbSequenceType;
/**
* <pre>
* AD-AND-OR ::= SEQUENCE {
* condition-count [0] Int32,
* elements [1] AuthorizationData
* }
* </pre>
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class AndOr extends KrbSequenceType {
protected enum AndOrField implements EnumType {
AndOr_ConditionCount, AndOr_Elements;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
/** The CamMac's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(AndOrField.AndOr_ConditionCount, Asn1Integer.class),
new ExplicitField(AndOrField.AndOr_Elements, AuthorizationData.class)};
public AndOr() {
super(fieldInfos);
}
public AndOr(int conditionCount, AuthorizationData authzData) {
super(fieldInfos);
setFieldAs(AndOrField.AndOr_ConditionCount, new Asn1Integer(conditionCount));
setFieldAs(AndOrField.AndOr_Elements, authzData);
}
public int getConditionCount() {
return getFieldAs(AndOrField.AndOr_ConditionCount, Asn1Integer.class).getValue().intValue();
}
public void setConditionCount(int conditionCount) {
setFieldAs(AndOrField.AndOr_ConditionCount, new Asn1Integer(conditionCount));
}
public AuthorizationData getAuthzData() {
return getFieldAs(AndOrField.AndOr_Elements, AuthorizationData.class);
}
public void setAuthzData(AuthorizationData authzData) {
setFieldAs(AndOrField.AndOr_Elements, authzData);
}
}
| 41 |
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/ad/CamMacVerifierMac.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.ad;
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.KrbSequenceType;
import org.apache.kerby.kerberos.kerb.type.base.CheckSum;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
/**
* <pre>
* Verifier-MAC ::= SEQUENCE {
* identifier [0] PrincipalName OPTIONAL,
* kvno [1] UInt32 OPTIONAL,
* enctype [2] Int32 OPTIONAL,
* mac [3] Checksum
* }
* </pre>
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class CamMacVerifierMac extends KrbSequenceType {
protected enum CamMacField implements EnumType {
CAMMAC_identifier, CAMMAC_kvno, CAMMAC_enctype, CAMMAC_mac;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
/** The CamMac's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(CamMacField.CAMMAC_identifier, PrincipalName.class),
new ExplicitField(CamMacField.CAMMAC_kvno, Asn1Integer.class),
new ExplicitField(CamMacField.CAMMAC_enctype, Asn1Integer.class),
new ExplicitField(CamMacField.CAMMAC_mac, CheckSum.class)};
public CamMacVerifierMac() {
super(fieldInfos);
}
public CamMacVerifierMac(PrincipalName identifier) {
super(fieldInfos);
setFieldAs(CamMacField.CAMMAC_identifier, identifier);
}
public PrincipalName getIdentifier() {
return getFieldAs(CamMacField.CAMMAC_identifier, PrincipalName.class);
}
public void setIdentifier(PrincipalName identifier) {
setFieldAs(CamMacField.CAMMAC_identifier, identifier);
}
public int getKvno() {
return getFieldAs(CamMacField.CAMMAC_kvno, Asn1Integer.class).getValue().intValue();
}
public void setKvno(int kvno) {
setFieldAs(CamMacField.CAMMAC_kvno, new Asn1Integer(kvno));
}
public int getEnctype() {
return getFieldAs(CamMacField.CAMMAC_enctype, Asn1Integer.class).getValue().intValue();
}
public void setEnctype(int encType) {
setFieldAs(CamMacField.CAMMAC_enctype, new Asn1Integer(encType));
}
public CheckSum getMac() {
return getFieldAs(CamMacField.CAMMAC_mac, CheckSum.class);
}
public void setMac(CheckSum mac) {
setFieldAs(CamMacField.CAMMAC_mac, mac);
}
}
| 42 |
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/ad/AuthorizationData.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.ad;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
* The AuthorizationData as defined in RFC 4120 :
* <pre>
* AuthorizationData ::= SEQUENCE OF SEQUENCE {
* ad-type [0] Int32,
* ad-data [1] OCTET STRING
* }
* </pre>
*
* This class is just empty, as the content is already stored in a SequenceOf.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AuthorizationData extends KrbSequenceOfType<AuthorizationDataEntry> {
public AuthorizationData clone() {
AuthorizationData result = new AuthorizationData();
for (AuthorizationDataEntry entry : super.getElements()) {
result.add(entry.clone());
}
return result;
}
}
| 43 |
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/ad/CamMacVerifierChoice.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.ad;
import org.apache.kerby.asn1.Asn1FieldInfo;
import org.apache.kerby.asn1.EnumType;
import org.apache.kerby.asn1.ExplicitField;
import org.apache.kerby.asn1.type.Asn1Choice;
import org.apache.kerby.asn1.type.Asn1Type;
/**
* <pre>
* Verifier ::= CHOICE {
mac Verifier-MAC,
...
}
* </pre>
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class CamMacVerifierChoice extends Asn1Choice {
protected enum VerifierChoice implements EnumType {
CAMMAC_verifierMac;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
/** The CamMac's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(VerifierChoice.CAMMAC_verifierMac, CamMacVerifierMac.class)};
public CamMacVerifierChoice() {
super(fieldInfos);
}
public void setChoice(EnumType type, Asn1Type choice) {
setChoiceValue(type, choice);
}
}
| 44 |
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/ad/AuthorizationDataEntry.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.ad;
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.Asn1Type;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* The AuthorizationData component as defined in RFC 4120 :
*
* <pre>
* AuthorizationData ::= SEQUENCE {
* ad-type [0] Int32,
* ad-data [1] OCTET STRING
* }
* </pre>
*
* We just implement what is in the SEQUENCE OF.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AuthorizationDataEntry extends KrbSequenceType {
private static final Logger LOG = LoggerFactory
.getLogger(AuthorizationDataEntry.class);
/**
* The possible fields
*/
protected enum AuthorizationDataEntryField implements EnumType {
AD_TYPE,
AD_DATA;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The AuthorizationDataEntry's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(AuthorizationDataEntryField.AD_TYPE, Asn1Integer.class),
new ExplicitField(AuthorizationDataEntryField.AD_DATA, Asn1OctetString.class)
};
/**
* Creates an AuthorizationDataEntry instance
*/
public AuthorizationDataEntry() {
super(fieldInfos);
}
/**
* Creates an AuthorizationDataEntry instance
* @param type The authorization type
*/
public AuthorizationDataEntry(AuthorizationType type) {
super(fieldInfos);
setAuthzType(type);
}
/**
* Creates an AuthorizationDataEntry instance
* @param type The authorization type
* @param authzData The authorization data
*/
public AuthorizationDataEntry(AuthorizationType type, byte[] authzData) {
super(fieldInfos);
setAuthzType(type);
setAuthzData(authzData);
}
/**
* @return The AuthorizationType (AD_TYPE) field
*/
public AuthorizationType getAuthzType() {
Integer value = getFieldAsInteger(AuthorizationDataEntryField.AD_TYPE);
return AuthorizationType.fromValue(value);
}
/**
* Sets the AuthorizationType (AD_TYPE) field
* @param authzType The AuthorizationType to set
*/
public void setAuthzType(AuthorizationType authzType) {
setFieldAsInt(AuthorizationDataEntryField.AD_TYPE, authzType.getValue());
}
/**
* @return The AuthorizationData (AD_DATA) field
*/
public byte[] getAuthzData() {
return getFieldAsOctets(AuthorizationDataEntryField.AD_DATA);
}
/**
* Sets the AuthorizationData (AD_DATA) field
* @param authzData The AuthorizationData to set
*/
public void setAuthzData(byte[] authzData) {
setFieldAsOctets(AuthorizationDataEntryField.AD_DATA, authzData);
}
/**
* @param <T> type The type
* @return The AuthorizationData (AD_DATA) field
*/
public <T extends Asn1Type> T getAuthzDataAs(Class<T> type) {
T result = null;
byte[] authzBytes = getFieldAsOctets(
AuthorizationDataEntryField.AD_DATA);
if (authzBytes != null) {
try {
result = type.newInstance();
result.decode(authzBytes);
} catch (InstantiationException | IllegalAccessException | IOException e) {
LOG.error("Failed to get the AD_DATA field. " + e.toString());
}
}
return result;
}
public AuthorizationDataEntry clone() {
return new AuthorizationDataEntry(getAuthzType(),
getAuthzData().clone());
}
}
| 45 |
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/ad/ADAndOr.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.ad;
import java.io.IOException;
import java.util.List;
import org.apache.kerby.asn1.Asn1Dumper;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADAndOr extends AuthorizationDataEntry {
private KrbSequenceOfType<AndOr> myAndOr;
public ADAndOr() {
super(AuthorizationType.AD_AND_OR);
myAndOr = new KrbSequenceOfType<>();
myAndOr.outerEncodeable = this;
}
public ADAndOr(byte[] encoded) throws IOException {
this();
myAndOr.decode(encoded);
}
public ADAndOr(List<AndOr> elements) {
this();
for (AndOr element : elements) {
myAndOr.add(element);
}
}
public List<AndOr> getAndOrs() throws IOException {
return myAndOr.getElements();
}
public void add(AndOr element) {
myAndOr.add(element);
}
@Override
protected int encodingBodyLength() throws IOException {
if (bodyLength == -1) {
setAuthzData(myAndOr.encode());
bodyLength = super.encodingBodyLength();
}
return bodyLength;
};
@Override
public void dumpWith(Asn1Dumper dumper, int indents) {
super.dumpWith(dumper, indents);
dumper.newLine();
myAndOr.dumpWith(dumper, indents + 8);
}
}
| 46 |
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/ad/AuthorizationType.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.ad;
import org.apache.kerby.asn1.EnumType;
/**
* The various AuthorizationType values, as defined in RFC 4120 and RFC 1510.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum AuthorizationType implements EnumType {
/**
* Constant for the "null" authorization type.
*/
NONE(0),
/**
* Constant for the "if relevant" authorization type.
*
* RFC 4120
*
* AD elements encapsulated within the if-relevant element are intended for
* interpretation only by application servers that understand the particular
* ad-type of the embedded element. Application servers that do not
* understand the type of an element embedded within the if-relevant element
* may ignore the uninterpretable element. This element promotes
* interoperability across implementations which may have local extensions
* for authorization.
*/
AD_IF_RELEVANT(1),
/**
* Constant for the "intended for server" authorization type.
*
* RFC 4120
*
* AD-INTENDED-FOR-SERVER SEQUENCE { intended-server[0] SEQUENCE OF
* PrincipalName elements[1] AuthorizationData }
*
* AD elements encapsulated within the intended-for-server element may be
* ignored if the application server is not in the list of principal names
* of intended servers. Further, a KDC issuing a ticket for an application
* server can remove this element if the application server is not in the
* list of intended servers.
*
* Application servers should check for their principal name in the
* intended-server field of this element. If their principal name is not
* found, this element should be ignored. If found, then the encapsulated
* elements should be evaluated in the same manner as if they were present
* in the top level authorization data field. Applications and application
* servers that do not implement this element should reject tickets that
* contain authorization data elements of this type.
*/
AD_INTENDED_FOR_SERVER(2),
/**
* Constant for the "intended for application class" authorization type.
*
* RFC 4120
*
* AD-INTENDED-FOR-APPLICATION-CLASS SEQUENCE {
* intended-application-class[0] SEQUENCE OF GeneralString elements[1]
* AuthorizationData } AD elements
*
* encapsulated within the intended-for-application-class element may be
* ignored if the application server is not in one of the named classes of
* application servers. Examples of application server classes include
* "FILESYSTEM", and other kinds of servers.
*
* This element and the elements it encapsulates may be safely ignored by
* applications, application servers, and KDCs that do not implement this
* element.
*/
AD_INTENDED_FOR_APPLICATION_CLASS(3),
/**
* Constant for the "kdc issued" authorization type.
*
* RFC 4120
*
* AD-KDCIssued SEQUENCE { ad-checksum[0] Checksum, i-realm[1] Realm
* OPTIONAL, i-sname[2] PrincipalName OPTIONAL, elements[3]
* AuthorizationData. }
*
* ad-checksum A checksum over the elements field using a cryptographic
* checksum method that is identical to the checksum used to protect the
* ticket itself (i.e. using the same hash function and the same encryption
* algorithm used to encrypt the ticket) and using a key derived from the
* same key used to protect the ticket. i-realm, i-sname The name of the
* issuing principal if different from the KDC itself. This field would be
* used when the KDC can verify the authenticity of elements signed by the
* issuing principal and it allows this KDC to notify the application server
* of the validity of those elements. elements A sequence of authorization
* data elements issued by the KDC.
*
* The KDC-issued ad-data field is intended to provide a means for Kerberos
* principal credentials to embed within themselves privilege attributes and
* other mechanisms for positive authorization, amplifying the privileges of
* the principal beyond what can be done using a credentials without such an
* a-data element.
*
* This can not be provided without this element because the definition of
* the authorization-data field allows elements to be added at will by the
* bearer of a TGT at the time that they request service tickets and
* elements may also be added to a delegated ticket by inclusion in the
* authenticator.
*/
AD_KDC_ISSUED(4),
/**
* Constant for the "and/or" authorization type.
*
* RFC 4120
*
* When restrictive AD elements encapsulated within the and-or element are
* encountered, only the number specified in condition-count of the
* encapsulated conditions must be met in order to satisfy this element.
* This element may be used to implement an "or" operation by setting the
* condition-count field to 1, and it may specify an "and" operation by
* setting the condition count to the number of embedded elements.
* Application servers that do not implement this element must reject
* tickets that contain authorization data elements of this type.
*/
AD_AND_OR(5),
/**
* Constant for the "mandatory ticket extensions" authorization type.
*
* RFC 4120
*
* AD-Mandatory-Ticket-Extensions Checksum
*
* An authorization data element of type mandatory-ticket-extensions
* specifies a collision-proof checksum using the same hash algorithm used
* to protect the integrity of the ticket itself. This checksum will be
* calculated over the entire extensions field. If there are more than one
* extension, all will be covered by the checksum. This restriction
* indicates that the ticket should not be accepted if the checksum does not
* match that calculated over the ticket extensions. Application servers
* that do not implement this element must reject tickets that contain
* authorization data elements of this type.
*/
AD_MANDATORY_TICKET_EXTENSIONS(6),
/**
* Constant for the "in ticket extensions" authorization type.
*
* RFC 4120
*
* AD-IN-Ticket-Extensions Checksum
*
* An authorization data element of type in-ticket-extensions specifies a
* collision-proof checksum using the same hash algorithm used to protect
* the integrity of the ticket itself. This checksum is calculated over a
* separate external AuthorizationData field carried in the ticket
* extensions. Application servers that do not implement this element must
* reject tickets that contain authorization data elements of this type.
* Application servers that do implement this element will search the ticket
* extensions for authorization data fields, calculate the specified
* checksum over each authorization data field and look for one matching the
* checksum in this in-ticket-extensions element. If not found, then the
* ticket must be rejected. If found, the corresponding authorization data
* elements will be interpreted in the same manner as if they were contained
* in the top level authorization data field.
*/
AD_IN_TICKET_EXTENSIONS(7),
/**
* Constant for the "mandatory-for-kdc" authorization type.
*
* RFC 4120
*
* AD-MANDATORY-FOR-KDC ::= AuthorizationData
*
* AD elements encapsulated within the mandatory-for-kdc element are to be
* interpreted by the KDC. KDCs that do not understand the type of an
* element embedded within the mandatory-for-kdc element MUST reject the
* request.
*/
AD_MANDATORY_FOR_KDC(8),
/**
* Constant for the "initial-verified-cas" authorization type.
*
* RFC 4556
*
* AD-INITIAL-VERIFIED-CAS ::= SEQUENCE OF ExternalPrincipalIdentifier --
* Identifies the certification path with which -- the client certificate
* was validated. -- Each ExternalPrincipalIdentifier identifies a CA -- or
* a CA certificate (thereby its public key).
*
* The AD-INITIAL-VERIFIED-CAS structure identifies the certification path
* with which the client certificate was validated. Each
* ExternalPrincipalIdentifier (as defined in Section 3.2.1) in the AD-
* INITIAL-VERIFIED-CAS structure identifies a CA or a CA certificate
* (thereby its public key).
*
* Note that the syntax for the AD-INITIAL-VERIFIED-CAS authorization data
* does permit empty SEQUENCEs to be encoded. Such empty sequences may only
* be used if the KDC itself vouches for the user's certificate.
*
* The AS wraps any AD-INITIAL-VERIFIED-CAS data in AD-IF-RELEVANT
* containers if the list of CAs satisfies the AS' realm's local policy
* (this corresponds to the TRANSITED-POLICY-CHECKED ticket flag [RFC4120]).
* Furthermore, any TGS MUST copy such authorization data from tickets used
* within a PA-TGS-REQ of the TGS-REQ into the resulting ticket. If the list
* of CAs satisfies the local KDC's realm's policy, the TGS MAY wrap the
* data into the AD-IF-RELEVANT container; otherwise, it MAY unwrap the
* authorization data out of the AD-IF-RELEVANT container.
*
* Application servers that understand this authorization data type SHOULD
* apply local policy to determine whether a given ticket bearing such a
* type *not* contained within an AD-IF-RELEVANT container is acceptable.
* (This corresponds to the AP server's checking the transited field when
* the TRANSITED-POLICY-CHECKED flag has not been set [RFC4120].) If such a
* data type is contained within an AD-IF- RELEVANT container, AP servers
* MAY apply local policy to determine whether the authorization data is
* acceptable.
*
* ExternalPrincipalIdentifier ::= SEQUENCE { subjectName [0] IMPLICIT OCTET
* STRING OPTIONAL, -- Contains a PKIX type Name encoded according to --
* [RFC3280]. -- Identifies the certificate subject by the -- distinguished
* subject name. -- REQUIRED when there is a distinguished subject -- name
* present in the certificate. issuerAndSerialNumber [1] IMPLICIT OCTET
* STRING OPTIONAL, -- Contains a CMS type IssuerAndSerialNumber encoded --
* according to [RFC3852]. -- Identifies a certificate of the subject. --
* REQUIRED for TD-INVALID-CERTIFICATES and -- TD-TRUSTED-CERTIFIERS.
* subjectKeyIdentifier [2] IMPLICIT OCTET STRING OPTIONAL, -- Identifies
* the subject's public key by a key -- identifier. When an X.509
* certificate is -- referenced, this key identifier matches the X.509 --
* subjectKeyIdentifier extension value. When other -- certificate formats
* are referenced, the documents -- that specify the certificate format and
* their use -- with the CMS must include details on matching the -- key
* identifier to the appropriate certificate -- field. -- RECOMMENDED for
* TD-TRUSTED-CERTIFIERS. ... }
*/
AD_INITIAL_VERIFIED_CAS(9),
/**
* Constant for the "OSF DCE" authorization type.
*
* RFC 1510
*/
OSF_DCE(64),
/**
* Constant for the "sesame" authorization type.
*
* RFC 4120
*/
SESAME(65),
/**
* Constant for the "OSF-DCE pki certid" authorization type.
*
* RFC 4120
*/
AD_OSF_DCE_PKI_CERTID(66),
/**
* Constant for the "CAM-MAC" authorization type.
*
* RFC 7751 for details.
*/
AD_CAMMAC(96),
/**
* Constant for the "Authentication-Indicator" authorization type.
*
* RFC 6711 An IANA Registry for Level of Assurance (LoA) Profiles provides
* the syntax and semantics of LoA profiles.
*
* RFC-8129 "Authentication Indicator in Kerberos Tickets" for details.
*/
AD_AUTHENTICATION_INDICATOR(97),
/**
* Constant for the "Windows 2K Privilege Attribute Certificate (PAC)"
* authorization type.
*
* RFC 4120
*
* See: Microsoft standard documents MS-PAC and MS-KILE.
*/
AD_WIN2K_PAC(128),
/**
* Constant for the "EncType-Negotiation" authorization type.
*
* RFC 4537 for details.
*/
AD_ETYPE_NEGOTIATION(129),
/**
* Constant for the Authorization Data Type. Note that this is not a
* standard Type as of yet.
*
* See the draft spec "Token Pre-Authentication for Kerberos".
*/
AD_TOKEN(256);
/** The internal value */
private final int value;
/**
* Create a new enum
*/
AuthorizationType(int value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
/**
* Get the AuthorizationType associated with a value.
*
* @param value The integer value of the AuthorizationType we are looking for
* @return The associated AuthorizationType, or NULL if not found or if value is null
*/
public static AuthorizationType fromValue(Integer value) {
if (value != null) {
for (EnumType e : values()) {
if (e.getValue() == value) {
return (AuthorizationType) e;
}
}
}
return NONE;
}
}
| 47 |
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/ad/ADAuthenticationIndicator.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.ad;
import java.io.IOException;
import java.util.List;
import org.apache.kerby.asn1.Asn1Dumper;
import org.apache.kerby.asn1.type.Asn1Utf8String;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADAuthenticationIndicator extends AuthorizationDataEntry {
private AuthIndicator myAuthIndicator;
private static class AuthIndicator extends KrbSequenceOfType<Asn1Utf8String> {
}
public ADAuthenticationIndicator() {
super(AuthorizationType.AD_AUTHENTICATION_INDICATOR);
myAuthIndicator = new AuthIndicator();
myAuthIndicator.outerEncodeable = this;
}
public ADAuthenticationIndicator(byte[] encoded) throws IOException {
this();
myAuthIndicator.decode(encoded);
}
public List<Asn1Utf8String> getAuthIndicators() {
return myAuthIndicator.getElements();
}
public void add(Asn1Utf8String indicator) {
myAuthIndicator.add(indicator);
resetBodyLength();
}
public void clear() {
myAuthIndicator.clear();
resetBodyLength();
}
@Override
protected int encodingBodyLength() throws IOException {
if (bodyLength == -1) {
setAuthzData(myAuthIndicator.encode());
bodyLength = super.encodingBodyLength();
}
return bodyLength;
};
@Override
public void dumpWith(Asn1Dumper dumper, int indents) {
super.dumpWith(dumper, indents);
dumper.newLine();
myAuthIndicator.dumpWith(dumper, indents + 8);
}
}
| 48 |
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/ad/CamMacOtherVerifiers.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.ad;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
/**
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class CamMacOtherVerifiers extends KrbSequenceOfType<CamMacVerifierChoice> {
}
| 49 |
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/ad/ADIntendedForApplicationClass.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.ad;
import java.io.IOException;
import org.apache.kerby.asn1.Asn1Dumper;
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.KerberosStrings;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
/**
* Asn1 Class for the "intended for application class" authorization type.
*
* RFC 4120
*
* AD-INTENDED-FOR-APPLICATION-CLASS SEQUENCE { intended-application-class[0]
* SEQUENCE OF GeneralString elements[1] AuthorizationData } AD elements
*
* encapsulated within the intended-for-application-class element may be ignored
* if the application server is not in one of the named classes of application
* servers. Examples of application server classes include "FILESYSTEM", and
* other kinds of servers.
*
* This element and the elements it encapsulates may be safely ignored by
* applications, application servers, and KDCs that do not implement this
* element.
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADIntendedForApplicationClass extends AuthorizationDataEntry {
private IntendedForApplicationClass myIntForAppClass;
private static class IntendedForApplicationClass extends KrbSequenceType {
private AuthorizationData authzData;
/**
* The possible fields
*/
protected enum IntendedForApplicationClassField implements EnumType {
IFAC_intendedAppClass, IFAC_elements;
/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return ordinal();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name();
}
}
/** The IntendedForApplicationClass's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(IntendedForApplicationClassField.IFAC_intendedAppClass, KerberosStrings.class),
new ExplicitField(IntendedForApplicationClassField.IFAC_elements, AuthorizationData.class)};
/**
* Creates an IntendedForApplicationClass instance
*/
IntendedForApplicationClass() {
super(fieldInfos);
}
/**
* Creates an IntendedForApplicationClass instance
*/
IntendedForApplicationClass(KerberosStrings intendedAppClass) {
super(fieldInfos);
setFieldAs(IntendedForApplicationClassField.IFAC_intendedAppClass, intendedAppClass);
}
public KerberosStrings getIntendedForApplicationClass() {
return getFieldAs(IntendedForApplicationClassField.IFAC_intendedAppClass, KerberosStrings.class);
}
/**
* Sets the Intended Application Class value.
*/
public void setIntendedForApplicationClass(KerberosStrings intendedAppClass) {
setFieldAs(IntendedForApplicationClassField.IFAC_intendedAppClass, intendedAppClass);
resetBodyLength();
}
public AuthorizationData getAuthzData() {
if (authzData == null) {
authzData = getFieldAs(IntendedForApplicationClassField.IFAC_elements, AuthorizationData.class);
}
return authzData;
}
public void setAuthzData(AuthorizationData authzData) {
this.authzData = authzData;
setFieldAs(IntendedForApplicationClassField.IFAC_elements, authzData);
resetBodyLength();
}
}
public ADIntendedForApplicationClass() {
super(AuthorizationType.AD_INTENDED_FOR_APPLICATION_CLASS);
myIntForAppClass = new IntendedForApplicationClass();
myIntForAppClass.outerEncodeable = this;
}
public ADIntendedForApplicationClass(byte[] encoded) throws IOException {
this();
myIntForAppClass.decode(encoded);
}
public ADIntendedForApplicationClass(KerberosStrings intendedAppClass) throws IOException {
this();
myIntForAppClass.setIntendedForApplicationClass(intendedAppClass);
}
public KerberosStrings getIntendedForApplicationClass() {
return myIntForAppClass.getIntendedForApplicationClass();
}
/**
* Sets the Intended Application Class value.
*/
public void setIntendedForApplicationClass(KerberosStrings intendedAppClass) {
myIntForAppClass.setIntendedForApplicationClass(intendedAppClass);
}
public AuthorizationData getAuthorizationData() {
return myIntForAppClass.getAuthzData();
}
public void setAuthorizationData(AuthorizationData authzData) {
myIntForAppClass.setAuthzData(authzData);
}
@Override
protected int encodingBodyLength() throws IOException {
if (bodyLength == -1) {
setAuthzData(myIntForAppClass.encode());
bodyLength = super.encodingBodyLength();
}
return bodyLength;
};
@Override
public void dumpWith(Asn1Dumper dumper, int indents) {
super.dumpWith(dumper, indents);
dumper.newLine();
myIntForAppClass.dumpWith(dumper, indents + 8);
}
}
| 50 |
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/ad/ADKdcIssued.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.ad;
import java.io.IOException;
import org.apache.kerby.asn1.Asn1Dumper;
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.CheckSum;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
import org.apache.kerby.kerberos.kerb.type.base.Realm;
/**
* <pre>
* AD-KDCIssued ::= SEQUENCE {
* ad-checksum [0] Checksum,
* i-realm [1] Realm OPTIONAL,
* i-sname [2] PrincipalName OPTIONAL,
* elements [3] AuthorizationData
* }
* </pre>
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADKdcIssued extends AuthorizationDataEntry {
private KdcIssued myKdcIssued;
private static class KdcIssued extends KrbSequenceType {
enum KdcIssuedField implements EnumType {
AD_CHECKSUM, I_REALM, I_SNAME, ELEMENTS;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
/** The AuthorizationDataEntry's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(KdcIssuedField.AD_CHECKSUM, CheckSum.class),
new ExplicitField(KdcIssuedField.I_REALM, Realm.class),
new ExplicitField(KdcIssuedField.I_SNAME, PrincipalName.class),
new ExplicitField(KdcIssuedField.ELEMENTS, AuthorizationData.class)};
KdcIssued() {
super(fieldInfos);
}
public CheckSum getCheckSum() {
return getFieldAs(KdcIssuedField.AD_CHECKSUM, CheckSum.class);
}
public void setCheckSum(CheckSum chkSum) {
setFieldAs(KdcIssuedField.AD_CHECKSUM, chkSum);
}
public Realm getRealm() {
return getFieldAs(KdcIssuedField.I_REALM, Realm.class);
}
public void setRealm(Realm realm) {
setFieldAs(KdcIssuedField.I_REALM, realm);
}
public PrincipalName getSname() {
return getFieldAs(KdcIssuedField.I_SNAME, PrincipalName.class);
}
public void setSname(PrincipalName sName) {
setFieldAs(KdcIssuedField.I_SNAME, sName);
}
public AuthorizationData getAuthzData() {
return getFieldAs(KdcIssuedField.ELEMENTS, AuthorizationData.class);
}
public void setAuthzData(AuthorizationData authzData) {
setFieldAs(KdcIssuedField.ELEMENTS, authzData);
}
}
public ADKdcIssued() {
super(AuthorizationType.AD_KDC_ISSUED);
myKdcIssued = new KdcIssued();
myKdcIssued.outerEncodeable = this;
}
public ADKdcIssued(byte[] encoded) throws IOException {
this();
myKdcIssued.decode(encoded);
}
public CheckSum getCheckSum() {
return myKdcIssued.getCheckSum();
}
public void setCheckSum(CheckSum chkSum) {
myKdcIssued.setCheckSum(chkSum);
}
public Realm getRealm() {
return myKdcIssued.getRealm();
}
public void setRealm(Realm realm) {
myKdcIssued.setRealm(realm);
}
public PrincipalName getSname() {
return myKdcIssued.getSname();
}
public void setSname(PrincipalName sName) {
myKdcIssued.setSname(sName);
}
public AuthorizationData getAuthorizationData() {
return myKdcIssued.getAuthzData();
}
public void setAuthzData(AuthorizationData authzData) {
myKdcIssued.setAuthzData(authzData);
}
@Override
protected int encodingBodyLength() throws IOException {
if (bodyLength == -1) {
setAuthzData(myKdcIssued.encode());
bodyLength = super.encodingBodyLength();
}
return bodyLength;
};
@Override
public void dumpWith(Asn1Dumper dumper, int indents) {
super.dumpWith(dumper, indents);
dumper.newLine();
myKdcIssued.dumpWith(dumper, indents + 8);
}
}
| 51 |
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/ad/PrincipalList.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.ad;
import org.apache.kerby.kerberos.kerb.type.KrbSequenceOfType;
import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
/**
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class PrincipalList extends KrbSequenceOfType<PrincipalName> {
}
| 52 |
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/ad/ADCamMac.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.ad;
import java.io.IOException;
import org.apache.kerby.asn1.Asn1Dumper;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <pre>
* AD-CAMMAC ::= SEQUENCE {
* elements [0] AuthorizationData,
* kdc-verifier [1] Verifier-MAC OPTIONAL,
* svc-verifier [2] Verifier-MAC OPTIONAL,
* other-verifiers [3] SEQUENCE (SIZE (1..MAX))
* OF Verifier OPTIONAL
* }
* </pre>
*
* Contributed to the Apache Kerby Project by: Prodentity - Corrales, NM
*
* @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
*/
public class ADCamMac extends AuthorizationDataEntry {
private static final Logger LOG = LoggerFactory
.getLogger(ADCamMac.class);
private CamMac myCamMac;
private static class CamMac extends KrbSequenceType {
protected enum CamMacField implements EnumType {
CAMMAC_elements, CAMMAC_kdc_verifier, CAMMAC_svc_verifier, CAMMAC_other_verifiers;
@Override
public int getValue() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
/** The CamMac's fields */
private static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
new ExplicitField(CamMacField.CAMMAC_elements, AuthorizationData.class),
new ExplicitField(CamMacField.CAMMAC_kdc_verifier, CamMacVerifierMac.class),
new ExplicitField(CamMacField.CAMMAC_svc_verifier, CamMacVerifierMac.class),
new ExplicitField(CamMacField.CAMMAC_other_verifiers, CamMacOtherVerifiers.class)};
CamMac() {
super(fieldInfos);
}
CamMac(byte[] authzFields) {
super(fieldInfos);
super.setFieldAsOctets(AuthorizationDataEntryField.AD_DATA, authzFields);
}
CamMac(AuthorizationData authzData) {
super(fieldInfos);
setFieldAs(CamMacField.CAMMAC_elements, authzData);
}
public AuthorizationData getAuthorizationData() {
return getFieldAs(CamMacField.CAMMAC_elements, AuthorizationData.class);
}
public void setAuthorizationData(AuthorizationData authzData) {
setFieldAs(CamMacField.CAMMAC_elements, authzData);
resetBodyLength();
}
public CamMacVerifierMac getKdcVerifier() {
return getFieldAs(CamMacField.CAMMAC_kdc_verifier, CamMacVerifierMac.class);
}
public void setKdcVerifier(CamMacVerifierMac kdcVerifier) {
setFieldAs(CamMacField.CAMMAC_kdc_verifier, kdcVerifier);
resetBodyLength();
}
public CamMacVerifierMac getSvcVerifier() {
return getFieldAs(CamMacField.CAMMAC_svc_verifier, CamMacVerifierMac.class);
}
public void setSvcVerifier(CamMacVerifierMac svcVerifier) {
setFieldAs(CamMacField.CAMMAC_svc_verifier, svcVerifier);
resetBodyLength();
}
public CamMacOtherVerifiers getOtherVerifiers() {
return getFieldAs(CamMacField.CAMMAC_other_verifiers, CamMacOtherVerifiers.class);
}
public void setOtherVerifiers(CamMacOtherVerifiers svcVerifier) {
setFieldAs(CamMacField.CAMMAC_other_verifiers, svcVerifier);
resetBodyLength();
}
}
public ADCamMac() {
super(AuthorizationType.AD_CAMMAC);
myCamMac = new CamMac();
myCamMac.outerEncodeable = this;
}
public ADCamMac(byte[] encoded) throws IOException {
this();
myCamMac.decode(encoded);
}
public AuthorizationData getAuthorizationData() {
return myCamMac.getAuthorizationData();
}
public void setAuthorizationData(AuthorizationData authzData) {
myCamMac.setAuthorizationData(authzData);
}
public CamMacVerifierMac getKdcVerifier() {
return myCamMac.getKdcVerifier();
}
public void setKdcVerifier(CamMacVerifierMac kdcVerifier) {
myCamMac.setKdcVerifier(kdcVerifier);
}
public CamMacVerifierMac getSvcVerifier() {
return myCamMac.getSvcVerifier();
}
public void setSvcVerifier(CamMacVerifierMac svcVerifier) {
myCamMac.setSvcVerifier(svcVerifier);
}
public CamMacOtherVerifiers getOtherVerifiers() {
return myCamMac.getOtherVerifiers();
}
public void setOtherVerifiers(CamMacOtherVerifiers otherVerifiers) {
myCamMac.setOtherVerifiers(otherVerifiers);
}
@Override
protected int encodingBodyLength() throws IOException {
if (bodyLength == -1) {
setAuthzData(myCamMac.encode());
bodyLength = super.encodingBodyLength();
}
return bodyLength;
};
@Override
public void dumpWith(Asn1Dumper dumper, int indents) {
try {
setAuthzData(myCamMac.encode());
} catch (IOException e) {
LOG.error("Failed to set the AD_DATA field. " + e.toString());
}
super.dumpWith(dumper, indents);
dumper.newLine();
myCamMac.dumpWith(dumper, indents + 8);
}
}
| 53 |
End of preview. Expand
in Dataset Viewer.
- Downloads last month
- 44