]> source.dussan.org Git - jgit.git/commitdiff
PushCertificateParser: Make pushee optional 08/51208/9
authorDave Borowitz <dborowitz@google.com>
Wed, 1 Jul 2015 18:44:09 +0000 (11:44 -0700)
committerDave Borowitz <dborowitz@google.com>
Thu, 9 Jul 2015 18:05:45 +0000 (11:05 -0700)
When pushing to an HTTP server using the C git client, I observed a
certificate lacking a pushee field. Handle this gracefully in the
parser.

Change-Id: I7f3c5fa78f2e35172a93180036e679687415cac4

org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateParser.java

index 26b4d88f5fde091e2e0daf6f4c20a42ee3f3fbaa..3a4b00d87642c7e4463b6b9955abf959b979dfab 100644 (file)
@@ -334,6 +334,26 @@ public class PushCertificateParserTest {
                assertNull(PushCertificateParser.fromReader(reader));
        }
 
+       @Test
+       public void testMissingPusheeField() throws Exception {
+               // Omit pushee line from existing cert. (This means the signature would not
+               // match, but we're not verifying it here.)
+               String input = INPUT.replace("0024pushee git://localhost/repo.git\n", "");
+               assertFalse(input.contains(PushCertificateParser.PUSHEE));
+
+               PacketLineIn pckIn = newPacketLineIn(input);
+               PushCertificateParser parser =
+                               new PushCertificateParser(db, newEnabledConfig());
+               parser.receiveHeader(pckIn, false);
+               parser.addCommand(pckIn.readString());
+               assertEquals(PushCertificateParser.BEGIN_SIGNATURE, pckIn.readString());
+               parser.receiveSignature(pckIn);
+
+               PushCertificate cert = parser.build();
+               assertEquals("0.1", cert.getVersion());
+               assertNull(cert.getPushee());
+       }
+
        private static String concatPacketLines(String input, int begin, int end)
                        throws IOException {
                StringBuilder result = new StringBuilder();
index fdc70adc888157eece3e32dbf462495c8f38508d..165a93908d20c633bc9d5c48979ff1b7db728403 100644 (file)
@@ -98,10 +98,6 @@ public class PushCertificate {
                        throw new IllegalArgumentException(MessageFormat.format(
                                        JGitText.get().pushCertificateInvalidField, PUSHER));
                }
-               if (pushee == null || pushee.isEmpty()) {
-                       throw new IllegalArgumentException(MessageFormat.format(
-                                       JGitText.get().pushCertificateInvalidField, PUSHEE));
-               }
                if (nonce == null || nonce.isEmpty()) {
                        throw new IllegalArgumentException(MessageFormat.format(
                                        JGitText.get().pushCertificateInvalidField, NONCE));
index 1bc73bb3ed26abfc255e17d71e0fa86c43c8464d..6494aea63ec6f80a0067b3175f4fcd80f3debc20 100644 (file)
@@ -273,7 +273,11 @@ public class PushCertificateParser {
 
        private static String parseHeader(StringReader reader, String header)
                        throws IOException {
-               String s = reader.read();
+               return parseHeader(reader.read(), header);
+       }
+
+       private static String parseHeader(String s, String header)
+                       throws IOException {
                if (s.isEmpty()) {
                        throw new EOFException();
                }
@@ -331,8 +335,13 @@ public class PushCertificateParser {
                                                JGitText.get().pushCertificateInvalidFieldValue,
                                                PUSHER, rawPusher));
                        }
-                       pushee = parseHeader(reader, PUSHEE);
-                       receivedNonce = parseHeader(reader, NONCE);
+                       String next = reader.read();
+                       if (next.startsWith(PUSHEE)) {
+                               pushee = parseHeader(next, PUSHEE);
+                               receivedNonce = parseHeader(reader, NONCE);
+                       } else {
+                               receivedNonce = parseHeader(next, NONCE);
+                       }
                        nonceStatus = nonceGenerator != null
                                        ? nonceGenerator.verify(
                                                receivedNonce, sentNonce(), db, stateless, nonceSlopLimit)