Class PushCertificateParser

java.lang.Object
org.eclipse.jgit.transport.PushCertificateParser

public class PushCertificateParser extends Object
Parser for signed push certificates.
Since:
4.0
  • Field Details

  • Constructor Details

    • PushCertificateParser

      public PushCertificateParser(Repository into, SignedPushConfig cfg)

      Constructor for PushCertificateParser.

      Parameters:
      into - destination repository for the push.
      cfg - configuration for signed push.
      Since:
      4.1
    • PushCertificateParser

      private PushCertificateParser()
  • Method Details

    • fromReader

      public static PushCertificate fromReader(Reader r) throws PackProtocolException, IOException
      Parse a push certificate from a reader.

      Differences from the PacketLineIn receiver methods:

      • Does not use pkt-line framing.
      • Reads an entire cert in one call rather than depending on a loop in the caller.
      • Does not assume a "push-cert-end" line.
      Parameters:
      r - input reader; consumed only up until the end of the next signature in the input.
      Returns:
      the parsed certificate, or null if the reader was at EOF.
      Throws:
      PackProtocolException - if the certificate is malformed.
      IOException - if there was an error reading from the input.
      Since:
      4.1
    • fromString

      public static PushCertificate fromString(String str) throws PackProtocolException, IOException
      Parse a push certificate from a string.
      Parameters:
      str - input string.
      Returns:
      the parsed certificate.
      Throws:
      PackProtocolException - if the certificate is malformed.
      IOException - if there was an error reading from the input.
      Since:
      4.1
      See Also:
    • parse

      Parse a push certificate from a reader.
      Parameters:
      r - input reader; consumed only up until the end of the next signature in the input.
      Returns:
      the parsed certificate, or null if the reader was at EOF.
      Throws:
      PackProtocolException - if the certificate is malformed.
      IOException - if there was an error reading from the input.
      Since:
      4.1
      See Also:
    • build

      public PushCertificate build() throws IOException
      Build the parsed certificate
      Returns:
      the parsed certificate, or null if push certificates are disabled.
      Throws:
      IOException - if the push certificate has missing or invalid fields.
      Since:
      4.1
    • enabled

      public boolean enabled()
      Whether the repository is configured to use signed pushes in this context.
      Returns:
      if the repository is configured to use signed pushes in this context.
      Since:
      4.0
    • getAdvertiseNonce

      public String getAdvertiseNonce()
      Get the whole string for the nonce to be included into the capability advertisement
      Returns:
      the whole string for the nonce to be included into the capability advertisement, or null if push certificates are disabled.
      Since:
      4.0
    • sentNonce

      private String sentNonce()
    • parseHeader

      private static String parseHeader(PushCertificateParser.StringReader reader, String header) throws IOException
      Throws:
      IOException
    • parseHeader

      private static String parseHeader(String s, String header) throws IOException
      Throws:
      IOException
    • receiveHeader

      public void receiveHeader(PacketLineIn pckIn, boolean stateless) throws IOException
      Receive a list of commands from the input encapsulated in a push certificate.

      This method doesn't parse the first line "push-cert \NUL <capabilities>", but assumes the first line including the capabilities has already been handled by the caller.

      Parameters:
      pckIn - where we take the push certificate header from.
      stateless - affects nonce verification. When stateless = true the NonceGenerator will allow for some time skew caused by clients disconnected and reconnecting in the stateless smart HTTP protocol.
      Throws:
      IOException - if the certificate from the client is badly malformed or the client disconnects before sending the entire certificate.
      Since:
      4.0
    • receiveHeader

      private void receiveHeader(PushCertificateParser.StringReader reader, boolean stateless) throws IOException
      Throws:
      IOException
    • receiveSignature

      public void receiveSignature(PacketLineIn pckIn) throws IOException
      Read the PGP signature.

      This method assumes the line "-----BEGIN PGP SIGNATURE-----" has already been parsed, and continues parsing until an "-----END PGP SIGNATURE-----" is found, followed by "push-cert-end".

      Parameters:
      pckIn - where we read the signature from.
      Throws:
      IOException - if the signature is invalid.
      Since:
      4.0
    • receiveSignature

      private void receiveSignature(PushCertificateParser.StringReader reader) throws IOException
      Throws:
      IOException
    • addCommand

      public void addCommand(ReceiveCommand cmd)
      Add a command to the signature.
      Parameters:
      cmd - the command.
      Since:
      4.1
    • addCommand

      public void addCommand(String line) throws PackProtocolException
      Add a command to the signature.
      Parameters:
      line - the line read from the wire that produced this command, with optional trailing newline already trimmed.
      Throws:
      PackProtocolException - if the raw line cannot be parsed to a command.
      Since:
      4.0