equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 * Portions Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Sun designates this |
7 * published by the Free Software Foundation. Sun designates this |
501 + (keyValue == null || keyValue.length == 0 ? |
501 + (keyValue == null || keyValue.length == 0 ? |
502 " Empty Key" : '\n' + Krb5.hexDumper.encode(keyValue) |
502 " Empty Key" : '\n' + Krb5.hexDumper.encode(keyValue) |
503 + '\n')); |
503 + '\n')); |
504 } |
504 } |
505 |
505 |
|
506 /** |
|
507 * Find a key with given etype |
|
508 */ |
506 public static EncryptionKey findKey(int etype, EncryptionKey[] keys) |
509 public static EncryptionKey findKey(int etype, EncryptionKey[] keys) |
|
510 throws KrbException { |
|
511 return findKey(etype, null, keys); |
|
512 } |
|
513 |
|
514 /** |
|
515 * Find a key with given etype and kvno |
|
516 * @param kvno if null, return any (first?) key |
|
517 */ |
|
518 public static EncryptionKey findKey(int etype, Integer kvno, EncryptionKey[] keys) |
507 throws KrbException { |
519 throws KrbException { |
508 |
520 |
509 // check if encryption type is supported |
521 // check if encryption type is supported |
510 if (!EType.isSupported(etype)) { |
522 if (!EType.isSupported(etype)) { |
511 throw new KrbException("Encryption type " + |
523 throw new KrbException("Encryption type " + |
514 |
526 |
515 int ktype; |
527 int ktype; |
516 for (int i = 0; i < keys.length; i++) { |
528 for (int i = 0; i < keys.length; i++) { |
517 ktype = keys[i].getEType(); |
529 ktype = keys[i].getEType(); |
518 if (EType.isSupported(ktype)) { |
530 if (EType.isSupported(ktype)) { |
519 if (etype == ktype) { |
531 Integer kv = keys[i].getKeyVersionNumber(); |
|
532 if (etype == ktype && (kvno == null || kvno.equals(kv))) { |
520 return keys[i]; |
533 return keys[i]; |
521 } |
534 } |
522 } |
535 } |
523 } |
536 } |
524 // Key not found. |
537 // Key not found. |
526 if ((etype == EncryptedData.ETYPE_DES_CBC_CRC || |
539 if ((etype == EncryptedData.ETYPE_DES_CBC_CRC || |
527 etype == EncryptedData.ETYPE_DES_CBC_MD5)) { |
540 etype == EncryptedData.ETYPE_DES_CBC_MD5)) { |
528 for (int i = 0; i < keys.length; i++) { |
541 for (int i = 0; i < keys.length; i++) { |
529 ktype = keys[i].getEType(); |
542 ktype = keys[i].getEType(); |
530 if (ktype == EncryptedData.ETYPE_DES_CBC_CRC || |
543 if (ktype == EncryptedData.ETYPE_DES_CBC_CRC || |
531 ktype == EncryptedData.ETYPE_DES_CBC_MD5) { |
544 ktype == EncryptedData.ETYPE_DES_CBC_MD5) { |
532 return new EncryptionKey(etype, keys[i].getBytes()); |
545 Integer kv = keys[i].getKeyVersionNumber(); |
|
546 if (kvno == null || kvno.equals(kv)) { |
|
547 return new EncryptionKey(etype, keys[i].getBytes()); |
|
548 } |
533 } |
549 } |
534 } |
550 } |
535 } |
551 } |
536 return null; |
552 return null; |
537 } |
553 } |