Class OperatorIdentity

java.lang.Object
org.cloudburstmc.netty.util.nethernet.OperatorIdentity

public class OperatorIdentity extends Object
The key an operator signs NetherNet identity assertions with, and the name players see it under.

A server presents it in every answer. A client presents it in its offer, derived for the player it connects on behalf of with forPlayer(java.lang.String, java.lang.String), which is what a proxy does toward a downstream server.

See Also:
  • Constructor Details

    • OperatorIdentity

      public OperatorIdentity(PrivateKey privateKey, PublicKey publicKey, Instant expiry, String domain) throws org.jose4j.lang.JoseException
      Throws:
      org.jose4j.lang.JoseException
  • Method Details

    • fromToken

      public static OperatorIdentity fromToken(KeyPair keyPair, String token, String domain)
      An identity whose token an auth service issued for the key, as a retail client's multiplayer token is: what a client presents to a server that validates against Minecraft's auth service rather than trusting the peer's own signature. The key has to be the one the token's cpk claim names, or the fingerprint signature will not verify.
      Parameters:
      keyPair - The key the token was issued for
      token - The compact JWT the auth service issued, carrying cpk, xid and xname
      domain - The identity provider named in the assertion
      Returns:
      An identity presenting that token
    • generate

      public static OperatorIdentity generate(String domain) throws org.jose4j.lang.JoseException
      Generate a brand-new server identity that is not stored
      Parameters:
      domain - The domain name for the server identity
      Returns:
      A new OperatorIdentity instance
      Throws:
      org.jose4j.lang.JoseException - If there is an error creating the JWT
    • fromPem

      public static OperatorIdentity fromPem(File pem, String domain) throws GeneralSecurityException, IOException, org.jose4j.lang.JoseException
      Loads the keypair from an unencrypted PEM private key, either SEC1 EC PRIVATE KEY or PKCS#8 PRIVATE KEY. The key must carry its public point, which OpenSSL includes by default and the standard library cannot recover from the scalar. A PEM has no expiry, so the token is issued without one.
      Parameters:
      pem - The PEM file
      domain - The domain name for the server identity, as a PEM carries no subject
      Returns:
      The loaded OperatorIdentity
      Throws:
      GeneralSecurityException - If the key is malformed or not on P-384
      IOException - If there is an I/O error
      org.jose4j.lang.JoseException - If there is an error creating the JWT
    • fromPemOrCreate

      public static OperatorIdentity fromPemOrCreate(File pem, String domain) throws GeneralSecurityException, IOException, org.jose4j.lang.JoseException
      Loads the identity from a PEM private key, creating a new P-384 key there on first use.

      The file is created readable only by its owner and is never replaced once it exists, because clients pin the public key and a new one prompts every returning player again.

      Parameters:
      pem - The PEM file to load or create
      domain - The identity domain, as a PEM carries no subject
      Returns:
      The loaded OperatorIdentity
      Throws:
      GeneralSecurityException - If the key is malformed or not on P-384
      IOException - If there is an I/O error
      org.jose4j.lang.JoseException - If there is an error creating the JWT
    • publicKey

      public PublicKey publicKey()
      The key players pin this operator by, for fingerprints and fleet checks.
      Returns:
      The public key
    • forPlayer

      public OperatorIdentity forPlayer(String xuid, String name) throws org.jose4j.lang.JoseException
      This identity acting for a player, for the offer a client sends on their behalf. The token names the player and expires, so derive one per connection rather than keeping it.
      Parameters:
      xuid - The player's XUID, which the server reads as xid
      name - The player's name, read as xname
      Returns:
      An identity with the same key and domain whose token carries the player
      Throws:
      org.jose4j.lang.JoseException - If there is an error signing the token
    • withAssertion

      public String withAssertion(String sdp) throws org.jose4j.lang.JoseException
      Inserts this identity's assertion into a description, offer or answer. The description has to be finished, because a peer checks the signature against exactly the fingerprints it receives, and the attribute goes ahead of the first media line as the spec requires.
      Parameters:
      sdp - The description without an identity line
      Returns:
      The description with the identity inserted
      Throws:
      org.jose4j.lang.JoseException - If there is an error signing