@Test void testASNEncoderGetASNEncodedKrbPrincipalKey() throws Exception { final int keyType17 = 17; final int keyType18 = 18; final int saltType = 4; GetActorWorkloadCredentialsResponse.Builder respBuilder = GetActorWorkloadCredentialsResponse.getDefaultInstance().toBuilder(); respBuilder.addKerberosKeysBuilder(0) .setSaltType(saltType) .setKeyType(keyType17) .setKeyValue("testKeyValue17") .setSaltValue("NonIodizedGrainOfSalt") .build(); respBuilder.addKerberosKeysBuilder(1) .setSaltType(saltType) .setKeyType(keyType18) .setKeyValue("testKeyValue18") .setSaltValue("IodizedGrainOfSalt") .build(); String expectedValue = "MIGLoAMCAQGhAwIBAaIDAgEBowMCAQGkdTBzMDmgIDAeoAMCAQShFwQVTm9uSW9kaXplZE" + "dyYWluT2ZTYWx0oRUwE6ADAgERoQwECrXrLSnslWpbntcwNqAdMBugAwIBBKEUBBJJb2RpemVkR3JhaW5PZlNhbHShFTAToAMCARKhDAQKtestKeyValue1w=="; String encodedValue = KrbKeySetEncoder.getASNEncodedKrbPrincipalKey(respBuilder.getKerberosKeysList()); assertEquals(expectedValue, encodedValue, "Must be equal"); }
public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException { ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()]; for (int i = 0; i < keys.size(); i++) { ActorKerberosKey key = keys.get(i); byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8)); asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue)); } DERSequence krbKeys = new DERSequence(asn1Encodables); DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_MKVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) }); return Base64.getEncoder().encodeToString(krbKeySet.getEncoded()); }
KrbKeySetEncoder { public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException { ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()]; for (int i = 0; i < keys.size(); i++) { ActorKerberosKey key = keys.get(i); byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8)); asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue)); } DERSequence krbKeys = new DERSequence(asn1Encodables); DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_MKVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) }); return Base64.getEncoder().encodeToString(krbKeySet.getEncoded()); } }
KrbKeySetEncoder { public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException { ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()]; for (int i = 0; i < keys.size(); i++) { ActorKerberosKey key = keys.get(i); byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8)); asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue)); } DERSequence krbKeys = new DERSequence(asn1Encodables); DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_MKVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) }); return Base64.getEncoder().encodeToString(krbKeySet.getEncoded()); } private  KrbKeySetEncoder(); }
KrbKeySetEncoder { public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException { ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()]; for (int i = 0; i < keys.size(); i++) { ActorKerberosKey key = keys.get(i); byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8)); asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue)); } DERSequence krbKeys = new DERSequence(asn1Encodables); DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_MKVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) }); return Base64.getEncoder().encodeToString(krbKeySet.getEncoded()); } private  KrbKeySetEncoder(); static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys); }
KrbKeySetEncoder { public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException { ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()]; for (int i = 0; i < keys.size(); i++) { ActorKerberosKey key = keys.get(i); byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8)); asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue)); } DERSequence krbKeys = new DERSequence(asn1Encodables); DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_MKVNO, new DERInteger(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) }); return Base64.getEncoder().encodeToString(krbKeySet.getEncoded()); } private  KrbKeySetEncoder(); static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys);  }