Class AppSigner
- java.lang.Object
-
- com.microej.util.appsigner.AppSigner
-
public class AppSigner extends java.lang.ObjectSigns MicroEJ Application binaries (.fo) so that MicroEJ Kernels can verify them before installation.A signer is created either directly from a signing key and its certificate path, or from a keystore file through
fromKeyStoreFile(java.lang.String, java.nio.file.Path, java.lang.String, java.lang.String, java.lang.String). The certificate path, ordered from the CA certificate to the user certificate, is validated when the signer is created. Both RSA (SHA256withRSA) and ECDSA (SHA256withECDSA) signing keys are supported.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description AppSigner(java.security.PrivateKey signingKey, java.util.List<java.security.cert.Certificate> certPath)Creates a signer from the given signing key and certificate path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AppSignerfromKeyStoreFile(java.lang.String keyStoreType, java.nio.file.Path keyStorePath, java.lang.String keyStorePassword, java.lang.String signingKeyAlias, java.lang.String signingKeyPassword)Creates a signer from a signing key stored in a keystore file.java.io.InputStreamsign(java.io.InputStream applicationBinary, java.lang.String appId, java.lang.String appVersion)Signs the given Application binary and returns the resulting signed Application binary as a stream.voidsign(java.nio.file.Path applicationBinaryPath, java.lang.String appId, java.lang.String appVersion, java.nio.file.Path signedApplicationBinaryPath)Signs the Application binary at the given path and writes the resulting signed Application binary.static voidverify(java.io.InputStream signedApplicationBinary)Verifies the given signed Application binary.static voidverify(java.nio.file.Path signedApplicationBinaryPath)Verifies the signed Application binary at the given path.
-
-
-
Constructor Detail
-
AppSigner
public AppSigner(java.security.PrivateKey signingKey, java.util.List<java.security.cert.Certificate> certPath) throws java.security.GeneralSecurityExceptionCreates a signer from the given signing key and certificate path.The given certificate path must be ordered from the CA certificate up to the user certificate; it is validated immediately.
- Parameters:
signingKey- the private key used to sign Application binaries (an RSA or EC key).certPath- the certificate chain, ordered from the CA certificate to the user certificate.- Throws:
java.security.GeneralSecurityException- if the given certificate path is not properly ordered or cannot be validated.- Since:
- 2.0
-
-
Method Detail
-
fromKeyStoreFile
public static AppSigner fromKeyStoreFile(java.lang.String keyStoreType, java.nio.file.Path keyStorePath, java.lang.String keyStorePassword, java.lang.String signingKeyAlias, @Nullable java.lang.String signingKeyPassword) throws java.security.GeneralSecurityException, java.io.IOException
Creates a signer from a signing key stored in a keystore file.The signing key and its certificate chain are loaded from the keystore using the given alias. The chain returned by the keystore is ordered with the user certificate first; it is reversed so that the resulting signer holds it ordered from the CA certificate to the user certificate.
- Parameters:
keyStoreType- the type of the keystore (for exampleJKSorPKCS12).keyStorePath- the path of the keystore file.keyStorePassword- the password protecting the keystore.signingKeyAlias- the alias of the signing key and its certificate chain in the keystore.signingKeyPassword- the password protecting the signing key, ornullto reuse the keystore password.- Returns:
- a signer holding the signing key and certificate path loaded from the keystore.
- Throws:
java.security.GeneralSecurityException- if the keystore cannot be loaded, the alias does not resolve to a private key and a certificate chain, or the certificate path cannot be validated.java.io.IOException- if the keystore file cannot be read.- Since:
- 2.0
-
sign
public void sign(java.nio.file.Path applicationBinaryPath, java.lang.String appId, java.lang.String appVersion, java.nio.file.Path signedApplicationBinaryPath) throws java.security.GeneralSecurityException, java.io.IOExceptionSigns the Application binary at the given path and writes the resulting signed Application binary.- Parameters:
applicationBinaryPath- the path of the Application binary (.fo) to sign.appId- the identifier of the application to install.appVersion- the version of the application to install.signedApplicationBinaryPath- the path of the signed Application binary (.fo.signed) to write.- Throws:
java.security.GeneralSecurityException- if the signing key algorithm is not supported or the Application binary cannot be signed.java.io.IOException- if the Application binary cannot be read or the signed Application binary cannot be written.- Since:
- 2.0
-
sign
public java.io.InputStream sign(java.io.InputStream applicationBinary, java.lang.String appId, java.lang.String appVersion) throws java.security.GeneralSecurityException, java.io.IOExceptionSigns the given Application binary and returns the resulting signed Application binary as a stream.The given stream is read fully but is not closed; the caller keeps its ownership.
- Parameters:
applicationBinary- the Application binary (.fo) to sign.appId- the identifier of the application to install.appVersion- the version of the application to install.- Returns:
- the signed Application binary as a stream.
- Throws:
java.security.GeneralSecurityException- if the signing key algorithm is not supported or the Application binary cannot be signed.java.io.IOException- if the Application binary cannot be read or the signed command cannot be encoded.- Since:
- 2.0
-
verify
public static void verify(java.nio.file.Path signedApplicationBinaryPath) throws java.security.GeneralSecurityException, java.io.IOExceptionVerifies the signed Application binary at the given path.This is a host-side structural check of a signing output: it confirms that the binary parses, that its embedded certificate path is internally consistent, and that its signature matches the embedded signer certificate. It is not a trust decision: it resolves no trust anchor and checks no certificate expiration or revocation. The trust verification before installation is performed by the
app-verifierlibrary, not here.- Parameters:
signedApplicationBinaryPath- the path of the signed Application binary (.fo.signed) to verify.- Throws:
java.security.GeneralSecurityException- if the signed Application binary cannot be parsed, its certificate path cannot be validated, or its signature does not verify.java.io.IOException- if the signed Application binary cannot be read.- Since:
- 2.0
-
verify
public static void verify(java.io.InputStream signedApplicationBinary) throws java.security.GeneralSecurityException, java.io.IOExceptionVerifies the given signed Application binary.This is a host-side structural check of a signing output: it confirms that the binary parses, that its embedded certificate path is internally consistent, and that its signature matches the embedded signer certificate. It is not a trust decision: it resolves no trust anchor and checks no certificate expiration or revocation. The trust verification before installation is performed by the
app-verifierlibrary, not here.The given stream is read fully but is not closed; the caller keeps its ownership.
- Parameters:
signedApplicationBinary- the signed Application binary (.fo.signed) to verify.- Throws:
java.security.GeneralSecurityException- if the signed Application binary cannot be parsed, its certificate path cannot be validated, or its signature does not verify.java.io.IOException- if the signed Application binary cannot be read.- Since:
- 2.0
-
-