Class PushCertificateParser


  • public class PushCertificateParser
    extends Object
    Parser for signed push certificates.
    Since:
    4.0
    • Constructor Detail

      • 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
    • Method Detail

      • 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
      • 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
      • 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
      • 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
      • 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