|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ka2ddo.yaac.auth.YAACKeyManager
public class YAACKeyManager
This class stores encryption keys used for signing and verifying messages. There are two meanings of signing:
This class is the repository for keys used for this signing and verifying, backed by a Java keystore. It supports:
It also provides the APRS message signing and verifying logic, and provides a means to associate other station's callsigns with keys and certificates. This class also provides services to create, export, import, and delete keys and certificates.
This is based on research reported by Bryan Hoyer KG6GEU in a presentation to the NW Digital Radio group on 2013-Mar-31
Nested Class Summary | |
---|---|
static class |
YAACKeyManager.KeyType
Enumeration identifying different types of encryption keys that can be stored in the KeyManager. |
Method Summary | |
---|---|
java.lang.String |
chooseClientAlias(java.lang.String[] keyTypes,
java.security.Principal[] principals,
java.net.Socket socket)
|
java.lang.String |
chooseServerAlias(java.lang.String algChoice,
java.security.Principal[] principals,
java.net.Socket socket)
|
void |
createSecretKey(java.lang.String alias)
Create a new secret (symmetric) key. |
void |
deleteKey(java.lang.String alias)
Delete a key from the local keystore. |
boolean |
doesKeystoreExistYet()
Test if the keystore has been created yet, |
java.lang.String[] |
findMatchingKeys(MessageMessage mm)
Search the keystore for keys that match the destination addressee of the specified message. |
java.lang.String[] |
findMatchingKeys(java.lang.String callsign,
YAACKeyManager.KeyType keyType)
Search the keystore for keys that match the destination addressee of the specified message. |
java.lang.String[] |
getAliases()
Get all key aliases stored in the keystore. |
java.lang.String[] |
getAssociations(java.lang.String alias)
Get all the associated callsigns allowed to use the key specified by the alias. |
java.security.cert.X509Certificate[] |
getCertificateChain(java.lang.String alias)
|
java.lang.String[] |
getClientAliases(java.lang.String algChoice,
java.security.Principal[] principals)
|
static YAACKeyManager |
getInstance()
Get the KeyManager singleton. |
java.security.Key |
getKey(java.lang.String alias)
Get the key associated with the specified alias. |
YAACKeyManager.KeyType |
getKeyType(java.lang.String alias)
Get the type of key associated with the specified alias. |
java.security.PrivateKey |
getPrivateKey(java.lang.String alias)
Get the PrivateKey associated with the specified alias. |
java.lang.String[] |
getServerAliases(java.lang.String algChoice,
java.security.Principal[] principals)
|
void |
insertPrivateKey(java.lang.String alias,
java.security.PrivateKey key,
java.security.cert.Certificate[] certs)
Insert a private key with its associated public key certificate chain. |
void |
insertPublicCertificateChain(java.lang.String alias,
java.security.cert.CertPath chain)
Store the public key certificates for some other station into the keystore. |
void |
insertSecretKey(java.lang.String alias,
byte[] encoded)
Store a byte-encoded secret (symmetric) key in the keystore. |
boolean |
isPasswordSet()
Test if the backing keystore's password has been set. |
static void |
main(java.lang.String[] args)
unit test. |
void |
setAssociations(java.lang.String alias,
java.lang.String[] associations)
Get all the associated callsigns allowed to use the key specified by the alias. |
void |
setPassword(char[] password)
Set the password to be used to decode keys in the backing keystore. |
void |
sign(AprsSignableMessage mm,
java.lang.String alias)
Sign a timestamped APRS message with the specified key. |
SignableMessage.SignatureState |
verify(AprsSignableMessage mm)
Verify the signature (if any) in an APRS message against the keys in the local keystore. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static YAACKeyManager getInstance()
public boolean isPasswordSet()
public void setPassword(char[] password) throws java.lang.NullPointerException, java.io.IOException, java.security.GeneralSecurityException
password
- char array of the password
java.lang.NullPointerException
- if password was null
java.io.IOException
- if keystore file could not be read for any reason
java.security.GeneralSecurityException
- if keystore file could not be decoded for any reasonpublic boolean doesKeystoreExistYet()
public java.security.Key getKey(java.lang.String alias) throws java.lang.NullPointerException
alias
- String alias name for a key
java.lang.NullPointerException
- if the keystore's password was not successfully set yetpublic java.lang.String[] getAliases() throws java.lang.NullPointerException
java.lang.NullPointerException
- if the keystore's password was not successfully set yetpublic YAACKeyManager.KeyType getKeyType(java.lang.String alias) throws java.lang.NullPointerException
alias
- String name associated with the desired key
java.lang.NullPointerException
- if the keystore's password was not successfully set yetpublic java.lang.String[] getAssociations(java.lang.String alias)
alias
- String name of the key to query
public void setAssociations(java.lang.String alias, java.lang.String[] associations)
alias
- String name of the key to modifyassociations
- array of callsign Strings to associate with named keypublic void createSecretKey(java.lang.String alias) throws java.lang.NullPointerException, java.security.KeyStoreException
alias
- String name to label the key
java.lang.NullPointerException
- if keystore password hasn't been correctly set yet
java.security.KeyStoreException
- if key can't be stored in backing keystore filepublic void insertSecretKey(java.lang.String alias, byte[] encoded) throws java.lang.NullPointerException, java.security.KeyStoreException
alias
- String name to associate with keyencoded
- byte array of the encoded key
java.lang.NullPointerException
- if keystore password hasn't been correctly set yet
java.security.KeyStoreException
- if key can't be stored in backing keystore filepublic void insertPublicCertificateChain(java.lang.String alias, java.security.cert.CertPath chain)
alias
- String name to associate with this public keychain
- array of Certificates containing the public key and identifying the issuers up to
the certificate authoritypublic void insertPrivateKey(java.lang.String alias, java.security.PrivateKey key, java.security.cert.Certificate[] certs) throws java.security.KeyStoreException
alias
- String name to associate with this key pairkey
- PrivateKeycerts
- array of Certificates listing the public key associated with the private key and the
issuers up to the certificate authority
java.security.KeyStoreException
- if the key pair could not be storedpublic void deleteKey(java.lang.String alias) throws java.security.KeyStoreException, java.io.IOException
alias
- String name of the key
java.security.KeyStoreException
- if the keystore can't be modified
java.io.IOException
- if the altered keystore can't be checkpointed to the backing disk filepublic java.lang.String[] findMatchingKeys(MessageMessage mm)
mm
- APRS text MessageMessage whose destination should be looked up
public java.lang.String[] findMatchingKeys(java.lang.String callsign, YAACKeyManager.KeyType keyType)
callsign
- String callsign to be matched against the known keyskeyType
- KeyType of keys to be searched for, or null to search for all types
public void sign(AprsSignableMessage mm, java.lang.String alias) throws java.lang.NullPointerException, java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.security.GeneralSecurityException
mm
- MessageMessage to signalias
- String name of key to use for signature
java.lang.NullPointerException
- if keystore password hasn't been correctly set yet
java.lang.IllegalStateException
- if message has already been signed
java.lang.IllegalArgumentException
- if no such key for specified alias
java.security.GeneralSecurityException
- if key does not exist or signature algorithm doesn't work or isn't availablepublic SignableMessage.SignatureState verify(AprsSignableMessage mm) throws java.security.GeneralSecurityException
mm
- MessageMessage to verify
java.security.GeneralSecurityException
- if key does not exist or signature algorithm doesn't work or isn't availablepublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- String array, [0] = password, [1] = alias to use for test
java.lang.Exception
- if test failspublic java.lang.String chooseClientAlias(java.lang.String[] keyTypes, java.security.Principal[] principals, java.net.Socket socket)
chooseClientAlias
in interface javax.net.ssl.X509KeyManager
public java.lang.String[] getClientAliases(java.lang.String algChoice, java.security.Principal[] principals)
getClientAliases
in interface javax.net.ssl.X509KeyManager
public java.lang.String[] getServerAliases(java.lang.String algChoice, java.security.Principal[] principals)
getServerAliases
in interface javax.net.ssl.X509KeyManager
public java.lang.String chooseServerAlias(java.lang.String algChoice, java.security.Principal[] principals, java.net.Socket socket)
chooseServerAlias
in interface javax.net.ssl.X509KeyManager
public java.security.cert.X509Certificate[] getCertificateChain(java.lang.String alias)
getCertificateChain
in interface javax.net.ssl.X509KeyManager
public java.security.PrivateKey getPrivateKey(java.lang.String alias) throws java.lang.NullPointerException
getPrivateKey
in interface javax.net.ssl.X509KeyManager
alias
- String name of key to look up
java.lang.NullPointerException
- if the keystore has not been opened yet
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |