Top Description Fields Constructors Methods
org.apache.sshd.certificate

public Class OpenSshCertificateBuilder

extends Object
Class Inheritance
Imports
java.security.KeyPair, .PublicKey, .SecureRandom, java.time.Instant, java.util.ArrayList, .Collection, .Collections, .Comparator, .HashSet, .List, .Map, .Set, java.util.stream.Collectors, org.apache.sshd.common.BaseBuilder, .NamedFactory, org.apache.sshd.common.config.keys.KeyUtils, .OpenSshCertificate, .OpenSshCertificate.Type, .OpenSshCertificateImpl, org.apache.sshd.common.keyprovider.KeyPairProvider, org.apache.sshd.common.random.JceRandom, org.apache.sshd.common.signature.BuiltinSignatures, .Signature, .SignatureFactory, org.apache.sshd.common.util.MapEntryUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.ByteArrayBuffer

Holds all the data necessary to create a signed OpenSSH Certificate

Field Summary

Modifier and TypeField and Description
protected List<OpenSshCertificate.CertificateOption>
protected List<OpenSshCertificate.CertificateOption>
protected String
protected byte[]
protected Collection<String>
protected PublicKey
protected long
protected static final Map<String, String>
protected final OpenSshCertificate.Type
protected long
protected long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public OpenSshCertificateBuilder
public OpenSshCertificateBuilder
public static OpenSshCertificateBuilder
public OpenSshCertificateBuilder
id(String id)

private List<OpenSshCertificate.CertificateOption>

Returns:

a list containing the options in lexical order
lexicallyOrderOptions
(List<OpenSshCertificate.CertificateOption>
the options to order
options
)

Lexically orders certificate options by name.

public OpenSshCertificateBuilder
nonce(byte[] nonce)

public OpenSshCertificateBuilder
public OpenSshCertificateBuilder
publicKey(PublicKey publicKey)

public OpenSshCertificateBuilder
serial(long serial)

public OpenSshCertificate

Returns:

the signed certificate
sign
(KeyPair
CA key used to sign
caKeypair
)

Creates a certificate signed with the given CA key.

public OpenSshCertificate

Returns:

the signed certificate
sign
(KeyPair
CA key used to sign
caKeypair
,
String
to use; if null automatically chosen based on the CA key type
signatureAlgorithm
)

Creates a certificate signed with the given CA key using the specified signature algorithm.

public static OpenSshCertificateBuilder
public OpenSshCertificateBuilder
validAfter(long validAfter)

public OpenSshCertificateBuilder

Returns:

Self reference
validAfter
(Instant
Instant to use for validBefore
validAfter
)

If null, uses OpenSshCertificate#MIN_EPOCH

protected void
private void
validateOptions(List<OpenSshCertificate.CertificateOption>
the options to check
options
)

Validates that there are no duplicate options.

public OpenSshCertificateBuilder
validBefore(long validBefore)

public OpenSshCertificateBuilder

Returns:

Self reference
validBefore
(Instant
Instant to use for validBefore
validBefore
)

If null, uses OpenSshCertificate#INFINITY

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

criticalOptionsback to summary
protected List<OpenSshCertificate.CertificateOption> criticalOptions
extensionsback to summary
protected List<OpenSshCertificate.CertificateOption> extensions
idback to summary
protected String id
nonceback to summary
protected byte[] nonce
principalsback to summary
protected Collection<String> principals
publicKeyback to summary
protected PublicKey publicKey
serialback to summary
protected long serial
SIGNATURE_ALGORITHM_MAPback to summary
protected static final Map<String, String> SIGNATURE_ALGORITHM_MAP
typeback to summary
protected final OpenSshCertificate.Type type
validAfterback to summary
protected long validAfter
validBeforeback to summary
protected long validBefore

Constructor Detail

OpenSshCertificateBuilderback to summary
protected OpenSshCertificateBuilder(OpenSshCertificate.Type type)

Method Detail

criticalOptionsback to summary
public OpenSshCertificateBuilder criticalOptions(List<OpenSshCertificate.CertificateOption> criticalOptions)
extensionsback to summary
public OpenSshCertificateBuilder extensions(List<OpenSshCertificate.CertificateOption> extensions)
hostCertificateback to summary
public static OpenSshCertificateBuilder hostCertificate()
idback to summary
public OpenSshCertificateBuilder id(String id)
lexicallyOrderOptionsback to summary
private List<OpenSshCertificate.CertificateOption> lexicallyOrderOptions(List<OpenSshCertificate.CertificateOption> options)

Lexically orders certificate options by name.

Parameters
options:List<OpenSshCertificate.CertificateOption>

the options to order

Returns:List<OpenSshCertificate.CertificateOption>

a list containing the options in lexical order

nonceback to summary
public OpenSshCertificateBuilder nonce(byte[] nonce)
principalsback to summary
public OpenSshCertificateBuilder principals(Collection<String> principals)
publicKeyback to summary
public OpenSshCertificateBuilder publicKey(PublicKey publicKey)
serialback to summary
public OpenSshCertificateBuilder serial(long serial)
signback to summary
public OpenSshCertificate sign(KeyPair caKeypair) throws Exception

Creates a certificate signed with the given CA key. For RSA keys "rsa-sha2-512" is used for the signature.

Parameters
caKeypair:KeyPair

CA key used to sign

Returns:OpenSshCertificate

the signed certificate

Exceptions
Exception:
if an error occurred
signback to summary
public OpenSshCertificate sign(KeyPair caKeypair, String signatureAlgorithm) throws Exception

Creates a certificate signed with the given CA key using the specified signature algorithm. If a signature algorithm is given, it must be appropriate for the CA key type, otherwise an exception is thrown. If signatureAlgorithm == null, an appropriate signature algorithm is chosen automatically, for RSA keys "rsa-sha2-512" is used then.

Parameters
caKeypair:KeyPair

CA key used to sign

signatureAlgorithm:String

to use; if null automatically chosen based on the CA key type

Returns:OpenSshCertificate

the signed certificate

Exceptions
Exception:
if an error occurred
userCertificateback to summary
public static OpenSshCertificateBuilder userCertificate()
validAfterback to summary
public OpenSshCertificateBuilder validAfter(long validAfter)
validAfterback to summary
public OpenSshCertificateBuilder validAfter(Instant validAfter)

If null, uses OpenSshCertificate#MIN_EPOCH

Parameters
validAfter:Instant

Instant to use for validBefore

Returns:OpenSshCertificateBuilder

Self reference

validateback to summary
protected void validate()
validateOptionsback to summary
private void validateOptions(List<OpenSshCertificate.CertificateOption> options)

Validates that there are no duplicate options.

Parameters
options:List<OpenSshCertificate.CertificateOption>

the options to check

Exceptions
IllegalArgumentException:
if there are duplicates
validBeforeback to summary
public OpenSshCertificateBuilder validBefore(long validBefore)
validBeforeback to summary
public OpenSshCertificateBuilder validBefore(Instant validBefore)

If null, uses OpenSshCertificate#INFINITY

Parameters
validBefore:Instant

Instant to use for validBefore

Returns:OpenSshCertificateBuilder

Self reference