Package net.dona.doip.util.tls

## Class AutoSelfSignedKeyManager

- java.lang.Object
- - javax.net.ssl.X509ExtendedKeyManager
  - - net.dona.doip.util.tls.AutoSelfSignedKeyManager

- All Implemented Interfaces:
    `javax.net.ssl.KeyManager`, `javax.net.ssl.X509KeyManager`

      public class AutoSelfSignedKeyManager
      extends javax.net.ssl.X509ExtendedKeyManager

  This object is used to provide a private key for authentication to the other side of a secure socket connection.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AutoSelfSignedKeyManager​(java.lang.String id)` | Constructs a key manager for the supplied identity with a newly minted keypair.
    `AutoSelfSignedKeyManager​(java.lang.String id, java.security.cert.X509Certificate[] chain, java.security.PrivateKey privKey)` | Constructs a key manager corresponding to the supplied certificate chain and private key.
    `AutoSelfSignedKeyManager​(java.lang.String id, java.security.cert.X509Certificate cert, java.security.PrivateKey privKey)` | Constructs a key manager corresponding to the supplied certificate and private key.
    `AutoSelfSignedKeyManager​(java.lang.String id, java.security.PublicKey pubKey, java.security.PrivateKey privKey)` | Constructs a key manager corresponding the the supplied keypair.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `java.lang.String` | `chooseClientAlias​(java.lang.String[] keyTypes, java.security.Principal[] issuers, java.net.Socket socket)` |
    `java.lang.String` | `chooseEngineClientAlias​(java.lang.String[] as, java.security.Principal[] aprincipal, javax.net.ssl.SSLEngine sslengine)` |
    `java.lang.String` | `chooseEngineServerAlias​(java.lang.String s, java.security.Principal[] aprincipal, javax.net.ssl.SSLEngine sslengine)` |
    `java.lang.String` | `chooseServerAlias​(java.lang.String keyType, java.security.Principal[] issuers, java.net.Socket socket)` |
    `java.security.cert.X509Certificate` | `getCertificate()` | Returns the certificate (supplied or generated).
    `java.security.cert.X509Certificate[]` | `getCertificateChain​(java.lang.String alias)` |
    `java.lang.String[]` | `getClientAliases​(java.lang.String keyType, java.security.Principal[] issuers)` |
    `java.security.PrivateKey` | `getPrivateKey​(java.lang.String alias)` |
    `java.lang.String[]` | `getServerAliases​(java.lang.String keyType, java.security.Principal[] issuers)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AutoSelfSignedKeyManager

          public AutoSelfSignedKeyManager​(java.lang.String id,
                                          java.security.cert.X509Certificate[] chain,
                                          java.security.PrivateKey privKey)

      Constructs a key manager corresponding to the supplied certificate chain and private key.
      Parameters:
        `id` - the identifier of the entity
        `chain` - the certificate chain of the entity
        `privKey` - the private key of the entity

    - #### AutoSelfSignedKeyManager

          public AutoSelfSignedKeyManager​(java.lang.String id,
                                          java.security.cert.X509Certificate cert,
                                          java.security.PrivateKey privKey)

      Constructs a key manager corresponding to the supplied certificate and private key.
      Parameters:
        `id` - the identifier of the entity
        `cert` - the certificate of the entity
        `privKey` - the private key of the entity

    - #### AutoSelfSignedKeyManager

          public AutoSelfSignedKeyManager​(java.lang.String id,
                                          java.security.PublicKey pubKey,
                                          java.security.PrivateKey privKey)

      Constructs a key manager corresponding the the supplied keypair. A self-signed certificate will be generated with the appropriate id.
      Parameters:
        `id` - the identifier of the entity
        `pubKey` - the public key of the entity
        `privKey` - the private key of the entity

    - #### AutoSelfSignedKeyManager

          public AutoSelfSignedKeyManager​(java.lang.String id)
                                   throws java.lang.Exception

      Constructs a key manager for the supplied identity with a newly minted keypair.
      Parameters:
        `id` - the identifier of the entity
      Throws:
        `java.lang.Exception` - if there is any issue minting a keypair

  - ### Method Detail

    - #### getCertificate

          public java.security.cert.X509Certificate getCertificate()

      Returns the certificate (supplied or generated).
      Returns:
        the certificate

    - #### chooseClientAlias

          public java.lang.String chooseClientAlias​(java.lang.String[] keyTypes,
                                                    java.security.Principal[] issuers,
                                                    java.net.Socket socket)

    - #### chooseServerAlias

          public java.lang.String chooseServerAlias​(java.lang.String keyType,
                                                    java.security.Principal[] issuers,
                                                    java.net.Socket socket)

    - #### getServerAliases

          public java.lang.String[] getServerAliases​(java.lang.String keyType,
                                                     java.security.Principal[] issuers)

    - #### getCertificateChain

          public java.security.cert.X509Certificate[] getCertificateChain​(java.lang.String alias)

    - #### getClientAliases

          public java.lang.String[] getClientAliases​(java.lang.String keyType,
                                                     java.security.Principal[] issuers)

    - #### getPrivateKey

          public java.security.PrivateKey getPrivateKey​(java.lang.String alias)

    - #### chooseEngineClientAlias

          public java.lang.String chooseEngineClientAlias​(java.lang.String[] as,
                                                          java.security.Principal[] aprincipal,
                                                          javax.net.ssl.SSLEngine sslengine)

      Overrides:
        `chooseEngineClientAlias` in class `javax.net.ssl.X509ExtendedKeyManager`

    - #### chooseEngineServerAlias

          public java.lang.String chooseEngineServerAlias​(java.lang.String s,
                                                          java.security.Principal[] aprincipal,
                                                          javax.net.ssl.SSLEngine sslengine)

      Overrides:
        `chooseEngineServerAlias` in class `javax.net.ssl.X509ExtendedKeyManager`