Class LicenseSigner

java.lang.Object
com.iizix.license.v2.LicenseSigner

public final class LicenseSigner extends Object
The issuing half of LICENSE-V2-DESIGN.md sections 2.2 and 2.4: the canonical payload bytes, the envelope and the Ed25519 signature. Two roles, told apart by the constructor:

The signer takes a PrivateKey and loads nothing: where the key comes from (the PKCS#8 file under /etc/iizi/mls/, the refusal of a file open to group or others) is the MLS's business in B-5b. An installation's own proofs (5.2, 5.4) need no signer: they are Ed25519.sign(PrivateKey, byte[]) over the bytes of Hello.

What the verifier's step 3 would refuse is refused here before it is signed: a payload with an unknown key, a missing required key or a value in another spelling is an IllegalArgumentException naming the rule.

Author:
Christopher Mindus
  • Constructor Details

    • LicenseSigner

      public LicenseSigner(String kid, PrivateKey key)
      Constructor for a root, or for a key whose certificate is not at hand: signs certificates and raw bytes, never a document.
      Parameters:
      kid - This key's ID, the kid line of what it signs.
      key - The Ed25519 private key.
      Throws:
      IllegalArgumentException - If the key ID is malformed or the key is not an Ed25519 key.
    • LicenseSigner

      public LicenseSigner(PrivateKey key, KeyCertificate certificate)
      Constructor for the MLS signing key: signs documents with its certificate in them.
      Parameters:
      key - The Ed25519 private key.
      certificate - Its certificate, verified under the pinned roots.
      Throws:
      IllegalArgumentException - If the key is not an Ed25519 key, or the certificate does not certify this key (a signature made here does not verify under the certified key).
  • Method Details

    • getKeyID

      public String getKeyID()
      Gets this key's ID.
      Returns:
      The key ID.
    • getCertificate

      public KeyCertificate getCertificate()
      Gets the certificate.
      Returns:
      The certificate, or null for a root.
    • sign

      public byte[] sign(byte[] bytes)
      Signs bytes: the MLS's hello proof over Hello.mlsHello(byte[], byte[], UUID).
      Parameters:
      bytes - The bytes.
      Returns:
      The 64-byte signature.
    • signCertificate

      public byte[] signCertificate(String keyID, PublicKey certified, Instant notBefore, Instant notAfter)
      Signs a key certificate: this key is the root, the kid line of the envelope.
      Parameters:
      keyID - The certified key's ID.
      certified - The certified Ed25519 public key.
      notBefore - The first instant the certificate is valid.
      notAfter - The last instant the certificate is valid; a year after notBefore for an MLS signing key (2.4).
      Returns:
      The IIZI-KEYCERT/1 envelope bytes.
      Throws:
      IllegalArgumentException - If the key ID is malformed, the key is not an Ed25519 key on the curve, or notBefore is after notAfter.
    • signDocument

      public byte[] signDocument(Map<String,String> payload)
      Signs a licence document: the payload in its one byte form, this key's signature over it, this key's certificate.
      Parameters:
      payload - The keys and values of LicenseDocument; v may be absent and is then written as 2.
      Returns:
      The IIZI-LICENSE/2 envelope bytes.
      Throws:
      IllegalStateException - If this signer has no certificate (a root).
      IllegalArgumentException - If v is present and not 2, or the payload is not one the verifier's step 3 accepts: the message names the rule.