IPrivateKeyring.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* IPrivateKeyring.java --
  2. Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  3. This file is a part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or (at
  7. your option) any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
  15. USA
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.javax.crypto.keyring;
  32. import java.security.Key;
  33. import java.security.PublicKey;
  34. import java.security.UnrecoverableKeyException;
  35. import java.security.cert.Certificate;
  36. /**
  37. * An interface to private, or "personal", keyrings, which contain private
  38. * credentials. The contract is that each such entry is known by a unique
  39. * <i>alias</i>.
  40. * <p>
  41. * What about public keys? and certificate-path?
  42. */
  43. public interface IPrivateKeyring
  44. extends IKeyring
  45. {
  46. /**
  47. * Tests if this keyring contains a private key entry with the given
  48. * <code>alias</code>.
  49. *
  50. * @param alias The alias to check.
  51. * @return <code>true</code> if this keyring contains a private key with the
  52. * given <code>alias</code>; <code>false</code> otherwise.
  53. */
  54. boolean containsPrivateKey(String alias);
  55. /**
  56. * Returns the private key with the given <code>alias</code>.
  57. *
  58. * @param alias The alias of the private key to find.
  59. * @param password The password of the private key.
  60. * @return The private, or secret, key if one is found; <code>null</code> if
  61. * none were found.
  62. * @throws UnrecoverableKeyException If the private key could not be
  63. * recovered, possibly due to a bad password.
  64. */
  65. Key getPrivateKey(String alias, char[] password)
  66. throws UnrecoverableKeyException;
  67. /**
  68. * Adds a private key to this keyring.
  69. *
  70. * @param alias The alias of the private key.
  71. * @param key The private key.
  72. * @param password The password used to protect this private key.
  73. */
  74. void putPrivateKey(String alias, Key key, char[] password);
  75. /**
  76. * Checks if this keyring contains a public key with the given
  77. * <code>alias</code>.
  78. *
  79. * @param alias The alias to test.
  80. * @return <code>true</code> if this keyring contains a public key entry
  81. * with the given <code>alias</code>; <code>false</code>
  82. * otherwise.
  83. */
  84. boolean containsPublicKey(String alias);
  85. /**
  86. * Returns the public key with the given <code>alias</code>, or
  87. * <code>null</code> if there is no such entry.
  88. *
  89. * @param alias The alias of the public key to find.
  90. * @return The public key; or <code>null</code> if none were found.
  91. */
  92. PublicKey getPublicKey(String alias);
  93. /**
  94. * Sets a public key entry.
  95. *
  96. * @param alias The alias for this public key.
  97. * @param key The public key.
  98. */
  99. void putPublicKey(String alias, PublicKey key);
  100. /**
  101. * Checks if this keyring contains a certificate path with the given
  102. * <code>alias</code>.
  103. *
  104. * @param alias The alias to check.
  105. * @return <code>true</code> if this keyring contains a certificate path
  106. * with the given <code>alias</code>; <code>false</code>
  107. * otherwise.
  108. */
  109. boolean containsCertPath(String alias);
  110. /**
  111. * Returns the certificate path with the given <code>alias</code>, or
  112. * <code>null</code> if there is no such entry.
  113. *
  114. * @param alias The alias of the certificate path to find.
  115. * @return The certificate path for the designated <code>alias</code>; or
  116. * <code>null</code> if none were found.
  117. */
  118. Certificate[] getCertPath(String alias);
  119. /**
  120. * Sets a certificate path entry.
  121. *
  122. * @param alias The alias for this certificate path.
  123. * @param path The certificate path.
  124. */
  125. void putCertPath(String alias, Certificate[] path);
  126. }