Bug 559106 - org.eclipse.jgit.hooks.GitHook uses org.bouncycastle.util.io.TeeOutputStream
Summary: org.eclipse.jgit.hooks.GitHook uses org.bouncycastle.util.io.TeeOutputStream
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.6   Edit
Hardware: PC Windows 10
: P3 major (vote)
Target Milestone: 5.7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-13 07:07 EST by kurt ablinger CLA
Modified: 2020-06-05 18:49 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kurt ablinger CLA 2020-01-13 07:07:34 EST
With version 5.6 of jGit we now get the error

java.lang.NoClassDefFoundError: org/bouncycastle/util/io/TeeOutputStream
	at org.eclipse.jgit.hooks.Hooks.prePush(Hooks.java:183)
...
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.util.io.TeeOutputStream


The problem is caused by the change in the doRun-method of GitHook.


Version 5.5 worked well.
We are using your jgit in a standalone-app - inside eclipse-ide it works fine.
Would be nice if you did not need extra dependencies.
Comment 1 Matthias Sohn CLA 2020-01-13 07:35:43 EST
org.eclipse.jgit:org.eclipse.jgit depends on Bouncycastle libraries since 5.3.0 when support for signed commits was introduced [1]. Feel free to contribute an alternative implementation of a TeeOutputStream which doesn't introduce another dependency.

[1] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/137e91a4654b4f516d1f82885c669e14473dbfd6
Comment 2 kurt ablinger CLA 2020-01-13 08:17:27 EST
... up to now this dependency did not hit us.

Maybe it will in future - depending on your policy - so I will have to update our apps classpath (or replace our dependency on jgit).

For me it's ok to close this 'bug'.


Anyway - here's a simple teeoutputstream - feel free to use it:

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

public class TeeOutputStream
  extends OutputStream {

  private final OutputStream[] osa;

  public TeeOutputStream(final OutputStream... streams) {
    super();
    osa = Arrays.copyOf(streams, streams.length);
  }

  @Override
  public void write(final int b) throws IOException {
    for (final OutputStream os : osa)
      os.write(b);
  }

  @Override
  public void write(final byte[] b) throws IOException {
    for (final OutputStream os : osa)
      os.write(b);
  }

  @Override
  public void write(final byte[] b, final int off, final int len)
    throws IOException {
    for (final OutputStream os : osa)
      os.write(b, off, len);
  }

  @Override
  public void flush() throws IOException {
    for (final OutputStream os : osa)
      os.flush();
  }

  @Override
  public void close() throws IOException {
    for (final OutputStream os : osa)
      os.close();
  }
}
Comment 3 kurt ablinger CLA 2020-01-13 09:10:37 EST
I just scanned the core-jgit-sources for 'bouncycastle':

Looks like there is only one other class that uses such a package (outside the jgit-bouncycastle-classes): WalkEncryption.

And there it's only one class in use:

  org.bouncycastle.util.encoders.Hex

Maybe with a little more re-thinking you could 'hide' this dependency (at least in the core-jar).

Here my search-results for bouncycastle:

.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\transport\WalkEncryption.java
  70: import org.bouncycastle.util.encoders.Hex;
.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\hooks\GitHook.java
  53: import org.bouncycastle.util.io.TeeOutputStream;
.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\lib\internal\BouncyCastleGpgKeyPassphrasePrompt.java
  49: import org.bouncycastle.openpgp.PGPException;
  50: import org.bouncycastle.util.encoders.Hex;
.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\lib\internal\BouncyCastleGpgKey.java
  47: import org.bouncycastle.openpgp.PGPSecretKey;
.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\lib\internal\BouncyCastleGpgSigner.java
  52: import org.bouncycastle.bcpg.ArmoredOutputStream;
  53: import org.bouncycastle.bcpg.BCPGOutputStream;
  54: import org.bouncycastle.bcpg.HashAlgorithmTags;
  55: import org.bouncycastle.jce.provider.BouncyCastleProvider;
  56: import org.bouncycastle.openpgp.PGPException;
  57: import org.bouncycastle.openpgp.PGPPrivateKey;
  58: import org.bouncycastle.openpgp.PGPSecretKey;
  59: import org.bouncycastle.openpgp.PGPSignature;
  60: import org.bouncycastle.openpgp.PGPSignatureGenerator;
  61: import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
  62: import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
.\org.eclipse.jgit.source_5.6.0.201912101111-r.jar ! org\eclipse\jgit\lib\internal\BouncyCastleGpgKeyLocator.java
  66: import org.bouncycastle.gpg.SExprParser;
  67: import org.bouncycastle.gpg.keybox.BlobType;
  68: import org.bouncycastle.gpg.keybox.KeyBlob;
  69: import org.bouncycastle.gpg.keybox.KeyBox;
  70: import org.bouncycastle.gpg.keybox.KeyInformation;
  71: import org.bouncycastle.gpg.keybox.PublicKeyRingBlob;
  72: import org.bouncycastle.gpg.keybox.UserID;
  73: import org.bouncycastle.gpg.keybox.jcajce.JcaKeyBoxBuilder;
  74: import org.bouncycastle.openpgp.PGPException;
  75: import org.bouncycastle.openpgp.PGPKeyFlags;
  76: import org.bouncycastle.openpgp.PGPPublicKey;
  77: import org.bouncycastle.openpgp.PGPPublicKeyRing;
  78: import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
  79: import org.bouncycastle.openpgp.PGPSecretKey;
  80: import org.bouncycastle.openpgp.PGPSecretKeyRing;
  81: import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
  82: import org.bouncycastle.openpgp.PGPSignature;
  83: import org.bouncycastle.openpgp.PGPUtil;
  84: import org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory;
  85: import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
  86: import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
  87: import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
  88: import org.bouncycastle.openpgp.operator.jcajce.JcePBEProtectionRemoverFactory;
  89: import org.bouncycastle.util.encoders.Hex;
Comment 4 Michael D CLA 2020-01-20 02:40:21 EST
My change addresses this

https://git.eclipse.org/r/156153
Comment 5 Eclipse Genie CLA 2020-02-13 20:09:13 EST
New Gerrit change created: https://git.eclipse.org/r/157680
Comment 6 Eclipse Genie CLA 2020-02-21 18:30:38 EST
Gerrit change https://git.eclipse.org/r/157680 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=40555223594005481cba95d09b32c4f6bb5dcff3
Comment 7 Eclipse Genie CLA 2020-04-27 06:04:54 EDT
New Gerrit change created: https://git.eclipse.org/r/161560
Comment 8 Eclipse Genie CLA 2020-05-22 11:40:37 EDT
New Gerrit change created: https://git.eclipse.org/r/163440
Comment 9 Eclipse Genie CLA 2020-05-23 11:35:28 EDT
New Gerrit change created: https://git.eclipse.org/r/163464
Comment 10 Eclipse Genie CLA 2020-05-24 05:02:34 EDT
Gerrit change https://git.eclipse.org/r/163464 was merged to [master].
Commit: http://git.eclipse.org/c/egit/egit.git/commit/?id=9fb4acae133b95670b931928f0580f420dfb0bf6
Comment 11 Eclipse Genie CLA 2020-06-01 18:36:36 EDT
Gerrit change https://git.eclipse.org/r/161560 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=77848d635b76d8294697ffaf11acf51256df2a5b
Comment 12 Eclipse Genie CLA 2020-06-05 16:57:06 EDT
Gerrit change https://git.eclipse.org/r/163440 was merged to [master].
Commit: http://git.eclipse.org/c/egit/egit.git/commit/?id=43622bdf29aa1db663d5812583f80ab76fce4c26